1 package org.apache.turbine.modules.layouts;
2
3 /*
4 * Copyright (c) 1997-1999 The Java Apache Project. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * 3. All advertising materials mentioning features or use of this
19 * software must display the following acknowledgment:
20 * "This product includes software developed by the Java Apache
21 * Project for use in the Apache JServ servlet engine project
22 * <http://java.apache.org/>."
23 *
24 * 4. The names "Apache JServ", "Apache JServ Servlet Engine", "Turbine",
25 * "Apache Turbine", "Turbine Project", "Apache Turbine Project" and
26 * "Java Apache Project" must not be used to endorse or promote products
27 * derived from this software without prior written permission.
28 *
29 * 5. Products derived from this software may not be called "Apache JServ"
30 * nor may "Apache" nor "Apache JServ" appear in their names without
31 * prior written permission of the Java Apache Project.
32 *
33 * 6. Redistributions of any form whatsoever must retain the following
34 * acknowledgment:
35 * "This product includes software developed by the Java Apache
36 * Project for use in the Apache JServ servlet engine project
37 * <http://java.apache.org/>."
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JAVA APACHE PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 *
52 * This software consists of voluntary contributions made by many
53 * individuals on behalf of the Java Apache Group. For more information
54 * on the Java Apache Project and the Apache JServ Servlet Engine project,
55 * please see <http://java.apache.org/>.
56 *
57 */
58
59 // JDK Imports
60 import java.io.StringReader;
61
62 // Turbine/Village/ECS Imports
63 import org.apache.ecs.ConcreteElement;
64 import org.apache.turbine.modules.Layout;
65 import org.apache.turbine.modules.ScreenLoader;
66 import org.apache.turbine.util.RunData;
67 import org.apache.turbine.util.template.TemplateNavigation;
68 import org.apache.turbine.services.velocity.TurbineVelocity;
69 import org.apache.turbine.services.xslt.TurbineXSLT;
70
71 // Velocity Stuff
72 import org.apache.velocity.context.Context;
73
74 /*
75 * This Layout module allows Velocity XML templates to be used as layouts.
76 * <br><br>
77 * Once the (XML) screen and navigation templates have been inserted into
78 * the layout template the result is transformed with a XSL stylesheet.
79 * The stylesheet (with the same name than the screen template) is loaded
80 * and executed by the XSLT service, so it is important that you correctly
81 * set up your XSLT service. If the named stylsheet does not exist the
82 * default.xsl stylesheet is executed. If default.xsl does not exist
83 * the XML is merely echoed.
84 * <br><br>
85 * Since dynamic content is supposed to be primarily
86 * located in screens and navigations there should be relatively few reasons
87 * to subclass this Layout.
88 *
89 * @author <a href="mailto:leon@opticode.co.za">Leon Messerschmidt</a>
90 */
91 public class VelocityXslLayout extends Layout
92 {
93 /***
94 * Method called by LayoutLoader.
95 *
96 * @param RunData
97 * @return processed template in a String
98 */
99 public void doBuild( RunData data ) throws Exception
100 {
101 long start = System.currentTimeMillis();
102
103 data.getResponse().setContentType ("text/html");
104 Context context = TurbineVelocity.getContext( data );
105 String returnValue = "";
106
107 /*
108 * First, generate the screen and put it in the context so
109 * we can grab it the layout template.
110 */
111
112 ConcreteElement results = ScreenLoader.getInstance()
113 .eval(data, data.getScreen());
114
115 if (results != null)
116 {
117 returnValue = results.toString();
118 }
119
120 /*
121 * variable for the screen in the layout template
122 */
123 context.put("screen_placeholder", returnValue);
124
125 /*
126 * variable to reference the navigation screen in
127 * the layout template
128 */
129 context.put("navigation", new TemplateNavigation( data ));
130
131 /*
132 * Grab the layout template set in the WebMacroSitePage.
133 * If null, then use the default layout template
134 * (done by the TemplateInfo object)
135 */
136 String templateName = data.getTemplateInfo().getLayoutTemplate();
137
138 /*
139 * Now, generate the layout template.
140 */
141 String temp = TurbineVelocity.handleRequest(context,
142 "layouts" + templateName);
143
144 /*
145 * Finally we do a transformation and send the result
146 * back to the browser
147 */
148 TurbineXSLT.transform (data.getTemplateInfo().getScreenTemplate(),
149 new StringReader(temp), data.getOut());
150 }
151 }
This page was automatically generated by Maven