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