KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > view > velocity > VelocityLayoutViewResolver


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.velocity;
18
19 import org.springframework.web.servlet.view.AbstractUrlBasedView;
20
21 /**
22  * Convenience subclass of VelocityViewResolver, adding support
23  * for VelocityLayoutView and its properties.
24  *
25  * <p>See VelocityViewResolver's javadoc for general usage info.
26  *
27  * @author Juergen Hoeller
28  * @since 1.2.7
29  * @see VelocityViewResolver
30  * @see VelocityLayoutView
31  * @see #setLayoutUrl
32  * @see #setLayoutKey
33  * @see #setScreenContentKey
34  */

35 public class VelocityLayoutViewResolver extends VelocityViewResolver {
36
37     private String JavaDoc layoutUrl;
38
39     private String JavaDoc layoutKey;
40
41     private String JavaDoc screenContentKey;
42
43
44     /**
45      * Requires VelocityLayoutView.
46      * @see VelocityLayoutView
47      */

48     protected Class JavaDoc requiredViewClass() {
49         return VelocityLayoutView.class;
50     }
51
52     /**
53      * Set the layout template to use. Default is "layout.vm".
54      * @param layoutUrl the template location (relative to the template
55      * root directory)
56      * @see VelocityLayoutView#setLayoutUrl
57      */

58     public void setLayoutUrl(String JavaDoc layoutUrl) {
59         this.layoutUrl = layoutUrl;
60     }
61
62     /**
63      * Set the context key used to specify an alternate layout to be used instead
64      * of the default layout. Screen content templates can override the layout
65      * template that they wish to be wrapped with by setting this value in the
66      * template, for example:<br>
67      * <code>#set( $layout = "MyLayout.vm" )</code>
68      * <p>The default key is "layout", as illustrated above.
69      * @param layoutKey the name of the key you wish to use in your
70      * screen content templates to override the layout template
71      * @see VelocityLayoutView#setLayoutKey
72      */

73     public void setLayoutKey(String JavaDoc layoutKey) {
74         this.layoutKey = layoutKey;
75     }
76
77     /**
78      * Set the name of the context key that will hold the content of
79      * the screen within the layout template. This key must be present
80      * in the layout template for the current screen to be rendered.
81      * <p>Default is "screen_content": accessed in VTL as
82      * <code>$screen_content</code>.
83      * @param screenContentKey the name of the screen content key to use
84      * @see VelocityLayoutView#setScreenContentKey
85      */

86     public void setScreenContentKey(String JavaDoc screenContentKey) {
87         this.screenContentKey = screenContentKey;
88     }
89
90
91     protected AbstractUrlBasedView buildView(String JavaDoc viewName) throws Exception JavaDoc {
92         VelocityLayoutView view = (VelocityLayoutView) super.buildView(viewName);
93         // Use not-null checks to preserve VelocityLayoutView's defaults.
94
if (this.layoutUrl != null) {
95             view.setLayoutUrl(this.layoutUrl);
96         }
97         if (this.layoutKey != null) {
98             view.setLayoutKey(this.layoutKey);
99         }
100         if (this.screenContentKey != null) {
101             view.setScreenContentKey(this.screenContentKey);
102         }
103         return view;
104     }
105
106 }
107
Popular Tags