KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2002-2005 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  * Abstract base class for template view resolvers like
21  * VelocityViewResolver and FreeMarkerViewResolver.
22  *
23  * <p>Provides a convenient way to specify AbstractTemplateView's
24  * exposure flags for request attributes, session attributes,
25  * and Spring's macro helpers.
26  *
27  * @author Juergen Hoeller
28  * @since 1.1
29  * @see AbstractTemplateView
30  * @see org.springframework.web.servlet.view.velocity.VelocityViewResolver
31  * @see org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver
32  */

33 public class AbstractTemplateViewResolver extends UrlBasedViewResolver {
34
35     private boolean exposeRequestAttributes = false;
36
37     private boolean exposeSessionAttributes = false;
38
39     private boolean exposeSpringMacroHelpers = false;
40
41     private boolean allowRequestOverride = false;
42
43     private boolean allowSessionOverride = false;
44
45
46     protected Class JavaDoc requiredViewClass() {
47         return AbstractTemplateView.class;
48     }
49
50     /**
51      * Set whether all request attributes should be added to the
52      * model prior to merging with the template. Default is "false".
53      * @see AbstractTemplateView#setExposeRequestAttributes
54      */

55     public void setExposeRequestAttributes(boolean exposeRequestAttributes) {
56         this.exposeRequestAttributes = exposeRequestAttributes;
57     }
58
59     /**
60      * Set whether all HttpSession attributes should be added to the
61      * model prior to merging with the template. Default is "false".
62      * @see AbstractTemplateView#setExposeSessionAttributes
63      */

64     public void setExposeSessionAttributes(boolean exposeSessionAttributes) {
65         this.exposeSessionAttributes = exposeSessionAttributes;
66     }
67
68     /**
69      * Set whether to expose a RequestContext for use by Spring's macro library,
70      * under the name "springBindRequestContext". Default is "false".
71      * @see AbstractTemplateView#setExposeSpringMacroHelpers
72      */

73     public void setExposeSpringMacroHelpers(boolean exposeSpringMacroHelpers) {
74         this.exposeSpringMacroHelpers = exposeSpringMacroHelpers;
75     }
76
77     /**
78      * Set whether HttpServletRequest attributes are allowed to override (hide)
79      * controller generated model attributes of the same name. Default is "false",
80      * which causes an exception to be thrown if request attributes of the same
81      * name as model attributes are found.
82      * @see AbstractTemplateView#setAllowRequestOverride
83      */

84     public void setAllowRequestOverride(boolean allowRequestOverride) {
85         this.allowRequestOverride = allowRequestOverride;
86     }
87
88     /**
89      * Set whether HttpSession attributes are allowed to override (hide)
90      * controller generated model attributes of the same name. Default is "false",
91      * which causes an exception to be thrown if session attributes of the same
92      * name as model attributes are found.
93      * @see AbstractTemplateView#setAllowSessionOverride
94      */

95     public void setAllowSessionOverride(boolean allowSessionOverride) {
96         this.allowSessionOverride = allowSessionOverride;
97     }
98
99
100     protected AbstractUrlBasedView buildView(String JavaDoc viewName) throws Exception JavaDoc {
101         AbstractTemplateView view = (AbstractTemplateView) super.buildView(viewName);
102         view.setExposeRequestAttributes(this.exposeRequestAttributes);
103         view.setExposeSessionAttributes(this.exposeSessionAttributes);
104         view.setExposeSpringMacroHelpers(this.exposeSpringMacroHelpers);
105         view.setAllowRequestOverride(this.allowRequestOverride);
106         view.setAllowSessionOverride(this.allowSessionOverride);
107         return view;
108     }
109
110 }
111
Popular Tags