KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > template > BaseTemplateEngineService


1 package org.apache.turbine.services.template;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.util.Hashtable JavaDoc;
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,v 1.11.2.2 2004/05/20 03:06:47 seade Exp $
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 JavaDoc configuration = new Hashtable JavaDoc();
49
50     /**
51      * @see org.apache.turbine.services.template.TemplateEngineService#registerConfiguration
52      */

53     public void registerConfiguration(String JavaDoc 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 JavaDoc getTemplateEngineServiceConfiguration()
63     {
64         return configuration;
65     }
66
67     /**
68      * @see org.apache.turbine.services.template.TemplateEngineService#getAssociatedFileExtensions
69      */

70     public String JavaDoc[] getAssociatedFileExtensions()
71     {
72         return (String JavaDoc[]) 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 JavaDoc defaultExt)
89     {
90         Configuration config = getConfiguration();
91
92         //
93
// Should modify the configuration class to take defaults
94
// here, should have to do this.
95
//
96
String JavaDoc[] fileExtensionAssociations =
97                 config.getStringArray(TEMPLATE_EXTENSIONS);
98
99         if (fileExtensionAssociations == null ||
100             fileExtensionAssociations.length == 0)
101         {
102             fileExtensionAssociations = new String JavaDoc[1];
103             fileExtensionAssociations[0] = config.getString(
104                     DEFAULT_TEMPLATE_EXTENSION, defaultExt);
105         }
106
107         configuration.put(TEMPLATE_EXTENSIONS, fileExtensionAssociations);
108
109         /*
110          * We need some better error checking here and should probably
111          * throw an exception here if these things aren't set
112          * up correctly.
113          */

114
115         String JavaDoc[] 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 JavaDoc template);
135 }
136
Popular Tags