author | joehw |
Mon, 13 Oct 2014 14:09:03 -0700 | |
changeset 27111 | 7a491d709b83 |
parent 26257 | 4ec17c54acb3 |
child 34463 | c269a10aca11 |
permissions | -rw-r--r-- |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1 |
/* |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2 |
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved. |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3 |
*/ |
12005 | 4 |
/* |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
5 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
6 |
* contributor license agreements. See the NOTICE file distributed with |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
7 |
* this work for additional information regarding copyright ownership. |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
8 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
9 |
* (the "License"); you may not use this file except in compliance with |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
10 |
* the License. You may obtain a copy of the License at |
12005 | 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.jaxp.validation; |
|
22 |
||
23 |
import java.util.HashMap; |
|
24 |
import java.util.Locale; |
|
25 |
import java.util.Iterator; |
|
26 |
import java.util.Map; |
|
27 |
||
28 |
import javax.xml.XMLConstants; |
|
29 |
||
30 |
import com.sun.org.apache.xerces.internal.impl.Constants; |
|
31 |
import com.sun.org.apache.xerces.internal.impl.XMLEntityManager; |
|
32 |
import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter; |
|
33 |
import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager; |
|
34 |
import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator; |
|
35 |
import com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter; |
|
36 |
import com.sun.org.apache.xerces.internal.util.DOMEntityResolverWrapper; |
|
37 |
import com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper; |
|
38 |
import com.sun.org.apache.xerces.internal.util.FeatureState; |
|
39 |
import com.sun.org.apache.xerces.internal.util.NamespaceSupport; |
|
40 |
import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings; |
|
41 |
import com.sun.org.apache.xerces.internal.util.PropertyState; |
|
42 |
import com.sun.org.apache.xerces.internal.util.Status; |
|
43 |
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:
17534
diff
changeset
|
44 |
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager; |
20964 | 45 |
import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager; |
12005 | 46 |
import com.sun.org.apache.xerces.internal.xni.NamespaceContext; |
47 |
import com.sun.org.apache.xerces.internal.xni.XNIException; |
|
48 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent; |
|
49 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; |
|
50 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; |
|
51 |
import org.w3c.dom.ls.LSResourceResolver; |
|
52 |
import org.xml.sax.ErrorHandler; |
|
53 |
||
54 |
/** |
|
55 |
* <p>An implementation of XMLComponentManager for a schema validator.</p> |
|
56 |
* |
|
57 |
* @author Michael Glavassevich, IBM |
|
58 |
*/ |
|
59 |
final class XMLSchemaValidatorComponentManager extends ParserConfigurationSettings implements |
|
60 |
XMLComponentManager { |
|
61 |
||
62 |
// feature identifiers |
|
63 |
||
64 |
/** Feature identifier: schema validation. */ |
|
65 |
private static final String SCHEMA_VALIDATION = |
|
66 |
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE; |
|
67 |
||
68 |
/** Feature identifier: validation. */ |
|
69 |
private static final String VALIDATION = |
|
70 |
Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; |
|
71 |
||
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
72 |
/** Feature identifier: use grammar pool only. */ |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
73 |
private static final String USE_GRAMMAR_POOL_ONLY = |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
74 |
Constants.XERCES_FEATURE_PREFIX + Constants.USE_GRAMMAR_POOL_ONLY_FEATURE; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
75 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
76 |
/** Feature identifier: whether to ignore xsi:type attributes until a global element declaration is encountered */ |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
77 |
protected static final String IGNORE_XSI_TYPE = |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
78 |
Constants.XERCES_FEATURE_PREFIX + Constants.IGNORE_XSI_TYPE_FEATURE; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
79 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
80 |
/** Feature identifier: whether to ignore ID/IDREF errors */ |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
81 |
protected static final String ID_IDREF_CHECKING = |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
82 |
Constants.XERCES_FEATURE_PREFIX + Constants.ID_IDREF_CHECKING_FEATURE; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
83 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
84 |
/** Feature identifier: whether to ignore unparsed entity errors */ |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
85 |
protected static final String UNPARSED_ENTITY_CHECKING = |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
86 |
Constants.XERCES_FEATURE_PREFIX + Constants.UNPARSED_ENTITY_CHECKING_FEATURE; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
87 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
88 |
/** Feature identifier: whether to ignore identity constraint errors */ |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
89 |
protected static final String IDENTITY_CONSTRAINT_CHECKING = |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
90 |
Constants.XERCES_FEATURE_PREFIX + Constants.IDC_CHECKING_FEATURE; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
91 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
92 |
/** Feature identifier: disallow DOCTYPE declaration */ |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
93 |
private static final String DISALLOW_DOCTYPE_DECL_FEATURE = |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
94 |
Constants.XERCES_FEATURE_PREFIX + Constants.DISALLOW_DOCTYPE_DECL_FEATURE; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
95 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
96 |
/** Feature identifier: expose schema normalized value */ |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
97 |
private static final String NORMALIZE_DATA = |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
98 |
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
99 |
|
12005 | 100 |
/** Feature identifier: send element default value via characters() */ |
101 |
private static final String SCHEMA_ELEMENT_DEFAULT = |
|
102 |
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT; |
|
103 |
||
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
104 |
/** Feature identifier: augment PSVI */ |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
105 |
private static final String SCHEMA_AUGMENT_PSVI = |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
106 |
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI; |
12005 | 107 |
|
108 |
// property identifiers |
|
109 |
||
110 |
/** Property identifier: entity manager. */ |
|
111 |
private static final String ENTITY_MANAGER = |
|
112 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; |
|
113 |
||
114 |
/** Property identifier: entity resolver. */ |
|
115 |
private static final String ENTITY_RESOLVER = |
|
116 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; |
|
117 |
||
118 |
/** Property identifier: error handler. */ |
|
119 |
private static final String ERROR_HANDLER = |
|
120 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY; |
|
121 |
||
122 |
/** Property identifier: error reporter. */ |
|
123 |
private static final String ERROR_REPORTER = |
|
124 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; |
|
125 |
||
126 |
/** Property identifier: namespace context. */ |
|
127 |
private static final String NAMESPACE_CONTEXT = |
|
128 |
Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_CONTEXT_PROPERTY; |
|
129 |
||
130 |
/** Property identifier: XML Schema validator. */ |
|
131 |
private static final String SCHEMA_VALIDATOR = |
|
132 |
Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY; |
|
133 |
||
134 |
/** Property identifier: security manager. */ |
|
135 |
private static final String SECURITY_MANAGER = |
|
136 |
Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY; |
|
137 |
||
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
138 |
/** Property identifier: security property manager. */ |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
139 |
private static final String XML_SECURITY_PROPERTY_MANAGER = |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
140 |
Constants.XML_SECURITY_PROPERTY_MANAGER; |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
141 |
|
12005 | 142 |
/** Property identifier: symbol table. */ |
143 |
private static final String SYMBOL_TABLE = |
|
144 |
Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; |
|
145 |
||
146 |
/** Property identifier: validation manager. */ |
|
147 |
private static final String VALIDATION_MANAGER = |
|
148 |
Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY; |
|
149 |
||
150 |
/** Property identifier: grammar pool. */ |
|
151 |
private static final String XMLGRAMMAR_POOL = |
|
152 |
Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; |
|
153 |
||
154 |
/** Property identifier: locale. */ |
|
155 |
private static final String LOCALE = |
|
156 |
Constants.XERCES_PROPERTY_PREFIX + Constants.LOCALE_PROPERTY; |
|
157 |
||
158 |
// |
|
159 |
// Data |
|
160 |
// |
|
161 |
/** |
|
162 |
* <p>State of secure mode.</p> |
|
163 |
*/ |
|
164 |
private boolean _isSecureMode = false; |
|
165 |
||
166 |
/** |
|
167 |
* fConfigUpdated is set to true if there has been any change to the configuration settings, |
|
168 |
* i.e a feature or a property was changed. |
|
169 |
*/ |
|
170 |
private boolean fConfigUpdated = true; |
|
171 |
||
172 |
/** |
|
173 |
* Tracks whether the validator should use components from |
|
174 |
* the grammar pool to the exclusion of all others. |
|
175 |
*/ |
|
176 |
private boolean fUseGrammarPoolOnly; |
|
177 |
||
178 |
/** Lookup map for components required for validation. **/ |
|
179 |
private final HashMap fComponents = new HashMap(); |
|
180 |
||
181 |
// |
|
182 |
// Components |
|
183 |
// |
|
184 |
||
185 |
/** Entity manager. */ |
|
186 |
private XMLEntityManager fEntityManager; |
|
187 |
||
188 |
/** Error reporter. */ |
|
189 |
private XMLErrorReporter fErrorReporter; |
|
190 |
||
191 |
/** Namespace context. */ |
|
192 |
private NamespaceContext fNamespaceContext; |
|
193 |
||
194 |
/** XML Schema validator. */ |
|
195 |
private XMLSchemaValidator fSchemaValidator; |
|
196 |
||
197 |
/** Validation manager. */ |
|
198 |
private ValidationManager fValidationManager; |
|
199 |
||
200 |
// |
|
201 |
// Configuration |
|
202 |
// |
|
203 |
||
204 |
/** Stores initial feature values for validator reset. */ |
|
205 |
private final HashMap fInitFeatures = new HashMap(); |
|
206 |
||
207 |
/** Stores initial property values for validator reset. */ |
|
208 |
private final HashMap fInitProperties = new HashMap(); |
|
209 |
||
210 |
/** Stores the initial security manager. */ |
|
20968 | 211 |
private XMLSecurityManager fInitSecurityManager; |
12005 | 212 |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
213 |
/** Stores the initial security property manager. */ |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
214 |
private final XMLSecurityPropertyManager fSecurityPropertyMgr; |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
215 |
|
12005 | 216 |
// |
217 |
// User Objects |
|
218 |
// |
|
219 |
||
220 |
/** Application's ErrorHandler. **/ |
|
221 |
private ErrorHandler fErrorHandler = null; |
|
222 |
||
223 |
/** Application's LSResourceResolver. */ |
|
224 |
private LSResourceResolver fResourceResolver = null; |
|
225 |
||
226 |
/** Locale chosen by the application. */ |
|
227 |
private Locale fLocale = null; |
|
228 |
||
229 |
/** Constructs a component manager suitable for Xerces' schema validator. */ |
|
230 |
public XMLSchemaValidatorComponentManager(XSGrammarPoolContainer grammarContainer) { |
|
231 |
// setup components |
|
232 |
fEntityManager = new XMLEntityManager(); |
|
233 |
fComponents.put(ENTITY_MANAGER, fEntityManager); |
|
234 |
||
235 |
fErrorReporter = new XMLErrorReporter(); |
|
236 |
fComponents.put(ERROR_REPORTER, fErrorReporter); |
|
237 |
||
238 |
fNamespaceContext = new NamespaceSupport(); |
|
239 |
fComponents.put(NAMESPACE_CONTEXT, fNamespaceContext); |
|
240 |
||
241 |
fSchemaValidator = new XMLSchemaValidator(); |
|
242 |
fComponents.put(SCHEMA_VALIDATOR, fSchemaValidator); |
|
243 |
||
244 |
fValidationManager = new ValidationManager(); |
|
245 |
fComponents.put(VALIDATION_MANAGER, fValidationManager); |
|
246 |
||
247 |
// setup other properties |
|
248 |
fComponents.put(ENTITY_RESOLVER, null); |
|
249 |
fComponents.put(ERROR_HANDLER, null); |
|
250 |
||
251 |
fComponents.put(SYMBOL_TABLE, new SymbolTable()); |
|
252 |
||
253 |
// setup grammar pool |
|
254 |
fComponents.put(XMLGRAMMAR_POOL, grammarContainer.getGrammarPool()); |
|
255 |
fUseGrammarPoolOnly = grammarContainer.isFullyComposed(); |
|
256 |
||
257 |
// add schema message formatter to error reporter |
|
258 |
fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, new XSMessageFormatter()); |
|
259 |
||
260 |
// add all recognized features and properties and apply their defaults |
|
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
261 |
final String [] recognizedFeatures = { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
262 |
DISALLOW_DOCTYPE_DECL_FEATURE, |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
263 |
NORMALIZE_DATA, |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
264 |
SCHEMA_ELEMENT_DEFAULT, |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
265 |
SCHEMA_AUGMENT_PSVI |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
266 |
}; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
267 |
addRecognizedFeatures(recognizedFeatures); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
268 |
fFeatures.put(DISALLOW_DOCTYPE_DECL_FEATURE, Boolean.FALSE); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
269 |
fFeatures.put(NORMALIZE_DATA, Boolean.FALSE); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
270 |
fFeatures.put(SCHEMA_ELEMENT_DEFAULT, Boolean.FALSE); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
271 |
fFeatures.put(SCHEMA_AUGMENT_PSVI, Boolean.TRUE); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
272 |
|
12005 | 273 |
addRecognizedParamsAndSetDefaults(fEntityManager, grammarContainer); |
274 |
addRecognizedParamsAndSetDefaults(fErrorReporter, grammarContainer); |
|
275 |
addRecognizedParamsAndSetDefaults(fSchemaValidator, grammarContainer); |
|
276 |
||
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
277 |
/* TODO: are other XMLSchemaValidator default values never set? |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
278 |
* Initial investigation indicates that they aren't set, but |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
279 |
* that they all have default values of false, so it works out |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
280 |
* anyway -PM |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
281 |
*/ |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
282 |
fFeatures.put(IGNORE_XSI_TYPE, Boolean.FALSE); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
283 |
fFeatures.put(ID_IDREF_CHECKING, Boolean.TRUE); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
284 |
fFeatures.put(IDENTITY_CONSTRAINT_CHECKING, Boolean.TRUE); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
285 |
fFeatures.put(UNPARSED_ENTITY_CHECKING, Boolean.TRUE); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
286 |
|
20968 | 287 |
boolean secureProcessing = grammarContainer.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING); |
288 |
if (System.getSecurityManager() != null) { |
|
289 |
_isSecureMode = true; |
|
290 |
secureProcessing = true; |
|
12005 | 291 |
} |
20968 | 292 |
|
293 |
fInitSecurityManager = (XMLSecurityManager) |
|
294 |
grammarContainer.getProperty(SECURITY_MANAGER); |
|
295 |
if (fInitSecurityManager != null ) { |
|
296 |
fInitSecurityManager.setSecureProcessing(secureProcessing); |
|
297 |
} else { |
|
298 |
fInitSecurityManager = new XMLSecurityManager(secureProcessing); |
|
12005 | 299 |
} |
20968 | 300 |
|
301 |
setProperty(SECURITY_MANAGER, fInitSecurityManager); |
|
12005 | 302 |
|
17534 | 303 |
//pass on properties set on SchemaFactory |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
304 |
fSecurityPropertyMgr = (XMLSecurityPropertyManager) |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
305 |
grammarContainer.getProperty(Constants.XML_SECURITY_PROPERTY_MANAGER); |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
306 |
setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr); |
12005 | 307 |
} |
308 |
||
309 |
/** |
|
310 |
* Returns the state of a feature. |
|
311 |
* |
|
312 |
* @param featureId The feature identifier. |
|
313 |
* @return true if the feature is supported |
|
314 |
* |
|
315 |
* @throws XMLConfigurationException Thrown for configuration error. |
|
316 |
* In general, components should |
|
317 |
* only throw this exception if |
|
318 |
* it is <strong>really</strong> |
|
319 |
* a critical error. |
|
320 |
*/ |
|
321 |
public FeatureState getFeatureState(String featureId) |
|
322 |
throws XMLConfigurationException { |
|
323 |
if (PARSER_SETTINGS.equals(featureId)) { |
|
324 |
return FeatureState.is(fConfigUpdated); |
|
325 |
} |
|
326 |
else if (VALIDATION.equals(featureId) || SCHEMA_VALIDATION.equals(featureId)) { |
|
327 |
return FeatureState.is(true); |
|
328 |
} |
|
329 |
else if (USE_GRAMMAR_POOL_ONLY.equals(featureId)) { |
|
330 |
return FeatureState.is(fUseGrammarPoolOnly); |
|
331 |
} |
|
332 |
else if (XMLConstants.FEATURE_SECURE_PROCESSING.equals(featureId)) { |
|
20968 | 333 |
return FeatureState.is(fInitSecurityManager.isSecureProcessing()); |
12005 | 334 |
} |
335 |
else if (SCHEMA_ELEMENT_DEFAULT.equals(featureId)) { |
|
336 |
return FeatureState.is(true); //pre-condition: VALIDATION and SCHEMA_VALIDATION are always true |
|
337 |
} |
|
338 |
return super.getFeatureState(featureId); |
|
339 |
} |
|
340 |
||
341 |
/** |
|
342 |
* Set the state of a feature. |
|
343 |
* |
|
344 |
* @param featureId The unique identifier (URI) of the feature. |
|
345 |
* @param state The requested state of the feature (true or false). |
|
346 |
* |
|
347 |
* @exception XMLConfigurationException If the requested feature is not known. |
|
348 |
*/ |
|
349 |
public void setFeature(String featureId, boolean value) throws XMLConfigurationException { |
|
350 |
if (PARSER_SETTINGS.equals(featureId)) { |
|
351 |
throw new XMLConfigurationException(Status.NOT_SUPPORTED, featureId); |
|
352 |
} |
|
353 |
else if (value == false && (VALIDATION.equals(featureId) || SCHEMA_VALIDATION.equals(featureId))) { |
|
354 |
throw new XMLConfigurationException(Status.NOT_SUPPORTED, featureId); |
|
355 |
} |
|
356 |
else if (USE_GRAMMAR_POOL_ONLY.equals(featureId) && value != fUseGrammarPoolOnly) { |
|
357 |
throw new XMLConfigurationException(Status.NOT_SUPPORTED, featureId); |
|
358 |
} |
|
359 |
if (XMLConstants.FEATURE_SECURE_PROCESSING.equals(featureId)) { |
|
360 |
if (_isSecureMode && !value) { |
|
361 |
throw new XMLConfigurationException(Status.NOT_ALLOWED, XMLConstants.FEATURE_SECURE_PROCESSING); |
|
362 |
} |
|
20968 | 363 |
|
364 |
fInitSecurityManager.setSecureProcessing(value); |
|
365 |
setProperty(SECURITY_MANAGER, fInitSecurityManager); |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
366 |
|
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
367 |
if (value && Constants.IS_JDK8_OR_ABOVE) { |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
368 |
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD, |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
369 |
XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP); |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
370 |
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA, |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
371 |
XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP); |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
372 |
setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr); |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
373 |
} |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
374 |
|
12005 | 375 |
return; |
376 |
} |
|
377 |
fConfigUpdated = true; |
|
378 |
fEntityManager.setFeature(featureId, value); |
|
379 |
fErrorReporter.setFeature(featureId, value); |
|
380 |
fSchemaValidator.setFeature(featureId, value); |
|
381 |
if (!fInitFeatures.containsKey(featureId)) { |
|
382 |
boolean current = super.getFeature(featureId); |
|
383 |
fInitFeatures.put(featureId, current ? Boolean.TRUE : Boolean.FALSE); |
|
384 |
} |
|
385 |
super.setFeature(featureId, value); |
|
386 |
} |
|
387 |
||
388 |
/** |
|
389 |
* Returns the value of a property. |
|
390 |
* |
|
391 |
* @param propertyId The property identifier. |
|
392 |
* @return the value of the property |
|
393 |
* |
|
394 |
* @throws XMLConfigurationException Thrown for configuration error. |
|
395 |
* In general, components should |
|
396 |
* only throw this exception if |
|
397 |
* it is <strong>really</strong> |
|
398 |
* a critical error. |
|
399 |
*/ |
|
400 |
public PropertyState getPropertyState(String propertyId) |
|
401 |
throws XMLConfigurationException { |
|
402 |
if (LOCALE.equals(propertyId)) { |
|
403 |
return PropertyState.is(getLocale()); |
|
404 |
} |
|
405 |
final Object component = fComponents.get(propertyId); |
|
406 |
if (component != null) { |
|
407 |
return PropertyState.is(component); |
|
408 |
} |
|
409 |
else if (fComponents.containsKey(propertyId)) { |
|
410 |
return PropertyState.is(null); |
|
411 |
} |
|
412 |
return super.getPropertyState(propertyId); |
|
413 |
} |
|
414 |
||
415 |
/** |
|
416 |
* Sets the state of a property. |
|
417 |
* |
|
418 |
* @param propertyId The unique identifier (URI) of the property. |
|
419 |
* @param value The requested state of the property. |
|
420 |
* |
|
421 |
* @exception XMLConfigurationException If the requested property is not known. |
|
422 |
*/ |
|
423 |
public void setProperty(String propertyId, Object value) throws XMLConfigurationException { |
|
424 |
if ( ENTITY_MANAGER.equals(propertyId) || ERROR_REPORTER.equals(propertyId) || |
|
425 |
NAMESPACE_CONTEXT.equals(propertyId) || SCHEMA_VALIDATOR.equals(propertyId) || |
|
426 |
SYMBOL_TABLE.equals(propertyId) || VALIDATION_MANAGER.equals(propertyId) || |
|
427 |
XMLGRAMMAR_POOL.equals(propertyId)) { |
|
428 |
throw new XMLConfigurationException(Status.NOT_SUPPORTED, propertyId); |
|
429 |
} |
|
430 |
fConfigUpdated = true; |
|
431 |
fEntityManager.setProperty(propertyId, value); |
|
432 |
fErrorReporter.setProperty(propertyId, value); |
|
433 |
fSchemaValidator.setProperty(propertyId, value); |
|
434 |
if (ENTITY_RESOLVER.equals(propertyId) || ERROR_HANDLER.equals(propertyId) || |
|
435 |
SECURITY_MANAGER.equals(propertyId)) { |
|
436 |
fComponents.put(propertyId, value); |
|
437 |
return; |
|
438 |
} |
|
439 |
else if (LOCALE.equals(propertyId)) { |
|
440 |
setLocale((Locale) value); |
|
441 |
fComponents.put(propertyId, value); |
|
442 |
return; |
|
443 |
} |
|
20968 | 444 |
//check if the property is managed by security manager |
445 |
if (fInitSecurityManager == null || |
|
446 |
!fInitSecurityManager.setLimit(propertyId, XMLSecurityManager.State.APIPROPERTY, value)) { |
|
447 |
//check if the property is managed by security property manager |
|
448 |
if (fSecurityPropertyMgr == null || |
|
449 |
!fSecurityPropertyMgr.setValue(propertyId, XMLSecurityPropertyManager.State.APIPROPERTY, value)) { |
|
450 |
//fall back to the existing property manager |
|
451 |
if (!fInitProperties.containsKey(propertyId)) { |
|
452 |
fInitProperties.put(propertyId, super.getProperty(propertyId)); |
|
453 |
} |
|
454 |
super.setProperty(propertyId, value); |
|
455 |
} |
|
12005 | 456 |
} |
457 |
} |
|
458 |
||
459 |
/** |
|
460 |
* Adds all of the component's recognized features and properties |
|
461 |
* to the list of default recognized features and properties, and |
|
462 |
* sets default values on the configuration for features and |
|
463 |
* properties which were previously absent from the configuration. |
|
464 |
* |
|
465 |
* @param component The component whose recognized features |
|
466 |
* and properties will be added to the configuration |
|
467 |
*/ |
|
468 |
public void addRecognizedParamsAndSetDefaults(XMLComponent component, XSGrammarPoolContainer grammarContainer) { |
|
469 |
||
470 |
// register component's recognized features |
|
471 |
final String[] recognizedFeatures = component.getRecognizedFeatures(); |
|
472 |
addRecognizedFeatures(recognizedFeatures); |
|
473 |
||
474 |
// register component's recognized properties |
|
475 |
final String[] recognizedProperties = component.getRecognizedProperties(); |
|
476 |
addRecognizedProperties(recognizedProperties); |
|
477 |
||
478 |
// set default values |
|
479 |
setFeatureDefaults(component, recognizedFeatures, grammarContainer); |
|
480 |
setPropertyDefaults(component, recognizedProperties); |
|
481 |
} |
|
482 |
||
483 |
/** Calls reset on each of the components owned by this component manager. **/ |
|
484 |
public void reset() throws XNIException { |
|
485 |
fNamespaceContext.reset(); |
|
486 |
fValidationManager.reset(); |
|
487 |
fEntityManager.reset(this); |
|
488 |
fErrorReporter.reset(this); |
|
489 |
fSchemaValidator.reset(this); |
|
490 |
// Mark configuration as fixed. |
|
491 |
fConfigUpdated = false; |
|
492 |
} |
|
493 |
||
494 |
void setErrorHandler(ErrorHandler errorHandler) { |
|
495 |
fErrorHandler = errorHandler; |
|
496 |
setProperty(ERROR_HANDLER, (errorHandler != null) ? new ErrorHandlerWrapper(errorHandler) : |
|
497 |
new ErrorHandlerWrapper(DraconianErrorHandler.getInstance())); |
|
498 |
} |
|
499 |
||
500 |
ErrorHandler getErrorHandler() { |
|
501 |
return fErrorHandler; |
|
502 |
} |
|
503 |
||
504 |
void setResourceResolver(LSResourceResolver resourceResolver) { |
|
505 |
fResourceResolver = resourceResolver; |
|
506 |
setProperty(ENTITY_RESOLVER, new DOMEntityResolverWrapper(resourceResolver)); |
|
507 |
} |
|
508 |
||
509 |
LSResourceResolver getResourceResolver() { |
|
510 |
return fResourceResolver; |
|
511 |
} |
|
512 |
||
513 |
void setLocale(Locale locale) { |
|
514 |
fLocale = locale; |
|
515 |
fErrorReporter.setLocale(locale); |
|
516 |
} |
|
517 |
||
518 |
Locale getLocale() { |
|
519 |
return fLocale; |
|
520 |
} |
|
521 |
||
522 |
/** Cleans out configuration, restoring it to its initial state. */ |
|
523 |
void restoreInitialState() { |
|
524 |
fConfigUpdated = true; |
|
525 |
||
526 |
// Remove error resolver and error handler |
|
527 |
fComponents.put(ENTITY_RESOLVER, null); |
|
528 |
fComponents.put(ERROR_HANDLER, null); |
|
529 |
||
530 |
// Set the Locale back to null. |
|
531 |
setLocale(null); |
|
532 |
fComponents.put(LOCALE, null); |
|
533 |
||
534 |
// Restore initial security manager |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
535 |
fInitSecurityManager.setSecureProcessing(true); |
12005 | 536 |
fComponents.put(SECURITY_MANAGER, fInitSecurityManager); |
537 |
||
538 |
// Set the Locale back to null. |
|
539 |
setLocale(null); |
|
540 |
fComponents.put(LOCALE, null); |
|
541 |
||
542 |
// Reset feature and property values to their initial values |
|
543 |
if (!fInitFeatures.isEmpty()) { |
|
544 |
Iterator iter = fInitFeatures.entrySet().iterator(); |
|
545 |
while (iter.hasNext()) { |
|
546 |
Map.Entry entry = (Map.Entry) iter.next(); |
|
547 |
String name = (String) entry.getKey(); |
|
548 |
boolean value = ((Boolean) entry.getValue()).booleanValue(); |
|
549 |
super.setFeature(name, value); |
|
550 |
} |
|
551 |
fInitFeatures.clear(); |
|
552 |
} |
|
553 |
if (!fInitProperties.isEmpty()) { |
|
554 |
Iterator iter = fInitProperties.entrySet().iterator(); |
|
555 |
while (iter.hasNext()) { |
|
556 |
Map.Entry entry = (Map.Entry) iter.next(); |
|
557 |
String name = (String) entry.getKey(); |
|
558 |
Object value = entry.getValue(); |
|
559 |
super.setProperty(name, value); |
|
560 |
} |
|
561 |
fInitProperties.clear(); |
|
562 |
} |
|
563 |
} |
|
564 |
||
565 |
/** Sets feature defaults for the given component on this configuration. */ |
|
566 |
private void setFeatureDefaults(final XMLComponent component, |
|
567 |
final String [] recognizedFeatures, XSGrammarPoolContainer grammarContainer) { |
|
568 |
if (recognizedFeatures != null) { |
|
569 |
for (int i = 0; i < recognizedFeatures.length; ++i) { |
|
570 |
String featureId = recognizedFeatures[i]; |
|
571 |
Boolean state = grammarContainer.getFeature(featureId); |
|
572 |
if (state == null) { |
|
573 |
state = component.getFeatureDefault(featureId); |
|
574 |
} |
|
575 |
if (state != null) { |
|
576 |
// Do not overwrite values already set on the configuration. |
|
577 |
if (!fFeatures.containsKey(featureId)) { |
|
578 |
fFeatures.put(featureId, state); |
|
579 |
// For newly added components who recognize this feature |
|
580 |
// but did not offer a default value, we need to make |
|
581 |
// sure these components will get an opportunity to read |
|
582 |
// the value before parsing begins. |
|
583 |
fConfigUpdated = true; |
|
584 |
} |
|
585 |
} |
|
586 |
} |
|
587 |
} |
|
588 |
} |
|
589 |
||
590 |
/** Sets property defaults for the given component on this configuration. */ |
|
591 |
private void setPropertyDefaults(final XMLComponent component, final String [] recognizedProperties) { |
|
592 |
if (recognizedProperties != null) { |
|
593 |
for (int i = 0; i < recognizedProperties.length; ++i) { |
|
594 |
String propertyId = recognizedProperties[i]; |
|
595 |
Object value = component.getPropertyDefault(propertyId); |
|
596 |
if (value != null) { |
|
597 |
// Do not overwrite values already set on the configuration. |
|
598 |
if (!fProperties.containsKey(propertyId)) { |
|
599 |
fProperties.put(propertyId, value); |
|
600 |
// For newly added components who recognize this property |
|
601 |
// but did not offer a default value, we need to make |
|
602 |
// sure these components will get an opportunity to read |
|
603 |
// the value before parsing begins. |
|
604 |
fConfigUpdated = true; |
|
605 |
} |
|
606 |
} |
|
607 |
} |
|
608 |
} |
|
609 |
} |
|
610 |
||
611 |
} // XMLSchemaValidatorComponentManager |