1 package org.apache.turbine.modules.navigations;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.ecs.ConcreteElement;
23 import org.apache.ecs.StringElement;
24 import org.apache.turbine.TurbineConstants;
25 import org.apache.turbine.services.template.TurbineTemplate;
26 import org.apache.turbine.services.velocity.TurbineVelocity;
27 import org.apache.turbine.util.RunData;
28 import org.apache.velocity.context.Context;
29
30 /***
31 * VelocityNavigation. This screen relies on the VelocityPage
32 * being set as the default page. The doBuildTemplate() assumes the
33 * user has put the template filename in the RunData parameter and set
34 * it to the value of the template file to execute. Specialized
35 * Navigations screens should extend this class and overide the
36 * doBuildTemplate( data , context) method.
37 *
38 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
39 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
40 * @version $Id: VelocityNavigation.java 534527 2007-05-02 16:10:59Z tv $
41 */
42 public class VelocityNavigation
43 extends TemplateNavigation
44 {
45 /*** The prefix for lookup up navigation pages */
46 private String prefix = TurbineConstants.NAVIGATION_PREFIX + "/";
47
48 /***
49 * Velocity Navigations extending this class should overide this
50 * method to perform any particular business logic and add
51 * information to the context.
52 *
53 * @param data Turbine information.
54 * @param context Context for web pages.
55 * @exception Exception, a generic exception.
56 */
57 protected void doBuildTemplate(RunData data,
58 Context context)
59 throws Exception
60 {
61 }
62
63 /***
64 * Needs to be implemented to make TemplateNavigation like us.
65 * The actual method that you should override is the one with the
66 * context in the parameter list.
67 *
68 * @param data Turbine information.
69 * @exception Exception, a generic exception.
70 */
71 protected void doBuildTemplate(RunData data)
72 throws Exception
73 {
74 doBuildTemplate(data, TurbineVelocity.getContext(data));
75 }
76
77 /***
78 * This Builds the Velocity template.
79 *
80 * @param data Turbine information.
81 * @return A ConcreteElement.
82 * @exception Exception, a generic exception.
83 */
84 public ConcreteElement buildTemplate(RunData data)
85 throws Exception
86 {
87 Context context = TurbineVelocity.getContext(data);
88
89 String navigationTemplate = data.getTemplateInfo().getNavigationTemplate();
90 String templateName
91 = TurbineTemplate.getNavigationTemplateName(navigationTemplate);
92
93 StringElement output = new StringElement();
94 output.setFilterState(false);
95 output.addElement(TurbineVelocity
96 .handleRequest(context, prefix + templateName));
97 return output;
98 }
99
100 }