1 package org.apache.turbine.services.template;
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.pipeline.PipelineData;
25 import org.apache.turbine.services.TurbineServices;
26
27 /**
28 * This is a simple static accessor to common TemplateService tasks such as
29 * getting a Screen that is associated with a screen template.
30 *
31 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
32 * @version $Id: TurbineTemplate.java 1709648 2015-10-20 17:08:10Z tv $
33 */
34 public abstract class TurbineTemplate
35 {
36 /**
37 * Utility method for accessing the service
38 * implementation
39 *
40 * @return a TemplateService implementation instance
41 */
42 public static TemplateService getService()
43 {
44 return (TemplateService) TurbineServices
45 .getInstance().getService(TemplateService.SERVICE_NAME);
46 }
47
48 /**
49 * Returns true if the Template Service has caching activated
50 *
51 * @return true if Caching is active.
52 */
53 public static final boolean isCaching()
54 {
55 return getService().isCaching();
56 }
57
58 /**
59 * Get the default extension given in the properties file.
60 *
61 * @return A String with the extension.
62 */
63 public static final String getDefaultExtension()
64 {
65 return getService().getDefaultExtension();
66 }
67
68 /**
69 * Return Extension for a supplied template
70 *
71 * @param template The template name
72 *
73 * @return extension The extension for the supplied template
74 */
75 public static final String getExtension(String template)
76 {
77 return getService().getExtension(template);
78 }
79
80 /**
81 * Returns the Default Template Name with the Default Extension.
82 * If the extension is unset, return only the template name
83 *
84 * @return The default template Name
85 */
86 public static final String getDefaultTemplate()
87 {
88 return getService().getDefaultTemplate();
89 }
90
91 /**
92 * Get the default page module name of the template engine
93 * service corresponding to the default template name extension.
94 *
95 * @return The default page module name.
96 */
97 public static final String getDefaultPage()
98 {
99 return getService().getDefaultPage();
100 }
101
102 /**
103 * Get the Screen template given in the properties file.
104 *
105 * @return A String which is the value of the TemplateService
106 * default.screen property.
107 */
108 public static final String getDefaultScreen()
109 {
110 return getService().getDefaultScreen();
111 }
112
113 /**
114 * Get the default layout module name of the template engine
115 * service corresponding to the default template name extension.
116 *
117 * @return The default layout module name.
118 */
119 public static final String getDefaultLayout()
120 {
121 return getService().getDefaultLayout();
122 }
123
124 /**
125 * Get the default Navigation given in the properties file.
126 *
127 * @return A String which is the value of the TemplateService
128 * default.navigation property.
129 */
130 public static final String getDefaultNavigation()
131 {
132 return getService().getDefaultNavigation();
133 }
134
135 /**
136 * Get the default layout template given in the properties file.
137 *
138 * @return A String which is the value of the TemplateService
139 * default.layout.template property.
140 */
141 public static final String getDefaultLayoutTemplate()
142 {
143 return getService().getDefaultLayoutTemplate();
144 }
145
146 /**
147 * Get the default page module name of the template engine
148 * service corresponding to the template name extension of
149 * the named template.
150 *
151 * @param template The template name.
152 * @return The default page module name.
153 */
154 public static final String getDefaultPageName(String template)
155 {
156 return getService().getDefaultPageName(template);
157 }
158
159 /**
160 * Get the default screen module name of the template engine
161 * service corresponding to the template name extension of
162 * the named template.
163 *
164 * @param template The template name.
165 * @return The default screen module name.
166 */
167 public static final String getDefaultScreenName(String template)
168 {
169 return getService().getDefaultScreenName(template);
170 }
171
172 /**
173 * Get the default layout module name of the template engine
174 * service corresponding to the template name extension of
175 * the named template.
176 *
177 * @param template The template name.
178 * @return The default layout module name.
179 */
180 public static final String getDefaultLayoutName(String template)
181 {
182 return getService().getDefaultLayoutName(template);
183 }
184
185 /**
186 * Get the default navigation module name of the template engine
187 * service corresponding to the template name extension of
188 * the named template.
189 *
190 * @param template The template name.
191 * @return The default navigation module name.
192 */
193 public static final String getDefaultNavigationName(String template)
194 {
195 return getService().getDefaultNavigationName(template);
196 }
197
198 /**
199 * Get the default layout template name of the template engine
200 * service corresponding to the template name extension of
201 * the named template.
202 *
203 * @param template The template name.
204 * @return The default layout template name.
205 */
206 public static final String getDefaultLayoutTemplateName(String template)
207 {
208 return getService().getDefaultLayoutTemplateName(template);
209 }
210
211 /**
212 * Find the default page module name for the given request.
213 *
214 * @param pipelineData The encapsulation of the request to retrieve the
215 * default page for.
216 * @return The default page module name.
217 */
218 public static final String getDefaultPageName(PipelineData pipelineData)
219 {
220 return getService().getDefaultPageName(pipelineData);
221 }
222
223 /**
224 * Find the default layout module name for the given request.
225 *
226 * @param pipelineData The encapsulation of the request to retrieve the
227 * default layout for.
228 * @return The default layout module name.
229 */
230 public static final String getDefaultLayoutName(PipelineData pipelineData)
231 {
232 return getService().getDefaultLayoutName(pipelineData);
233 }
234
235 /**
236 * Locate and return the name of a Screen module.
237 *
238 * @param name A String with the name of the template.
239 * @return A String with the name of the screen.
240 * @exception Exception, a generic exception.
241 */
242 public static final String getScreenName(String name)
243 throws Exception
244 {
245 return getService().getScreenName(name);
246 }
247
248 /**
249 * Locate and return the name of the layout module to be used
250 * with the named layout template.
251 *
252 * @param template The layout template name.
253 * @return The found layout module name.
254 * @exception Exception, a generic exception.
255 */
256 public static final String getLayoutName(String template)
257 throws Exception
258 {
259 return getService().getLayoutName(template);
260 }
261
262 /**
263 * Locate and return the name of the navigation module to be used
264 * with the named navigation template.
265 *
266 * @param template The navigation template name.
267 * @return The found navigation module name.
268 * @exception Exception, a generic exception.
269 */
270 public static final String getNavigationName(String template)
271 throws Exception
272 {
273 return getService().getNavigationName(template);
274 }
275
276 /**
277 * Locate and return the name of a screen template.
278 *
279 * @param key A String which is the key to the template.
280 * @return A String with the screen template path.
281 * @exception Exception, a generic exception.
282 */
283 public static final String getScreenTemplateName(String key)
284 throws Exception
285 {
286 return getService().getScreenTemplateName(key);
287 }
288
289 /**
290 * Locate and return the name of a layout template.
291 *
292 * @param name A String with the name of the template.
293 * @return A String with the layout template path.
294 * @exception Exception, a generic exception.
295 */
296 public static final String getLayoutTemplateName(String name)
297 throws Exception
298 {
299 return getService().getLayoutTemplateName(name);
300 }
301
302 /**
303 * Locate and return the name of a navigation template.
304 *
305 * @param key A String which is the key to the template.
306 * @return A String with the navigation template path.
307 * @exception Exception, a generic exception.
308 */
309 public static final String getNavigationTemplateName(String key)
310 throws Exception
311 {
312 return getService().getNavigationTemplateName(key);
313 }
314
315 /**
316 * Translates the supplied template paths into their Turbine-canonical
317 * equivalent (probably absolute paths).
318 *
319 * @param templatePaths An array of template paths.
320 * @return An array of translated template paths.
321 * @deprecated Each template engine service should know how to translate
322 * a request onto a file.
323 */
324 @Deprecated
325 public static final String[] translateTemplatePaths(String[] templatePaths)
326 {
327 return getService().translateTemplatePaths(templatePaths);
328 }
329
330 /**
331 * Delegates to the appropriate {@link
332 * org.apache.turbine.services.template.TemplateEngineService} to
333 * check the existence of the specified template.
334 *
335 * @param template The template to check for the existence of.
336 * @param templatePaths The paths to check for the template.
337 * @return true if the template exists
338 * @deprecated Use templateExists from the various Templating Engines
339 */
340 @Deprecated
341 public static final boolean templateExists(String template, String[] templatePaths)
342 {
343 return getService().templateExists(template, templatePaths);
344 }
345
346 /**
347 * Registers the provided template engine for use by the
348 * <code>TemplateService</code>.
349 *
350 * @param service The <code>TemplateEngineService</code> to register.
351 */
352 public static final void registerTemplateEngineService(TemplateEngineService service)
353 {
354 getService().registerTemplateEngineService(service);
355 }
356
357 /**
358 * The {@link org.apache.turbine.services.template.TemplateEngineService}
359 * associated with the specified template's file extension.
360 *
361 * @param template The template name.
362 * @return The template engine service.
363 */
364 public static final TemplateEngineService getTemplateEngineService(String template)
365 {
366 return getService().getTemplateEngineService(template);
367 }
368 }