KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > template > TurbineTemplate


1 package org.apache.turbine.services.template;
2
3 /*
4  * Copyright 2001-2004 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.turbine.services.TurbineServices;
20
21 import org.apache.turbine.util.RunData;
22
23 /**
24  * This is a simple static accessor to common TemplateService tasks such as
25  * getting a Screen that is associated with a screen template.
26  *
27  * @author <a HREF="mailto:john.mcnally@clearink.com">John D. McNally</a>
28  * @version $Id: TurbineTemplate.java,v 1.9.2.2 2004/05/20 03:06:47 seade Exp $
29  */

30 public abstract class TurbineTemplate
31 {
32     /**
33      * Utility method for accessing the service
34      * implementation
35      *
36      * @return a TemplateService implementation instance
37      */

38     public static TemplateService getService()
39     {
40         return (TemplateService) TurbineServices
41             .getInstance().getService(TemplateService.SERVICE_NAME);
42     }
43
44     /**
45      * Returns true if the Template Service has caching activated
46      *
47      * @return true if Caching is active.
48      */

49     public static final boolean isCaching()
50     {
51         return getService().isCaching();
52     }
53
54     /**
55      * Get the default extension given in the properties file.
56      *
57      * @return A String with the extension.
58      */

59     public static final String JavaDoc getDefaultExtension()
60     {
61         return getService().getDefaultExtension();
62     }
63
64     /**
65      * Return Extension for a supplied template
66      *
67      * @param template The template name
68      *
69      * @return extension The extension for the supplied template
70      */

71     public static final String JavaDoc getExtension(String JavaDoc template)
72     {
73         return getService().getExtension(template);
74     }
75
76     /**
77      * Returns the Default Template Name with the Default Extension.
78      * If the extension is unset, return only the template name
79      *
80      * @return The default template Name
81      */

82     public static final String JavaDoc getDefaultTemplate()
83     {
84         return getService().getDefaultTemplate();
85     }
86
87     /**
88      * Get the default page module name of the template engine
89      * service corresponding to the default template name extension.
90      *
91      * @return The default page module name.
92      */

93     public static final String JavaDoc getDefaultPage()
94     {
95         return getService().getDefaultPage();
96     }
97
98     /**
99      * Get the Screen template given in the properties file.
100      *
101      * @return A String which is the value of the TemplateService
102      * default.screen property.
103      */

104     public static final String JavaDoc getDefaultScreen()
105     {
106         return getService().getDefaultScreen();
107     }
108
109     /**
110      * Get the default layout module name of the template engine
111      * service corresponding to the default template name extension.
112      *
113      * @return The default layout module name.
114      */

115     public static final String JavaDoc getDefaultLayout()
116     {
117         return getService().getDefaultLayout();
118     }
119
120     /**
121      * Get the default Navigation given in the properties file.
122      *
123      * @return A String which is the value of the TemplateService
124      * default.navigation property.
125      */

126     public static final String JavaDoc getDefaultNavigation()
127     {
128         return getService().getDefaultNavigation();
129     }
130
131     /**
132      * Get the default layout template given in the properties file.
133      *
134      * @return A String which is the value of the TemplateService
135      * default.layout.template property.
136      */

137     public static final String JavaDoc getDefaultLayoutTemplate()
138     {
139         return getService().getDefaultLayoutTemplate();
140     }
141
142     /**
143      * Get the default page module name of the template engine
144      * service corresponding to the template name extension of
145      * the named template.
146      *
147      * @param template The template name.
148      * @return The default page module name.
149      */

150     public static final String JavaDoc getDefaultPageName(String JavaDoc template)
151     {
152         return getService().getDefaultPageName(template);
153     }
154
155     /**
156      * Get the default screen module name of the template engine
157      * service corresponding to the template name extension of
158      * the named template.
159      *
160      * @param template The template name.
161      * @return The default screen module name.
162      */

163     public static final String JavaDoc getDefaultScreenName(String JavaDoc template)
164     {
165         return getService().getDefaultScreenName(template);
166     }
167
168     /**
169      * Get the default layout module name of the template engine
170      * service corresponding to the template name extension of
171      * the named template.
172      *
173      * @param template The template name.
174      * @return The default layout module name.
175      */

176     public static final String JavaDoc getDefaultLayoutName(String JavaDoc template)
177     {
178         return getService().getDefaultLayoutName(template);
179     }
180
181     /**
182      * Get the default navigation module name of the template engine
183      * service corresponding to the template name extension of
184      * the named template.
185      *
186      * @param template The template name.
187      * @return The default navigation module name.
188      */

189     public static final String JavaDoc getDefaultNavigationName(String JavaDoc template)
190     {
191         return getService().getDefaultNavigationName(template);
192     }
193
194     /**
195      * Get the default layout template name of the template engine
196      * service corresponding to the template name extension of
197      * the named template.
198      *
199      * @param template The template name.
200      * @return The default layout template name.
201      */

202     public static final String JavaDoc getDefaultLayoutTemplateName(String JavaDoc template)
203     {
204         return getService().getDefaultLayoutTemplateName(template);
205     }
206
207     /**
208      * Find the default page module name for the given request.
209      *
210      * @param data The encapsulation of the request to retrieve the
211      * default page for.
212      * @return The default page module name.
213      */

214     public static final String JavaDoc getDefaultPageName(RunData data)
215     {
216         return getService().getDefaultPageName(data);
217     }
218
219     /**
220      * Find the default layout module name for the given request.
221      *
222      * @param data The encapsulation of the request to retrieve the
223      * default layout for.
224      * @return The default layout module name.
225      */

226     public static final String JavaDoc getDefaultLayoutName(RunData data)
227     {
228         return getService().getDefaultLayoutName(data);
229     }
230
231     /**
232      * Locate and return the name of a Screen module.
233      *
234      * @param name A String with the name of the template.
235      * @return A String with the name of the screen.
236      * @exception Exception, a generic exception.
237      */

238     public static final String JavaDoc getScreenName(String JavaDoc name)
239         throws Exception JavaDoc
240     {
241         return getService().getScreenName(name);
242     }
243
244     /**
245      * Locate and return the name of the layout module to be used
246      * with the named layout template.
247      *
248      * @param template The layout template name.
249      * @return The found layout module name.
250      * @exception Exception, a generic exception.
251      */

252     public static final String JavaDoc getLayoutName(String JavaDoc template)
253         throws Exception JavaDoc
254     {
255         return getService().getLayoutName(template);
256     }
257
258     /**
259      * Locate and return the name of the navigation module to be used
260      * with the named navigation template.
261      *
262      * @param template The navigation template name.
263      * @return The found navigation module name.
264      * @exception Exception, a generic exception.
265      */

266     public static final String JavaDoc getNavigationName(String JavaDoc template)
267         throws Exception JavaDoc
268     {
269         return getService().getNavigationName(template);
270     }
271
272     /**
273      * Locate and return the name of a screen template.
274      *
275      * @param key A String which is the key to the template.
276      * @return A String with the screen template path.
277      * @exception Exception, a generic exception.
278      */

279     public static final String JavaDoc getScreenTemplateName(String JavaDoc key)
280         throws Exception JavaDoc
281     {
282         return getService().getScreenTemplateName(key);
283     }
284
285     /**
286      * Locate and return the name of a layout template.
287      *
288      * @param name A String with the name of the template.
289      * @return A String with the layout template path.
290      * @exception Exception, a generic exception.
291      */

292     public static final String JavaDoc getLayoutTemplateName(String JavaDoc name)
293         throws Exception JavaDoc
294     {
295         return getService().getLayoutTemplateName(name);
296     }
297
298     /**
299      * Locate and return the name of a navigation template.
300      *
301      * @param key A String which is the key to the template.
302      * @return A String with the navigation template path.
303      * @exception Exception, a generic exception.
304      */

305     public static final String JavaDoc getNavigationTemplateName(String JavaDoc key)
306         throws Exception JavaDoc
307     {
308         return getService().getNavigationTemplateName(key);
309     }
310
311     /**
312      * Translates the supplied template paths into their Turbine-canonical
313      * equivalent (probably absolute paths).
314      *
315      * @param templatePaths An array of template paths.
316      * @return An array of translated template paths.
317      * @deprecated Each template engine service should know how to translate
318      * a request onto a file.
319      */

320     public static final String JavaDoc[] translateTemplatePaths(String JavaDoc[] templatePaths)
321     {
322         return getService().translateTemplatePaths(templatePaths);
323     }
324
325     /**
326      * Delegates to the appropriate {@link
327      * org.apache.turbine.services.template.TemplateEngineService} to
328      * check the existance of the specified template.
329      *
330      * @param template The template to check for the existance of.
331      * @param templatePaths The paths to check for the template.
332      * @deprecated Use templateExists from the various Templating Engines
333      */

334     public static final boolean templateExists(String JavaDoc template, String JavaDoc[] templatePaths)
335     {
336         return getService().templateExists(template, templatePaths);
337     }
338
339     /**
340      * Registers the provided template engine for use by the
341      * <code>TemplateService</code>.
342      *
343      * @param service The <code>TemplateEngineService</code> to register.
344      */

345     public static final void registerTemplateEngineService(TemplateEngineService service)
346     {
347         getService().registerTemplateEngineService(service);
348     }
349
350     /**
351      * The {@link org.apache.turbine.services.template.TemplateEngineService}
352      * associated with the specified template's file extension.
353      *
354      * @param template The template name.
355      * @return The template engine service.
356      */

357     public static final TemplateEngineService getTemplateEngineService(String JavaDoc template)
358     {
359         return getService().getTemplateEngineService(template);
360     }
361 }
362
Popular Tags