1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. 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 package org.apache.xerces.parsers;
19
20 import org.apache.xerces.impl.Constants;
21 import org.apache.xerces.util.SymbolTable;
22 import org.apache.xerces.xni.grammars.XMLGrammarPool;
23 import org.apache.xerces.xni.parser.XMLParserConfiguration;
24
25 /**
26 * This is the main Xerces SAX parser class. It uses the abstract SAX
27 * parser with a document scanner, a dtd scanner, and a validator, as
28 * well as a grammar pool.
29 *
30 * @author Arnaud Le Hors, IBM
31 * @author Andy Clark, IBM
32 *
33 * @version $Id: SAXParser.java 447239 2006-09-18 05:08:26Z mrglavas $
34 */
35 public class SAXParser
36 extends AbstractSAXParser {
37
38 //
39 // Constants
40 //
41
42 // features
43
44 /** Feature identifier: notify built-in refereces. */
45 protected static final String NOTIFY_BUILTIN_REFS =
46 Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE;
47
48 /** Recognized features. */
49 private static final String[] RECOGNIZED_FEATURES = {
50 NOTIFY_BUILTIN_REFS,
51 };
52
53 // properties
54
55 /** Property identifier: symbol table. */
56 protected static final String SYMBOL_TABLE =
57 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;
58
59 /** Property identifier: XML grammar pool. */
60 protected static final String XMLGRAMMAR_POOL =
61 Constants.XERCES_PROPERTY_PREFIX+Constants.XMLGRAMMAR_POOL_PROPERTY;
62
63 /** Recognized properties. */
64 private static final String[] RECOGNIZED_PROPERTIES = {
65 SYMBOL_TABLE,
66 XMLGRAMMAR_POOL,
67 };
68
69 //
70 // Constructors
71 //
72
73 /**
74 * Constructs a SAX parser using the specified parser configuration.
75 */
76 public SAXParser(XMLParserConfiguration config) {
77 super(config);
78 } // <init>(XMLParserConfiguration)
79
80 /**
81 * Constructs a SAX parser using the dtd/xml schema parser configuration.
82 */
83 public SAXParser() {
84 this(null, null);
85 } // <init>()
86
87 /**
88 * Constructs a SAX parser using the specified symbol table.
89 */
90 public SAXParser(SymbolTable symbolTable) {
91 this(symbolTable, null);
92 } // <init>(SymbolTable)
93
94 /**
95 * Constructs a SAX parser using the specified symbol table and
96 * grammar pool.
97 */
98 public SAXParser(SymbolTable symbolTable, XMLGrammarPool grammarPool) {
99 super((XMLParserConfiguration)ObjectFactory.createObject(
100 "org.apache.xerces.xni.parser.XMLParserConfiguration",
101 "org.apache.xerces.parsers.XIncludeAwareParserConfiguration"
102 ));
103
104 // set features
105 fConfiguration.addRecognizedFeatures(RECOGNIZED_FEATURES);
106 fConfiguration.setFeature(NOTIFY_BUILTIN_REFS, true);
107
108 // set properties
109 fConfiguration.addRecognizedProperties(RECOGNIZED_PROPERTIES);
110 if (symbolTable != null) {
111 fConfiguration.setProperty(SYMBOL_TABLE, symbolTable);
112 }
113 if (grammarPool != null) {
114 fConfiguration.setProperty(XMLGRAMMAR_POOL, grammarPool);
115 }
116
117 } // <init>(SymbolTable,XMLGrammarPool)
118
119 } // class SAXParser