1 package org.apache.turbine.modules.navigations;
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/Village/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.services.webmacro.TurbineWebMacro;
62 import org.apache.turbine.services.webmacro.WebMacroService;
63
64 // WebMacro Stuff
65 import org.webmacro.servlet.WebContext;
66
67
68 /***
69 * WebMacroSiteNavigation. This screen relies on the WebMacroSitePage
70 * being set as the default page. This screen can be called directly
71 * to generate a WebMacro Screen. The doBuildTemplate() assumes the
72 * user has put the template filename in the RunData parameter and set
73 * it to the value of the template file to execute. Specialized
74 * Navigations screens should extend this class and overide the
75 * doBuildTemplate( data , context) method.
76 *
77 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
78 * @version $Id: WebMacroSiteNavigation.java,v 1.1.1.1 2001/08/16 05:08:35 jvanzyl Exp $
79 * @deprecated you should use velocity
80 */
81 public class WebMacroSiteNavigation extends TemplateNavigation
82 {
83 /***
84 * WebMacro Navigations extending this class should overide this
85 * method to perform any particular business logic and add
86 * information to the context.
87 *
88 * @param data Turbine information.
89 * @param context Context for web pages.
90 * @exception Exception, a generic exception.
91 */
92 protected void doBuildTemplate( RunData data,
93 WebContext context )
94 throws Exception
95 {
96 }
97
98 /***
99 * Needs to be implemented to make TemplateNavigation like us.
100 * The actual method that you should override is the one with the
101 * context in the parameter list.
102 *
103 * @param data Turbine information.
104 * @exception Exception, a generic exception.
105 */
106 protected void doBuildTemplate( RunData data )
107 throws Exception
108 {
109 doBuildTemplate( data, getContext(data) );
110 }
111
112 /***
113 * This Builds the WebMacro template.
114 *
115 * @param data Turbine information.
116 * @return A ConcreteElement.
117 * @exception Exception, a generic exception.
118 */
119 public ConcreteElement buildTemplate( RunData data )
120 throws Exception
121 {
122 WebContext context = getContext( data );
123
124 String templateName = data.getTemplateInfo().getNavigationTemplate();
125
126 StringElement output = new StringElement();
127 output.setFilterState(false);
128 output.addElement(
129 buildWMTemplate(context,"navigations/" + templateName));
130 return output;
131 }
132
133 /***
134 * Return the WebContext needed by WebMacro.
135 *
136 *
137 * @param data Turbine information.
138 * @return A WebContext.
139 */
140 protected WebContext getContext(RunData data)
141 {
142 // Attempt to get it from the TemplateInfo first. If it
143 // doesn't exist, create it and then stuff it into the
144 // TemplateInfo.
145 WebContext wc = (WebContext)data.getTemplateInfo().getTemplateContext(
146 WebMacroService.WEBMACRO_CONTEXT);
147 if (wc == null)
148 {
149 wc = TurbineWebMacro.getContext(data);
150 data.getTemplateInfo().setTemplateContext(
151 WebMacroService.WEBMACRO_CONTEXT, wc);
152 }
153 return wc;
154 }
155
156 /***
157 * Build WM template.
158 *
159 * @param context A WebContext.
160 * @param templateFile A String, the name of the template file.
161 * @return A String with the processed template.
162 * @exception Exception, a generic exception.
163 */
164 protected String buildWMTemplate(WebContext context,
165 String templateFile)
166 throws Exception
167 {
168 return TurbineWebMacro.handleRequest(context, templateFile);
169 }
170 }
This page was automatically generated by Maven