author | joehw |
Tue, 20 Aug 2013 09:02:25 -0700 | |
changeset 20973 | cc1cc8eb501b |
parent 20968 | dde41f8b7b96 |
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; |
|
20968 | 25 |
import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager; |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
26 |
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager; |
12005 | 27 |
import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; |
28 |
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
|
29 |
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
|
30 |
import org.xml.sax.SAXNotSupportedException; |
12005 | 31 |
|
32 |
/** |
|
33 |
* This is the main Xerces SAX parser class. It uses the abstract SAX |
|
34 |
* parser with a document scanner, a dtd scanner, and a validator, as |
|
35 |
* well as a grammar pool. |
|
36 |
* |
|
37 |
* @author Arnaud Le Hors, IBM |
|
38 |
* @author Andy Clark, IBM |
|
39 |
* |
|
12458 | 40 |
* @version $Id: SAXParser.java,v 1.7 2010-11-01 04:40:09 joehw Exp $ |
12005 | 41 |
*/ |
42 |
public class SAXParser |
|
43 |
extends AbstractSAXParser { |
|
44 |
||
45 |
// |
|
46 |
// Constants |
|
47 |
// |
|
48 |
||
49 |
// features |
|
50 |
||
51 |
/** Feature identifier: notify built-in refereces. */ |
|
52 |
protected static final String NOTIFY_BUILTIN_REFS = |
|
53 |
Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE; |
|
54 |
||
55 |
protected static final String REPORT_WHITESPACE = |
|
56 |
Constants.SUN_SCHEMA_FEATURE_PREFIX + Constants.SUN_REPORT_IGNORED_ELEMENT_CONTENT_WHITESPACE; |
|
57 |
||
58 |
/** Recognized features. */ |
|
59 |
private static final String[] RECOGNIZED_FEATURES = { |
|
60 |
NOTIFY_BUILTIN_REFS, |
|
61 |
REPORT_WHITESPACE |
|
62 |
}; |
|
63 |
||
64 |
// properties |
|
65 |
||
66 |
/** Property identifier: symbol table. */ |
|
67 |
protected static final String SYMBOL_TABLE = |
|
68 |
Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; |
|
69 |
||
70 |
/** Property identifier: XML grammar pool. */ |
|
71 |
protected static final String XMLGRAMMAR_POOL = |
|
72 |
Constants.XERCES_PROPERTY_PREFIX+Constants.XMLGRAMMAR_POOL_PROPERTY; |
|
73 |
||
74 |
/** Recognized properties. */ |
|
75 |
private static final String[] RECOGNIZED_PROPERTIES = { |
|
76 |
SYMBOL_TABLE, |
|
77 |
XMLGRAMMAR_POOL, |
|
78 |
}; |
|
79 |
||
20973 | 80 |
|
12005 | 81 |
// |
82 |
// Constructors |
|
83 |
// |
|
84 |
||
85 |
/** |
|
86 |
* Constructs a SAX parser using the specified parser configuration. |
|
87 |
*/ |
|
88 |
public SAXParser(XMLParserConfiguration config) { |
|
89 |
super(config); |
|
90 |
} // <init>(XMLParserConfiguration) |
|
91 |
||
92 |
/** |
|
93 |
* Constructs a SAX parser using the dtd/xml schema parser configuration. |
|
94 |
*/ |
|
95 |
public SAXParser() { |
|
96 |
this(null, null); |
|
97 |
} // <init>() |
|
98 |
||
99 |
/** |
|
100 |
* Constructs a SAX parser using the specified symbol table. |
|
101 |
*/ |
|
102 |
public SAXParser(SymbolTable symbolTable) { |
|
103 |
this(symbolTable, null); |
|
104 |
} // <init>(SymbolTable) |
|
105 |
||
106 |
/** |
|
107 |
* Constructs a SAX parser using the specified symbol table and |
|
108 |
* grammar pool. |
|
109 |
*/ |
|
110 |
public SAXParser(SymbolTable symbolTable, XMLGrammarPool grammarPool) { |
|
12458 | 111 |
super(new XIncludeAwareParserConfiguration()); |
12005 | 112 |
|
113 |
// set features |
|
114 |
fConfiguration.addRecognizedFeatures(RECOGNIZED_FEATURES); |
|
115 |
fConfiguration.setFeature(NOTIFY_BUILTIN_REFS, true); |
|
116 |
||
117 |
// set properties |
|
118 |
fConfiguration.addRecognizedProperties(RECOGNIZED_PROPERTIES); |
|
119 |
if (symbolTable != null) { |
|
120 |
fConfiguration.setProperty(SYMBOL_TABLE, symbolTable); |
|
121 |
} |
|
122 |
if (grammarPool != null) { |
|
123 |
fConfiguration.setProperty(XMLGRAMMAR_POOL, grammarPool); |
|
124 |
} |
|
125 |
||
126 |
} // <init>(SymbolTable,XMLGrammarPool) |
|
127 |
||
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
128 |
/** |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
129 |
* 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
|
130 |
* org.xml.sax.XMLReader. |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
131 |
*/ |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
132 |
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
|
133 |
throws SAXNotRecognizedException, SAXNotSupportedException { |
20973 | 134 |
/** |
135 |
* It's possible for users to set a security manager through the interface. |
|
136 |
* If it's the old SecurityManager, convert it to the new XMLSecurityManager |
|
137 |
*/ |
|
138 |
if (name.equals(Constants.SECURITY_MANAGER)) { |
|
139 |
securityManager = XMLSecurityManager.convert(value, securityManager); |
|
140 |
super.setProperty(Constants.SECURITY_MANAGER, securityManager); |
|
141 |
return; |
|
142 |
} |
|
143 |
if (name.equals(Constants.XML_SECURITY_PROPERTY_MANAGER)) { |
|
144 |
if (value == null) { |
|
145 |
securityPropertyManager = new XMLSecurityPropertyManager(); |
|
146 |
} else { |
|
147 |
securityPropertyManager = (XMLSecurityPropertyManager)value; |
|
148 |
} |
|
149 |
super.setProperty(Constants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager); |
|
150 |
return; |
|
151 |
} |
|
152 |
||
153 |
if (securityManager == null) { |
|
154 |
securityManager = new XMLSecurityManager(true); |
|
155 |
super.setProperty(Constants.SECURITY_MANAGER, securityManager); |
|
156 |
} |
|
157 |
||
20968 | 158 |
if (securityPropertyManager == null) { |
159 |
securityPropertyManager = new XMLSecurityPropertyManager(); |
|
20973 | 160 |
super.setProperty(Constants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager); |
20968 | 161 |
} |
20973 | 162 |
|
20968 | 163 |
int index = securityPropertyManager.getIndex(name); |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
164 |
if (index > -1) { |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
165 |
/** |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
166 |
* 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
|
167 |
* 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
|
168 |
* XMLSecurityPropertyManager |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
169 |
*/ |
20968 | 170 |
securityPropertyManager.setValue(index, XMLSecurityPropertyManager.State.APIPROPERTY, (String)value); |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
171 |
} else { |
20968 | 172 |
//check if the property is managed by security manager |
20973 | 173 |
if (!securityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, value)) { |
174 |
//fall back to the default configuration to handle the property |
|
20968 | 175 |
super.setProperty(name, value); |
176 |
} |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
177 |
} |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
12458
diff
changeset
|
178 |
} |
12005 | 179 |
} // class SAXParser |