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
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
62 TemplateEngineService tes =
63 TurbineTemplate.getTemplateEngineService(components[components.length - 1]);
64
65 String templatePackage = StringUtils.join(components, String.valueOf(separator));
66
67
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