1 package org.apache.turbine.modules.screens;
2
3 /* ====================================================================
4 * The Apache Software License, Version 1.1
5 *
6 * Copyright (c) 2001 The Apache Software Foundation. All rights
7 * reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. The end-user documentation included with the redistribution,
22 * if any, must include the following acknowledgment:
23 * "This product includes software developed by the
24 * Apache Software Foundation (http://www.apache.org/)."
25 * Alternately, this acknowledgment may appear in the software itself,
26 * if and wherever such third-party acknowledgments normally appear.
27 *
28 * 4. The names "Apache" and "Apache Software Foundation" and
29 * "Apache Turbine" must not be used to endorse or promote products
30 * derived from this software without prior written permission. For
31 * written permission, please contact apache@apache.org.
32 *
33 * 5. Products derived from this software may not be called "Apache",
34 * "Apache Turbine", nor may "Apache" appear in their name, without
35 * prior written permission of the Apache Software Foundation.
36 *
37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This software consists of voluntary contributions made by many
52 * individuals on behalf of the Apache Software Foundation. For more
53 * information on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57 // Turbine/ECS Imports
58 import org.apache.ecs.ConcreteElement;
59 import org.apache.turbine.modules.Screen;
60 import org.apache.turbine.modules.ScreenLoader;
61 import org.apache.turbine.util.RunData;
62 import org.apache.turbine.services.template.TurbineTemplate;
63
64
65 /***
66 * Template Screen.
67 *
68 * Base Template Screens should extend this class and override the
69 * buildTemplate() method. Users of the particular service can then
70 * override the doBuildTemplate() for any specific pre-processing.
71 * You can also override the doBuild() method in order to add extra
72 * functionality to your system, but you need to make sure to at least
73 * duplicate the existing functionality in order for things to work.
74 * Look at the code for the doBuild() method to get an idea of what is
75 * going on there (it is quite simple really).
76 *
77 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
78 * @version $Id: TemplateScreen.java,v 1.1.1.1 2001/08/16 05:08:36 jvanzyl Exp $
79 */
80 public abstract class TemplateScreen extends Screen
81 {
82 /***
83 * This method should be overidden by subclasses that wish to add
84 * specific business logic.
85 *
86 * @param data Turbine information.
87 * @exception Exception, a generic exception.
88 */
89 protected abstract void doBuildTemplate( RunData data )
90 throws Exception;
91
92 /***
93 * This method should be implemented by Base template classes. It
94 * should contain the specific template service code to generate
95 * the template.
96 *
97 * @param data Turbine information.
98 * @return A ConcreteElement.
99 * @exception Exception, a generic exception.
100 */
101 public abstract ConcreteElement buildTemplate( RunData data )
102 throws Exception;
103
104 /***
105 * This method can be overridden to write code that executes when
106 * the template has been built (called from a finally clause, so
107 * executes regardless of whether an exception is thrown or not)
108 */
109 protected void doPostBuildTemplate( RunData data )
110 {
111 // empty
112 }
113
114 /***
115 * This method is called by the Screenloader to construct the
116 * Screen.
117 *
118 * @param data Turbine information.
119 * @return A ConcreteElement.
120 * @exception Exception, a generic exception.
121 */
122 protected ConcreteElement doBuild( RunData data )
123 throws Exception
124 {
125 ConcreteElement out = null;
126
127 try
128 {
129 doBuildTemplate(data);
130 out = buildTemplate(data);
131 }
132 finally
133 {
134 doPostBuildTemplate(data);
135 }
136
137 return out;
138 }
139
140 /***
141 * This method is used when you want to short circuit a Screen and
142 * change the template that will be executed next. <b>Note that the current
143 * context will be applied to the next template that is executed.
144 * If you want to have the context executed for the next screen,
145 * to be the same one as the next screen, then you should use the
146 * TemplateScreen.doRedirect() method.</b>
147 *
148 * @param data Turbine information.
149 * @param template The name of the next template.
150 */
151 public static void setTemplate(RunData data, String template)
152 {
153 data.getTemplateInfo().setScreenTemplate(template);
154 try
155 {
156 // We have do call getScreenTemplate because of the path
157 // separator.
158 data.getTemplateInfo().setLayoutTemplate(
159 TurbineTemplate.getLayoutTemplateName(
160 data.getTemplateInfo().getScreenTemplate()));
161 }
162 catch( Exception e )
163 {
164 // Nothing to do.
165 }
166 }
167
168 /***
169 * You can call this within a Screen to cause an internal redirect
170 * to happen. It essentially allows you to stop execution in one
171 * Screen and instantly execute another Screen. Don't worry, this
172 * does not do a HTTP redirect and also if you have anything added
173 * in the Context, it will get carried over.
174 *
175 * <p>
176 *
177 * This class is useful if you have a Screen that submits to
178 * another Screen and you want it to do error validation before
179 * executing the other Screen. If there is an error, you can
180 * doRedirect() back to the original Screen.
181 *
182 * @param data Turbine information.
183 * @param screen Name of screen to redirect to.
184 * @param template Name of template.
185 * @exception Exception, a generic exception.
186 */
187 public void doRedirect(RunData data, String screen, String template )
188 throws Exception
189 {
190 setTemplate(data, template);
191 ScreenLoader.getInstance().exec(data,screen);
192 }
193
194 /***
195 * You can call this within a Screen to cause an internal redirect
196 * to happen. It essentially allows you to stop execution in one
197 * Screen and instantly execute another Screen. Don't worry, this
198 * does not do a HTTP redirect and also if you have anything added
199 * in the Context, it will get carried over.
200 *
201 * <p>
202 *
203 * This class is useful if you have a Screen that submits to
204 * another Screen and you want it to do error validation before
205 * executing the other Screen. If there is an error, you can
206 * doRedirect() back to the original Screen.
207 *
208 * @param data Turbine information.
209 * @param template Name of template.
210 * @exception Exception, a generic exception.
211 */
212 public void doRedirect(RunData data, String template)
213 throws Exception
214 {
215 doRedirect (data, TurbineTemplate.getScreenName(template), template );
216 }
217 }
This page was automatically generated by Maven