KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ecs > ECSDefaults


1 package org.apache.ecs;
2
3 /*
4  * ====================================================================
5  *
6  * The Apache Software License, Version 1.1
7  *
8  * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
9  * reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * 2. Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in
20  * the documentation and/or other materials provided with the
21  * distribution.
22  *
23  * 3. The end-user documentation included with the redistribution, if
24  * any, must include the following acknowlegement:
25  * "This product includes software developed by the
26  * Apache Software Foundation (http://www.apache.org/)."
27  * Alternately, this acknowlegement may appear in the software itself,
28  * if and wherever such third-party acknowlegements normally appear.
29  *
30  * 4. The names "The Jakarta Project", "Jakarta Element Construction Set",
31  * "Jakarta ECS" , and "Apache Software Foundation" must not be used
32  * to endorse or promote products derived
33  * from this software without prior written permission. For written
34  * permission, please contact apache@apache.org.
35  *
36  * 5. Products derived from this software may not be called "Apache",
37  * "Jakarta Element Construction Set" nor "Jakarta ECS" nor may "Apache"
38  * appear in their names without prior written permission of the Apache Group.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
44  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Apache Software Foundation. For more
56  * information on the Apache Software Foundation, please see
57  * <http://www.apache.org/>.
58  *
59  */

60
61 import java.util.ResourceBundle JavaDoc;
62
63 /**
64     This class is responsible for loading the ecs.properties file and
65     getting the default settings for ECS. This allows you to edit a
66     simple text file instead of having to edit the .java files and
67     recompile.
68     The property file can be specified via the 'ecs.properties' system property.
69     For example, java -Decs.properties="my.ecs.properties". If ecs.properties is null
70     then the standard ecs.properties resource in the ECS jar is used.
71     If the property file cannot be loaded, a message is printed to standard
72     error and hard-coded defaults are used instead.
73
74     @version $Id: ECSDefaults.java,v 1.5 2003/04/27 09:43:24 rdonkin Exp $
75 */

