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.TemplateService;
25 import org.apache.turbine.services.template.TurbineTemplate;
26
27 /***
28 * This is a mapper like the BaseMapper but it returns its
29 * results with the extension of the template names passed or (if no
30 * extension is passed), the default extension.
31 *
32 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
33 * @version $Id: BaseTemplateMapper.java 534527 2007-05-02 16:10:59Z tv $
34 */
35
36 public abstract class BaseTemplateMapper
37 extends BaseMapper
38 {
39 /*** A prefix which is used to separate the various template types (screen, layouts, navigation) */
40 protected String prefix = "";
41
42 /***
43 * Default C'tor. If you use this C'tor, you must use
44 * the bean setter to set the various properties needed for
45 * this mapper before first usage.
46 */
47 public BaseTemplateMapper()
48 {
49 super();
50 }
51
52 /***
53 * Get the Prefix value.
54 * @return the Prefix value.
55 */
56 public String getPrefix()
57 {
58 return prefix;
59 }
60
61 /***
62 * Set the Prefix value.
63 * @param prefix The new Prefix value.
64 */
65 public void setPrefix(String prefix)
66 {
67 this.prefix = prefix;
68 }
69
70 /***
71 * Returns the default name for the passed Template.
72 * If the template has no extension, the default extension
73 * is added.
74 * If the template is empty, the default template is
75 * returned.
76 *
77 * @param template The template name.
78 *
79 * @return the mapped default name for the template.
80 */
81 public String getDefaultName(String template)
82 {
83 String res = super.getDefaultName(template);
84
85
86 String [] components
87 = StringUtils.split(res, String.valueOf(separator));
88
89 if (components[components.length -1 ].indexOf(TemplateService.EXTENSION_SEPARATOR) < 0)
90 {
91 StringBuffer resBuf = new StringBuffer();
92 resBuf.append(res);
93 String [] templateComponents = StringUtils.split(template, String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR));
94
95
96 int dotIndex = templateComponents[templateComponents.length -1].lastIndexOf(TemplateService.EXTENSION_SEPARATOR);
97 if (dotIndex < 0)
98 {
99 if (StringUtils.isNotEmpty(TurbineTemplate.getDefaultExtension()))
100 {
101 resBuf.append(TemplateService.EXTENSION_SEPARATOR);
102 resBuf.append(TurbineTemplate.getDefaultExtension());
103 }
104 }
105 else
106 {
107 resBuf.append(templateComponents[templateComponents.length -1].substring(dotIndex));
108 }
109 res = resBuf.toString();
110 }
111 return res;
112 }
113 }