    001package org.apache.turbine.services.template;
    002
    003
    004/*
    005 * Licensed to the Apache Software Foundation (ASF) under one
    006 * or more contributor license agreements.  See the NOTICE file
    007 * distributed with this work for additional information
    008 * regarding copyright ownership.  The ASF licenses this file
    009 * to you under the Apache License, Version 2.0 (the
    010 * "License"); you may not use this file except in compliance
    011 * with the License.  You may obtain a copy of the License at
    012 *
    013 *   http://www.apache.org/licenses/LICENSE-2.0
    014 *
    015 * Unless required by applicable law or agreed to in writing,
    016 * software distributed under the License is distributed on an
    017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    018 * KIND, either express or implied.  See the License for the
    019 * specific language governing permissions and limitations
    020 * under the License.
    021 */
    022
    023
    024import org.apache.turbine.pipeline.PipelineData;
    025import org.apache.turbine.services.TurbineServices;
    026
    027/**
    028 * This is a simple static accessor to common TemplateService tasks such as
    029 * getting a Screen that is associated with a screen template.
    030 *
    031 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
    032 * @version $Id: TurbineTemplate.java 1709648 2015-10-20 17:08:10Z tv $
    033 */
    034public abstract class TurbineTemplate
    035{
    036    /**
    037     * Utility method for accessing the service
    038     * implementation
    039     *
    040     * @return a TemplateService implementation instance
    041     */
    042    public static TemplateService getService()
    043    {
    044        return (TemplateService) TurbineServices
    045            .getInstance().getService(TemplateService.SERVICE_NAME);
    046    }
    047
    048    /**
    049     * Returns true if the Template Service has caching activated
    050     *
    051     * @return true if Caching is active.
    052     */
    053    public static final boolean isCaching()
    054    {
    055        return getService().isCaching();
    056    }
    057
    058    /**
    059     * Get the default extension given in the properties file.
    060     *
    061     * @return A String with the extension.
    062     */
    063    public static final String getDefaultExtension()
    064    {
    065        return getService().getDefaultExtension();
    066    }
    067
    068    /**
    069     * Return Extension for a supplied template
    070     *
    071     * @param template The template name
    072     *
    073     * @return extension The extension for the supplied template
    074     */
    075    public static final String getExtension(String template)
    076    {
    077        return getService().getExtension(template);
    078    }
    079
    080    /**
    081     * Returns the Default Template Name with the Default Extension.
    082     * If the extension is unset, return only the template name
    083     *
    084     * @return The default template Name
    085     */
    086    public static final String getDefaultTemplate()
    087    {
    088        return getService().getDefaultTemplate();
    089    }
    090
    091    /**
    092     * Get the default page module name of the template engine
    093     * service corresponding to the default template name extension.
    094     *
    095     * @return The default page module name.
    096     */
    097    public static final String getDefaultPage()
    098    {
    099        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}