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