01: /* $Id: ParserFeatureSetterFactory.java 467222 2006-10-24 03:17:11Z markt $
02: *
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
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: package org.apache.tomcat.util.digester;
20:
21: import java.util.Properties;
22:
23: import javax.xml.parsers.ParserConfigurationException;
24: import javax.xml.parsers.SAXParser;
25:
26: import org.xml.sax.SAXException;
27: import org.xml.sax.SAXNotRecognizedException;
28: import org.xml.sax.SAXNotSupportedException;
29:
30: /**
31: * Creates a <code>SAXParser</code> based on the underlying parser.
32: * Allows logical properties depending on logical parser versions
33: * to be set.
34: *
35: * @since 1.6
36: */
37: public class ParserFeatureSetterFactory {
38:
39: /**
40: * <code>true</code> is Xerces is used.
41: */
42: private static boolean isXercesUsed;
43:
44: static {
45: try {
46: // Use reflection to avoid a build dependency with Xerces.
47: Class versionClass = Class
48: .forName("org.apache.xerces.impl.Version");
49: isXercesUsed = true;
50: } catch (Exception ex) {
51: isXercesUsed = false;
52: }
53: }
54:
55: /**
56: * Create a new <code>SAXParser</code>
57: * @param properties (logical) properties to be set on parser
58: * @return a <code>SAXParser</code> configured based on the underlying
59: * parser implementation.
60: */
61: public static SAXParser newSAXParser(Properties properties)
62: throws ParserConfigurationException, SAXException,
63: SAXNotRecognizedException, SAXNotSupportedException {
64:
65: if (isXercesUsed) {
66: return XercesParser.newSAXParser(properties);
67: } else {
68: return GenericParser.newSAXParser(properties);
69: }
70: }
71:
72: }
|