View Javadoc

1   package org.apache.turbine.services.template.mapper;
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.commons.lang.StringUtils;
23  
24  import org.apache.turbine.services.template.TemplateEngineService;
25  import org.apache.turbine.services.template.TemplateService;
26  import org.apache.turbine.services.template.TurbineTemplate;
27  
28  /***
29   * This is a pretty simple mapper which returns template pathes for
30   * a supplied template name. This path can be used by the TemplateEngine
31   * to access a certain resource to actually render the template.
32   *
33   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
34   * @version $Id: ScreenTemplateMapper.java 534527 2007-05-02 16:10:59Z tv $
35   */
36  
37  public class ScreenTemplateMapper
38      extends BaseTemplateMapper
39      implements Mapper
40  {
41      /***
42       * Default C'tor. If you use this C'tor, you must use
43       * the bean setter to set the various properties needed for
44       * this mapper before first usage.
45       */
46      public ScreenTemplateMapper()
47      {
48      }
49  
50      /***
51       * Check, whether the provided name exists. Returns null
52       * if the screen does not exist.
53       *
54       * @param template The template name.
55       * @return The matching screen name.
56       */
57      public String doMapping(String template)
58      {
59          String [] components = StringUtils.split(template, String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR));
60  
61          // Last element decides, which template Service to use...
62          TemplateEngineService tes =
63              TurbineTemplate.getTemplateEngineService(components[components.length - 1]);
64  
65          String templatePackage = StringUtils.join(components, String.valueOf(separator));
66  
67          // But the Templating service must look for the name with prefix
68          StringBuffer testPath = new StringBuffer();
69          if (StringUtils.isNotEmpty(prefix))
70          {
71              testPath.append(prefix);
72              testPath.append(separator);
73          }
74          testPath.append(templatePackage);
75  
76          return (tes != null && tes.templateExists(testPath.toString()))
77              ? templatePackage
78              : null;
79      }
80  }
81  
82  
83  
84