KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > cofax > TemplateLoader


1 /*
2  * TemplateLoader is part of the Cofax content management system library.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Please see http://www.cofax.org for contact information and other related informaion.
19  *
20  * $Header: /cvsroot/cofax/cofax/src/org/cofax/TemplateLoader.java,v 1.10.2.1 2006/12/11 16:28:43 fxrobin Exp $
21  */

22
23 package org.cofax;
24
25 /**
26  * Cofax's top level template loader class. Cofax compatible template loaders
27  * implement this API. A template loader loads a template from some system and
28  * makes it available for use. Examples of modules that extend this would be<br />
29  * <code>FilesTemplateLoader</code> (loads templates from file system),<br />
30  * <code>DataStoreTemplateLoader</code> (loads templates via the Cofax
31  * <code>DataStore</code> API which fetch from a SQL database (For fetching
32  * directly from the fie system use <code>FilesTemplateLoader</code>
33  * instead.),<br />
34  * <code>UrlTemplateLoader</code>.<br />
35  * Cofax compatible template loaders extend this abstract class.
36  * <p>
37  *
38  * <code>TemplateLoader</code> classes are listed in the configuration and
39  * loaded dynamically.
40  * </p>
41  *
42  * @author Rajiv Pant
43  * @author Karl Martino
44  * @author Lee Bolding
45  * @created April 1, 2002
46  */

47
48 public abstract class TemplateLoader {
49
50     private String JavaDoc defaultIndex = "";
51
52     private String JavaDoc defaultObject = "";
53
54     private String JavaDoc templateRoot = "";
55
56     private String JavaDoc templateSearch = "";
57
58     private int templateMode = 0;
59
60     private int templateSearchLimit = 0;
61
62     /**
63      * Initializes variables.
64      *
65      * @param defaultIndex
66      * The default index template
67      * @param defaultObject
68      * The default object template
69      * @param templateRoot
70      * The root directory of the template tree
71      */

72     public void init(String JavaDoc defaultIndex, String JavaDoc defaultObject, String JavaDoc templateRoot, int templateSwitch, int templateSearchLimit) {
73         this.defaultIndex = defaultIndex;
74         this.defaultObject = defaultObject;
75         this.templateRoot = templateRoot;
76         this.templateSearchLimit = templateSearchLimit;
77     }
78
79     /**
80      * Gets the template mode
81      *
82      * @return The templateMode value
83      */

84     public int getTemplateMode() {
85         return templateMode;
86     }
87
88     /**
89      * Sets the template mode
90      *
91      * @param templateMode
92      * The new templateMode value
93      */

94     public void setTemplateMode(int templateMode) {
95         this.templateMode = templateMode;
96     }
97
98     /**
99      * Gets the template search limit
100      *
101      * @return The templateSearchLimit value
102      */

103     public int getTemplateSearchLimit() {
104         return templateSearchLimit;
105     }
106
107     /**
108      * Sets the template mode
109      *
110      * @param templateMode
111      * The new templateMode value
112      */

113     public void setTemplateSearchLimit(int templateSearchLimit) {
114         this.templateSearchLimit = templateSearchLimit;
115     }
116
117     /**
118      * Gets the template root directory.
119      *
120      * @return The templateRoot value
121      */

122     public String JavaDoc getTemplateRoot() {
123         return templateRoot;
124     }
125
126     /**
127      * Sets the template root directory.
128      *
129      * @param templateRoot
130      * The new templateRoot value
131      */

132     public void setTemplateRoot(String JavaDoc templateRoot) {
133         this.templateRoot = templateRoot;
134     }
135
136     /**
137      * Gets the default index template.
138      *
139      * @return The default index template.
140      */

141     public String JavaDoc getDefaultIndex() {
142         return defaultIndex;
143     }
144
145     /**
146      * Sets the default index template.
147      *
148      * @param defaultIndex
149      * The new default index template.
150      */

151     public void setDefaultIndex(String JavaDoc defaultIndex) {
152         this.defaultIndex = defaultIndex;
153     }
154
155     /**
156      * Gets the default object template.
157      *
158      * @return The default object template.
159      */

160     public String JavaDoc getDefaultObject() {
161         return defaultObject;
162     }
163
164     /**
165      * Sets the default object template.
166      *
167      * @param The
168      * new default object template.
169      */

170     public void setDefaultObject(String JavaDoc defaultObject) {
171         this.defaultObject = defaultObject;
172     }
173
174     /**
175      * Gets the folder to search from
176      *
177      * @return A folder above in the hirearchy from template root
178      */

179     public String JavaDoc getTemplateSearch() {
180         return templateSearch;
181     }
182
183     /**
184      * Sets the folder to search from
185      *
186      * @param templateSearch
187      * A folder above the hirearchy from template root.
188      */

189     public void setTemplateSearch(String JavaDoc templateSearch) {
190         this.templateSearch = templateSearch;
191     }
192
193     public String JavaDoc toString() {
194         return "Instance Of: " + getClass().getName() + "\n" + "defaultIndex: " + defaultIndex + "\n" + "defaultObject: " + defaultObject + "\n"
195                 + "templateRoot: " + templateRoot + "\n" + "templateMode: " + templateMode + "\n" + "templateSearchLimit: " + templateSearchLimit;
196     }
197
198     /**
199      * Determine's the template's ID based upon a search.
200      *
201      * @param templateFile
202      * Description of the Parameter
203      * @param overrideTemplate
204      * Description of the Parameter
205      * @return Description of the Return Value
206      */

207     public abstract String JavaDoc choose(String JavaDoc templateFile, String JavaDoc overrideTemplate, String JavaDoc fileNameExtension);
208
209     /**
210      * Translates a template id into an includable URI
211      *
212      * @param templateId
213      * Description of the Parameter
214      * @param applicationPath
215      * Description of the Parameter
216      * @return The resource value
217      */

218     public abstract String JavaDoc getResource(String JavaDoc templateId, String JavaDoc applicationPath);
219
220     /**
221      * Loads a template.
222      *
223      * @param templateId
224      * Description of the Parameter
225      * @return Description of the Return Value
226      */

227     public abstract CofaxPage load(String JavaDoc templateId);
228
229 }
230 // end abstract class TemplateLoader
231

232
Popular Tags