001 package org.apache.turbine.modules.navigations;
002
003
004 /*
005 * Licensed to the Apache Software Foundation (ASF) under one
006 * or more contributor license agreements. See the NOTICE file
007 * distributed with this work for additional information
008 * regarding copyright ownership. The ASF licenses this file
009 * to you under the Apache License, Version 2.0 (the
010 * "License"); you may not use this file except in compliance
011 * with the License. You may obtain a copy of the License at
012 *
013 * http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing,
016 * software distributed under the License is distributed on an
017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018 * KIND, either express or implied. See the License for the
019 * specific language governing permissions and limitations
020 * under the License.
021 */
022
023
024 import org.apache.ecs.ConcreteElement;
025 import org.apache.ecs.StringElement;
026 import org.apache.turbine.modules.Navigation;
027 import org.apache.turbine.pipeline.PipelineData;
028 import org.apache.turbine.services.template.TurbineTemplate;
029 import org.apache.turbine.services.velocity.TurbineVelocity;
030 import org.apache.turbine.util.RunData;
031 import org.apache.velocity.context.Context;
032
033 /**
034 * VelocityNavigation. This screen relies on the VelocityPage
035 * being set as the default page. The doBuildTemplate() assumes the
036 * user has put the template filename in the RunData parameter and set
037 * it to the value of the template file to execute. Specialized
038 * Navigations screens should extend this class and override the
039 * doBuildTemplate( data , context) method.
040 *
041 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
042 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
043 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
044 * @version $Id: VelocityNavigation.java 1078552 2011-03-06 19:58:46Z tv $
045 */
046 public class VelocityNavigation
047 extends TemplateNavigation
048 {
049 /** The prefix for lookup up navigation pages */
050 private final String prefix = Navigation.PREFIX + "/";
051
052 /**
053 * Velocity Navigations extending this class should overide this
054 * method to perform any particular business logic and add
055 * information to the context.
056 *
057 * @deprecated Use PipelineData version instead.
058 * @param data Turbine information.
059 * @param context Context for web pages.
060 * @exception Exception, a generic exception.
061 */
062 @Deprecated
063 protected void doBuildTemplate(RunData data,
064 Context context)
065 throws Exception
066 {
067 // empty
068 }
069
070 /**
071 * Velocity Navigations extending this class should overide this
072 * method to perform any particular business logic and add
073 * information to the context.
074 *
075 * @param data Turbine information.
076 * @param context Context for web pages.
077 * @exception Exception, a generic exception.
078 */
079 protected void doBuildTemplate(PipelineData pipelineData,
080 Context context)
081 throws Exception
082 {
083 // empty
084 }
085
086 /**
087 * Needs to be implemented to make TemplateNavigation like us.
088 * The actual method that you should override is the one with the
089 * context in the parameter list.
090 *
091 * @deprecated Use PipelineData version instead.
092 * @param data Turbine information.
093 * @exception Exception, a generic exception.
094 */
095 @Deprecated
096 @Override
097 protected void doBuildTemplate(RunData data)
098 throws Exception
099 {
100 doBuildTemplate(data, TurbineVelocity.getContext(data));
101 }
102
103
104 /**
105 * Needs to be implemented to make TemplateNavigation like us.
106 * The actual method that you should override is the one with the
107 * context in the parameter list.
108 *
109 * @param pipelineData Turbine information.
110 * @exception Exception, a generic exception.
111 */
112 @Override
113 protected void doBuildTemplate(PipelineData pipelineData)
114 throws Exception
115 {
116 doBuildTemplate(pipelineData, TurbineVelocity.getContext(pipelineData));
117 }
118
119 /**
120 * This Builds the Velocity template.
121 *
122 * @deprecated Use PipelineData version instead.
123 * @param data Turbine information.
124 * @return A ConcreteElement.
125 * @exception Exception, a generic exception.
126 */
127 @Deprecated
128 @Override
129 public ConcreteElement buildTemplate(RunData data)
130 throws Exception
131 {
132 Context context = TurbineVelocity.getContext(data);
133
134 String navigationTemplate = data.getTemplateInfo().getNavigationTemplate();
135 String templateName
136 = TurbineTemplate.getNavigationTemplateName(navigationTemplate);
137
138 StringElement output = new StringElement();
139 output.setFilterState(false);
140 output.addElement(TurbineVelocity
141 .handleRequest(context, prefix + templateName));
142 return output;
143 }
144
145 /**
146 * This Builds the Velocity template.
147 *
148 * @param data Turbine information.
149 * @return A ConcreteElement.
150 * @exception Exception, a generic exception.
151 */
152 @Override
153 public ConcreteElement buildTemplate(PipelineData pipelineData)
154 throws Exception
155 {
156 RunData data = getRunData(pipelineData);
157 Context context = TurbineVelocity.getContext(pipelineData);
158
159 String navigationTemplate = data.getTemplateInfo().getNavigationTemplate();
160 String templateName
161 = TurbineTemplate.getNavigationTemplateName(navigationTemplate);
162
163 StringElement output = new StringElement();
164 output.setFilterState(false);
165 output.addElement(TurbineVelocity
166 .handleRequest(context, prefix + templateName));
167 return output;
168 }
169
170
171 }