author | joehw |
Fri, 09 Aug 2013 12:10:41 -0700 | |
changeset 19479 | e4f3adf06beb |
parent 18890 | 25bdeca3173b |
child 20975 | 298d79f9a705 |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
2 |
* reserved comment block |
|
3 |
* DO NOT REMOVE OR ALTER! |
|
4 |
*/ |
|
5 |
/* |
|
6 |
* Copyright 2000-2005 The Apache Software Foundation. |
|
7 |
* |
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
9 |
* you may not use this file except in compliance with the License. |
|
10 |
* You may obtain a copy of the License at |
|
11 |
* |
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13 |
* |
|
14 |
* Unless required by applicable law or agreed to in writing, software |
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17 |
* See the License for the specific language governing permissions and |
|
18 |
* limitations under the License. |
|
19 |
*/ |
|
20 |
||
21 |
package com.sun.org.apache.xerces.internal.parsers; |
|
22 |
||
23 |
import com.sun.org.apache.xerces.internal.impl.Constants; |
|
24 |
import com.sun.org.apache.xerces.internal.util.SymbolTable; |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
25 |
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager; |
12005 | 26 |
import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; |
27 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration; |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
28 |
import org.xml.sax.SAXNotRecognizedException; |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
29 |
import org.xml.sax.SAXNotSupportedException; |
12005 | 30 |
|
31 |
/** |
|
32 |
* This is the main Xerces SAX parser class. It uses the abstract SAX |
|
33 |
* parser with a document scanner, a dtd scanner, and a validator, as |
|
34 |
* well as a grammar pool. |
|
35 |
* |
|
36 |
* @author Arnaud Le Hors, IBM |
|
37 |
* @author Andy Clark, IBM |
|
38 |
* |
|
12458 | 39 |
* @version $Id: SAXParser.java,v 1.7 2010-11-01 04:40:09 joehw Exp $ |
12005 | 40 |
*/ |
41 |
public class SAXParser |
|
42 |
extends AbstractSAXParser { |
|
43 |
||
44 |
// |
|
45 |
// Constants |
|
46 |
// |
|
47 |
||
48 |
// features |
|
49 |
||
50 |
/** Feature identifier: notify built-in refereces. */ |
|
51 |
protected static final String NOTIFY_BUILTIN_REFS = |
|
52 |
Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE; |
|
53 |
||
54 |
protected static final String REPORT_WHITESPACE = |
|
55 |
Constants.SUN_SCHEMA_FEATURE_PREFIX + Constants.SUN_REPORT_IGNORED_ELEMENT_CONTENT_WHITESPACE; |
|
56 |
||
57 |
/** Recognized features. */ |
|
58 |
private static final String[] RECOGNIZED_FEATURES = { |
|
59 |
NOTIFY_BUILTIN_REFS, |
|
60 |
REPORT_WHITESPACE |
|
61 |
}; |
|
62 |
||
63 |
// properties |
|
64 |
||
65 |
/** Property identifier: symbol table. */ |
|
66 |
protected static final String SYMBOL_TABLE = |
|
67 |
Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; |
|
68 |
||
69 |
/** Property identifier: XML grammar pool. */ |
|
70 |
protected static final String XMLGRAMMAR_POOL = |
|
71 |
Constants.XERCES_PROPERTY_PREFIX+Constants.XMLGRAMMAR_POOL_PROPERTY; |
|
72 |
||
73 |
/** Recognized properties. */ |
|
74 |
private static final String[] RECOGNIZED_PROPERTIES = { |
|
75 |
SYMBOL_TABLE, |
|
76 |
XMLGRAMMAR_POOL, |
|
77 |
}; |
|
78 |
||
19479
e4f3adf06beb
8022548: SPECJVM2008 has errors introduced in 7u40-b34
joehw
parents:
18890
diff
changeset
|
79 |
XMLSecurityPropertyManager securityPropertyManager; |
12005 | 80 |
// |
81 |
// Constructors |
|
82 |
// |
|
83 |
||
84 |
/** |
|
85 |
* Constructs a SAX parser using the specified parser configuration. |
|
86 |
*/ |
|
87 |
public SAXParser(XMLParserConfiguration config) { |
|
88 |
super(config); |
|
89 |
} // <init>(XMLParserConfiguration) |
|
90 |
||
91 |
/** |
|
92 |
* Constructs a SAX parser using the dtd/xml schema parser configuration. |
|
93 |
*/ |
|
94 |
public SAXParser() { |
|
95 |
this(null, null); |
|
96 |
} // <init>() |
|
97 |
||
98 |
/** |
|
99 |
* Constructs a SAX parser using the specified symbol table. |
|
100 |
*/ |
|
101 |
public SAXParser(SymbolTable symbolTable) { |
|
102 |
this(symbolTable, null); |
|
103 |
} // <init>(SymbolTable) |
|
104 |
||
105 |
/** |
|
106 |
* Constructs a SAX parser using the specified symbol table and |
|
107 |
* grammar pool. |
|
108 |
*/ |
|
109 |
public SAXParser(SymbolTable symbolTable, XMLGrammarPool grammarPool) { |
|
12458 | 110 |
super(new XIncludeAwareParserConfiguration()); |
12005 | 111 |
|
112 |
// set features |
|
113 |
fConfiguration.addRecognizedFeatures(RECOGNIZED_FEATURES); |
|
114 |
fConfiguration.setFeature(NOTIFY_BUILTIN_REFS, true); |
|
115 |
||
116 |
// set properties |
|
117 |
fConfiguration.addRecognizedProperties(RECOGNIZED_PROPERTIES); |
|
118 |
if (symbolTable != null) { |
|
119 |
fConfiguration.setProperty(SYMBOL_TABLE, symbolTable); |
|
120 |
} |
|
121 |
if (grammarPool != null) { |
|
122 |
fConfiguration.setProperty(XMLGRAMMAR_POOL, grammarPool); |
|
123 |
} |
|
124 |
||
125 |
} // <init>(SymbolTable,XMLGrammarPool) |
|
126 |
||
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
127 |
/** |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
128 |
* Sets the particular property in the underlying implementation of |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
129 |
* org.xml.sax.XMLReader. |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
130 |
*/ |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
131 |
public void setProperty(String name, Object value) |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
132 |
throws SAXNotRecognizedException, SAXNotSupportedException { |
19479
e4f3adf06beb
8022548: SPECJVM2008 has errors introduced in 7u40-b34
joehw
parents:
18890
diff
changeset
|
133 |
if (securityPropertyManager == null) { |
e4f3adf06beb
8022548: SPECJVM2008 has errors introduced in 7u40-b34
joehw
parents:
18890
diff
changeset
|
134 |
securityPropertyManager = new XMLSecurityPropertyManager(); |
e4f3adf06beb
8022548: SPECJVM2008 has errors introduced in 7u40-b34
joehw
parents:
18890
diff
changeset
|
135 |
} |
e4f3adf06beb
8022548: SPECJVM2008 has errors introduced in 7u40-b34
joehw
parents:
18890
diff
changeset
|
136 |
int index = securityPropertyManager.getIndex(name); |
e4f3adf06beb
8022548: SPECJVM2008 has errors introduced in 7u40-b34
joehw
parents:
18890
diff
changeset
|
137 |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
138 |
if (index > -1) { |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
139 |
/** |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
140 |
* this is a direct call to this parser, not a subclass since |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
141 |
* internally the support of this property is done through |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
142 |
* XMLSecurityPropertyManager |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
143 |
*/ |
19479
e4f3adf06beb
8022548: SPECJVM2008 has errors introduced in 7u40-b34
joehw
parents:
18890
diff
changeset
|
144 |
securityPropertyManager.setValue(index, XMLSecurityPropertyManager.State.APIPROPERTY, (String)value); |
e4f3adf06beb
8022548: SPECJVM2008 has errors introduced in 7u40-b34
joehw
parents:
18890
diff
changeset
|
145 |
super.setProperty(Constants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager); |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
146 |
} else { |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
147 |
super.setProperty(name, value); |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
148 |
} |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
149 |
} |
12005 | 150 |
} // class SAXParser |