1 package org.apache.turbine.services.template;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Hashtable;
23
24 import org.apache.commons.configuration.Configuration;
25
26 import org.apache.turbine.services.TurbineBaseService;
27
28 /***
29 * The base implementation of Turbine {@link
30 * org.apache.turbine.services.template.TemplateEngineService}.
31 *
32 * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
33 * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
34 * @version $Id: BaseTemplateEngineService.java 534527 2007-05-02 16:10:59Z tv $
35 */
36 public abstract class BaseTemplateEngineService
37 extends TurbineBaseService
38 implements TemplateEngineService
39 {
40 /***
41 * A Map containing the configuration for the template
42 * engine service. The configuration contains:
43 *
44 * 1) template extensions
45 * 2) default page
46 * 3) default screen
47 * 4) default layout
48 * 5) default navigation
49 * 6) default error screen
50 */
51 private Hashtable configuration = new Hashtable();
52
53 /***
54 * @see org.apache.turbine.services.template.TemplateEngineService#registerConfiguration
55 */
56 public void registerConfiguration(String defaultExt)
57 {
58 initConfiguration(defaultExt);
59 TurbineTemplate.registerTemplateEngineService(this);
60 }
61
62 /***
63 * @see org.apache.turbine.services.template.TemplateEngineService#getTemplateEngineServiceConfiguration
64 */
65 public Hashtable getTemplateEngineServiceConfiguration()
66 {
67 return configuration;
68 }
69
70 /***
71 * @see org.apache.turbine.services.template.TemplateEngineService#getAssociatedFileExtensions
72 */
73 public String[] getAssociatedFileExtensions()
74 {
75 return (String[]) configuration.get(TEMPLATE_EXTENSIONS);
76 }
77
78 /***
79 * Initialize the Template Engine Service.
80 *
81 * Note engine file extension associations. First attempts to
82 * pull a list of custom extensions from the property file value
83 * keyed by <code>template.extension</code>. If none are defined,
84 * uses the value keyed by
85 * <code>template.default.extension</code>, defaulting to the
86 * emergency value supplied by <code>defaultExt</code>.
87 *
88 * @param defaultExt The default used when the default defined in the
89 * properties file is missing or misconfigured.
90 */
91 protected void initConfiguration(String defaultExt)
92 {
93 Configuration config = getConfiguration();
94
95
96
97
98
99 String[] fileExtensionAssociations =
100 config.getStringArray(TEMPLATE_EXTENSIONS);
101
102 if (fileExtensionAssociations == null ||
103 fileExtensionAssociations.length == 0)
104 {
105 fileExtensionAssociations = new String[1];
106 fileExtensionAssociations[0] = config.getString(
107 DEFAULT_TEMPLATE_EXTENSION, defaultExt);
108 }
109
110 configuration.put(TEMPLATE_EXTENSIONS, fileExtensionAssociations);
111
112
113
114
115
116
117
118 String[] copyParams = {
119 DEFAULT_PAGE,
120 DEFAULT_SCREEN,
121 DEFAULT_LAYOUT,
122 DEFAULT_NAVIGATION,
123 DEFAULT_ERROR_SCREEN,
124 DEFAULT_LAYOUT_TEMPLATE,
125 DEFAULT_SCREEN_TEMPLATE
126 };
127
128 for (int i = 0; i < copyParams.length; i++)
129 {
130 configuration.put(copyParams[i], config.getString(copyParams[i], ""));
131 }
132 }
133
134 /***
135 * @see org.apache.turbine.services.template.TemplateEngineService#templateExists
136 */
137 public abstract boolean templateExists(String template);
138 }