76 public final class ECSDefaults
77 {
78     /**
79     This singleton allows the properties to gracefully default in the
80     case of an error.
81     */

82     private static ECSDefaults defaults = new ECSDefaults();
83
84     // now follows the private methods called by the
85
private ResourceBundle JavaDoc resource;
86     
87     // assign original default values in case the props can't be loaded.
88
private boolean filter_state =false;
89     private boolean filter_attribute_state = false;
90     private char attribute_equality_sign = '=';
91     private char begin_start_modifier = ' ';
92     private char end_start_modifier = ' ';
93     private char begin_end_modifier = ' ';
94     private char end_end_modifier = ' ';
95     private char attribute_quote_char = '\"';
96     private boolean attribute_quote = true;
97     private boolean end_element = true;
98     private String JavaDoc codeset = "UTF-8";
99     private int position = 4;
100     private int case_type = 3;
101     private char start_tag = '<';
102     private char end_tag = '>';
103     private boolean pretty_print = false;
104
105     /**
106         Should we filter the value of &lt;&gt;VALUE&lt;/&gt;
107     */

108     public static boolean getDefaultFilterState()
109     {
110         return defaults.filter_state;
111     }
112
113     /**
114         Should we filter the value of the element attributes
115     */

116     public static boolean getDefaultFilterAttributeState()
117     {
118         return defaults.filter_attribute_state;
119     }
120
121     /**
122         What is the equality character for an attribute.
123     */

124     public static char getDefaultAttributeEqualitySign()
125     {
126         return defaults.attribute_equality_sign;
127     }
128
129     /**
130         What the start modifier should be
131     */

132     public static char getDefaultBeginStartModifier()
133     {
134         return defaults.begin_start_modifier;
135     }
136
137     /**
138         What the start modifier should be
139     */

140     public static char getDefaultEndStartModifier()
141     {
142         return defaults.end_start_modifier;
143     }
144
145     /**
146         What the end modifier should be
147     */

148     public static char getDefaultBeginEndModifier()
149     {
150         return defaults.begin_end_modifier;
151     }
152
153     /**
154         What the end modifier should be
155     */

156     public static char getDefaultEndEndModifier()
157     {
158         return defaults.end_end_modifier;
159     }
160
161     /*
162         What character should we use for quoting attributes.
163     */

164     public static char getDefaultAttributeQuoteChar()
165     {
166         return defaults.attribute_quote_char;
167     }
168
169     /*
170         Should we wrap quotes around an attribute?
171     */

172     public static boolean getDefaultAttributeQuote()
173     {
174         return defaults.attribute_quote;
175     }
176
177     /**
178         Does this element need a closing tag?
179     */

180     public static boolean getDefaultEndElement()
181     {
182         return defaults.end_element;
183     }
184
185     /**
186         What codeset are we going to use the default is UTF-8.
187     */

188     public static String JavaDoc getDefaultCodeset()
189     {
190         return defaults.codeset;
191     }
192
193     /**
194         Position of tag relative to start and end.
195     */

196     public static int getDefaultPosition()
197     {
198         return defaults.position;
199     }
200     
201     /**
202         Default value to set case type
203     */

204     public static int getDefaultCaseType()
205     {
206         return defaults.case_type;
207     }
208
209     /**
210         Default start-of-tag character.
211     */

212     public static char getDefaultStartTag()
213     {
214         return defaults.start_tag;
215     }
216
217     /**
218         Default end-of-tag character.
219     */

220     public static char getDefaultEndTag()
221     {
222         return defaults.end_tag;
223     }
224
225     /**
226         Should we print html in a more readable format?
227     */

228     public static boolean getDefaultPrettyPrint()
229     {
230         return defaults.pretty_print;
231     }
232
233     /**
234         This private constructor is used to create the singleton used in the public static methods.
235     */

236     private ECSDefaults ()
237     {
238         try
239         {
240             // if the ecs.properties system property is set, use that
241
String JavaDoc props=System.getProperty("ecs.properties");
242             if (props==null)
243             {
244                 resource = ResourceBundle.getBundle("org.apache.ecs.ecs");
245             } else {
246                 resource = new java.util.PropertyResourceBundle JavaDoc(new java.io.FileInputStream JavaDoc(props));
247             }
248
249             // set up variables
250
filter_state = new Boolean JavaDoc(resource.getString("filter_state")).booleanValue();
251             filter_attribute_state = new Boolean JavaDoc(resource.getString("filter_attribute_state")).booleanValue();
252             attribute_equality_sign = resource.getString("attribute_equality_sign").charAt(1);
253             begin_start_modifier = resource.getString("begin_start_modifier").charAt(1);
254             end_start_modifier = resource.getString("end_start_modifier").charAt(1);
255             begin_end_modifier = resource.getString("begin_end_modifier").charAt(1);
256             end_end_modifier = resource.getString("end_end_modifier").charAt(1);
257             attribute_quote_char = resource.getString("attribute_quote_char").charAt(0);
258             attribute_quote = new Boolean JavaDoc(resource.getString("attribute_quote")).booleanValue();
259             end_element = new Boolean JavaDoc(resource.getString("end_element")).booleanValue();
260             codeset = resource.getString("codeset");
261             position = Integer.parseInt(resource.getString("position"));
262             case_type = Integer.parseInt(resource.getString("case_type"));
263             start_tag = resource.getString("start_tag").charAt(0);
264             end_tag = resource.getString("end_tag").charAt(0);
265             pretty_print = new Boolean JavaDoc(resource.getString("pretty_print")).booleanValue();
266
267         }
268         catch(Exception JavaDoc e)
269         {
270             System.err.println("The following error preventing " +
271                 "ecs.properties being loaded:");
272             System.err.println(e.toString());
273         }
274     }
275     
276     /**
277         This method returns a string showing the current values.
278     */

279     public static String JavaDoc debugString()
280     {
281         return
282             "ECSDefaults:" + '\n'
283             + '\t' + "DefaultFilterState=" + getDefaultFilterState() +'\n'
284             + '\t' + "DefaultFilterAttributeState=" + getDefaultFilterAttributeState() +'\n'
285             + '\t' + "DefaultAttributeEqualitySign='" + getDefaultAttributeEqualitySign() +"'\n"
286             + '\t' + "DefaultBeginStartModifier='" + getDefaultBeginStartModifier() + "'\n"
287             + '\t' + "DefaultEndStartModifier='" + getDefaultEndStartModifier() + "'\n"
288             + '\t' + "DefaultBeginEndModifier='" + getDefaultBeginEndModifier() + "'\n"
289             + '\t' + "DefaultEndEndModifier='" + getDefaultEndEndModifier() + "'\n"
290             + '\t' + "DefaultAttributeQuoteChar=" + getDefaultAttributeQuoteChar() + '\n'
291             + '\t' + "DefaultAttributeQuote=" + getDefaultAttributeQuote() +'\n'
292             + '\t' + "DefaultEndElement=" + getDefaultEndElement() +'\n'
293             + '\t' + "DefaultCodeset='" + getDefaultCodeset() + "'\n"
294             + '\t' + "DefaultPosition=" + getDefaultPosition() +'\n'
295             + '\t' + "DefaultCaseType=" + getDefaultCaseType() +'\n'
296             + '\t' + "DefaultStartTag='" + getDefaultStartTag() + "'\n"
297             + '\t' + "DefaultEndTag='" + getDefaultEndTag() + "'\n"
298             + '\t' + "DefaultPrettyPrint=" + getDefaultPrettyPrint();
299     }
300 }
301
Popular Tags