KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jpublish > template > AbstractTemplateManager


1 /*--
2
3  Copyright (C) 2001-2003 Aetrion LLC.
4  All rights reserved.
5  
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions
8  are met:
9  
10  1. Redistributions of source code must retain the above copyright
11     notice, this list of conditions, and the following disclaimer.
12  
13  2. Redistributions in binary form must reproduce the above copyright
14     notice, this list of conditions, and the disclaimer that follows
15     these conditions in the documentation and/or other materials
16     provided with the distribution.
17
18  3. The name "JPublish" must not be used to endorse or promote products
19     derived from this software without prior written permission. For
20     written permission, please contact info@aetrion.com.
21  
22  4. Products derived from this software may not be called "JPublish", nor
23     may "JPublish" appear in their name, without prior written permission
24     from Aetrion LLC (info@aetrion.com).
25  
26  In addition, the authors of this software request (but do not require)
27  that you include in the end-user documentation provided with the
28  redistribution and/or in the software itself an acknowledgement equivalent
29  to the following:
30      "This product includes software developed by
31       Aetrion LLC (http://www.aetrion.com/)."
32
33  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
34  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36  DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
37  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
39  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
41  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
42  IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43  POSSIBILITY OF SUCH DAMAGE.
44
45  For more information on JPublish, please see <http://www.jpublish.org/>.
46  
47  */

48
49 package org.jpublish.template;
50
51 import java.io.IOException JavaDoc;
52
53 import com.anthonyeden.lib.config.Configuration;
54 import com.anthonyeden.lib.config.ConfigurationException;
55 import org.jpublish.ManagerBase;
56
57 /**
58  * The AbstractRTemplateManager base class can be used as a superclass for template manager implementations. It
59  * provides convenience methods which are standard for all template managers.
60  *
61  * @author Anthony Eden
62  */

63
64 public abstract class AbstractTemplateManager extends ManagerBase
65         implements TemplateManager {
66
67     protected String JavaDoc name = null;
68     protected boolean writeAllowed = false;
69
70     /**
71      * Get a String representation of the content. This method is a convenience method which can be used to quickly
72      * pull template text from a TemplateManager.
73      *
74      * @param path The template path
75      * @return The template String
76      * @throws IOException
77      * @throws TemplateNotFoundException
78      */

79
80     public String JavaDoc get(String JavaDoc path)
81             throws IOException JavaDoc, TemplateNotFoundException {
82         return getTemplate(path).getText();
83     }
84
85     /**
86      * Get the name of the template manager. This name is used to expose the TemplateManager in the view renderer.
87      *
88      * @return The TemplateManager name
89      */

90
91     public String JavaDoc getName() {
92         return name;
93     }
94
95     /**
96      * Set the name of the template manager.
97      *
98      * @param name The name
99      */

100
101     public void setName(String JavaDoc name) {
102         this.name = name;
103     }
104
105     /**
106      * Return true if writing is allowed.
107      *
108      * @return True if write is allowed
109      */

110
111     public boolean isWriteAllowed() {
112         return writeAllowed;
113     }
114
115     /**
116      * Set to true to allow writing.
117      *
118      * @param writeAllowed True to enable writing
119      */

120
121     public void setWriteAllowed(boolean writeAllowed) {
122         this.writeAllowed = writeAllowed;
123     }
124
125     /**
126      * Set to "true" to allow writing.
127      *
128      * @param writeAllowed Set to the String "true" to allow writing
129      */

130
131     public void setWriteAllowed(String JavaDoc writeAllowed) {
132         if (writeAllowed != null) {
133             setWriteAllowed("true".equals(writeAllowed));
134         }
135     }
136
137     /**
138      * Load the template manager configuration.
139      *
140      * @param configuration The Configuration object
141      * @throws ConfigurationException
142      */

143
144     public void loadConfiguration(Configuration configuration)
145             throws ConfigurationException {
146         super.loadConfiguration(configuration);
147         setName(configuration.getAttribute("name"));
148         setWriteAllowed(configuration.getChildValue("write-allowed"));
149     }
150
151 }
152
Popular Tags