KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > util > XMLResourceDescriptor


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

18
19 package org.apache.batik.util;
20
21 import java.io.InputStream JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.util.Properties JavaDoc;
24 import java.util.MissingResourceException JavaDoc;
25
26 /**
27  * This class describes the XML resources needed to use the various batik
28  * modules.
29  *
30  * @author <a HREF="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
31  * @version $Id: XMLResourceDescriptor.java,v 1.6 2004/10/30 18:38:06 deweese Exp $
32  */

33 public class XMLResourceDescriptor {
34
35     /**
36      * The XML parser class name key.
37      */

38     public final static String JavaDoc XML_PARSER_CLASS_NAME_KEY =
39         "org.xml.sax.driver";
40
41     /**
42      * The CSS parser class name key.
43      */

44     public final static String JavaDoc CSS_PARSER_CLASS_NAME_KEY =
45         "org.w3c.css.sac.driver";
46
47     /**
48      * The resources file name
49      */

50     public final static String JavaDoc RESOURCES =
51         "resources/XMLResourceDescriptor.properties";
52
53     /**
54      * The resource bundle
55      */

56     protected static Properties JavaDoc parserProps = null;;
57
58     /**
59      * The class name of the XML parser to use.
60      */

61     protected static String JavaDoc xmlParserClassName;
62
63     /**
64      * The class name of the CSS parser to use.
65      */

66     protected static String JavaDoc cssParserClassName;
67
68     protected static synchronized Properties JavaDoc getParserProps() {
69         if (parserProps != null) return parserProps;
70
71         parserProps = new Properties JavaDoc();
72         try {
73             Class JavaDoc cls = XMLResourceDescriptor.class;
74             InputStream JavaDoc is = cls.getResourceAsStream(RESOURCES);
75             parserProps.load(is);
76         } catch (IOException JavaDoc ioe) {
77             throw new MissingResourceException JavaDoc(ioe.getMessage(),
78                                                RESOURCES, null);
79         }
80         return parserProps;
81     }
82
83     /**
84      * Returns the class name of the XML parser to use.
85      *
86      * <p>This method first checks if any XML parser has been specified using
87      * the <tt>setXMLParserClassName</tt> method. If any, this method will
88      * return the value of the property 'org.xml.sax.driver' specified in the
89      * <tt>resources/XMLResourceDescriptor.properties</tt> resource file.
90      */

91     public static String JavaDoc getXMLParserClassName() {
92         if (xmlParserClassName == null) {
93             xmlParserClassName = getParserProps().getProperty
94                 (XML_PARSER_CLASS_NAME_KEY);
95         }
96         return xmlParserClassName;
97     }
98
99     /**
100      * Sets the class name of the XML parser to use.
101      *
102      * @param xmlParserClassName the classname of the XML parser
103      */

104     public static void setXMLParserClassName(String JavaDoc xmlParserClassName) {
105         XMLResourceDescriptor.xmlParserClassName = xmlParserClassName;
106     }
107
108     /**
109      * Returns the class name of the CSS parser to use.
110      *
111      * <p>This method first checks if any CSS parser has been
112      * specified using the <tt>setCSSParserClassName</tt> method. If
113      * any, this method will return the value of the property
114      * 'org.w3c.css.sac.driver' specified in the
115      * <tt>resources/XMLResourceDescriptor.properties</tt> resource
116      * file.
117      */

118     public static String JavaDoc getCSSParserClassName() {
119         if (cssParserClassName == null) {
120             cssParserClassName = getParserProps().getProperty
121                 (CSS_PARSER_CLASS_NAME_KEY);
122         }
123         return cssParserClassName;
124     }
125
126     /**
127      * Sets the class name of the CSS parser to use.
128      *
129      * @param cssParserClassName the classname of the CSS parser
130      */

131     public static void setCSSParserClassName(String JavaDoc cssParserClassName) {
132         XMLResourceDescriptor.cssParserClassName = cssParserClassName;
133     }
134 }
135
Popular Tags