author | joehw |
Wed, 04 Oct 2017 10:54:18 -0700 | |
changeset 47312 | d4f959806fe9 |
parent 47216 | 71c04702a3d5 |
child 47359 | e1a6c0168741 |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
47312 | 2 |
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. |
3 |
* @LastModified: Sep 2017 |
|
12005 | 4 |
*/ |
5 |
/* |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
7 |
* contributor license agreements. See the NOTICE file distributed with |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
8 |
* this work for additional information regarding copyright ownership. |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
9 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
10 |
* (the "License"); you may not use this file except in compliance with |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
11 |
* the License. You may obtain a copy of the License at |
12005 | 12 |
* |
13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
14 |
* |
|
15 |
* Unless required by applicable law or agreed to in writing, software |
|
16 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
18 |
* See the License for the specific language governing permissions and |
|
19 |
* limitations under the License. |
|
20 |
*/ |
|
21 |
||
22 |
package com.sun.org.apache.xerces.internal.dom; |
|
23 |
||
24 |
import com.sun.org.apache.xerces.internal.impl.Constants; |
|
25 |
import com.sun.org.apache.xerces.internal.impl.XMLEntityManager; |
|
26 |
import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter; |
|
27 |
import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory; |
|
28 |
import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; |
|
29 |
import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager; |
|
30 |
import com.sun.org.apache.xerces.internal.util.DOMEntityResolverWrapper; |
|
31 |
import com.sun.org.apache.xerces.internal.util.DOMErrorHandlerWrapper; |
|
32 |
import com.sun.org.apache.xerces.internal.util.MessageFormatter; |
|
33 |
import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings; |
|
17534 | 34 |
import com.sun.org.apache.xerces.internal.util.PropertyState; |
12005 | 35 |
import com.sun.org.apache.xerces.internal.util.SymbolTable; |
17534 | 36 |
import com.sun.org.apache.xerces.internal.utils.ObjectFactory; |
20968 | 37 |
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:
17534
diff
changeset
|
38 |
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager; |
12005 | 39 |
import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler; |
40 |
import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler; |
|
41 |
import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; |
|
42 |
import com.sun.org.apache.xerces.internal.xni.XNIException; |
|
43 |
import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; |
|
44 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent; |
|
45 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; |
|
46 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; |
|
47 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver; |
|
48 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler; |
|
49 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; |
|
50 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration; |
|
17534 | 51 |
import java.io.IOException; |
52 |
import java.util.ArrayList; |
|
53 |
import java.util.HashMap; |
|
54 |
import java.util.Locale; |
|
39907 | 55 |
import javax.xml.XMLConstants; |
56 |
import javax.xml.catalog.CatalogFeatures; |
|
57 |
import jdk.xml.internal.JdkXmlUtils; |
|
17534 | 58 |
import org.w3c.dom.DOMConfiguration; |
59 |
import org.w3c.dom.DOMErrorHandler; |
|
12005 | 60 |
import org.w3c.dom.DOMException; |
17534 | 61 |
import org.w3c.dom.DOMStringList; |
12005 | 62 |
import org.w3c.dom.ls.LSResourceResolver; |
63 |
||
64 |
||
20968 | 65 |
|
12005 | 66 |
/** |
67 |
* Xerces implementation of DOMConfiguration that maintains a table of recognized parameters. |
|
68 |
* |
|
69 |
* @xerces.internal |
|
70 |
* |
|
71 |
* @author Elena Litani, IBM |
|
72 |
* @author Neeraj Bajaj, Sun Microsystems. |
|
73 |
*/ |
|
74 |
public class DOMConfigurationImpl extends ParserConfigurationSettings |
|
75 |
implements XMLParserConfiguration, DOMConfiguration { |
|
76 |
||
77 |
// |
|
78 |
// Constants |
|
79 |
// |
|
80 |
||
81 |
// feature identifiers |
|
82 |
||
83 |
/** Feature identifier: validation. */ |
|
84 |
protected static final String XERCES_VALIDATION = |
|
85 |
Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; |
|
86 |
||
87 |
/** Feature identifier: namespaces. */ |
|
88 |
protected static final String XERCES_NAMESPACES = |
|
89 |
Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE; |
|
90 |
||
91 |
protected static final String SCHEMA = |
|
92 |
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE; |
|
93 |
||
94 |
protected static final String SCHEMA_FULL_CHECKING = |
|
95 |
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING; |
|
96 |
||
97 |
protected static final String DYNAMIC_VALIDATION = |
|
98 |
Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE; |
|
99 |
||
100 |
protected static final String NORMALIZE_DATA = |
|
101 |
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE; |
|
102 |
||
103 |
/** sending psvi in the pipeline */ |
|
104 |
protected static final String SEND_PSVI = |
|
105 |
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI; |
|
106 |
||
107 |
protected final static String DTD_VALIDATOR_FACTORY_PROPERTY = |
|
108 |
Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY; |
|
109 |
||
110 |
/** Feature identifier: namespace growth */ |
|
111 |
protected static final String NAMESPACE_GROWTH = |
|
112 |
Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACE_GROWTH_FEATURE; |
|
113 |
||
114 |
protected static final String TOLERATE_DUPLICATES = |
|
115 |
Constants.XERCES_FEATURE_PREFIX + Constants.TOLERATE_DUPLICATES_FEATURE; |
|
116 |
||
117 |
// property identifiers |
|
118 |
||
119 |
/** Property identifier: entity manager. */ |
|
120 |
protected static final String ENTITY_MANAGER = |
|
121 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; |
|
122 |
||
123 |
/** Property identifier: error reporter. */ |
|
124 |
protected static final String ERROR_REPORTER = |
|
125 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; |
|
126 |
||
127 |
/** Property identifier: xml string. */ |
|
128 |
protected static final String XML_STRING = |
|
129 |
Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY; |
|
130 |
||
131 |
/** Property identifier: symbol table. */ |
|
132 |
protected static final String SYMBOL_TABLE = |
|
133 |
Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; |
|
134 |
||
135 |
/** Property id: Grammar pool*/ |
|
136 |
protected static final String GRAMMAR_POOL = |
|
137 |
Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; |
|
138 |
||
139 |
/** Property identifier: error handler. */ |
|
140 |
protected static final String ERROR_HANDLER = |
|
141 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY; |
|
142 |
||
143 |
/** Property identifier: entity resolver. */ |
|
144 |
protected static final String ENTITY_RESOLVER = |
|
145 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; |
|
146 |
||
147 |
/** Property identifier: JAXP schema language / DOM schema-type. */ |
|
148 |
protected static final String JAXP_SCHEMA_LANGUAGE = |
|
149 |
Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE; |
|
150 |
||
151 |
/** Property identifier: JAXP schema source/ DOM schema-location. */ |
|
152 |
protected static final String JAXP_SCHEMA_SOURCE = |
|
153 |
Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE; |
|
154 |
||
155 |
protected static final String VALIDATION_MANAGER = |
|
156 |
Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY; |
|
157 |
||
158 |
/** Property identifier: Schema DV Factory */ |
|
159 |
protected static final String SCHEMA_DV_FACTORY = |
|
160 |
Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_DV_FACTORY_PROPERTY; |
|
161 |
||
20968 | 162 |
/** Property identifier: Security manager. */ |
163 |
private static final String SECURITY_MANAGER = Constants.SECURITY_MANAGER; |
|
164 |
||
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
165 |
/** 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
|
166 |
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
|
167 |
Constants.XML_SECURITY_PROPERTY_MANAGER; |
17534 | 168 |
|
12005 | 169 |
// |
170 |
// Data |
|
171 |
// |
|
172 |
XMLDocumentHandler fDocumentHandler; |
|
173 |
||
174 |
/** Normalization features*/ |
|
175 |
protected short features = 0; |
|
176 |
||
177 |
protected final static short NAMESPACES = 0x1<<0; |
|
178 |
protected final static short DTNORMALIZATION = 0x1<<1; |
|
179 |
protected final static short ENTITIES = 0x1<<2; |
|
180 |
protected final static short CDATA = 0x1<<3; |
|
181 |
protected final static short SPLITCDATA = 0x1<<4; |
|
182 |
protected final static short COMMENTS = 0x1<<5; |
|
183 |
protected final static short VALIDATE = 0x1<<6; |
|
184 |
protected final static short PSVI = 0x1<<7; |
|
185 |
protected final static short WELLFORMED = 0x1<<8; |
|
186 |
protected final static short NSDECL = 0x1<<9; |
|
187 |
||
188 |
protected final static short INFOSET_TRUE_PARAMS = NAMESPACES | COMMENTS | WELLFORMED | NSDECL; |
|
189 |
protected final static short INFOSET_FALSE_PARAMS = ENTITIES | DTNORMALIZATION | CDATA; |
|
190 |
protected final static short INFOSET_MASK = INFOSET_TRUE_PARAMS | INFOSET_FALSE_PARAMS; |
|
191 |
||
192 |
// components |
|
193 |
||
194 |
/** Symbol table. */ |
|
195 |
protected SymbolTable fSymbolTable; |
|
196 |
||
197 |
/** Components. */ |
|
39907 | 198 |
protected ArrayList<XMLComponent> fComponents; |
12005 | 199 |
|
200 |
protected ValidationManager fValidationManager; |
|
201 |
||
202 |
/** Locale. */ |
|
203 |
protected Locale fLocale; |
|
204 |
||
205 |
/** Error reporter */ |
|
206 |
protected XMLErrorReporter fErrorReporter; |
|
207 |
||
208 |
protected final DOMErrorHandlerWrapper fErrorHandlerWrapper = |
|
209 |
new DOMErrorHandlerWrapper(); |
|
210 |
||
211 |
// private data |
|
212 |
||
213 |
private DOMStringList fRecognizedParameters; |
|
214 |
||
215 |
||
216 |
// |
|
217 |
// Constructors |
|
218 |
// |
|
219 |
||
220 |
/** Default Constructor. */ |
|
221 |
protected DOMConfigurationImpl() { |
|
222 |
this(null, null); |
|
223 |
} // <init>() |
|
224 |
||
225 |
/** |
|
226 |
* Constructs a parser configuration using the specified symbol table. |
|
227 |
* |
|
228 |
* @param symbolTable The symbol table to use. |
|
229 |
*/ |
|
230 |
protected DOMConfigurationImpl(SymbolTable symbolTable) { |
|
231 |
this(symbolTable, null); |
|
232 |
} // <init>(SymbolTable) |
|
233 |
||
234 |
/** |
|
235 |
* Constructs a parser configuration using the specified symbol table |
|
236 |
* and parent settings. |
|
237 |
* |
|
238 |
* @param symbolTable The symbol table to use. |
|
239 |
* @param parentSettings The parent settings. |
|
240 |
*/ |
|
241 |
protected DOMConfigurationImpl(SymbolTable symbolTable, |
|
242 |
XMLComponentManager parentSettings) { |
|
243 |
super(parentSettings); |
|
244 |
||
245 |
||
246 |
// create table for features and properties |
|
247 |
fFeatures = new HashMap(); |
|
248 |
fProperties = new HashMap(); |
|
249 |
||
250 |
// add default recognized features |
|
251 |
final String[] recognizedFeatures = { |
|
252 |
XERCES_VALIDATION, |
|
253 |
XERCES_NAMESPACES, |
|
254 |
SCHEMA, |
|
255 |
SCHEMA_FULL_CHECKING, |
|
256 |
DYNAMIC_VALIDATION, |
|
257 |
NORMALIZE_DATA, |
|
258 |
SEND_PSVI, |
|
259 |
NAMESPACE_GROWTH, |
|
39907 | 260 |
TOLERATE_DUPLICATES, |
261 |
XMLConstants.USE_CATALOG |
|
12005 | 262 |
}; |
263 |
addRecognizedFeatures(recognizedFeatures); |
|
264 |
||
265 |
// set state for default features |
|
266 |
setFeature(XERCES_VALIDATION, false); |
|
267 |
setFeature(SCHEMA, false); |
|
268 |
setFeature(SCHEMA_FULL_CHECKING, false); |
|
269 |
setFeature(DYNAMIC_VALIDATION, false); |
|
270 |
setFeature(NORMALIZE_DATA, false); |
|
271 |
setFeature(XERCES_NAMESPACES, true); |
|
272 |
setFeature(SEND_PSVI, true); |
|
273 |
setFeature(NAMESPACE_GROWTH, false); |
|
39907 | 274 |
setFeature(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT); |
12005 | 275 |
|
276 |
// add default recognized properties |
|
277 |
final String[] recognizedProperties = { |
|
278 |
XML_STRING, |
|
279 |
SYMBOL_TABLE, |
|
280 |
ERROR_HANDLER, |
|
281 |
ENTITY_RESOLVER, |
|
282 |
ERROR_REPORTER, |
|
283 |
ENTITY_MANAGER, |
|
284 |
VALIDATION_MANAGER, |
|
285 |
GRAMMAR_POOL, |
|
286 |
JAXP_SCHEMA_SOURCE, |
|
287 |
JAXP_SCHEMA_LANGUAGE, |
|
288 |
DTD_VALIDATOR_FACTORY_PROPERTY, |
|
17534 | 289 |
SCHEMA_DV_FACTORY, |
20968 | 290 |
SECURITY_MANAGER, |
39907 | 291 |
XML_SECURITY_PROPERTY_MANAGER, |
292 |
JdkXmlUtils.CATALOG_DEFER, |
|
293 |
JdkXmlUtils.CATALOG_FILES, |
|
294 |
JdkXmlUtils.CATALOG_PREFER, |
|
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
295 |
JdkXmlUtils.CATALOG_RESOLVE, |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
296 |
JdkXmlUtils.CDATA_CHUNK_SIZE |
12005 | 297 |
}; |
298 |
addRecognizedProperties(recognizedProperties); |
|
299 |
||
300 |
// set default values for normalization features |
|
301 |
features |= NAMESPACES; |
|
302 |
features |= ENTITIES; |
|
303 |
features |= COMMENTS; |
|
304 |
features |= CDATA; |
|
305 |
features |= SPLITCDATA; |
|
306 |
features |= WELLFORMED; |
|
307 |
features |= NSDECL; |
|
308 |
||
309 |
if (symbolTable == null) { |
|
310 |
symbolTable = new SymbolTable(); |
|
311 |
} |
|
312 |
fSymbolTable = symbolTable; |
|
313 |
||
39907 | 314 |
fComponents = new ArrayList<>(); |
12005 | 315 |
|
316 |
setProperty(SYMBOL_TABLE, fSymbolTable); |
|
317 |
fErrorReporter = new XMLErrorReporter(); |
|
318 |
setProperty(ERROR_REPORTER, fErrorReporter); |
|
319 |
addComponent(fErrorReporter); |
|
320 |
||
321 |
setProperty(DTD_VALIDATOR_FACTORY_PROPERTY, DTDDVFactory.getInstance()); |
|
322 |
||
323 |
XMLEntityManager manager = new XMLEntityManager(); |
|
324 |
setProperty(ENTITY_MANAGER, manager); |
|
325 |
addComponent(manager); |
|
326 |
||
327 |
fValidationManager = createValidationManager(); |
|
328 |
setProperty(VALIDATION_MANAGER, fValidationManager); |
|
329 |
||
20968 | 330 |
setProperty(SECURITY_MANAGER, new XMLSecurityManager(true)); |
331 |
||
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
332 |
setProperty(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
|
333 |
new XMLSecurityPropertyManager()); |
12005 | 334 |
|
335 |
// add message formatters |
|
336 |
if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) { |
|
337 |
XMLMessageFormatter xmft = new XMLMessageFormatter(); |
|
338 |
fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft); |
|
339 |
fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft); |
|
340 |
} |
|
341 |
||
342 |
// REVISIT: try to include XML Schema formatter. |
|
343 |
// This is a hack to allow DTD configuration to be build. |
|
344 |
// |
|
345 |
if (fErrorReporter.getMessageFormatter("http://www.w3.org/TR/xml-schema-1") == null) { |
|
346 |
MessageFormatter xmft = null; |
|
347 |
try { |
|
348 |
xmft = (MessageFormatter)( |
|
12458 | 349 |
ObjectFactory.newInstance("com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter", true)); |
12005 | 350 |
} catch (Exception exception){ |
351 |
} |
|
352 |
||
353 |
if (xmft != null) { |
|
354 |
fErrorReporter.putMessageFormatter("http://www.w3.org/TR/xml-schema-1", xmft); |
|
355 |
} |
|
356 |
} |
|
357 |
||
358 |
||
359 |
// set locale |
|
360 |
try { |
|
361 |
setLocale(Locale.getDefault()); |
|
362 |
} |
|
363 |
catch (XNIException e) { |
|
364 |
// do nothing |
|
365 |
// REVISIT: What is the right thing to do? -Ac |
|
366 |
} |
|
367 |
||
39907 | 368 |
// Initialize Catalog features |
369 |
for( CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) { |
|
370 |
setProperty(f.getPropertyName(), null); |
|
371 |
} |
|
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
372 |
|
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
373 |
setProperty(JdkXmlUtils.CDATA_CHUNK_SIZE, JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT); |
12005 | 374 |
} // <init>(SymbolTable) |
375 |
||
376 |
||
377 |
// |
|
378 |
// XMLParserConfiguration methods |
|
379 |
// |
|
380 |
||
381 |
/** |
|
382 |
* Parse an XML document. |
|
383 |
* <p> |
|
384 |
* The parser can use this method to instruct this configuration |
|
385 |
* to begin parsing an XML document from any valid input source |
|
386 |
* (a character stream, a byte stream, or a URI). |
|
387 |
* <p> |
|
388 |
* Parsers may not invoke this method while a parse is in progress. |
|
389 |
* Once a parse is complete, the parser may then parse another XML |
|
390 |
* document. |
|
391 |
* <p> |
|
392 |
* This method is synchronous: it will not return until parsing |
|
393 |
* has ended. If a client application wants to terminate |
|
394 |
* parsing early, it should throw an exception. |
|
395 |
* |
|
396 |
* @param source The input source for the top-level of the |
|
397 |
* XML document. |
|
398 |
* |
|
399 |
* @exception XNIException Any XNI exception, possibly wrapping |
|
400 |
* another exception. |
|
401 |
* @exception IOException An IO exception from the parser, possibly |
|
402 |
* from a byte stream or character stream |
|
403 |
* supplied by the parser. |
|
404 |
*/ |
|
405 |
public void parse(XMLInputSource inputSource) |
|
406 |
throws XNIException, IOException{ |
|
407 |
// no-op |
|
408 |
} |
|
409 |
||
410 |
/** |
|
411 |
* Sets the document handler on the last component in the pipeline |
|
412 |
* to receive information about the document. |
|
413 |
* |
|
414 |
* @param documentHandler The document handler. |
|
415 |
*/ |
|
416 |
public void setDocumentHandler(XMLDocumentHandler documentHandler) { |
|
417 |
fDocumentHandler = documentHandler; |
|
418 |
} // setDocumentHandler(XMLDocumentHandler) |
|
419 |
||
420 |
/** Returns the registered document handler. */ |
|
421 |
public XMLDocumentHandler getDocumentHandler() { |
|
422 |
return fDocumentHandler; |
|
423 |
} // getDocumentHandler():XMLDocumentHandler |
|
424 |
||
425 |
/** |
|
426 |
* Sets the DTD handler. |
|
427 |
* |
|
428 |
* @param dtdHandler The DTD handler. |
|
429 |
*/ |
|
430 |
public void setDTDHandler(XMLDTDHandler dtdHandler) { |
|
431 |
//no-op |
|
432 |
} // setDTDHandler(XMLDTDHandler) |
|
433 |
||
434 |
/** Returns the registered DTD handler. */ |
|
435 |
public XMLDTDHandler getDTDHandler() { |
|
436 |
return null; |
|
437 |
} // getDTDHandler():XMLDTDHandler |
|
438 |
||
439 |
/** |
|
440 |
* Sets the DTD content model handler. |
|
441 |
* |
|
442 |
* @param handler The DTD content model handler. |
|
443 |
*/ |
|
444 |
public void setDTDContentModelHandler(XMLDTDContentModelHandler handler) { |
|
445 |
//no-op |
|
446 |
||
447 |
} // setDTDContentModelHandler(XMLDTDContentModelHandler) |
|
448 |
||
449 |
/** Returns the registered DTD content model handler. */ |
|
450 |
public XMLDTDContentModelHandler getDTDContentModelHandler() { |
|
451 |
return null; |
|
452 |
} // getDTDContentModelHandler():XMLDTDContentModelHandler |
|
453 |
||
454 |
/** |
|
455 |
* Sets the resolver used to resolve external entities. The EntityResolver |
|
456 |
* interface supports resolution of public and system identifiers. |
|
457 |
* |
|
458 |
* @param resolver The new entity resolver. Passing a null value will |
|
459 |
* uninstall the currently installed resolver. |
|
460 |
*/ |
|
461 |
public void setEntityResolver(XMLEntityResolver resolver) { |
|
462 |
if (resolver !=null) { |
|
463 |
fProperties.put(ENTITY_RESOLVER, resolver); |
|
464 |
} |
|
465 |
} // setEntityResolver(XMLEntityResolver) |
|
466 |
||
467 |
/** |
|
468 |
* Return the current entity resolver. |
|
469 |
* |
|
470 |
* @return The current entity resolver, or null if none |
|
471 |
* has been registered. |
|
472 |
* @see #setEntityResolver |
|
473 |
*/ |
|
474 |
public XMLEntityResolver getEntityResolver() { |
|
475 |
return (XMLEntityResolver)fProperties.get(ENTITY_RESOLVER); |
|
476 |
} // getEntityResolver():XMLEntityResolver |
|
477 |
||
478 |
/** |
|
479 |
* Allow an application to register an error event handler. |
|
480 |
* |
|
481 |
* <p>If the application does not register an error handler, all |
|
482 |
* error events reported by the SAX parser will be silently |
|
483 |
* ignored; however, normal processing may not continue. It is |
|
484 |
* highly recommended that all SAX applications implement an |
|
485 |
* error handler to avoid unexpected bugs.</p> |
|
486 |
* |
|
487 |
* <p>Applications may register a new or different handler in the |
|
488 |
* middle of a parse, and the SAX parser must begin using the new |
|
489 |
* handler immediately.</p> |
|
490 |
* |
|
491 |
* @param errorHandler The error handler. |
|
492 |
* @exception java.lang.NullPointerException If the handler |
|
493 |
* argument is null. |
|
494 |
* @see #getErrorHandler |
|
495 |
*/ |
|
496 |
public void setErrorHandler(XMLErrorHandler errorHandler) { |
|
497 |
if (errorHandler != null) { |
|
498 |
fProperties.put(ERROR_HANDLER, errorHandler); |
|
499 |
} |
|
500 |
} // setErrorHandler(XMLErrorHandler) |
|
501 |
||
502 |
/** |
|
503 |
* Return the current error handler. |
|
504 |
* |
|
505 |
* @return The current error handler, or null if none |
|
506 |
* has been registered. |
|
507 |
* @see #setErrorHandler |
|
508 |
*/ |
|
509 |
public XMLErrorHandler getErrorHandler() { |
|
510 |
return (XMLErrorHandler)fProperties.get(ERROR_HANDLER); |
|
511 |
} // getErrorHandler():XMLErrorHandler |
|
512 |
||
513 |
/** |
|
514 |
* Set the state of a feature. |
|
515 |
* |
|
516 |
* Set the state of any feature in a SAX2 parser. The parser |
|
517 |
* might not recognize the feature, and if it does recognize |
|
518 |
* it, it might not be able to fulfill the request. |
|
519 |
* |
|
520 |
* @param featureId The unique identifier (URI) of the feature. |
|
521 |
* @param state The requested state of the feature (true or false). |
|
522 |
* |
|
523 |
* @exception com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException If the |
|
524 |
* requested feature is not known. |
|
525 |
*/ |
|
526 |
public void setFeature(String featureId, boolean state) |
|
527 |
throws XMLConfigurationException { |
|
528 |
||
529 |
// save state if noone "objects" |
|
530 |
super.setFeature(featureId, state); |
|
531 |
||
532 |
} // setFeature(String,boolean) |
|
533 |
||
534 |
/** |
|
535 |
* setProperty |
|
536 |
* |
|
537 |
* @param propertyId |
|
538 |
* @param value |
|
539 |
*/ |
|
540 |
public void setProperty(String propertyId, Object value) |
|
541 |
throws XMLConfigurationException { |
|
542 |
||
543 |
// store value if noone "objects" |
|
544 |
super.setProperty(propertyId, value); |
|
545 |
||
546 |
} // setProperty(String,Object) |
|
547 |
||
548 |
/** |
|
549 |
* Set the locale to use for messages. |
|
550 |
* |
|
551 |
* @param locale The locale object to use for localization of messages. |
|
552 |
* |
|
553 |
* @exception XNIException Thrown if the parser does not support the |
|
554 |
* specified locale. |
|
555 |
*/ |
|
556 |
public void setLocale(Locale locale) throws XNIException { |
|
557 |
fLocale = locale; |
|
558 |
fErrorReporter.setLocale(locale); |
|
559 |
||
560 |
} // setLocale(Locale) |
|
561 |
||
562 |
/** Returns the locale. */ |
|
563 |
public Locale getLocale() { |
|
564 |
return fLocale; |
|
565 |
} // getLocale():Locale |
|
566 |
||
567 |
/** |
|
568 |
* DOM Level 3 WD - Experimental. |
|
569 |
* setParameter |
|
570 |
*/ |
|
571 |
public void setParameter(String name, Object value) throws DOMException { |
|
572 |
boolean found = true; |
|
573 |
||
574 |
// REVISIT: Recognizes DOM L3 default features only. |
|
575 |
// Does not yet recognize Xerces features. |
|
576 |
if(value instanceof Boolean){ |
|
577 |
boolean state = ((Boolean)value).booleanValue(); |
|
578 |
||
579 |
if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) { |
|
580 |
features = (short) (state ? features | COMMENTS : features & ~COMMENTS); |
|
581 |
} |
|
582 |
else if (name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) { |
|
583 |
setFeature(NORMALIZE_DATA, state); |
|
584 |
features = |
|
585 |
(short) (state ? features | DTNORMALIZATION : features & ~DTNORMALIZATION); |
|
586 |
if (state) { |
|
587 |
features = (short) (features | VALIDATE); |
|
588 |
} |
|
589 |
} |
|
590 |
else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) { |
|
591 |
features = (short) (state ? features | NAMESPACES : features & ~NAMESPACES); |
|
592 |
} |
|
593 |
else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) { |
|
594 |
features = (short) (state ? features | CDATA : features & ~CDATA); |
|
595 |
} |
|
596 |
else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) { |
|
597 |
features = (short) (state ? features | ENTITIES : features & ~ENTITIES); |
|
598 |
} |
|
599 |
else if (name.equalsIgnoreCase(Constants.DOM_SPLIT_CDATA)) { |
|
600 |
features = (short) (state ? features | SPLITCDATA : features & ~SPLITCDATA); |
|
601 |
} |
|
602 |
else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) { |
|
603 |
features = (short) (state ? features | VALIDATE : features & ~VALIDATE); |
|
604 |
} |
|
605 |
else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED)) { |
|
606 |
features = (short) (state ? features | WELLFORMED : features & ~WELLFORMED ); |
|
607 |
} |
|
608 |
else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)) { |
|
609 |
features = (short) (state ? features | NSDECL : features & ~NSDECL); |
|
610 |
} |
|
611 |
else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) { |
|
612 |
// Setting to false has no effect. |
|
613 |
if (state) { |
|
614 |
features = (short) (features | INFOSET_TRUE_PARAMS); |
|
615 |
features = (short) (features & ~INFOSET_FALSE_PARAMS); |
|
616 |
setFeature(NORMALIZE_DATA, false); |
|
617 |
} |
|
618 |
} |
|
619 |
else if (name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) |
|
620 |
|| name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM) |
|
621 |
|| name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA) |
|
622 |
|| name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION) |
|
623 |
) { |
|
624 |
if (state) { // true is not supported |
|
625 |
String msg = |
|
626 |
DOMMessageFormatter.formatMessage( |
|
627 |
DOMMessageFormatter.DOM_DOMAIN, |
|
628 |
"FEATURE_NOT_SUPPORTED", |
|
629 |
new Object[] { name }); |
|
630 |
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg); |
|
631 |
} |
|
632 |
} |
|
633 |
else if ( name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) { |
|
634 |
if (!state) { // false is not supported |
|
635 |
String msg = |
|
636 |
DOMMessageFormatter.formatMessage( |
|
637 |
DOMMessageFormatter.DOM_DOMAIN, |
|
638 |
"FEATURE_NOT_SUPPORTED", |
|
639 |
new Object[] { name }); |
|
640 |
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg); |
|
641 |
} |
|
642 |
} |
|
643 |
else if (name.equalsIgnoreCase(SEND_PSVI) ){ |
|
644 |
// REVISIT: turning augmentation of PSVI is not support, |
|
645 |
// because in this case we won't be able to retrieve element |
|
646 |
// default value. |
|
647 |
if (!state) { // false is not supported |
|
648 |
String msg = |
|
649 |
DOMMessageFormatter.formatMessage( |
|
650 |
DOMMessageFormatter.DOM_DOMAIN, |
|
651 |
"FEATURE_NOT_SUPPORTED", |
|
652 |
new Object[] { name }); |
|
653 |
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg); |
|
654 |
} |
|
655 |
} |
|
656 |
else if (name.equalsIgnoreCase(Constants.DOM_PSVI)){ |
|
657 |
features = (short) (state ? features | PSVI : features & ~PSVI); |
|
658 |
} |
|
659 |
else { |
|
660 |
found = false; |
|
661 |
/* |
|
662 |
String msg = |
|
663 |
DOMMessageFormatter.formatMessage( |
|
664 |
DOMMessageFormatter.DOM_DOMAIN, |
|
665 |
"FEATURE_NOT_FOUND", |
|
666 |
new Object[] { name }); |
|
667 |
throw new DOMException(DOMException.NOT_FOUND_ERR, msg); |
|
668 |
*/ |
|
669 |
} |
|
670 |
||
671 |
} |
|
672 |
||
673 |
if (!found || !(value instanceof Boolean)) { // set properties |
|
674 |
found = true; |
|
675 |
||
676 |
if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) { |
|
677 |
if (value instanceof DOMErrorHandler || value == null) { |
|
678 |
fErrorHandlerWrapper.setErrorHandler((DOMErrorHandler)value); |
|
679 |
setErrorHandler(fErrorHandlerWrapper); |
|
680 |
} |
|
681 |
||
682 |
else { |
|
683 |
// REVISIT: type mismatch |
|
684 |
String msg = |
|
685 |
DOMMessageFormatter.formatMessage( |
|
686 |
DOMMessageFormatter.DOM_DOMAIN, |
|
687 |
"TYPE_MISMATCH_ERR", |
|
688 |
new Object[] { name }); |
|
689 |
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg); |
|
690 |
} |
|
691 |
} |
|
692 |
else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) { |
|
693 |
if (value instanceof LSResourceResolver || value == null) { |
|
694 |
try { |
|
695 |
setEntityResolver(new DOMEntityResolverWrapper((LSResourceResolver) value)); |
|
696 |
} |
|
697 |
catch (XMLConfigurationException e) {} |
|
698 |
} |
|
699 |
else { |
|
700 |
// REVISIT: type mismatch |
|
701 |
String msg = |
|
702 |
DOMMessageFormatter.formatMessage( |
|
703 |
DOMMessageFormatter.DOM_DOMAIN, |
|
704 |
"TYPE_MISMATCH_ERR", |
|
705 |
new Object[] { name }); |
|
706 |
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg); |
|
707 |
} |
|
708 |
||
709 |
} |
|
710 |
else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) { |
|
711 |
if (value instanceof String || value == null) { |
|
712 |
try { |
|
713 |
// map DOM schema-location to JAXP schemaSource property |
|
714 |
setProperty( |
|
715 |
Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, |
|
716 |
value); |
|
717 |
} |
|
718 |
catch (XMLConfigurationException e) {} |
|
719 |
} |
|
720 |
else { |
|
721 |
// REVISIT: type mismatch |
|
722 |
String msg = |
|
723 |
DOMMessageFormatter.formatMessage( |
|
724 |
DOMMessageFormatter.DOM_DOMAIN, |
|
725 |
"TYPE_MISMATCH_ERR", |
|
726 |
new Object[] { name }); |
|
727 |
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg); |
|
728 |
} |
|
729 |
||
730 |
} |
|
731 |
else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) { |
|
732 |
if (value instanceof String || value == null) { |
|
733 |
try { |
|
734 |
if (value == null) { |
|
735 |
setProperty( |
|
736 |
Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, |
|
737 |
null); |
|
738 |
} |
|
739 |
else if (value.equals(Constants.NS_XMLSCHEMA)) { |
|
740 |
// REVISIT: when add support to DTD validation |
|
741 |
setProperty( |
|
742 |
Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, |
|
743 |
Constants.NS_XMLSCHEMA); |
|
744 |
} |
|
745 |
else if (value.equals(Constants.NS_DTD)) { |
|
746 |
// Added support for revalidation against DTDs |
|
747 |
setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, |
|
748 |
Constants.NS_DTD); |
|
749 |
} |
|
750 |
} |
|
751 |
catch (XMLConfigurationException e) {} |
|
752 |
} |
|
753 |
else { |
|
754 |
String msg = |
|
755 |
DOMMessageFormatter.formatMessage( |
|
756 |
DOMMessageFormatter.DOM_DOMAIN, |
|
757 |
"TYPE_MISMATCH_ERR", |
|
758 |
new Object[] { name }); |
|
759 |
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg); |
|
760 |
} |
|
761 |
||
762 |
} |
|
763 |
else if (name.equalsIgnoreCase(SYMBOL_TABLE)){ |
|
764 |
// Xerces Symbol Table |
|
765 |
if (value instanceof SymbolTable){ |
|
766 |
setProperty(SYMBOL_TABLE, value); |
|
767 |
} |
|
768 |
else { |
|
769 |
// REVISIT: type mismatch |
|
770 |
String msg = |
|
771 |
DOMMessageFormatter.formatMessage( |
|
772 |
DOMMessageFormatter.DOM_DOMAIN, |
|
773 |
"TYPE_MISMATCH_ERR", |
|
774 |
new Object[] { name }); |
|
775 |
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg); |
|
776 |
} |
|
777 |
} |
|
778 |
else if (name.equalsIgnoreCase (GRAMMAR_POOL)){ |
|
779 |
if (value instanceof XMLGrammarPool){ |
|
780 |
setProperty(GRAMMAR_POOL, value); |
|
781 |
} |
|
782 |
else { |
|
783 |
// REVISIT: type mismatch |
|
784 |
String msg = |
|
785 |
DOMMessageFormatter.formatMessage( |
|
786 |
DOMMessageFormatter.DOM_DOMAIN, |
|
787 |
"TYPE_MISMATCH_ERR", |
|
788 |
new Object[] { name }); |
|
789 |
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg); |
|
790 |
} |
|
791 |
||
792 |
} |
|
793 |
else { |
|
794 |
// REVISIT: check if this is a boolean parameter -- type mismatch should be thrown. |
|
795 |
//parameter is not recognized |
|
796 |
String msg = |
|
797 |
DOMMessageFormatter.formatMessage( |
|
798 |
DOMMessageFormatter.DOM_DOMAIN, |
|
799 |
"FEATURE_NOT_FOUND", |
|
800 |
new Object[] { name }); |
|
801 |
throw new DOMException(DOMException.NOT_FOUND_ERR, msg); |
|
802 |
} |
|
803 |
} |
|
804 |
||
805 |
} |
|
806 |
||
807 |
||
808 |
/** |
|
809 |
* DOM Level 3 WD - Experimental. |
|
810 |
* getParameter |
|
811 |
*/ |
|
812 |
public Object getParameter(String name) throws DOMException { |
|
813 |
||
814 |
// REVISIT: Recognizes DOM L3 default features only. |
|
815 |
// Does not yet recognize Xerces features. |
|
816 |
||
817 |
if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) { |
|
818 |
return ((features & COMMENTS) != 0) ? Boolean.TRUE : Boolean.FALSE; |
|
819 |
} |
|
820 |
else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) { |
|
821 |
return (features & NAMESPACES) != 0 ? Boolean.TRUE : Boolean.FALSE; |
|
822 |
} |
|
823 |
else if (name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) { |
|
824 |
// REVISIT: datatype-normalization only takes effect if validation is on |
|
825 |
return (features & DTNORMALIZATION) != 0 ? Boolean.TRUE : Boolean.FALSE; |
|
826 |
} |
|
827 |
else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) { |
|
828 |
return (features & CDATA) != 0 ? Boolean.TRUE : Boolean.FALSE; |
|
829 |
} |
|
830 |
else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) { |
|
831 |
return (features & ENTITIES) != 0 ? Boolean.TRUE : Boolean.FALSE; |
|
832 |
} |
|
833 |
else if (name.equalsIgnoreCase(Constants.DOM_SPLIT_CDATA)) { |
|
834 |
return (features & SPLITCDATA) != 0 ? Boolean.TRUE : Boolean.FALSE; |
|
835 |
} |
|
836 |
else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) { |
|
837 |
return (features & VALIDATE) != 0 ? Boolean.TRUE : Boolean.FALSE; |
|
838 |
} |
|
839 |
else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED)) { |
|
840 |
return (features & WELLFORMED) != 0 ? Boolean.TRUE : Boolean.FALSE; |
|
841 |
} |
|
842 |
else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)) { |
|
843 |
return (features & NSDECL) != 0 ? Boolean.TRUE : Boolean.FALSE; |
|
844 |
} |
|
845 |
else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) { |
|
846 |
return (features & INFOSET_MASK) == INFOSET_TRUE_PARAMS ? Boolean.TRUE : Boolean.FALSE; |
|
847 |
} |
|
848 |
else if (name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) |
|
849 |
|| name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM) |
|
850 |
|| name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA) |
|
851 |
|| name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION) |
|
852 |
) { |
|
853 |
return Boolean.FALSE; |
|
854 |
} |
|
855 |
else if (name.equalsIgnoreCase(SEND_PSVI)) { |
|
856 |
return Boolean.TRUE; |
|
857 |
} |
|
858 |
else if (name.equalsIgnoreCase(Constants.DOM_PSVI)) { |
|
859 |
return (features & PSVI) != 0 ? Boolean.TRUE : Boolean.FALSE; |
|
860 |
} |
|
861 |
else if (name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) { |
|
862 |
return Boolean.TRUE; |
|
863 |
} |
|
864 |
else if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) { |
|
865 |
return fErrorHandlerWrapper.getErrorHandler(); |
|
866 |
} |
|
867 |
else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) { |
|
868 |
XMLEntityResolver entityResolver = getEntityResolver(); |
|
869 |
if (entityResolver != null && entityResolver instanceof DOMEntityResolverWrapper) { |
|
870 |
return ((DOMEntityResolverWrapper) entityResolver).getEntityResolver(); |
|
871 |
} |
|
872 |
return null; |
|
873 |
} |
|
874 |
else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) { |
|
875 |
return getProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE); |
|
876 |
} |
|
877 |
else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) { |
|
878 |
return getProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE); |
|
879 |
} |
|
880 |
else if (name.equalsIgnoreCase(SYMBOL_TABLE)){ |
|
881 |
return getProperty(SYMBOL_TABLE); |
|
882 |
} |
|
883 |
else if (name.equalsIgnoreCase(GRAMMAR_POOL)){ |
|
884 |
return getProperty(GRAMMAR_POOL); |
|
885 |
} |
|
886 |
else { |
|
887 |
String msg = |
|
888 |
DOMMessageFormatter.formatMessage( |
|
889 |
DOMMessageFormatter.DOM_DOMAIN, |
|
890 |
"FEATURE_NOT_FOUND", |
|
891 |
new Object[] { name }); |
|
892 |
throw new DOMException(DOMException.NOT_FOUND_ERR, msg); |
|
893 |
} |
|
894 |
||
895 |
} |
|
896 |
||
897 |
/** |
|
898 |
* DOM Level 3 WD - Experimental. |
|
899 |
* Check if setting a parameter to a specific value is supported. |
|
900 |
* |
|
901 |
* @param name The name of the parameter to check. |
|
902 |
* |
|
903 |
* @param value An object. if null, the returned value is true. |
|
904 |
* |
|
905 |
* @return true if the parameter could be successfully set to the |
|
906 |
* specified value, or false if the parameter is not recognized or |
|
907 |
* the requested value is not supported. This does not change the |
|
908 |
* current value of the parameter itself. |
|
909 |
*/ |
|
910 |
public boolean canSetParameter(String name, Object value) { |
|
911 |
||
912 |
if (value == null){ |
|
913 |
//if null, the returned value is true. |
|
914 |
//REVISIT: I dont like this --- even for unrecognized parameter it would |
|
915 |
//return 'true'. I think it should return false in that case. |
|
916 |
// Application will be surprised to find that setParameter throws not |
|
917 |
//recognized exception when canSetParameter returns 'true' Then what is the use |
|
918 |
//of having canSetParameter ??? - nb. |
|
919 |
return true ; |
|
920 |
} |
|
921 |
if( value instanceof Boolean ){ |
|
922 |
//features whose parameter value can be set either 'true' or 'false' |
|
923 |
// or they accept any boolean value -- so we just need to check that |
|
924 |
// its a boolean value.. |
|
925 |
if (name.equalsIgnoreCase(Constants.DOM_COMMENTS) |
|
926 |
|| name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION) |
|
927 |
|| name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS) |
|
928 |
|| name.equalsIgnoreCase(Constants.DOM_ENTITIES) |
|
929 |
|| name.equalsIgnoreCase(Constants.DOM_SPLIT_CDATA) |
|
930 |
|| name.equalsIgnoreCase(Constants.DOM_NAMESPACES) |
|
931 |
|| name.equalsIgnoreCase(Constants.DOM_VALIDATE) |
|
932 |
|| name.equalsIgnoreCase(Constants.DOM_WELLFORMED) |
|
933 |
|| name.equalsIgnoreCase(Constants.DOM_INFOSET) |
|
934 |
|| name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS) |
|
935 |
) { |
|
936 |
return true; |
|
937 |
}//features whose parameter value can not be set to 'true' |
|
938 |
else if ( |
|
939 |
name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) |
|
940 |
|| name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM) |
|
941 |
|| name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA) |
|
942 |
|| name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION) |
|
943 |
) { |
|
944 |
return (value.equals(Boolean.TRUE)) ? false : true; |
|
945 |
}//features whose parameter value can not be set to 'false' |
|
946 |
else if( name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE) |
|
947 |
|| name.equalsIgnoreCase(SEND_PSVI) |
|
948 |
) { |
|
949 |
return (value.equals(Boolean.TRUE)) ? true : false; |
|
950 |
}// if name is not among the above listed above -- its not recognized. return false |
|
951 |
else { |
|
952 |
return false ; |
|
953 |
} |
|
954 |
} |
|
955 |
else if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) { |
|
956 |
return (value instanceof DOMErrorHandler) ? true : false ; |
|
957 |
} |
|
958 |
else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) { |
|
959 |
return (value instanceof LSResourceResolver) ? true : false ; |
|
960 |
} |
|
961 |
else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) { |
|
962 |
return (value instanceof String) ? true : false ; |
|
963 |
} |
|
964 |
else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) { |
|
965 |
// REVISIT: should null value be supported? |
|
966 |
//as of now we are only supporting W3C XML Schema |
|
967 |
return ( (value instanceof String) && value.equals(Constants.NS_XMLSCHEMA) ) ? true : false ; |
|
968 |
} |
|
969 |
else if (name.equalsIgnoreCase(SYMBOL_TABLE)){ |
|
970 |
// Xerces Symbol Table |
|
971 |
return (value instanceof SymbolTable) ? true : false ; |
|
972 |
} |
|
973 |
else if (name.equalsIgnoreCase (GRAMMAR_POOL)){ |
|
974 |
return (value instanceof XMLGrammarPool) ? true : false ; |
|
975 |
} |
|
976 |
else { |
|
977 |
//false if the parameter is not recognized or the requested value is not supported. |
|
978 |
return false ; |
|
979 |
} |
|
980 |
||
981 |
} //canSetParameter |
|
982 |
||
983 |
/** |
|
984 |
* DOM Level 3 CR - Experimental. |
|
985 |
* |
|
986 |
* The list of the parameters supported by this |
|
987 |
* <code>DOMConfiguration</code> object and for which at least one value |
|
988 |
* can be set by the application. Note that this list can also contain |
|
989 |
* parameter names defined outside this specification. |
|
990 |
*/ |
|
991 |
public DOMStringList getParameterNames() { |
|
992 |
if (fRecognizedParameters == null){ |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
993 |
ArrayList parameters = new ArrayList(); |
12005 | 994 |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
995 |
//Add DOM recognized parameters |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
996 |
//REVISIT: Would have been nice to have a list of |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
997 |
//recognized paramters. |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
998 |
parameters.add(Constants.DOM_COMMENTS); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
999 |
parameters.add(Constants.DOM_DATATYPE_NORMALIZATION); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1000 |
parameters.add(Constants.DOM_CDATA_SECTIONS); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1001 |
parameters.add(Constants.DOM_ENTITIES); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1002 |
parameters.add(Constants.DOM_SPLIT_CDATA); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1003 |
parameters.add(Constants.DOM_NAMESPACES); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1004 |
parameters.add(Constants.DOM_VALIDATE); |
12005 | 1005 |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1006 |
parameters.add(Constants.DOM_INFOSET); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1007 |
parameters.add(Constants.DOM_NORMALIZE_CHARACTERS); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1008 |
parameters.add(Constants.DOM_CANONICAL_FORM); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1009 |
parameters.add(Constants.DOM_VALIDATE_IF_SCHEMA); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1010 |
parameters.add(Constants.DOM_CHECK_CHAR_NORMALIZATION); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1011 |
parameters.add(Constants.DOM_WELLFORMED); |
12005 | 1012 |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1013 |
parameters.add(Constants.DOM_NAMESPACE_DECLARATIONS); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1014 |
parameters.add(Constants.DOM_ELEMENT_CONTENT_WHITESPACE); |
12005 | 1015 |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1016 |
parameters.add(Constants.DOM_ERROR_HANDLER); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1017 |
parameters.add(Constants.DOM_SCHEMA_TYPE); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1018 |
parameters.add(Constants.DOM_SCHEMA_LOCATION); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1019 |
parameters.add(Constants.DOM_RESOURCE_RESOLVER); |
12005 | 1020 |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1021 |
//Add recognized xerces features and properties |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1022 |
parameters.add(GRAMMAR_POOL); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1023 |
parameters.add(SYMBOL_TABLE); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1024 |
parameters.add(SEND_PSVI); |
12005 | 1025 |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
1026 |
fRecognizedParameters = new DOMStringListImpl(parameters); |
12005 | 1027 |
} |
1028 |
||
1029 |
return fRecognizedParameters; |
|
1030 |
}//getParameterNames |
|
1031 |
||
1032 |
// |
|
1033 |
// Protected methods |
|
1034 |
// |
|
1035 |
||
1036 |
/** |
|
1037 |
* reset all components before parsing |
|
1038 |
*/ |
|
1039 |
protected void reset() throws XNIException { |
|
1040 |
||
1041 |
if (fValidationManager != null) |
|
1042 |
fValidationManager.reset(); |
|
1043 |
||
1044 |
int count = fComponents.size(); |
|
1045 |
for (int i = 0; i < count; i++) { |
|
39907 | 1046 |
XMLComponent c = fComponents.get(i); |
12005 | 1047 |
c.reset(this); |
1048 |
} |
|
1049 |
||
1050 |
} // reset() |
|
1051 |
||
1052 |
/** |
|
1053 |
* Check a property. If the property is known and supported, this method |
|
1054 |
* simply returns. Otherwise, the appropriate exception is thrown. |
|
1055 |
* |
|
1056 |
* @param propertyId The unique identifier (URI) of the property |
|
1057 |
* being set. |
|
1058 |
* @exception com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException If the |
|
1059 |
* requested feature is not known or supported. |
|
1060 |
*/ |
|
1061 |
protected PropertyState checkProperty(String propertyId) |
|
1062 |
throws XMLConfigurationException { |
|
1063 |
||
1064 |
// special cases |
|
1065 |
if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) { |
|
1066 |
final int suffixLength = propertyId.length() - Constants.SAX_PROPERTY_PREFIX.length(); |
|
1067 |
||
1068 |
// |
|
1069 |
// http://xml.org/sax/properties/xml-string |
|
1070 |
// Value type: String |
|
1071 |
// Access: read-only |
|
1072 |
// Get the literal string of characters associated with the |
|
1073 |
// current event. If the parser recognises and supports this |
|
1074 |
// property but is not currently parsing text, it should return |
|
1075 |
// null (this is a good way to check for availability before the |
|
1076 |
// parse begins). |
|
1077 |
// |
|
1078 |
if (suffixLength == Constants.XML_STRING_PROPERTY.length() && |
|
1079 |
propertyId.endsWith(Constants.XML_STRING_PROPERTY)) { |
|
1080 |
// REVISIT - we should probably ask xml-dev for a precise |
|
1081 |
// definition of what this is actually supposed to return, and |
|
1082 |
// in exactly which circumstances. |
|
1083 |
return PropertyState.NOT_SUPPORTED; |
|
1084 |
} |
|
1085 |
} |
|
1086 |
||
1087 |
// check property |
|
1088 |
return super.checkProperty(propertyId); |
|
1089 |
||
1090 |
} // checkProperty(String) |
|
1091 |
||
1092 |
||
1093 |
protected void addComponent(XMLComponent component) { |
|
1094 |
||
1095 |
// don't add a component more than once |
|
1096 |
if (fComponents.contains(component)) { |
|
1097 |
return; |
|
1098 |
} |
|
1099 |
fComponents.add(component); |
|
1100 |
||
1101 |
// register component's recognized features |
|
1102 |
String[] recognizedFeatures = component.getRecognizedFeatures(); |
|
1103 |
addRecognizedFeatures(recognizedFeatures); |
|
1104 |
||
1105 |
// register component's recognized properties |
|
1106 |
String[] recognizedProperties = component.getRecognizedProperties(); |
|
1107 |
addRecognizedProperties(recognizedProperties); |
|
1108 |
||
1109 |
} // addComponent(XMLComponent) |
|
1110 |
||
1111 |
protected ValidationManager createValidationManager(){ |
|
1112 |
return new ValidationManager(); |
|
1113 |
} |
|
1114 |
||
1115 |
} // class XMLParser |