KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > view > InternalResourceViewResolver


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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     /**
52      * Sets default viewClass to <code>requiredViewClass</code>.
53      * @see #setViewClass
54      * @see #requiredViewClass
55      */

56     public InternalResourceViewResolver() {
57         setViewClass(requiredViewClass());
58     }
59
60     /**
61      * Requires InternalResourceView.
62      * @see InternalResourceView
63      */

64     protected Class JavaDoc requiredViewClass() {
65         return InternalResourceView.class;
66     }
67
68     /**
69      * Specify whether to always include the view rather than forward to it.
70      * <p>Default is "false". Switch this flag on to enforce the use of a
71      * Servlet include, even if a forward would be possible.
72      * @see InternalResourceView#setAlwaysInclude
73      */

74     public void setAlwaysInclude(boolean alwaysInclude) {
75         this.alwaysInclude = alwaysInclude;
76     }
77
78
79     protected AbstractUrlBasedView buildView(String JavaDoc viewName) throws Exception JavaDoc {
80         InternalResourceView view = (InternalResourceView) super.buildView(viewName);
81         view.setAlwaysInclude(this.alwaysInclude);
82         return view;
83     }
84
85 }
86
Popular Tags