/** * Copyright 2005-2010 hdiv.org * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.hdiv.web.servlet.view; import java.util.Locale; import org.springframework.web.servlet.View; import org.springframework.web.servlet.view.InternalResourceView; import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView; import org.springframework.web.servlet.view.UrlBasedViewResolver; /** * Convenient subclass of {@link UrlBasedViewResolver} that supports * {@link InternalResourceView} (i.e. Servlets and JSPs) and subclasses * such as {@link JstlView} * * <p>The view class for all views generated by this resolver can be specified * via {@link #setViewClass}. See {@link UrlBasedViewResolver}'s javadoc for details. * The default is {@link InternalResourceView}, or {@link JstlView} if the * JSTL API is present. * * <p>BTW, it's good practice to put JSP files that just serve as views under * WEB-INF, to hide them from direct access (e.g. via a manually entered URL). * Only controllers will be able to access them then. * * <p><b>Note:</b> When chaining ViewResolvers, an InternalResourceViewResolver * always needs to be last, as it will attempt to resolve any view name, * no matter whether the underlying resource actually exists. * * @author Gorka Vicente * @since HDIV 2.0.6 * @see #setViewClass * @see #setPrefix * @see #setSuffix * @see #setRequestContextAttribute * @see InternalResourceView * @see JstlView */ public class InternalResourceViewResolverHDIV extends InternalResourceViewResolver { /** * Overridden to implement check for "redirect:" prefix. * <p>Not possible in <code>loadView</code>, since overridden * <code>loadView</code> versions in subclasses might rely on the * superclass always creating instances of the required view class. * @see #loadView * @see #requiredViewClass */ @Override protected View createView(String viewName, Locale locale) throws Exception { // If this resolver is not supposed to handle the given view, // return null to pass on to the next resolver in the chain. if (!canHandle(viewName, locale)) { return null; } // Check for special "redirect:" prefix. if (viewName.startsWith(REDIRECT_URL_PREFIX)) { String redirectUrl = viewName.substring(REDIRECT_URL_PREFIX.length()); return new RedirectViewHDIV(redirectUrl, isRedirectContextRelative(), isRedirectHttp10Compatible()); } // Check for special "forward:" prefix. if (viewName.startsWith(FORWARD_URL_PREFIX)) { String forwardUrl = viewName.substring(FORWARD_URL_PREFIX.length()); return new InternalResourceView(forwardUrl); } // Else fall back to superclass implementation: calling loadView. return super.createView(viewName, locale); } }