1 package org.apache.turbine.services.template.mapper;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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 doMapping(String template)
55 {
56 String [] components = StringUtils.split(template, String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR));
57
58
59 TemplateEngineService tes =
60 TurbineTemplate.getTemplateEngineService(components[components.length - 1]);
61
62 String templatePackage = StringUtils.join(components, String.valueOf(separator));
63
64
65 StringBuffer testPath = new StringBuffer();
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