1 package org.apache.turbine.modules.navigations;
2
3
4 /*
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 */
22
23
24 import org.apache.turbine.annotation.TurbineService;
25 import org.apache.turbine.modules.Navigation;
26 import org.apache.turbine.pipeline.PipelineData;
27 import org.apache.turbine.services.template.TemplateService;
28 import org.apache.turbine.services.velocity.VelocityService;
29 import org.apache.turbine.util.RunData;
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 override 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 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
43 * @version $Id: VelocityNavigation.java 1709648 2015-10-20 17:08:10Z tv $
44 */
45 public class VelocityNavigation
46 extends TemplateNavigation
47 {
48 /** The prefix for lookup up navigation pages */
49 private final String prefix = Navigation.PREFIX + "/";
50
51 /** Injected service instance */
52 @TurbineService
53 private VelocityService velocity;
54
55 /** Injected service instance */
56 @TurbineService
57 private TemplateService templateService;
58
59 /**
60 * Velocity Navigations extending this class should override this
61 * method to perform any particular business logic and add
62 * information to the context.
63 *
64 * @param pipelineData Turbine information.
65 * @param context Context for web pages.
66 * @exception Exception, a generic exception.
67 */
68 protected void doBuildTemplate(PipelineData pipelineData,
69 Context context)
70 throws Exception
71 {
72 // empty
73 }
74
75 /**
76 * Needs to be implemented to make TemplateNavigation like us.
77 * The actual method that you should override is the one with the
78 * context in the parameter list.
79 *
80 * @param pipelineData Turbine information.
81 * @exception Exception, a generic exception.
82 */
83 @Override
84 protected void doBuildTemplate(PipelineData pipelineData)
85 throws Exception
86 {
87 doBuildTemplate(pipelineData, velocity.getContext(pipelineData));
88 }
89
90 /**
91 * This builds the Velocity template.
92 *
93 * @param pipelineData Turbine information.
94 * @return the content of the navigation module
95 * @exception Exception, a generic exception.
96 */
97 @Override
98 public String buildTemplate(PipelineData pipelineData)
99 throws Exception
100 {
101 RunData data = getRunData(pipelineData);
102 Context context = velocity.getContext(pipelineData);
103
104 String navigationTemplate = data.getTemplateInfo().getNavigationTemplate();
105 String templateName
106 = templateService.getNavigationTemplateName(navigationTemplate);
107
108 return velocity.handleRequest(context, prefix + templateName);
109 }
110 }