View Javadoc

1   package org.apache.turbine.modules.navigations;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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 }