View Javadoc
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.pipeline.PipelineData;
26  import org.apache.turbine.services.template.TemplateService;
27  import org.apache.turbine.services.velocity.VelocityService;
28  import org.apache.turbine.util.RunData;
29  import org.apache.velocity.context.Context;
30  
31  /**
32   * VelocityNavigation.  This screen relies on the VelocityPage
33   * being set as the default page.  The doBuildTemplate() assumes the
34   * user has put the template filename in the RunData parameter and set
35   * it to the value of the template file to execute.  Specialized
36   * Navigations screens should extend this class and override the
37   * doBuildTemplate( data , context) method.
38   *
39   * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
40   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
41   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
42   * @version $Id$
43   */
44  public class VelocityNavigation
45          extends TemplateNavigation
46  {
47      /** The prefix for lookup up navigation pages */
48      private static final String prefix = PREFIX + "/";
49  
50      /** Injected service instance */
51      @TurbineService
52      private VelocityService velocity;
53  
54      /** Injected service instance */
55      @TurbineService
56      private TemplateService templateService;
57  
58      /**
59       * Velocity Navigations extending this class should override this
60       * method to perform any particular business logic and add
61       * information to the context.
62       *
63       * @param pipelineData Turbine information.
64       * @param context Context for web pages.
65       * @throws Exception a generic exception.
66       */
67      protected void doBuildTemplate(PipelineData pipelineData,
68                                     Context context)
69              throws Exception
70      {
71          // empty
72      }
73  
74      /**
75       * Needs to be implemented to make TemplateNavigation like us.
76       * The actual method that you should override is the one with the
77       * context in the parameter list.
78       *
79       * @param pipelineData Turbine information.
80       * @throws Exception a generic exception.
81       */
82      @Override
83      protected void doBuildTemplate(PipelineData pipelineData)
84              throws Exception
85      {
86          doBuildTemplate(pipelineData, velocity.getContext(pipelineData));
87      }
88  
89      /**
90       * This builds the Velocity template.
91       *
92       * @param pipelineData Turbine information.
93       * @return the content of the navigation module
94       * @throws Exception a generic exception.
95       */
96      @Override
97      public String buildTemplate(PipelineData pipelineData)
98              throws Exception
99      {
100         RunData data = pipelineData.getRunData();
101         Context context = velocity.getContext(pipelineData);
102 
103         String navigationTemplate = data.getTemplateInfo().getNavigationTemplate();
104         String templateName
105                 = templateService.getNavigationTemplateName(navigationTemplate);
106 
107         return velocity.handleRequest(context, prefix + templateName);
108     }
109 }