KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > digester > ParserFeatureSetterFactory


1 /* $Id: ParserFeatureSetterFactory.java 179714 2005-06-03 03:53:39Z skitching $
2  *
3  * Copyright 2004 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.commons.digester;
20
21 import java.util.Properties JavaDoc;
22
23 import javax.xml.parsers.ParserConfigurationException JavaDoc;
24 import javax.xml.parsers.SAXParser JavaDoc;
25
26 import org.apache.commons.digester.parser.GenericParser;
27 import org.apache.commons.digester.parser.XercesParser;
28
29 import org.xml.sax.SAXException JavaDoc;
30 import org.xml.sax.SAXNotRecognizedException JavaDoc;
31 import org.xml.sax.SAXNotSupportedException JavaDoc;
32
33 /**
34  * Creates a <code>SAXParser</code> based on the underlying parser.
35  * Allows logical properties depending on logical parser versions
36  * to be set.
37  *
38  * @since 1.6
39  */

40 public class ParserFeatureSetterFactory{
41
42     /**
43      * <code>true</code> is Xerces is used.
44      */

45     private static boolean isXercesUsed;
46
47     static {
48         try{
49             // Use reflection to avoid a build dependency with Xerces.
50
Class JavaDoc versionClass =
51                             Class.forName("org.apache.xerces.impl.Version");
52             isXercesUsed = true;
53         } catch (Exception JavaDoc ex){
54             isXercesUsed = false;
55         }
56     }
57
58     /**
59      * Create a new <code>SAXParser</code>
60      * @param properties (logical) properties to be set on parser
61      * @return a <code>SAXParser</code> configured based on the underlying
62      * parser implementation.
63      */

64     public static SAXParser JavaDoc newSAXParser(Properties JavaDoc properties)
65             throws ParserConfigurationException JavaDoc,
66                    SAXException JavaDoc,
67                    SAXNotRecognizedException JavaDoc,
68                    SAXNotSupportedException JavaDoc {
69
70         if (isXercesUsed){
71             return XercesParser.newSAXParser(properties);
72         } else {
73             return GenericParser.newSAXParser(properties);
74         }
75     }
76
77 }
Popular Tags