%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.turbine.util.template.TemplateNavigation |
|
|
1 | package org.apache.turbine.util.template; |
|
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.commons.logging.Log; |
|
20 | import org.apache.commons.logging.LogFactory; |
|
21 | ||
22 | import org.apache.ecs.ConcreteElement; |
|
23 | ||
24 | import org.apache.turbine.modules.NavigationLoader; |
|
25 | ||
26 | import org.apache.turbine.services.template.TurbineTemplate; |
|
27 | ||
28 | import org.apache.turbine.util.RunData; |
|
29 | ||
30 | /** |
|
31 | * Returns output of a Navigation module. An instance of this is |
|
32 | * placed in the WebMacro context by the WebMacroSiteLayout. This |
|
33 | * allows template authors to set the navigation template they'd like |
|
34 | * to place in their templates. Here's how it's used in a |
|
35 | * template: |
|
36 | * |
|
37 | * <p><code> |
|
38 | * $navigation.setTemplate("admin_navigation.wm") |
|
39 | * </code> |
|
40 | * |
|
41 | * @author <a href="mbryson@mont.mindspring.com">Dave Bryson</a> |
|
42 | * @version $Id: TemplateNavigation.java 264148 2005-08-29 14:21:04Z henning $ |
|
43 | */ |
|
44 | public class TemplateNavigation |
|
45 | { |
|
46 | /** Logging */ |
|
47 | 0 | private static Log log = LogFactory.getLog(TemplateNavigation.class); |
48 | ||
49 | /* The RunData object. */ |
|
50 | private RunData data; |
|
51 | ||
52 | /* The name of the navigation template. */ |
|
53 | 0 | private String template = null; |
54 | ||
55 | /** |
|
56 | * Constructor |
|
57 | * |
|
58 | * @param data A Turbine RunData object. |
|
59 | */ |
|
60 | public TemplateNavigation(RunData data) |
|
61 | 0 | { |
62 | 0 | this.data = data; |
63 | 0 | } |
64 | ||
65 | /** |
|
66 | * Set the template. |
|
67 | * |
|
68 | * @param template A String with the name of the navigation |
|
69 | * template. |
|
70 | * @return A TemplateNavigation (self). |
|
71 | */ |
|
72 | public TemplateNavigation setTemplate(String template) |
|
73 | { |
|
74 | 0 | log.debug("setTemplate(" + template + ")"); |
75 | 0 | this.template = template; |
76 | 0 | return this; |
77 | } |
|
78 | ||
79 | /** |
|
80 | * Builds the output of the navigation template. |
|
81 | * |
|
82 | * @return A String. |
|
83 | */ |
|
84 | public String toString() |
|
85 | { |
|
86 | 0 | String module = null; |
87 | 0 | String returnValue = null; |
88 | ||
89 | try |
|
90 | { |
|
91 | 0 | if (template == null) |
92 | { |
|
93 | 0 | returnValue = "Navigation Template is null (Might be unset)"; |
94 | 0 | throw new Exception(returnValue); |
95 | } |
|
96 | ||
97 | 0 | data.getTemplateInfo().setNavigationTemplate(template); |
98 | 0 | module = TurbineTemplate.getNavigationName(template); |
99 | ||
100 | 0 | if (module == null) |
101 | { |
|
102 | 0 | returnValue = "Template Service returned null for Navigation Template " + template; |
103 | 0 | throw new Exception(returnValue); |
104 | } |
|
105 | ||
106 | 0 | ConcreteElement results = |
107 | NavigationLoader.getInstance().eval(data, module); |
|
108 | 0 | returnValue = results.toString(); |
109 | } |
|
110 | 0 | catch (Exception e) |
111 | { |
|
112 | 0 | if (returnValue == null) |
113 | { |
|
114 | 0 | returnValue = "Error processing navigation template: " |
115 | + template + ", using module: " + module; |
|
116 | } |
|
117 | 0 | log.error(returnValue, e); |
118 | 0 | } |
119 | ||
120 | 0 | return class="keyword">returnValue; |
121 | } |
|
122 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |