View Javadoc

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