##### Coverage Report - org.apache.turbine.modules.navigations.VelocityNavigation

Classes in this File | Line Coverage | Branch Coverage | Complexity
VelocityNavigation |
8% | 2/23
N/A | N/A
| 1.0;1

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.ecs.ConcreteElement;
25 |  |
     import org.apache.ecs.StringElement;
26 |  |
     import org.apache.turbine.modules.Navigation;
27 |  |
     import org.apache.turbine.pipeline.PipelineData;
28 |  |
     import org.apache.turbine.services.template.TurbineTemplate;
29 |  |
     import org.apache.turbine.services.velocity.TurbineVelocity;
30 |  |
     import org.apache.turbine.util.RunData;
31 |  |
     import org.apache.velocity.context.Context;
32 |  |
33 |  |
     /**
34 |  |
      * VelocityNavigation.  This screen relies on the VelocityPage
35 |  |
      * being set as the default page.  The doBuildTemplate() assumes the
36 |  |
      * user has put the template filename in the RunData parameter and set
37 |  |
      * it to the value of the template file to execute.  Specialized
38 |  |
      * Navigations screens should extend this class and override the
39 |  |
      * doBuildTemplate( data , context) method.
40 |  |
      *
41 |  |
      * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
42 |  |
      * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
43 |  |
      * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
44 |  |
      * @version $Id: VelocityNavigation.java 1078552 2011-03-06 19:58:46Z tv $
45 |  |
      */
46 | 8 |
     public class VelocityNavigation
47 |  |
             extends TemplateNavigation
48 |  |
     {
49 |  |
         /** The prefix for lookup up navigation pages */
50 | 8 |
         private final String prefix = Navigation.PREFIX + "/";
51 |  |
52 |  |
         /**
53 |  |
          * Velocity Navigations extending this class should overide this
54 |  |
          * method to perform any particular business logic and add
55 |  |
          * information to the context.
56 |  |
          *
57 |  |
          * @deprecated Use PipelineData version instead.
58 |  |
          * @param data Turbine information.
59 |  |
          * @param context Context for web pages.
60 |  |
          * @exception Exception, a generic exception.
61 |  |
          */
62 |  |
         @Deprecated
63 |  |
         protected void doBuildTemplate(RunData data,
64 |  |
                                        Context context)
65 |  |
                 throws Exception
66 |  |
         {
67 |  |
             // empty
68 | 0 |
         }
69 |  |
70 |  |
         /**
71 |  |
          * Velocity Navigations extending this class should overide this
72 |  |
          * method to perform any particular business logic and add
73 |  |
          * information to the context.
74 |  |
          *
75 |  |
          * @param data Turbine information.
76 |  |
          * @param context Context for web pages.
77 |  |
          * @exception Exception, a generic exception.
78 |  |
          */
79 |  |
         protected void doBuildTemplate(PipelineData pipelineData,
80 |  |
                                        Context context)
81 |  |
                 throws Exception
82 |  |
         {
83 |  |
             // empty
84 | 0 |
         }
85 |  |
86 |  |
         /**
87 |  |
          * Needs to be implemented to make TemplateNavigation like us.
88 |  |
          * The actual method that you should override is the one with the
89 |  |
          * context in the parameter list.
90 |  |
          *
91 |  |
          * @deprecated Use PipelineData version instead.
92 |  |
          * @param data Turbine information.
93 |  |
          * @exception Exception, a generic exception.
94 |  |
          */
95 |  |
         @Deprecated
96 |  |
         @Override
97 |  |
         protected void doBuildTemplate(RunData data)
98 |  |
                 throws Exception
99 |  |
         {
100 | 0 |
             doBuildTemplate(data, TurbineVelocity.getContext(data));
101 | 0 |
         }
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 | 0 |
             doBuildTemplate(pipelineData, TurbineVelocity.getContext(pipelineData));
117 | 0 |
         }
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 | 0 |
             Context context = TurbineVelocity.getContext(data);
133 |  |
134 | 0 |
             String navigationTemplate = data.getTemplateInfo().getNavigationTemplate();
135 | 0 |
             String templateName
136 |  |
                     = TurbineTemplate.getNavigationTemplateName(navigationTemplate);
137 |  |
138 | 0 |
             StringElement output = new StringElement();
139 | 0 |
             output.setFilterState(false);
140 | 0 |
             output.addElement(TurbineVelocity
141 |  |
                     .handleRequest(context, prefix + templateName));
142 | 0 |
             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 | 0 |
             RunData data = getRunData(pipelineData);
157 | 0 |
             Context context = TurbineVelocity.getContext(pipelineData);
158 |  |
159 | 0 |
             String navigationTemplate = data.getTemplateInfo().getNavigationTemplate();
160 | 0 |
             String templateName
161 |  |
                     = TurbineTemplate.getNavigationTemplateName(navigationTemplate);
162 |  |
163 | 0 |
             StringElement output = new StringElement();
164 | 0 |
             output.setFilterState(false);
165 | 0 |
             output.addElement(TurbineVelocity
166 |  |
                     .handleRequest(context, prefix + templateName));
167 | 0 |
             return output;
168 |  |
         }
169 |  |
170 |  |
171 |  |
     }