01: package org.apache.turbine.modules.navigations;
02:
03: /*
04: * Copyright 2001-2005 The Apache Software Foundation.
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License")
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import org.apache.ecs.ConcreteElement;
20: import org.apache.ecs.StringElement;
21: import org.apache.turbine.TurbineConstants;
22: import org.apache.turbine.services.template.TurbineTemplate;
23: import org.apache.turbine.services.velocity.TurbineVelocity;
24: import org.apache.turbine.util.RunData;
25: import org.apache.velocity.context.Context;
26:
27: /**
28: * VelocityNavigation. This screen relies on the VelocityPage
29: * being set as the default page. The doBuildTemplate() assumes the
30: * user has put the template filename in the RunData parameter and set
31: * it to the value of the template file to execute. Specialized
32: * Navigations screens should extend this class and overide the
33: * doBuildTemplate( data , context) method.
34: *
35: * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
36: * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
37: * @version $Id: VelocityNavigation.java 278824 2005-09-05 20:01:15Z henning $
38: */
39: public class VelocityNavigation extends TemplateNavigation {
40: /** The prefix for lookup up navigation pages */
41: private String prefix = TurbineConstants.NAVIGATION_PREFIX + "/";
42:
43: /**
44: * Velocity Navigations extending this class should overide this
45: * method to perform any particular business logic and add
46: * information to the context.
47: *
48: * @param data Turbine information.
49: * @param context Context for web pages.
50: * @exception Exception, a generic exception.
51: */
52: protected void doBuildTemplate(RunData data, Context context)
53: throws Exception {
54: }
55:
56: /**
57: * Needs to be implemented to make TemplateNavigation like us.
58: * The actual method that you should override is the one with the
59: * context in the parameter list.
60: *
61: * @param data Turbine information.
62: * @exception Exception, a generic exception.
63: */
64: protected void doBuildTemplate(RunData data) throws Exception {
65: doBuildTemplate(data, TurbineVelocity.getContext(data));
66: }
67:
68: /**
69: * This Builds the Velocity template.
70: *
71: * @param data Turbine information.
72: * @return A ConcreteElement.
73: * @exception Exception, a generic exception.
74: */
75: public ConcreteElement buildTemplate(RunData data) throws Exception {
76: Context context = TurbineVelocity.getContext(data);
77:
78: String navigationTemplate = data.getTemplateInfo()
79: .getNavigationTemplate();
80: String templateName = TurbineTemplate
81: .getNavigationTemplateName(navigationTemplate);
82:
83: StringElement output = new StringElement();
84: output.setFilterState(false);
85: output.addElement(TurbineVelocity.handleRequest(context, prefix
86: + templateName));
87: return output;
88: }
89:
90: }
|