View Javadoc

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