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.ecs.StringElement;
60 import org.apache.turbine.util.RunData;
61 import org.apache.turbine.util.StringUtils;
62 import org.apache.turbine.services.webmacro.TurbineWebMacro;
63 import org.apache.turbine.services.webmacro.WebMacroService;
64 import org.apache.turbine.services.resources.TurbineResources;
65
66 // WebMacro Stuff
67 import org.webmacro.servlet.WebContext;
68
69
70 /***
71 * Base WebMacro Screen. This screen relies on the WebMacroSitePage
72 * being set as the default page. This screen can be called directly
73 * to generate a WebMacro Screen. The buildTemplate() assumes the
74 * template parameter has been set in the RunData object (a default
75 * template is specified in the WebMacroSitePage). This provides the
76 * ability to execute several templates from one Screen.
77 *
78 * <p>
79 *
80 * If you need more specific behavior in your application, extend this
81 * class and override the doBuildTemplate() method.
82 *
83 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
84 * @version $Id: WebMacroSiteScreen.java,v 1.1.1.1 2001/08/16 05:08:38 jvanzyl Exp $
85 * @deprecated you should use velocity
86 */
87 public class WebMacroSiteScreen extends TemplateScreen
88 {
89 /***
90 * WebMacro Screens extending this class should overide this
91 * method to perform any particular business logic and add
92 * information to the context.
93 *
94 * @param data Turbine information.
95 * @param context Context for web pages.
96 * @exception Exception, a generic exception.
97 */
98 protected void doBuildTemplate( RunData data, WebContext context )
99 throws Exception
100 {
101 }
102
103 /***
104 * Needs to be implemented to make TemplateScreen like us. The
105 * actual method that you should override is the one with the
106 * context in the parameter list.
107 *
108 * @param data Turbine information.
109 * @exception Exception, a generic exception.
110 */
111 protected void doBuildTemplate( RunData data )
112 throws Exception
113 {
114 doBuildTemplate(data, getContext(data));
115 }
116
117 /***
118 * This builds the WebMacro template.
119 *
120 * @param data Turbine information.
121 * @return A ConcreteElement.
122 * @exception Exception, a generic exception.
123 */
124 public ConcreteElement buildTemplate( RunData data ) throws Exception
125 {
126 WebContext context = getContext(data);
127
128 // This will already be properly set and will not be null
129 // because of WebMacroSitePage.
130 String templateName = data.getTemplateInfo().getScreenTemplate();
131
132 // Template service adds the leading slash, but make it sure.
133 if ((templateName.length() > 0) &&
134 (templateName.charAt(0) != '/'))
135 {
136 templateName = '/' + templateName;
137 }
138
139 StringElement output = new StringElement();
140 output.setFilterState(false);
141
142 String screenData = null;
143 try
144 {
145 screenData = buildWMTemplate(context, "screens" + templateName);
146 }
147 catch (Exception e)
148 {
149 // If there is an error, build a $processingException and
150 // attempt to call the error.wm template in the screens
151 // directory.
152 context.put( "processingException", e.toString() );
153 context.put( "stackTrace", StringUtils.stackTrace(e) );
154 templateName = TurbineResources.getString(
155 "template.error", "/error.wm");
156 if ((templateName.length() > 0) &&
157 (templateName.charAt(0) != '/'))
158 {
159 templateName = '/' + templateName;
160 }
161 screenData = buildWMTemplate(
162 context, "screens" + templateName);
163 }
164 output.addElement(screenData);
165 return output;
166 }
167
168
169 /***
170 * Return the WebContext needed by WebMacro.
171 *
172 * @param data Turbine information.
173 * @return A WebContext.
174 */
175 public static WebContext getContext(RunData data)
176 {
177 // Attempt to get it from the session first. If it doesn't
178 // exist, create it and then stuff it into the session.
179 WebContext wc = (WebContext)data.getTemplateInfo().getTemplateContext(
180 WebMacroService.WEBMACRO_CONTEXT);
181 if (wc == null)
182 {
183 wc = TurbineWebMacro.getContext(data);
184 data.getTemplateInfo().setTemplateContext(
185 WebMacroService.WEBMACRO_CONTEXT, wc);
186 }
187 return wc;
188 }
189
190 /***
191 * TurbineWebMacro.handleRequest(context,templateFile) the template.
192 * This will return a string containing the processed template file.
193 *
194 * @param context Context for web apps.
195 * @param templateFile Name of template file.
196 * @return A String with the processed template file.
197 * @exception Exception, a generic exception.
198 */
199 protected String buildWMTemplate(WebContext context,
200 String templateFile)
201 throws Exception
202 {
203 return TurbineWebMacro.handleRequest(context,templateFile);
204 }
205 }
This page was automatically generated by Maven