1 package org.apache.turbine.util.template;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.turbine.modules.NavigationLoader;
27 import org.apache.turbine.services.TurbineServices;
28 import org.apache.turbine.services.template.TemplateService;
29 import org.apache.turbine.util.RunData;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 public class TemplateNavigation
46 {
47
48 private static Log log = LogFactory.getLog(TemplateNavigation.class);
49
50
51 private RunData data;
52
53
54 private String template = null;
55
56
57
58
59
60
61 public TemplateNavigation(RunData data)
62 {
63 this.data = data;
64 }
65
66
67
68
69
70
71
72
73 public TemplateNavigation setTemplate(String template)
74 {
75 log.debug("setTemplate(" + template + ")");
76 this.template = template;
77 return this;
78 }
79
80
81
82
83
84
85 @Override
86 public String toString()
87 {
88 String module = null;
89 String returnValue = null;
90
91 try
92 {
93 if (template == null)
94 {
95 returnValue = "Navigation Template is null (Might be unset)";
96 throw new Exception(returnValue);
97 }
98
99 data.getTemplateInfo().setNavigationTemplate(template);
100 TemplateService templateService = (TemplateService)TurbineServices.getInstance().getService(TemplateService.SERVICE_NAME);
101 module = templateService.getNavigationName(template);
102
103 if (module == null)
104 {
105 returnValue = "Template Service returned null for Navigation Template " + template;
106 throw new Exception(returnValue);
107 }
108
109 returnValue = NavigationLoader.getInstance().eval(data, module);
110 }
111 catch (Exception e)
112 {
113 if (returnValue == null)
114 {
115 returnValue = "Error processing navigation template: "
116 + template + ", using module: " + module;
117 }
118 log.error(returnValue, e);
119 }
120
121 return returnValue;
122 }
123 }