View Javadoc

1   package org.apache.turbine.modules.navigations;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License")
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import org.apache.ecs.ConcreteElement;
20  import org.apache.ecs.StringElement;
21  import org.apache.turbine.TurbineConstants;
22  import org.apache.turbine.services.template.TurbineTemplate;
23  import org.apache.turbine.services.velocity.TurbineVelocity;
24  import org.apache.turbine.util.RunData;
25  import org.apache.velocity.context.Context;
26  
27  /***
28   * VelocityNavigation.  This screen relies on the VelocityPage
29   * being set as the default page.  The doBuildTemplate() assumes the
30   * user has put the template filename in the RunData parameter and set
31   * it to the value of the template file to execute.  Specialized
32   * Navigations screens should extend this class and overide the
33   * doBuildTemplate( data , context) method.
34   *
35   * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
36   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
37   * @version $Id: VelocityNavigation.java 278824 2005-09-05 20:01:15Z henning $
38   */
39  public class VelocityNavigation
40          extends TemplateNavigation
41  {
42      /*** The prefix for lookup up navigation pages */
43      private String prefix = TurbineConstants.NAVIGATION_PREFIX + "/";
44  
45      /***
46       * Velocity Navigations extending this class should overide this
47       * method to perform any particular business logic and add
48       * information to the context.
49       *
50       * @param data Turbine information.
51       * @param context Context for web pages.
52       * @exception Exception, a generic exception.
53       */
54      protected void doBuildTemplate(RunData data,
55                                     Context context)
56              throws Exception
57      {
58      }
59  
60      /***
61       * Needs to be implemented to make TemplateNavigation like us.
62       * The actual method that you should override is the one with the
63       * context in the parameter list.
64       *
65       * @param data Turbine information.
66       * @exception Exception, a generic exception.
67       */
68      protected void doBuildTemplate(RunData data)
69              throws Exception
70      {
71          doBuildTemplate(data, TurbineVelocity.getContext(data));
72      }
73  
74      /***
75       * This Builds the Velocity template.
76       *
77       * @param data Turbine information.
78       * @return A ConcreteElement.
79       * @exception Exception, a generic exception.
80       */
81      public ConcreteElement buildTemplate(RunData data)
82              throws Exception
83      {
84          Context context = TurbineVelocity.getContext(data);
85  
86          String navigationTemplate = data.getTemplateInfo().getNavigationTemplate();
87          String templateName
88                  = TurbineTemplate.getNavigationTemplateName(navigationTemplate);
89  
90          StringElement output = new StringElement();
91          output.setFilterState(false);
92          output.addElement(TurbineVelocity
93                  .handleRequest(context, prefix + templateName));
94          return output;
95      }
96  
97  }