KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > template > mapper > ScreenTemplateMapper


1 package org.apache.turbine.services.template.mapper;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.commons.lang.StringUtils;
20
21 import org.apache.turbine.services.template.TemplateEngineService;
22 import org.apache.turbine.services.template.TemplateService;
23 import org.apache.turbine.services.template.TurbineTemplate;
24
25 /**
26  * This is a pretty simple mapper which returns template pathes for
27  * a supplied template name. This path can be used by the TemplateEngine
28  * to access a certain resource to actually render the template.
29  *
30  * @author <a HREF="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
31  * @version $Id: ScreenTemplateMapper.java,v 1.1.2.2 2004/05/20 03:06:48 seade Exp $
32  */

33
34 public class ScreenTemplateMapper
35     extends BaseTemplateMapper
36     implements Mapper
37 {
38     /**
39      * Default C'tor. If you use this C'tor, you must use
40      * the bean setter to set the various properties needed for
41      * this mapper before first usage.
42      */

43     public ScreenTemplateMapper()
44     {
45     }
46
47     /**
48      * Check, whether the provided name exists. Returns null
49      * if the screen does not exist.
50      *
51      * @param template The template name.
52      * @return The matching screen name.
53      */

54     public String JavaDoc doMapping(String JavaDoc template)
55     {
56         String JavaDoc [] components = StringUtils.split(template, String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR));
57
58         // Last element decides, which template Service to use...
59
TemplateEngineService tes =
60             TurbineTemplate.getTemplateEngineService(components[components.length - 1]);
61
62         String JavaDoc templatePackage = StringUtils.join(components, String.valueOf(separator));
63
64         // But the Templating service must look for the name with prefix
65
StringBuffer JavaDoc testPath = new StringBuffer JavaDoc();
66         if (StringUtils.isNotEmpty(prefix))
67         {
68             testPath.append(prefix);
69             testPath.append(separator);
70         }
71         testPath.append(templatePackage);
72
73         return (tes != null && tes.templateExists(testPath.toString()))
74             ? templatePackage
75             : null;
76     }
77 }
78
79
80
81
82
Popular Tags