01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.web.servlet.view;
18:
19: /**
20: * Convenient subclass of {@link UrlBasedViewResolver} that supports
21: * {@link InternalResourceView} (i.e. Servlets and JSPs) and subclasses
22: * such as {@link JstlView} and
23: * {@link org.springframework.web.servlet.view.tiles.TilesView}.
24: *
25: * <p>The view class for all views generated by this resolver can be specified
26: * via {@link #setViewClass}. See UrlBasedViewResolver's javadoc for details.
27: *
28: * <p>BTW, it's good practice to put JSP files that just serve as views under
29: * WEB-INF, to hide them from direct access (e.g. via a manually entered URL).
30: * Only controllers will be able to access them then.
31: *
32: * <p><b>Note:</b> When chaining ViewResolvers, an InternalResourceViewResolver
33: * always needs to be last, as it will attempt to resolve any view name,
34: * no matter whether the underlying resource actually exists.
35: *
36: * @author Juergen Hoeller
37: * @since 17.02.2003
38: * @see #setViewClass
39: * @see #setPrefix
40: * @see #setSuffix
41: * @see #setRequestContextAttribute
42: * @see InternalResourceView
43: * @see JstlView
44: * @see org.springframework.web.servlet.view.tiles.TilesView
45: */
46: public class InternalResourceViewResolver extends UrlBasedViewResolver {
47:
48: private boolean alwaysInclude = false;
49:
50: /**
51: * Sets default viewClass to <code>requiredViewClass</code>.
52: * @see #setViewClass
53: * @see #requiredViewClass
54: */
55: public InternalResourceViewResolver() {
56: setViewClass(requiredViewClass());
57: }
58:
59: /**
60: * Requires InternalResourceView.
61: * @see InternalResourceView
62: */
63: protected Class requiredViewClass() {
64: return InternalResourceView.class;
65: }
66:
67: /**
68: * Specify whether to always include the view rather than forward to it.
69: * <p>Default is "false". Switch this flag on to enforce the use of a
70: * Servlet include, even if a forward would be possible.
71: * @see InternalResourceView#setAlwaysInclude
72: */
73: public void setAlwaysInclude(boolean alwaysInclude) {
74: this .alwaysInclude = alwaysInclude;
75: }
76:
77: protected AbstractUrlBasedView buildView(String viewName)
78: throws Exception {
79: InternalResourceView view = (InternalResourceView) super
80: .buildView(viewName);
81: view.setAlwaysInclude(this.alwaysInclude);
82: return view;
83: }
84:
85: }
|