01: package org.apache.turbine.services.template.mapper;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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 extends BaseTemplateMapper implements
38: Mapper {
39: /**
40: * Default C'tor. If you use this C'tor, you must use
41: * the bean setter to set the various properties needed for
42: * this mapper before first usage.
43: */
44: public ScreenTemplateMapper() {
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 doMapping(String template) {
55: String[] components = StringUtils.split(template, String
56: .valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR));
57:
58: // Last element decides, which template Service to use...
59: TemplateEngineService tes = TurbineTemplate
60: .getTemplateEngineService(components[components.length - 1]);
61:
62: String templatePackage = StringUtils.join(components, String
63: .valueOf(separator));
64:
65: // But the Templating service must look for the name with prefix
66: StringBuffer testPath = new StringBuffer();
67: if (StringUtils.isNotEmpty(prefix)) {
68: testPath.append(prefix);
69: testPath.append(separator);
70: }
71: testPath.append(templatePackage);
72:
73: return (tes != null && tes.templateExists(testPath.toString())) ? templatePackage
74: : null;
75: }
76: }
|