01: package org.apache.turbine.services.template.mapper;
02:
03: /*
04: * Copyright 2001-2005 The Apache Software Foundation.
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License")
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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 264148 2005-08-29 14:21:04Z henning $
32: */
33:
34: public class ScreenTemplateMapper extends BaseTemplateMapper implements
35: Mapper {
36: /**
37: * Default C'tor. If you use this C'tor, you must use
38: * the bean setter to set the various properties needed for
39: * this mapper before first usage.
40: */
41: public ScreenTemplateMapper() {
42: }
43:
44: /**
45: * Check, whether the provided name exists. Returns null
46: * if the screen does not exist.
47: *
48: * @param template The template name.
49: * @return The matching screen name.
50: */
51: public String doMapping(String template) {
52: String[] components = StringUtils.split(template, String
53: .valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR));
54:
55: // Last element decides, which template Service to use...
56: TemplateEngineService tes = TurbineTemplate
57: .getTemplateEngineService(components[components.length - 1]);
58:
59: String templatePackage = StringUtils.join(components, String
60: .valueOf(separator));
61:
62: // But the Templating service must look for the name with prefix
63: StringBuffer testPath = new StringBuffer();
64: if (StringUtils.isNotEmpty(prefix)) {
65: testPath.append(prefix);
66: testPath.append(separator);
67: }
68: testPath.append(templatePackage);
69:
70: return (tes != null && tes.templateExists(testPath.toString())) ? templatePackage
71: : null;
72: }
73: }
|