001: package org.apache.turbine.services.template;
002:
003: /*
004: * Copyright 2001-2005 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License")
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import org.apache.turbine.services.TurbineServices;
020:
021: import org.apache.turbine.util.RunData;
022:
023: /**
024: * This is a simple static accessor to common TemplateService tasks such as
025: * getting a Screen that is associated with a screen template.
026: *
027: * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
028: * @version $Id: TurbineTemplate.java 264148 2005-08-29 14:21:04Z henning $
029: */
030: public abstract class TurbineTemplate {
031: /**
032: * Utility method for accessing the service
033: * implementation
034: *
035: * @return a TemplateService implementation instance
036: */
037: public static TemplateService getService() {
038: return (TemplateService) TurbineServices.getInstance()
039: .getService(TemplateService.SERVICE_NAME);
040: }
041:
042: /**
043: * Returns true if the Template Service has caching activated
044: *
045: * @return true if Caching is active.
046: */
047: public static final boolean isCaching() {
048: return getService().isCaching();
049: }
050:
051: /**
052: * Get the default extension given in the properties file.
053: *
054: * @return A String with the extension.
055: */
056: public static final String getDefaultExtension() {
057: return getService().getDefaultExtension();
058: }
059:
060: /**
061: * Return Extension for a supplied template
062: *
063: * @param template The template name
064: *
065: * @return extension The extension for the supplied template
066: */
067: public static final String getExtension(String template) {
068: return getService().getExtension(template);
069: }
070:
071: /**
072: * Returns the Default Template Name with the Default Extension.
073: * If the extension is unset, return only the template name
074: *
075: * @return The default template Name
076: */
077: public static final String getDefaultTemplate() {
078: return getService().getDefaultTemplate();
079: }
080:
081: /**
082: * Get the default page module name of the template engine
083: * service corresponding to the default template name extension.
084: *
085: * @return The default page module name.
086: */
087: public static final String getDefaultPage() {
088: return getService().getDefaultPage();
089: }
090:
091: /**
092: * Get the Screen template given in the properties file.
093: *
094: * @return A String which is the value of the TemplateService
095: * default.screen property.
096: */
097: public static final String getDefaultScreen() {
098: return getService().getDefaultScreen();
099: }
100:
101: /**
102: * Get the default layout module name of the template engine
103: * service corresponding to the default template name extension.
104: *
105: * @return The default layout module name.
106: */
107: public static final String getDefaultLayout() {
108: return getService().getDefaultLayout();
109: }
110:
111: /**
112: * Get the default Navigation given in the properties file.
113: *
114: * @return A String which is the value of the TemplateService
115: * default.navigation property.
116: */
117: public static final String getDefaultNavigation() {
118: return getService().getDefaultNavigation();
119: }
120:
121: /**
122: * Get the default layout template given in the properties file.
123: *
124: * @return A String which is the value of the TemplateService
125: * default.layout.template property.
126: */
127: public static final String getDefaultLayoutTemplate() {
128: return getService().getDefaultLayoutTemplate();
129: }
130:
131: /**
132: * Get the default page module name of the template engine
133: * service corresponding to the template name extension of
134: * the named template.
135: *
136: * @param template The template name.
137: * @return The default page module name.
138: */
139: public static final String getDefaultPageName(String template) {
140: return getService().getDefaultPageName(template);
141: }
142:
143: /**
144: * Get the default screen module name of the template engine
145: * service corresponding to the template name extension of
146: * the named template.
147: *
148: * @param template The template name.
149: * @return The default screen module name.
150: */
151: public static final String getDefaultScreenName(String template) {
152: return getService().getDefaultScreenName(template);
153: }
154:
155: /**
156: * Get the default layout 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 layout module name.
162: */
163: public static final String getDefaultLayoutName(String template) {
164: return getService().getDefaultLayoutName(template);
165: }
166:
167: /**
168: * Get the default navigation module name of the template engine
169: * service corresponding to the template name extension of
170: * the named template.
171: *
172: * @param template The template name.
173: * @return The default navigation module name.
174: */
175: public static final String getDefaultNavigationName(String template) {
176: return getService().getDefaultNavigationName(template);
177: }
178:
179: /**
180: * Get the default layout template name of the template engine
181: * service corresponding to the template name extension of
182: * the named template.
183: *
184: * @param template The template name.
185: * @return The default layout template name.
186: */
187: public static final String getDefaultLayoutTemplateName(
188: String template) {
189: return getService().getDefaultLayoutTemplateName(template);
190: }
191:
192: /**
193: * Find the default page module name for the given request.
194: *
195: * @param data The encapsulation of the request to retrieve the
196: * default page for.
197: * @return The default page module name.
198: */
199: public static final String getDefaultPageName(RunData data) {
200: return getService().getDefaultPageName(data);
201: }
202:
203: /**
204: * Find the default layout module name for the given request.
205: *
206: * @param data The encapsulation of the request to retrieve the
207: * default layout for.
208: * @return The default layout module name.
209: */
210: public static final String getDefaultLayoutName(RunData data) {
211: return getService().getDefaultLayoutName(data);
212: }
213:
214: /**
215: * Locate and return the name of a Screen module.
216: *
217: * @param name A String with the name of the template.
218: * @return A String with the name of the screen.
219: * @exception Exception, a generic exception.
220: */
221: public static final String getScreenName(String name)
222: throws Exception {
223: return getService().getScreenName(name);
224: }
225:
226: /**
227: * Locate and return the name of the layout module to be used
228: * with the named layout template.
229: *
230: * @param template The layout template name.
231: * @return The found layout module name.
232: * @exception Exception, a generic exception.
233: */
234: public static final String getLayoutName(String template)
235: throws Exception {
236: return getService().getLayoutName(template);
237: }
238:
239: /**
240: * Locate and return the name of the navigation module to be used
241: * with the named navigation template.
242: *
243: * @param template The navigation template name.
244: * @return The found navigation module name.
245: * @exception Exception, a generic exception.
246: */
247: public static final String getNavigationName(String template)
248: throws Exception {
249: return getService().getNavigationName(template);
250: }
251:
252: /**
253: * Locate and return the name of a screen template.
254: *
255: * @param key A String which is the key to the template.
256: * @return A String with the screen template path.
257: * @exception Exception, a generic exception.
258: */
259: public static final String getScreenTemplateName(String key)
260: throws Exception {
261: return getService().getScreenTemplateName(key);
262: }
263:
264: /**
265: * Locate and return the name of a layout template.
266: *
267: * @param name A String with the name of the template.
268: * @return A String with the layout template path.
269: * @exception Exception, a generic exception.
270: */
271: public static final String getLayoutTemplateName(String name)
272: throws Exception {
273: return getService().getLayoutTemplateName(name);
274: }
275:
276: /**
277: * Locate and return the name of a navigation template.
278: *
279: * @param key A String which is the key to the template.
280: * @return A String with the navigation template path.
281: * @exception Exception, a generic exception.
282: */
283: public static final String getNavigationTemplateName(String key)
284: throws Exception {
285: return getService().getNavigationTemplateName(key);
286: }
287:
288: /**
289: * Translates the supplied template paths into their Turbine-canonical
290: * equivalent (probably absolute paths).
291: *
292: * @param templatePaths An array of template paths.
293: * @return An array of translated template paths.
294: * @deprecated Each template engine service should know how to translate
295: * a request onto a file.
296: */
297: public static final String[] translateTemplatePaths(
298: String[] templatePaths) {
299: return getService().translateTemplatePaths(templatePaths);
300: }
301:
302: /**
303: * Delegates to the appropriate {@link
304: * org.apache.turbine.services.template.TemplateEngineService} to
305: * check the existance of the specified template.
306: *
307: * @param template The template to check for the existance of.
308: * @param templatePaths The paths to check for the template.
309: * @deprecated Use templateExists from the various Templating Engines
310: */
311: public static final boolean templateExists(String template,
312: String[] templatePaths) {
313: return getService().templateExists(template, templatePaths);
314: }
315:
316: /**
317: * Registers the provided template engine for use by the
318: * <code>TemplateService</code>.
319: *
320: * @param service The <code>TemplateEngineService</code> to register.
321: */
322: public static final void registerTemplateEngineService(
323: TemplateEngineService service) {
324: getService().registerTemplateEngineService(service);
325: }
326:
327: /**
328: * The {@link org.apache.turbine.services.template.TemplateEngineService}
329: * associated with the specified template's file extension.
330: *
331: * @param template The template name.
332: * @return The template engine service.
333: */
334: public static final TemplateEngineService getTemplateEngineService(
335: String template) {
336: return getService().getTemplateEngineService(template);
337: }
338: }
|