KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tomcat > util > digester > ParserFeatureSetterFactory


1 /* $Id: ParserFeatureSetterFactory.java 467222 2006-10-24 03:17:11Z markt $
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19
20 package org.apache.tomcat.util.digester;
21
22 import java.util.Properties JavaDoc;
23
24 import javax.xml.parsers.ParserConfigurationException JavaDoc;
25 import javax.xml.parsers.SAXParser JavaDoc;
26
27 import org.xml.sax.SAXException JavaDoc;
28 import org.xml.sax.SAXNotRecognizedException JavaDoc;
29 import org.xml.sax.SAXNotSupportedException JavaDoc;
30
31 /**
32  * Creates a <code>SAXParser</code> based on the underlying parser.
33  * Allows logical properties depending on logical parser versions
34  * to be set.
35  *
36  * @since 1.6
37  */

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

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

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