author | joehw |
Thu, 15 Dec 2016 13:57:04 -0800 | |
changeset 42802 | 2a03abb03c06 |
parent 42394 | 285ea8081752 |
child 44800 | bc291f6e8320 |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
42394
285ea8081752
8167340: XMLStreamReader.getElementText return corrupt content when size of element is > 8192
joehw
parents:
39080
diff
changeset
|
2 |
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. |
12005 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.org.apache.xerces.internal.impl; |
|
27 |
||
42802 | 28 |
import com.sun.org.apache.xerces.internal.util.NamespaceContextWrapper; |
29 |
import com.sun.org.apache.xerces.internal.util.NamespaceSupport; |
|
30 |
import com.sun.org.apache.xerces.internal.util.SymbolTable; |
|
31 |
import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl; |
|
32 |
import com.sun.org.apache.xerces.internal.util.XMLChar; |
|
33 |
import com.sun.org.apache.xerces.internal.util.XMLStringBuffer; |
|
34 |
import com.sun.org.apache.xerces.internal.xni.XNIException; |
|
35 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; |
|
12005 | 36 |
import com.sun.xml.internal.stream.Entity; |
37 |
import com.sun.xml.internal.stream.StaxErrorReporter; |
|
38 |
import com.sun.xml.internal.stream.XMLEntityStorage; |
|
42802 | 39 |
import com.sun.xml.internal.stream.dtd.nonvalidating.DTDGrammar; |
40 |
import com.sun.xml.internal.stream.dtd.nonvalidating.XMLNotationDecl; |
|
12005 | 41 |
import com.sun.xml.internal.stream.events.EntityDeclarationImpl; |
42 |
import com.sun.xml.internal.stream.events.NotationDeclarationImpl; |
|
43 |
import java.io.BufferedInputStream; |
|
44 |
import java.io.BufferedReader; |
|
45 |
import java.io.IOException; |
|
46 |
import java.io.InputStream; |
|
47 |
import java.io.Reader; |
|
48 |
import java.util.ArrayList; |
|
49 |
import java.util.List; |
|
42802 | 50 |
import java.util.Map; |
51 |
import javax.xml.XMLConstants; |
|
52 |
import javax.xml.namespace.NamespaceContext; |
|
53 |
import javax.xml.namespace.QName; |
|
54 |
import javax.xml.stream.Location; |
|
12005 | 55 |
import javax.xml.stream.XMLInputFactory; |
56 |
import javax.xml.stream.XMLStreamConstants; |
|
57 |
import javax.xml.stream.XMLStreamException; |
|
42802 | 58 |
import javax.xml.stream.events.EntityDeclaration; |
59 |
import javax.xml.stream.events.NotationDeclaration; |
|
60 |
import javax.xml.stream.events.XMLEvent; |
|
12005 | 61 |
|
42802 | 62 |
/** |
63 |
* This class implements javax.xml.stream.XMLStreamReader. It makes use of |
|
64 |
* XML*Scanner classes to derive most of its functionality. If desired, |
|
65 |
* Application can reuse this instance by calling reset() and setInputSource(). |
|
12005 | 66 |
* |
67 |
* @author Neeraj Bajaj Sun Microsystems,Inc. |
|
68 |
* @author K.Venugopal Sun Microsystems,Inc. |
|
69 |
* @author Sunitha Reddy Sun Microsystems,Inc. |
|
70 |
*/ |
|
71 |
public class XMLStreamReaderImpl implements javax.xml.stream.XMLStreamReader { |
|
72 |
||
42802 | 73 |
/** |
74 |
* Property identifier: entity manager. |
|
75 |
*/ |
|
76 |
protected static final String ENTITY_MANAGER |
|
77 |
= Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; |
|
12005 | 78 |
|
42802 | 79 |
/** |
80 |
* Property identifier: Error Reporter. |
|
81 |
*/ |
|
82 |
protected static final String ERROR_REPORTER |
|
83 |
= Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; |
|
12005 | 84 |
|
42802 | 85 |
/** |
86 |
* Property identifier: Symbol table. |
|
87 |
*/ |
|
88 |
protected static final String SYMBOL_TABLE |
|
89 |
= Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; |
|
12005 | 90 |
|
42802 | 91 |
protected static final String READER_IN_DEFINED_STATE |
92 |
= Constants.READER_IN_DEFINED_STATE; |
|
12005 | 93 |
|
94 |
private SymbolTable fSymbolTable = new SymbolTable(); |
|
95 |
||
42802 | 96 |
/** |
97 |
* Document scanner. |
|
98 |
*/ |
|
12005 | 99 |
protected XMLDocumentScannerImpl fScanner = new XMLNSDocumentScannerImpl(); |
100 |
||
42802 | 101 |
//make Global NamespaceContextWrapper object, fScanner.getNamespaceContext() |
102 |
//is dynamic object and ita value changes as per the state of the parser. |
|
103 |
protected NamespaceContextWrapper fNamespaceContextWrapper = |
|
104 |
new NamespaceContextWrapper((NamespaceSupport) fScanner.getNamespaceContext()); |
|
12005 | 105 |
protected XMLEntityManager fEntityManager = new XMLEntityManager(); |
106 |
protected StaxErrorReporter fErrorReporter = new StaxErrorReporter(); |
|
107 |
||
42802 | 108 |
/** |
109 |
* Entity scanner, this alwasy works on last entity that was opened. |
|
110 |
*/ |
|
12005 | 111 |
protected XMLEntityScanner fEntityScanner = null; |
112 |
||
42802 | 113 |
/** |
114 |
* Input Source |
|
115 |
*/ |
|
12005 | 116 |
protected XMLInputSource fInputSource = null; |
42802 | 117 |
/** |
118 |
* Store properties |
|
119 |
*/ |
|
120 |
protected PropertyManager fPropertyManager = null; |
|
12005 | 121 |
|
42802 | 122 |
/** |
123 |
* current event type |
|
124 |
*/ |
|
125 |
private int fEventType; |
|
126 |
/** |
|
127 |
* debug flag |
|
128 |
*/ |
|
129 |
static final boolean DEBUG = false; |
|
130 |
/** |
|
131 |
* more to scan |
|
132 |
*/ |
|
12005 | 133 |
private boolean fReuse = true; |
42802 | 134 |
private boolean fReaderInDefinedState = true; |
12005 | 135 |
private String fDTDDecl = null; |
136 |
private String versionStr = null; |
|
137 |
||
138 |
/** |
|
139 |
* @param inputStream |
|
140 |
* @param props |
|
141 |
* @throws XMLStreamException |
|
142 |
*/ |
|
42802 | 143 |
public XMLStreamReaderImpl(InputStream inputStream, PropertyManager props) throws XMLStreamException { |
12005 | 144 |
init(props); |
145 |
//publicId, systemid, baseSystemId, inputStream, enocding |
|
42802 | 146 |
XMLInputSource inputSource = new XMLInputSource(null, null, null, inputStream, null); |
12005 | 147 |
//pass the input source to document scanner impl. |
148 |
setInputSource(inputSource); |
|
149 |
} |
|
150 |
||
42802 | 151 |
public XMLDocumentScannerImpl getScanner() { |
12005 | 152 |
System.out.println("returning scanner"); |
153 |
return fScanner; |
|
154 |
} |
|
42802 | 155 |
|
12005 | 156 |
/** |
157 |
* @param systemid |
|
158 |
* @param props |
|
159 |
* @throws XMLStreamException |
|
160 |
*/ |
|
42802 | 161 |
public XMLStreamReaderImpl(String systemid, PropertyManager props) throws XMLStreamException { |
12005 | 162 |
init(props); |
163 |
//publicId, systemid, baseSystemId, inputStream, enocding |
|
39080
57563e513b11
8158204: accessExternalSchema property handling is inconsistent and differs from spec.
joehw
parents:
33349
diff
changeset
|
164 |
XMLInputSource inputSource = new XMLInputSource(null, systemid, null, false); |
12005 | 165 |
//pass the input source to document scanner impl. |
166 |
setInputSource(inputSource); |
|
167 |
} |
|
168 |
||
169 |
/** |
|
170 |
* @param inputStream |
|
171 |
* @param encoding |
|
172 |
* @param props |
|
173 |
* @throws XMLStreamException |
|
174 |
*/ |
|
42802 | 175 |
public XMLStreamReaderImpl(InputStream inputStream, String encoding, PropertyManager props) |
176 |
throws XMLStreamException { |
|
12005 | 177 |
init(props); |
178 |
//publicId, systemid, baseSystemId, inputStream, enocding |
|
42802 | 179 |
XMLInputSource inputSource = new XMLInputSource(null, null, null, |
180 |
new BufferedInputStream(inputStream), encoding); |
|
12005 | 181 |
//pass the input source to document scanner impl. |
182 |
setInputSource(inputSource); |
|
183 |
} |
|
184 |
||
185 |
/** |
|
186 |
* @param reader |
|
187 |
* @param props |
|
188 |
* @throws XMLStreamException |
|
189 |
*/ |
|
42802 | 190 |
public XMLStreamReaderImpl(Reader reader, PropertyManager props) |
191 |
throws XMLStreamException { |
|
12005 | 192 |
init(props); |
193 |
//publicId, systemid, baseSystemId, inputStream, enocding |
|
194 |
//xxx: Using buffered reader |
|
42802 | 195 |
XMLInputSource inputSource = new XMLInputSource(null, null, null, |
196 |
new BufferedReader(reader), null); |
|
12005 | 197 |
//pass the input source to document scanner impl. |
198 |
setInputSource(inputSource); |
|
199 |
} |
|
200 |
||
201 |
/** |
|
202 |
* @param inputSource |
|
203 |
* @param props |
|
204 |
* @throws XMLStreamException |
|
205 |
*/ |
|
42802 | 206 |
public XMLStreamReaderImpl(XMLInputSource inputSource, PropertyManager props) |
207 |
throws XMLStreamException { |
|
12005 | 208 |
init(props); |
209 |
//pass the input source to document scanner impl. |
|
210 |
setInputSource(inputSource); |
|
211 |
} |
|
212 |
||
213 |
/** |
|
214 |
* @param inputSource |
|
215 |
* @throws XMLStreamException |
|
216 |
*/ |
|
42802 | 217 |
public final void setInputSource(XMLInputSource inputSource) throws XMLStreamException { |
12005 | 218 |
//once setInputSource() is called this instance is busy parsing the inputsource supplied |
219 |
//this instances is free for reuse if parser has reached END_DOCUMENT state or application has |
|
220 |
//called close() |
|
221 |
fReuse = false; |
|
222 |
||
42802 | 223 |
try { |
12005 | 224 |
|
42802 | 225 |
fScanner.setInputSource(inputSource); |
12005 | 226 |
//XMLStreamReader should be in defined state |
42802 | 227 |
if (fReaderInDefinedState) { |
12005 | 228 |
fEventType = fScanner.next(); |
42802 | 229 |
if (versionStr == null) { |
12005 | 230 |
versionStr = getVersion(); |
42802 | 231 |
} |
12005 | 232 |
|
42802 | 233 |
if (fEventType == XMLStreamConstants.START_DOCUMENT && versionStr != null |
234 |
&& versionStr.equals("1.1")) { |
|
12005 | 235 |
switchToXML11Scanner(); |
236 |
} |
|
237 |
||
238 |
} |
|
42802 | 239 |
} catch (java.io.IOException ex) { |
12005 | 240 |
throw new XMLStreamException(ex); |
42802 | 241 |
} catch (XNIException ex) { //Issue 56 XNIException not caught |
12005 | 242 |
throw new XMLStreamException(ex.getMessage(), getLocation(), ex.getException()); |
243 |
} |
|
244 |
}//setInputSource |
|
245 |
||
42802 | 246 |
final void init(PropertyManager propertyManager) throws XMLStreamException { |
12005 | 247 |
fPropertyManager = propertyManager; |
248 |
//set Stax internal properties -- Note that these instances are being created in XMLReaderImpl. |
|
249 |
//1.SymbolTable |
|
250 |
//2.XMLMessageFormatter |
|
251 |
//3.XMLEntityManager |
|
252 |
//4. call reset() |
|
253 |
//1. |
|
42802 | 254 |
propertyManager.setProperty(SYMBOL_TABLE, fSymbolTable); |
12005 | 255 |
//2. |
42802 | 256 |
propertyManager.setProperty(ERROR_REPORTER, fErrorReporter); |
12005 | 257 |
//3. |
258 |
propertyManager.setProperty(ENTITY_MANAGER, fEntityManager); |
|
259 |
//4. |
|
260 |
reset(); |
|
261 |
} |
|
262 |
||
42802 | 263 |
/** |
264 |
* This function tells if this instances is available for reuse. One must |
|
265 |
* call reset() and setInputSource() to be able to reuse this instance. |
|
12005 | 266 |
*/ |
42802 | 267 |
public boolean canReuse() { |
268 |
if (DEBUG) { |
|
12005 | 269 |
System.out.println("fReuse = " + fReuse); |
42802 | 270 |
System.out.println("fEventType = " + getEventTypeString(fEventType)); |
12005 | 271 |
} |
272 |
//when parsing begins, fReuse is set to false |
|
273 |
//fReuse is set to 'true' when application calls close() |
|
274 |
return fReuse; |
|
275 |
} |
|
276 |
||
277 |
/** |
|
278 |
* Resets this instance so that this instance is ready for reuse. |
|
279 |
*/ |
|
42802 | 280 |
public void reset() { |
12005 | 281 |
fReuse = true; |
42802 | 282 |
fEventType = 0; |
12005 | 283 |
//reset entity manager |
284 |
fEntityManager.reset(fPropertyManager); |
|
285 |
//reset the scanner |
|
286 |
fScanner.reset(fPropertyManager); |
|
287 |
//REVISIT:this is too ugly -- we are getting XMLEntityManager and XMLEntityReader from |
|
288 |
//property manager, it should be only XMLEntityManager |
|
289 |
fDTDDecl = null; |
|
42802 | 290 |
fEntityScanner = fEntityManager.getEntityScanner(); |
291 |
//default value for this property is true. However, this should be false |
|
292 |
//when using XMLEventReader, because XMLEventReader should not have defined state. |
|
293 |
fReaderInDefinedState = ((Boolean) fPropertyManager.getProperty(READER_IN_DEFINED_STATE)); |
|
12005 | 294 |
versionStr = null; |
295 |
} |
|
296 |
||
42802 | 297 |
/** |
298 |
* Frees any resources associated with this Reader. This method does not |
|
299 |
* close the underlying input source. |
|
300 |
* |
|
301 |
* @throws XMLStreamException if there are errors freeing associated |
|
302 |
* resources |
|
12005 | 303 |
*/ |
304 |
public void close() throws XMLStreamException { |
|
305 |
//xxx: Check what this function is intended to do. |
|
306 |
//reset(); |
|
42802 | 307 |
fReuse = true; |
12005 | 308 |
} |
309 |
||
42802 | 310 |
/** |
311 |
* Returns the character encoding declared on the xml declaration Returns |
|
312 |
* null if none was declared |
|
313 |
* |
|
12005 | 314 |
* @return the encoding declared in the document or null |
315 |
*/ |
|
316 |
public String getCharacterEncodingScheme() { |
|
317 |
return fScanner.getCharacterEncodingScheme(); |
|
318 |
||
319 |
} |
|
320 |
||
321 |
/** |
|
322 |
* @return |
|
323 |
*/ |
|
324 |
public int getColumnNumber() { |
|
325 |
return fEntityScanner.getColumnNumber(); |
|
326 |
}//getColumnNumber |
|
327 |
||
42802 | 328 |
/** |
329 |
* Return input encoding if known or null if unknown. |
|
330 |
* |
|
12005 | 331 |
* @return the encoding of this instance or null |
332 |
*/ |
|
333 |
public String getEncoding() { |
|
334 |
return fEntityScanner.getEncoding(); |
|
335 |
}//getEncoding |
|
336 |
||
42802 | 337 |
/** |
338 |
* Returns the current value of the parse event as a string, this returns |
|
339 |
* the string value of a CHARACTERS event, returns the value of a COMMENT, |
|
340 |
* the replacement value for an ENTITY_REFERENCE, the string value of a |
|
341 |
* CDATA section, the string value for a SPACE event, or the String value of |
|
342 |
* the internal subset of the DTD. If an ENTITY_REFERENCE has been resolved, |
|
343 |
* any character data will be reported as CHARACTERS events. |
|
344 |
* |
|
12005 | 345 |
* @return the current text or null |
346 |
*/ |
|
347 |
public int getEventType() { |
|
42802 | 348 |
return fEventType; |
12005 | 349 |
}//getEventType |
350 |
||
351 |
/** |
|
352 |
* @return |
|
353 |
*/ |
|
354 |
public int getLineNumber() { |
|
42802 | 355 |
return fEntityScanner.getLineNumber(); |
12005 | 356 |
}//getLineNumber |
357 |
||
358 |
public String getLocalName() { |
|
42802 | 359 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT) { |
12005 | 360 |
//xxx check whats the value of fCurrentElement |
42802 | 361 |
return fScanner.getElementQName().localpart; |
362 |
} else if (fEventType == XMLEvent.ENTITY_REFERENCE) { |
|
12005 | 363 |
return fScanner.getEntityName(); |
364 |
} |
|
42802 | 365 |
throw new IllegalStateException("Method getLocalName() cannot be called for " |
366 |
+ getEventTypeString(fEventType) + " event."); |
|
12005 | 367 |
}//getLocalName() |
368 |
||
369 |
/** |
|
370 |
* @return |
|
371 |
*/ |
|
372 |
public String getNamespaceURI() { |
|
373 |
//doesn't take care of Attribute as separte event |
|
42802 | 374 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT) { |
375 |
return fScanner.getElementQName().uri; |
|
12005 | 376 |
} |
42802 | 377 |
return null; |
12005 | 378 |
}//getNamespaceURI |
379 |
||
42802 | 380 |
/** |
381 |
* Get the data section of a processing instruction |
|
382 |
* |
|
12005 | 383 |
* @return the data or null |
384 |
*/ |
|
385 |
public String getPIData() { |
|
42802 | 386 |
if (fEventType == XMLEvent.PROCESSING_INSTRUCTION) { |
12005 | 387 |
return fScanner.getPIData().toString(); |
42802 | 388 |
} else { |
389 |
throw new java.lang.IllegalStateException("Current state of the parser is " + getEventTypeString(fEventType) |
|
390 |
+ " But Expected state is " + XMLEvent.PROCESSING_INSTRUCTION); |
|
12005 | 391 |
} |
392 |
}//getPIData |
|
393 |
||
42802 | 394 |
/** |
395 |
* Get the target of a processing instruction |
|
396 |
* |
|
12005 | 397 |
* @return the target or null |
398 |
*/ |
|
399 |
public String getPITarget() { |
|
42802 | 400 |
if (fEventType == XMLEvent.PROCESSING_INSTRUCTION) { |
12005 | 401 |
return fScanner.getPITarget(); |
42802 | 402 |
} else { |
403 |
throw new java.lang.IllegalStateException("Current state of the parser is " + getEventTypeString(fEventType) |
|
404 |
+ " But Expected state is " + XMLEvent.PROCESSING_INSTRUCTION); |
|
12005 | 405 |
} |
406 |
||
407 |
}//getPITarget |
|
408 |
||
409 |
/** |
|
42802 | 410 |
* @return the prefix of the current event, or null if the event does not |
411 |
* have a prefix. For START_ELEMENT and END_ELEMENT, return |
|
412 |
* XMLConstants.DEFAULT_NS_PREFIX when no prefix is available. |
|
413 |
*/ |
|
12005 | 414 |
public String getPrefix() { |
42802 | 415 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT) { |
12005 | 416 |
String prefix = fScanner.getElementQName().prefix; |
417 |
return prefix == null ? XMLConstants.DEFAULT_NS_PREFIX : prefix; |
|
418 |
} |
|
42802 | 419 |
return null; |
12005 | 420 |
}//getPrefix() |
421 |
||
422 |
/** |
|
423 |
* @return |
|
424 |
*/ |
|
425 |
public char[] getTextCharacters() { |
|
42802 | 426 |
if (fEventType == XMLEvent.CHARACTERS || fEventType == XMLEvent.COMMENT |
427 |
|| fEventType == XMLEvent.CDATA || fEventType == XMLEvent.SPACE) { |
|
428 |
return fScanner.getCharacterData().ch; |
|
429 |
} else { |
|
430 |
throw new IllegalStateException("Current state = " + getEventTypeString(fEventType) |
|
431 |
+ " is not among the states " + getEventTypeString(XMLEvent.CHARACTERS) + " , " |
|
432 |
+ getEventTypeString(XMLEvent.COMMENT) + " , " + getEventTypeString(XMLEvent.CDATA) |
|
433 |
+ " , " + getEventTypeString(XMLEvent.SPACE) + " valid for getTextCharacters() "); |
|
434 |
} |
|
12005 | 435 |
} |
436 |
||
437 |
/** |
|
438 |
* @return |
|
439 |
*/ |
|
440 |
public int getTextLength() { |
|
42802 | 441 |
if (fEventType == XMLEvent.CHARACTERS || fEventType == XMLEvent.COMMENT |
442 |
|| fEventType == XMLEvent.CDATA || fEventType == XMLEvent.SPACE) { |
|
443 |
return fScanner.getCharacterData().length; |
|
444 |
} else { |
|
445 |
throw new IllegalStateException("Current state = " + getEventTypeString(fEventType) |
|
446 |
+ " is not among the states " + getEventTypeString(XMLEvent.CHARACTERS) + " , " |
|
447 |
+ getEventTypeString(XMLEvent.COMMENT) + " , " + getEventTypeString(XMLEvent.CDATA) |
|
448 |
+ " , " + getEventTypeString(XMLEvent.SPACE) + " valid for getTextLength() "); |
|
449 |
} |
|
12005 | 450 |
|
42802 | 451 |
} |
12005 | 452 |
|
453 |
/** |
|
454 |
* @return |
|
455 |
*/ |
|
456 |
public int getTextStart() { |
|
42802 | 457 |
if (fEventType == XMLEvent.CHARACTERS || fEventType == XMLEvent.COMMENT |
458 |
|| fEventType == XMLEvent.CDATA || fEventType == XMLEvent.SPACE) { |
|
459 |
return fScanner.getCharacterData().offset; |
|
460 |
} else { |
|
461 |
throw new IllegalStateException("Current state = " + getEventTypeString(fEventType) |
|
462 |
+ " is not among the states " + getEventTypeString(XMLEvent.CHARACTERS) + " , " |
|
463 |
+ getEventTypeString(XMLEvent.COMMENT) + " , " + getEventTypeString(XMLEvent.CDATA) |
|
464 |
+ " , " + getEventTypeString(XMLEvent.SPACE) + " valid for getTextStart() "); |
|
465 |
} |
|
12005 | 466 |
} |
467 |
||
468 |
/** |
|
469 |
* @return |
|
470 |
*/ |
|
471 |
public String getValue() { |
|
42802 | 472 |
if (fEventType == XMLEvent.PROCESSING_INSTRUCTION) { |
12005 | 473 |
return fScanner.getPIData().toString(); |
42802 | 474 |
} else if (fEventType == XMLEvent.COMMENT) { |
12005 | 475 |
return fScanner.getComment(); |
42802 | 476 |
} else if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT) { |
477 |
return fScanner.getElementQName().localpart; |
|
478 |
} else if (fEventType == XMLEvent.CHARACTERS) { |
|
12005 | 479 |
return fScanner.getCharacterData().toString(); |
480 |
} |
|
481 |
return null; |
|
482 |
}//getValue() |
|
483 |
||
42802 | 484 |
/** |
485 |
* Get the XML language version of the current document being parsed |
|
486 |
*/ |
|
12005 | 487 |
public String getVersion() { |
12458 | 488 |
//apply SAP's patch: the default version in the scanner was set to 1.0 because of DOM and SAX |
489 |
//so this patch is a workaround of the difference between StAX and DOM |
|
490 |
// SAPJVM: Return null if the XML version has not been declared (as specified in the JavaDoc). |
|
491 |
||
492 |
String version = fEntityScanner.getXMLVersion(); |
|
493 |
||
494 |
return "1.0".equals(version) && !fEntityScanner.xmlVersionSetExplicitly ? null : version; |
|
12005 | 495 |
} |
496 |
||
497 |
/** |
|
498 |
* @return |
|
499 |
*/ |
|
500 |
public boolean hasAttributes() { |
|
42802 | 501 |
return fScanner.getAttributeIterator().getLength() > 0 ? true : false; |
12005 | 502 |
} |
503 |
||
42802 | 504 |
/** |
505 |
* this Funtion returns true if the current event has name |
|
506 |
*/ |
|
12005 | 507 |
public boolean hasName() { |
42802 | 508 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT) { |
12005 | 509 |
return true; |
42802 | 510 |
} else { |
12005 | 511 |
return false; |
512 |
} |
|
513 |
}//hasName() |
|
514 |
||
515 |
/** |
|
516 |
* @throws XMLStreamException |
|
517 |
* @return |
|
518 |
*/ |
|
519 |
public boolean hasNext() throws XMLStreamException { |
|
520 |
//the scanner returns -1 when it detects a broken stream |
|
42802 | 521 |
if (fEventType == -1) { |
522 |
return false; |
|
523 |
} |
|
12005 | 524 |
//we can check in scanners if the scanner state is not set to |
525 |
//terminating, we still have more events. |
|
526 |
return fEventType != XMLEvent.END_DOCUMENT; |
|
527 |
} |
|
528 |
||
529 |
/** |
|
530 |
* @return |
|
531 |
*/ |
|
532 |
public boolean hasValue() { |
|
42802 | 533 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT |
534 |
|| fEventType == XMLEvent.ENTITY_REFERENCE || fEventType == XMLEvent.PROCESSING_INSTRUCTION |
|
535 |
|| fEventType == XMLEvent.COMMENT || fEventType == XMLEvent.CHARACTERS) { |
|
12005 | 536 |
return true; |
537 |
} else { |
|
538 |
return false; |
|
539 |
} |
|
540 |
||
541 |
} |
|
542 |
||
543 |
/** |
|
544 |
* @return |
|
545 |
*/ |
|
546 |
public boolean isEndElement() { |
|
547 |
return fEventType == XMLEvent.END_ELEMENT; |
|
548 |
} |
|
549 |
||
550 |
/** |
|
551 |
* @return |
|
552 |
*/ |
|
553 |
public boolean isStandalone() { |
|
554 |
return fScanner.isStandAlone(); |
|
555 |
} |
|
556 |
||
557 |
/** |
|
558 |
* @return |
|
559 |
*/ |
|
560 |
public boolean isStartElement() { |
|
561 |
return fEventType == XMLEvent.START_ELEMENT; |
|
562 |
} |
|
563 |
||
564 |
/** |
|
42802 | 565 |
* Returns true if the cursor points to a character data event that consists |
566 |
* of all whitespace Application calling this method needs to cache the |
|
567 |
* value and avoid calling this method again for the same event. |
|
568 |
* |
|
12005 | 569 |
* @return |
570 |
*/ |
|
571 |
public boolean isWhiteSpace() { |
|
42802 | 572 |
if (isCharacters() || (fEventType == XMLStreamConstants.CDATA)) { |
573 |
char[] ch = this.getTextCharacters(); |
|
12005 | 574 |
final int start = this.getTextStart(); |
575 |
final int end = start + this.getTextLength(); |
|
42802 | 576 |
for (int i = start; i < end; i++) { |
577 |
if (!XMLChar.isSpace(ch[i])) { |
|
12005 | 578 |
return false; |
579 |
} |
|
580 |
} |
|
581 |
return true; |
|
582 |
} |
|
583 |
return false; |
|
584 |
} |
|
585 |
||
586 |
/** |
|
587 |
* @throws XMLStreamException |
|
588 |
* @return |
|
589 |
*/ |
|
590 |
public int next() throws XMLStreamException { |
|
42802 | 591 |
if (!hasNext()) { |
12005 | 592 |
if (fEventType != -1) { |
42802 | 593 |
throw new java.util.NoSuchElementException( |
594 |
"END_DOCUMENT reached: no more elements on the stream."); |
|
12005 | 595 |
} else { |
42802 | 596 |
throw new XMLStreamException( |
597 |
"Error processing input source. The input stream is not complete."); |
|
12005 | 598 |
} |
599 |
} |
|
600 |
try { |
|
601 |
fEventType = fScanner.next(); |
|
602 |
||
603 |
if (versionStr == null) { |
|
604 |
versionStr = getVersion(); |
|
605 |
} |
|
606 |
||
607 |
if (fEventType == XMLStreamConstants.START_DOCUMENT |
|
608 |
&& versionStr != null |
|
609 |
&& versionStr.equals("1.1")) { |
|
610 |
switchToXML11Scanner(); |
|
611 |
} |
|
612 |
||
613 |
return fEventType; |
|
614 |
} catch (IOException ex) { |
|
615 |
// if this error occured trying to resolve the external DTD subset |
|
616 |
// and IS_VALIDATING == false, then this is not an XML error |
|
42802 | 617 |
if (fScanner.fScannerState == XMLDocumentScannerImpl.SCANNER_STATE_DTD_EXTERNAL) { |
12005 | 618 |
Boolean isValidating = (Boolean) fPropertyManager.getProperty( |
619 |
XMLInputFactory.IS_VALIDATING); |
|
620 |
if (isValidating != null |
|
621 |
&& !isValidating.booleanValue()) { |
|
622 |
// ignore the error, set scanner to known state |
|
623 |
fEventType = XMLEvent.DTD; |
|
42802 | 624 |
fScanner.setScannerState(XMLDocumentScannerImpl.SCANNER_STATE_PROLOG); |
12005 | 625 |
fScanner.setDriver(fScanner.fPrologDriver); |
626 |
if (fDTDDecl == null |
|
627 |
|| fDTDDecl.length() == 0) { |
|
628 |
fDTDDecl = "<!-- " |
|
629 |
+ "Exception scanning External DTD Subset. " |
|
630 |
+ "True contents of DTD cannot be determined. " |
|
631 |
+ "Processing will continue as XMLInputFactory.IS_VALIDATING == false." |
|
632 |
+ " -->"; |
|
633 |
} |
|
634 |
return XMLEvent.DTD; |
|
635 |
} |
|
636 |
} |
|
637 |
||
638 |
// else real error |
|
639 |
throw new XMLStreamException(ex.getMessage(), getLocation(), ex); |
|
640 |
} catch (XNIException ex) { |
|
641 |
throw new XMLStreamException( |
|
642 |
ex.getMessage(), |
|
643 |
getLocation(), |
|
644 |
ex.getException()); |
|
645 |
} |
|
646 |
} //next() |
|
647 |
||
42802 | 648 |
private void switchToXML11Scanner() throws IOException { |
12005 | 649 |
|
650 |
int oldEntityDepth = fScanner.fEntityDepth; |
|
42802 | 651 |
com.sun.org.apache.xerces.internal.xni.NamespaceContext oldNamespaceContext |
652 |
= fScanner.fNamespaceContext; |
|
12005 | 653 |
|
654 |
fScanner = new XML11NSDocumentScannerImpl(); |
|
655 |
||
656 |
//get the new scanner state to old scanner's previous state |
|
657 |
fScanner.reset(fPropertyManager); |
|
658 |
fScanner.setPropertyManager(fPropertyManager); |
|
42394
285ea8081752
8167340: XMLStreamReader.getElementText return corrupt content when size of element is > 8192
joehw
parents:
39080
diff
changeset
|
659 |
fEntityScanner = fEntityManager.getEntityScanner(); |
285ea8081752
8167340: XMLStreamReader.getElementText return corrupt content when size of element is > 8192
joehw
parents:
39080
diff
changeset
|
660 |
fEntityScanner.registerListener(fScanner); |
12005 | 661 |
fEntityManager.fCurrentEntity.mayReadChunks = true; |
662 |
fScanner.setScannerState(XMLEvent.START_DOCUMENT); |
|
663 |
||
664 |
fScanner.fEntityDepth = oldEntityDepth; |
|
665 |
fScanner.fNamespaceContext = oldNamespaceContext; |
|
666 |
fEventType = fScanner.next(); |
|
667 |
} |
|
668 |
||
669 |
final static String getEventTypeString(int eventType) { |
|
42802 | 670 |
switch (eventType) { |
12005 | 671 |
case XMLEvent.START_ELEMENT: |
672 |
return "START_ELEMENT"; |
|
673 |
case XMLEvent.END_ELEMENT: |
|
674 |
return "END_ELEMENT"; |
|
675 |
case XMLEvent.PROCESSING_INSTRUCTION: |
|
676 |
return "PROCESSING_INSTRUCTION"; |
|
677 |
case XMLEvent.CHARACTERS: |
|
678 |
return "CHARACTERS"; |
|
679 |
case XMLEvent.COMMENT: |
|
680 |
return "COMMENT"; |
|
681 |
case XMLEvent.START_DOCUMENT: |
|
682 |
return "START_DOCUMENT"; |
|
683 |
case XMLEvent.END_DOCUMENT: |
|
684 |
return "END_DOCUMENT"; |
|
685 |
case XMLEvent.ENTITY_REFERENCE: |
|
686 |
return "ENTITY_REFERENCE"; |
|
687 |
case XMLEvent.ATTRIBUTE: |
|
688 |
return "ATTRIBUTE"; |
|
689 |
case XMLEvent.DTD: |
|
690 |
return "DTD"; |
|
691 |
case XMLEvent.CDATA: |
|
692 |
return "CDATA"; |
|
693 |
case XMLEvent.SPACE: |
|
694 |
return "SPACE"; |
|
695 |
} |
|
696 |
return "UNKNOWN_EVENT_TYPE, " + String.valueOf(eventType); |
|
697 |
} |
|
698 |
||
42802 | 699 |
/** |
700 |
* Returns the count of attributes on this START_ELEMENT, this method is |
|
701 |
* only valid on a START_ELEMENT or ATTRIBUTE. This count excludes namespace |
|
702 |
* definitions. Attribute indices are zero-based. |
|
703 |
* |
|
12005 | 704 |
* @return returns the number of attributes |
705 |
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE |
|
706 |
*/ |
|
707 |
public int getAttributeCount() { |
|
708 |
//xxx: recognize SAX properties namespace, namespace-prefix to get XML Namespace declarations |
|
709 |
//does length includes namespace declarations ? |
|
710 |
||
711 |
//State should be either START_ELEMENT or ATTRIBUTE |
|
42802 | 712 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { |
713 |
return fScanner.getAttributeIterator().getLength(); |
|
714 |
} else { |
|
715 |
throw new java.lang.IllegalStateException("Current state is not among the states " |
|
716 |
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , " |
|
717 |
+ getEventTypeString(XMLEvent.ATTRIBUTE) |
|
718 |
+ "valid for getAttributeCount()"); |
|
12005 | 719 |
} |
720 |
}//getAttributeCount |
|
721 |
||
42802 | 722 |
/** |
723 |
* Returns the localName of the attribute at the provided index |
|
724 |
* |
|
12005 | 725 |
* @param index the position of the attribute |
726 |
* @return the localName of the attribute |
|
727 |
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE |
|
728 |
*/ |
|
729 |
public QName getAttributeName(int index) { |
|
730 |
//State should be either START_ELEMENT or ATTRIBUTE |
|
42802 | 731 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { |
732 |
return convertXNIQNametoJavaxQName(fScanner.getAttributeIterator().getQualifiedName(index)); |
|
733 |
} else { |
|
12005 | 734 |
throw new java.lang.IllegalStateException("Current state is not among the states " |
42802 | 735 |
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , " |
736 |
+ getEventTypeString(XMLEvent.ATTRIBUTE) |
|
737 |
+ "valid for getAttributeName()"); |
|
12005 | 738 |
} |
739 |
}//getAttributeName |
|
740 |
||
741 |
/** |
|
742 |
* @param index |
|
743 |
* @return |
|
744 |
*/ |
|
745 |
public String getAttributeLocalName(int index) { |
|
746 |
//State should be either START_ELEMENT or ATTRIBUTE |
|
42802 | 747 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { |
748 |
return fScanner.getAttributeIterator().getLocalName(index); |
|
749 |
} else { |
|
750 |
throw new java.lang.IllegalStateException(); |
|
12005 | 751 |
} |
752 |
}//getAttributeName |
|
753 |
||
42802 | 754 |
/** |
755 |
* Returns the namespace of the attribute at the provided index |
|
756 |
* |
|
12005 | 757 |
* @param index the position of the attribute |
758 |
* @return the namespace URI (can be null) |
|
759 |
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE |
|
760 |
*/ |
|
761 |
public String getAttributeNamespace(int index) { |
|
762 |
//State should be either START_ELEMENT or ATTRIBUTE |
|
42802 | 763 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { |
12005 | 764 |
return fScanner.getAttributeIterator().getURI(index); |
42802 | 765 |
} else { |
12005 | 766 |
throw new java.lang.IllegalStateException("Current state is not among the states " |
42802 | 767 |
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , " |
768 |
+ getEventTypeString(XMLEvent.ATTRIBUTE) |
|
769 |
+ "valid for getAttributeNamespace()"); |
|
12005 | 770 |
} |
771 |
||
772 |
}//getAttributeNamespace |
|
773 |
||
42802 | 774 |
/** |
775 |
* Returns the prefix of this attribute at the provided index |
|
776 |
* |
|
12005 | 777 |
* @param index the position of the attribute |
778 |
* @return the prefix of the attribute |
|
779 |
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE |
|
780 |
*/ |
|
781 |
public String getAttributePrefix(int index) { |
|
782 |
//State should be either START_ELEMENT or ATTRIBUTE |
|
42802 | 783 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { |
12005 | 784 |
return fScanner.getAttributeIterator().getPrefix(index); |
42802 | 785 |
} else { |
12005 | 786 |
throw new java.lang.IllegalStateException("Current state is not among the states " |
42802 | 787 |
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , " |
788 |
+ getEventTypeString(XMLEvent.ATTRIBUTE) |
|
789 |
+ "valid for getAttributePrefix()"); |
|
12005 | 790 |
} |
791 |
}//getAttributePrefix |
|
792 |
||
42802 | 793 |
/** |
794 |
* Returns the qname of the attribute at the provided index |
|
12005 | 795 |
* |
796 |
* @param index the position of the attribute |
|
797 |
* @return the QName of the attribute |
|
798 |
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE |
|
799 |
*/ |
|
800 |
public javax.xml.namespace.QName getAttributeQName(int index) { |
|
801 |
//State should be either START_ELEMENT or ATTRIBUTE |
|
42802 | 802 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { |
12005 | 803 |
// create new object at runtime.. |
42802 | 804 |
String localName = fScanner.getAttributeIterator().getLocalName(index); |
805 |
String uri = fScanner.getAttributeIterator().getURI(index); |
|
806 |
return new javax.xml.namespace.QName(uri, localName); |
|
807 |
} else { |
|
12005 | 808 |
throw new java.lang.IllegalStateException("Current state is not among the states " |
42802 | 809 |
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , " |
810 |
+ getEventTypeString(XMLEvent.ATTRIBUTE) |
|
811 |
+ "valid for getAttributeQName()"); |
|
12005 | 812 |
} |
813 |
}//getAttributeQName |
|
814 |
||
42802 | 815 |
/** |
816 |
* Returns the XML type of the attribute at the provided index |
|
817 |
* |
|
12005 | 818 |
* @param index the position of the attribute |
819 |
* @return the XML type of the attribute |
|
820 |
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE |
|
821 |
*/ |
|
822 |
public String getAttributeType(int index) { |
|
823 |
//State should be either START_ELEMENT or ATTRIBUTE |
|
42802 | 824 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { |
825 |
return fScanner.getAttributeIterator().getType(index); |
|
826 |
} else { |
|
12005 | 827 |
throw new java.lang.IllegalStateException("Current state is not among the states " |
42802 | 828 |
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , " |
829 |
+ getEventTypeString(XMLEvent.ATTRIBUTE) |
|
830 |
+ "valid for getAttributeType()"); |
|
12005 | 831 |
} |
832 |
||
833 |
}//getAttributeType |
|
834 |
||
42802 | 835 |
/** |
836 |
* Returns the value of the attribute at the index |
|
837 |
* |
|
12005 | 838 |
* @param index the position of the attribute |
839 |
* @return the attribute value |
|
840 |
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE |
|
841 |
*/ |
|
842 |
public String getAttributeValue(int index) { |
|
843 |
//State should be either START_ELEMENT or ATTRIBUTE |
|
42802 | 844 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { |
845 |
return fScanner.getAttributeIterator().getValue(index); |
|
846 |
} else { |
|
12005 | 847 |
throw new java.lang.IllegalStateException("Current state is not among the states " |
42802 | 848 |
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , " |
849 |
+ getEventTypeString(XMLEvent.ATTRIBUTE) |
|
850 |
+ "valid for getAttributeValue()"); |
|
12005 | 851 |
} |
852 |
||
853 |
}//getAttributeValue |
|
854 |
||
855 |
/** |
|
856 |
* @param namespaceURI |
|
857 |
* @param localName |
|
858 |
* @return |
|
859 |
*/ |
|
860 |
public String getAttributeValue(String namespaceURI, String localName) { |
|
861 |
//State should be either START_ELEMENT or ATTRIBUTE |
|
42802 | 862 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { |
12005 | 863 |
XMLAttributesImpl attributes = fScanner.getAttributeIterator(); |
864 |
if (namespaceURI == null) { //sjsxp issue 70 |
|
42802 | 865 |
return attributes.getValue(attributes.getIndexByLocalName(localName)); |
12005 | 866 |
} else { |
867 |
return fScanner.getAttributeIterator().getValue( |
|
42802 | 868 |
namespaceURI.length() == 0 ? null : namespaceURI, localName); |
12005 | 869 |
} |
870 |
||
42802 | 871 |
} else { |
12005 | 872 |
throw new java.lang.IllegalStateException("Current state is not among the states " |
42802 | 873 |
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , " |
874 |
+ getEventTypeString(XMLEvent.ATTRIBUTE) |
|
875 |
+ "valid for getAttributeValue()"); |
|
12005 | 876 |
} |
877 |
||
878 |
} |
|
879 |
||
42802 | 880 |
/** |
881 |
* Reads the content of a text-only element. Precondition: the current event |
|
882 |
* is START_ELEMENT. Postcondition: The current event is the corresponding |
|
883 |
* END_ELEMENT. |
|
884 |
* |
|
885 |
* @throws XMLStreamException if the current event is not a START_ELEMENT or |
|
886 |
* if a non text element is encountered |
|
12005 | 887 |
*/ |
888 |
public String getElementText() throws XMLStreamException { |
|
889 |
||
42802 | 890 |
if (getEventType() != XMLStreamConstants.START_ELEMENT) { |
12005 | 891 |
throw new XMLStreamException( |
42802 | 892 |
"parser must be on START_ELEMENT to read next text", getLocation()); |
12005 | 893 |
} |
894 |
int eventType = next(); |
|
42802 | 895 |
StringBuilder content = new StringBuilder(); |
896 |
while (eventType != XMLStreamConstants.END_ELEMENT) { |
|
897 |
if (eventType == XMLStreamConstants.CHARACTERS |
|
898 |
|| eventType == XMLStreamConstants.CDATA |
|
899 |
|| eventType == XMLStreamConstants.SPACE |
|
900 |
|| eventType == XMLStreamConstants.ENTITY_REFERENCE) { |
|
12005 | 901 |
content.append(getText()); |
42802 | 902 |
} else if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION |
903 |
|| eventType == XMLStreamConstants.COMMENT) { |
|
12005 | 904 |
// skipping |
42802 | 905 |
} else if (eventType == XMLStreamConstants.END_DOCUMENT) { |
12005 | 906 |
throw new XMLStreamException( |
42802 | 907 |
"unexpected end of document when reading element text content"); |
908 |
} else if (eventType == XMLStreamConstants.START_ELEMENT) { |
|
909 |
throw new XMLStreamException("elementGetText() function expects text " |
|
910 |
+ "only elment but START_ELEMENT was encountered.", getLocation()); |
|
12005 | 911 |
} else { |
912 |
throw new XMLStreamException( |
|
42802 | 913 |
"Unexpected event type " + eventType, getLocation()); |
12005 | 914 |
} |
915 |
eventType = next(); |
|
916 |
} |
|
917 |
return content.toString(); |
|
918 |
} |
|
919 |
||
42802 | 920 |
/** |
921 |
* Return the current location of the processor. If the Location is unknown |
|
922 |
* the processor should return an implementation of Location that returns -1 |
|
923 |
* for the location and null for the publicId and systemId. The location |
|
924 |
* information is only valid until next() is called. |
|
12005 | 925 |
*/ |
926 |
public Location getLocation() { |
|
927 |
return new Location() { |
|
928 |
String _systemId = fEntityScanner.getExpandedSystemId(); |
|
929 |
String _publicId = fEntityScanner.getPublicId(); |
|
930 |
int _offset = fEntityScanner.getCharacterOffset(); |
|
931 |
int _columnNumber = fEntityScanner.getColumnNumber(); |
|
932 |
int _lineNumber = fEntityScanner.getLineNumber(); |
|
42802 | 933 |
|
934 |
public String getLocationURI() { |
|
12005 | 935 |
return _systemId; |
936 |
} |
|
937 |
||
42802 | 938 |
public int getCharacterOffset() { |
12005 | 939 |
return _offset; |
940 |
} |
|
941 |
||
942 |
public int getColumnNumber() { |
|
943 |
return _columnNumber; |
|
944 |
} |
|
945 |
||
42802 | 946 |
public int getLineNumber() { |
12005 | 947 |
return _lineNumber; |
948 |
} |
|
949 |
||
42802 | 950 |
public String getPublicId() { |
12005 | 951 |
return _publicId; |
952 |
} |
|
953 |
||
42802 | 954 |
public String getSystemId() { |
12005 | 955 |
return _systemId; |
956 |
} |
|
957 |
||
42802 | 958 |
public String toString() { |
959 |
StringBuilder sbuffer = new StringBuilder(); |
|
12005 | 960 |
sbuffer.append("Line number = " + getLineNumber()); |
42802 | 961 |
sbuffer.append("\n"); |
12005 | 962 |
sbuffer.append("Column number = " + getColumnNumber()); |
42802 | 963 |
sbuffer.append("\n"); |
12005 | 964 |
sbuffer.append("System Id = " + getSystemId()); |
42802 | 965 |
sbuffer.append("\n"); |
12005 | 966 |
sbuffer.append("Public Id = " + getPublicId()); |
42802 | 967 |
sbuffer.append("\n"); |
12005 | 968 |
sbuffer.append("Location Uri= " + getLocationURI()); |
42802 | 969 |
sbuffer.append("\n"); |
12005 | 970 |
sbuffer.append("CharacterOffset = " + getCharacterOffset()); |
42802 | 971 |
sbuffer.append("\n"); |
12005 | 972 |
return sbuffer.toString(); |
973 |
} |
|
42802 | 974 |
}; |
12005 | 975 |
|
976 |
} |
|
977 |
||
42802 | 978 |
/** |
979 |
* Returns a QName for the current START_ELEMENT or END_ELEMENT event |
|
980 |
* |
|
12005 | 981 |
* @return the QName for the current START_ELEMENT or END_ELEMENT event |
982 |
*/ |
|
983 |
public javax.xml.namespace.QName getName() { |
|
42802 | 984 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT) { |
12005 | 985 |
return convertXNIQNametoJavaxQName(fScanner.getElementQName()); |
42802 | 986 |
} else { |
987 |
throw new java.lang.IllegalStateException("Illegal to call getName() " |
|
988 |
+ "when event type is " + getEventTypeString(fEventType) + "." |
|
989 |
+ " Valid states are " + getEventTypeString(XMLEvent.START_ELEMENT) + ", " |
|
990 |
+ getEventTypeString(XMLEvent.END_ELEMENT)); |
|
991 |
} |
|
12005 | 992 |
} |
993 |
||
42802 | 994 |
/** |
995 |
* Returns a read only namespace context for the current position. The |
|
996 |
* context is transient and only valid until a call to next() changes the |
|
997 |
* state of the reader. |
|
998 |
* |
|
12005 | 999 |
* @return return a namespace context |
1000 |
*/ |
|
1001 |
public NamespaceContext getNamespaceContext() { |
|
42802 | 1002 |
return fNamespaceContextWrapper; |
12005 | 1003 |
} |
1004 |
||
42802 | 1005 |
/** |
1006 |
* Returns the count of namespaces declared on this START_ELEMENT or |
|
1007 |
* END_ELEMENT, this method is only valid on a START_ELEMENT, END_ELEMENT or |
|
1008 |
* NAMESPACE. On an END_ELEMENT the count is of the namespaces that are |
|
1009 |
* about to go out of scope. This is the equivalent of the information |
|
1010 |
* reported by SAX callback for an end element event. |
|
1011 |
* |
|
1012 |
* @return returns the number of namespace declarations on this specific |
|
1013 |
* element |
|
1014 |
* @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT |
|
1015 |
* or NAMESPACE |
|
12005 | 1016 |
*/ |
1017 |
public int getNamespaceCount() { |
|
1018 |
//namespaceContext is dynamic object. |
|
1019 |
//REVISIT: check if it specifies all conditions mentioned in the javadoc |
|
42802 | 1020 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT |
1021 |
|| fEventType == XMLEvent.NAMESPACE) { |
|
1022 |
return fScanner.getNamespaceContext().getDeclaredPrefixCount(); |
|
1023 |
} else { |
|
12005 | 1024 |
throw new IllegalStateException("Current event state is " + getEventTypeString(fEventType) |
42802 | 1025 |
+ " is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) |
1026 |
+ ", " + getEventTypeString(XMLEvent.END_ELEMENT) + ", " |
|
1027 |
+ getEventTypeString(XMLEvent.NAMESPACE) |
|
1028 |
+ " valid for getNamespaceCount()."); |
|
12005 | 1029 |
} |
1030 |
} |
|
1031 |
||
42802 | 1032 |
/** |
1033 |
* Returns the prefix for the namespace declared at the index. Returns null |
|
1034 |
* if this is the default namespace declaration |
|
12005 | 1035 |
* |
1036 |
* @param index the position of the namespace declaration |
|
1037 |
* @return returns the namespace prefix |
|
42802 | 1038 |
* @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT |
1039 |
* or NAMESPACE |
|
12005 | 1040 |
*/ |
1041 |
public String getNamespacePrefix(int index) { |
|
42802 | 1042 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT |
1043 |
|| fEventType == XMLEvent.NAMESPACE) { |
|
12005 | 1044 |
//namespaceContext is dynamic object. |
42802 | 1045 |
String prefix = fScanner.getNamespaceContext().getDeclaredPrefixAt(index); |
1046 |
return prefix.equals("") ? null : prefix; |
|
1047 |
} else { |
|
12005 | 1048 |
throw new IllegalStateException("Current state " + getEventTypeString(fEventType) |
42802 | 1049 |
+ " is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) |
1050 |
+ ", " + getEventTypeString(XMLEvent.END_ELEMENT) + ", " |
|
1051 |
+ getEventTypeString(XMLEvent.NAMESPACE) |
|
1052 |
+ " valid for getNamespacePrefix()."); |
|
12005 | 1053 |
} |
1054 |
} |
|
1055 |
||
42802 | 1056 |
/** |
1057 |
* Returns the uri for the namespace declared at the index. |
|
12005 | 1058 |
* |
1059 |
* @param index the position of the namespace declaration |
|
1060 |
* @return returns the namespace uri |
|
42802 | 1061 |
* @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT |
1062 |
* or NAMESPACE |
|
12005 | 1063 |
*/ |
1064 |
public String getNamespaceURI(int index) { |
|
42802 | 1065 |
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT |
1066 |
|| fEventType == XMLEvent.NAMESPACE) { |
|
12005 | 1067 |
//namespaceContext is dynamic object. |
42802 | 1068 |
return fScanner.getNamespaceContext().getURI(fScanner.getNamespaceContext() |
1069 |
.getDeclaredPrefixAt(index)); |
|
1070 |
} else { |
|
12005 | 1071 |
throw new IllegalStateException("Current state " + getEventTypeString(fEventType) |
42802 | 1072 |
+ " is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) |
1073 |
+ ", " + getEventTypeString(XMLEvent.END_ELEMENT) + ", " |
|
1074 |
+ getEventTypeString(XMLEvent.NAMESPACE) |
|
1075 |
+ " valid for getNamespaceURI()."); |
|
12005 | 1076 |
} |
1077 |
||
1078 |
} |
|
1079 |
||
42802 | 1080 |
/** |
1081 |
* Get the value of a feature/property from the underlying implementation |
|
1082 |
* |
|
12005 | 1083 |
* @param name The name of the property, may not be null |
1084 |
* @return The value of the property |
|
1085 |
* @throws IllegalArgumentException if name is null |
|
1086 |
*/ |
|
1087 |
public Object getProperty(java.lang.String name) throws java.lang.IllegalArgumentException { |
|
42802 | 1088 |
if (name == null) { |
1089 |
throw new java.lang.IllegalArgumentException(); |
|
1090 |
} |
|
1091 |
if (fPropertyManager != null) { |
|
1092 |
if (name.equals(PropertyManager.STAX_NOTATIONS)) { |
|
12005 | 1093 |
return getNotationDecls(); |
42802 | 1094 |
} else if (name.equals(PropertyManager.STAX_ENTITIES)) { |
12005 | 1095 |
return getEntityDecls(); |
42802 | 1096 |
} else { |
12005 | 1097 |
return fPropertyManager.getProperty(name); |
42802 | 1098 |
} |
12005 | 1099 |
} |
1100 |
return null; |
|
1101 |
} |
|
1102 |
||
42802 | 1103 |
/** |
1104 |
* Returns the current value of the parse event as a string, this returns |
|
1105 |
* the string value of a CHARACTERS event, returns the value of a COMMENT, |
|
1106 |
* the replacement value for an ENTITY_REFERENCE, or the String value of the |
|
1107 |
* DTD |
|
1108 |
* |
|
12005 | 1109 |
* @return the current text or null |
42802 | 1110 |
* @throws java.lang.IllegalStateException if this state is not a valid text |
1111 |
* state. |
|
12005 | 1112 |
*/ |
1113 |
public String getText() { |
|
42802 | 1114 |
if (fEventType == XMLEvent.CHARACTERS || fEventType == XMLEvent.COMMENT |
1115 |
|| fEventType == XMLEvent.CDATA || fEventType == XMLEvent.SPACE) { |
|
12005 | 1116 |
//this requires creation of new string |
1117 |
//fEventType == XMLEvent.ENTITY_REFERENCE |
|
42802 | 1118 |
return fScanner.getCharacterData().toString(); |
1119 |
} else if (fEventType == XMLEvent.ENTITY_REFERENCE) { |
|
12005 | 1120 |
String name = fScanner.getEntityName(); |
42802 | 1121 |
if (name != null) { |
1122 |
if (fScanner.foundBuiltInRefs) { |
|
12005 | 1123 |
return fScanner.getCharacterData().toString(); |
42802 | 1124 |
} |
12005 | 1125 |
|
1126 |
XMLEntityStorage entityStore = fEntityManager.getEntityStore(); |
|
12458 | 1127 |
Entity en = entityStore.getEntity(name); |
42802 | 1128 |
if (en == null) { |
12458 | 1129 |
return null; |
42802 | 1130 |
} |
1131 |
if (en.isExternal()) { |
|
1132 |
return ((Entity.ExternalEntity) en).entityLocation.getExpandedSystemId(); |
|
1133 |
} else { |
|
1134 |
return ((Entity.InternalEntity) en).text; |
|
1135 |
} |
|
1136 |
} else { |
|
12005 | 1137 |
return null; |
42802 | 1138 |
} |
1139 |
} else if (fEventType == XMLEvent.DTD) { |
|
1140 |
if (fDTDDecl != null) { |
|
12005 | 1141 |
return fDTDDecl; |
42802 | 1142 |
} |
1143 |
XMLStringBuffer tmpBuffer = fScanner.getDTDDecl(); |
|
1144 |
fDTDDecl = tmpBuffer.toString(); |
|
1145 |
return fDTDDecl; |
|
1146 |
} else { |
|
1147 |
throw new IllegalStateException("Current state " + getEventTypeString(fEventType) |
|
1148 |
+ " is not among the states" + getEventTypeString(XMLEvent.CHARACTERS) + ", " |
|
1149 |
+ getEventTypeString(XMLEvent.COMMENT) + ", " |
|
1150 |
+ getEventTypeString(XMLEvent.CDATA) + ", " |
|
1151 |
+ getEventTypeString(XMLEvent.SPACE) + ", " |
|
1152 |
+ getEventTypeString(XMLEvent.ENTITY_REFERENCE) + ", " |
|
1153 |
+ getEventTypeString(XMLEvent.DTD) + " valid for getText() "); |
|
12005 | 1154 |
} |
1155 |
}//getText |
|
1156 |
||
42802 | 1157 |
/** |
1158 |
* Test if the current event is of the given type and if the namespace and |
|
1159 |
* name match the current namespace and name of the current event. If the |
|
1160 |
* namespaceURI is null it is not checked for equality, if the localName is |
|
1161 |
* null it is not checked for equality. |
|
1162 |
* |
|
12005 | 1163 |
* @param type the event type |
1164 |
* @param namespaceURI the uri of the event, may be null |
|
1165 |
* @param localName the localName of the event, may be null |
|
1166 |
* @throws XMLStreamException if the required values are not matched. |
|
1167 |
*/ |
|
1168 |
public void require(int type, String namespaceURI, String localName) throws XMLStreamException { |
|
42802 | 1169 |
if (type != fEventType) { |
1170 |
throw new XMLStreamException("Event type " + getEventTypeString(type) + " specified did " |
|
1171 |
+ "not match with current parser event " + getEventTypeString(fEventType)); |
|
1172 |
} |
|
1173 |
if (namespaceURI != null && !namespaceURI.equals(getNamespaceURI())) { |
|
1174 |
throw new XMLStreamException("Namespace URI " + namespaceURI + " specified did not match " |
|
1175 |
+ "with current namespace URI"); |
|
1176 |
} |
|
1177 |
if (localName != null && !localName.equals(getLocalName())) { |
|
1178 |
throw new XMLStreamException("LocalName " + localName + " specified did not match with " |
|
1179 |
+ "current local name"); |
|
1180 |
} |
|
12005 | 1181 |
return; |
1182 |
} |
|
1183 |
||
42802 | 1184 |
/** |
1185 |
* Gets the the text associated with a CHARACTERS, SPACE or CDATA event. |
|
1186 |
* Text starting a "sourceStart" is copied into "destination" starting at |
|
1187 |
* "targetStart". Up to "length" characters are copied. The number of |
|
1188 |
* characters actually copied is returned. |
|
12005 | 1189 |
* |
42802 | 1190 |
* The "sourceStart" argument must be greater or equal to 0 and less than or |
1191 |
* equal to the number of characters associated with the event. Usually, one |
|
1192 |
* requests text starting at a "sourceStart" of 0. If the number of |
|
1193 |
* characters actually copied is less than the "length", then there is no |
|
1194 |
* more text. Otherwise, subsequent calls need to be made until all text has |
|
1195 |
* been retrieved. For example: |
|
12005 | 1196 |
* |
1197 |
* <code> |
|
1198 |
* int length = 1024; |
|
1199 |
* char[] myBuffer = new char[ length ]; |
|
1200 |
* |
|
1201 |
* for ( int sourceStart = 0 ; ; sourceStart += length ) |
|
1202 |
* { |
|
1203 |
* int nCopied = stream.getTextCharacters( sourceStart, myBuffer, 0, length ); |
|
1204 |
* |
|
1205 |
* if (nCopied < length) |
|
1206 |
* break; |
|
1207 |
* } |
|
42802 | 1208 |
* </code> XMLStreamException may be thrown if there are any XML errors in |
1209 |
* the underlying source. The "targetStart" argument must be greater than or |
|
1210 |
* equal to 0 and less than the length of "target", Length must be greater |
|
1211 |
* than 0 and "targetStart + length" must be less than or equal to length of |
|
1212 |
* "target". |
|
12005 | 1213 |
* |
42802 | 1214 |
* @param sourceStart the index of the first character in the source array |
1215 |
* to copy |
|
12005 | 1216 |
* @param target the destination array |
1217 |
* @param targetStart the start offset in the target array |
|
1218 |
* @param length the number of characters to copy |
|
1219 |
* @return the number of characters actually copied |
|
42802 | 1220 |
* @throws XMLStreamException if the underlying XML source is not |
1221 |
* well-formed |
|
1222 |
* @throws IndexOutOfBoundsException if targetStart < 0 or > than the length |
|
1223 |
* of target |
|
1224 |
* @throws IndexOutOfBoundwhile(isCharacters()) ;sException if length < 0 or targetStart + length |
|
1225 |
* > length of target |
|
12005 | 1226 |
* @throws UnsupportedOperationException if this method is not supported |
1227 |
* @throws NullPointerException is if target is null |
|
1228 |
*/ |
|
42802 | 1229 |
public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) |
1230 |
throws XMLStreamException { |
|
12005 | 1231 |
|
42802 | 1232 |
if (target == null) { |
1233 |
throw new NullPointerException("target char array can't be null"); |
|
12005 | 1234 |
} |
1235 |
||
42802 | 1236 |
if (targetStart < 0 || length < 0 || sourceStart < 0 || targetStart >= target.length |
1237 |
|| (targetStart + length) > target.length) { |
|
12005 | 1238 |
throw new IndexOutOfBoundsException(); |
1239 |
} |
|
1240 |
||
1241 |
//getTextStart() + sourceStart should not be greater than the lenght of number of characters |
|
1242 |
//present |
|
1243 |
int copiedLength = 0; |
|
1244 |
//int presentDataLen = getTextLength() - (getTextStart()+sourceStart); |
|
1245 |
int available = getTextLength() - sourceStart; |
|
42802 | 1246 |
if (available < 0) { |
1247 |
throw new IndexOutOfBoundsException("sourceStart is greater than" |
|
1248 |
+ "number of characters associated with this event"); |
|
12005 | 1249 |
} |
42802 | 1250 |
if (available < length) { |
12005 | 1251 |
copiedLength = available; |
42802 | 1252 |
} else { |
12005 | 1253 |
copiedLength = length; |
1254 |
} |
|
1255 |
||
42802 | 1256 |
System.arraycopy(getTextCharacters(), getTextStart() + sourceStart, target, targetStart, copiedLength); |
12005 | 1257 |
return copiedLength; |
1258 |
} |
|
1259 |
||
42802 | 1260 |
/** |
1261 |
* Return true if the current event has text, false otherwise The following |
|
1262 |
* events have text: CHARACTERS,DTD ,ENTITY_REFERENCE, COMMENT |
|
12005 | 1263 |
*/ |
1264 |
public boolean hasText() { |
|
42802 | 1265 |
if (DEBUG) { |
1266 |
pr("XMLReaderImpl#EVENT TYPE = " + fEventType); |
|
1267 |
} |
|
1268 |
if (fEventType == XMLEvent.CHARACTERS || fEventType == XMLEvent.COMMENT |
|
1269 |
|| fEventType == XMLEvent.CDATA) { |
|
33349 | 1270 |
return fScanner.getCharacterData().length > 0; |
42802 | 1271 |
} else if (fEventType == XMLEvent.ENTITY_REFERENCE) { |
12005 | 1272 |
String name = fScanner.getEntityName(); |
42802 | 1273 |
if (name != null) { |
1274 |
if (fScanner.foundBuiltInRefs) { |
|
12005 | 1275 |
return true; |
42802 | 1276 |
} |
12005 | 1277 |
|
1278 |
XMLEntityStorage entityStore = fEntityManager.getEntityStore(); |
|
12458 | 1279 |
Entity en = entityStore.getEntity(name); |
42802 | 1280 |
if (en == null) { |
12005 | 1281 |
return false; |
42802 | 1282 |
} |
1283 |
if (en.isExternal()) { |
|
1284 |
return ((Entity.ExternalEntity) en).entityLocation.getExpandedSystemId() != null; |
|
1285 |
} else { |
|
1286 |
return ((Entity.InternalEntity) en).text != null; |
|
12005 | 1287 |
} |
42802 | 1288 |
} else { |
12005 | 1289 |
return false; |
42802 | 1290 |
} |
1291 |
} else if (fEventType == XMLEvent.DTD) { |
|
1292 |
return fScanner.fSeenDoctypeDecl; |
|
12005 | 1293 |
} |
1294 |
return false; |
|
1295 |
} |
|
1296 |
||
42802 | 1297 |
/** |
1298 |
* Returns a boolean which indicates if this attribute was created by |
|
1299 |
* default |
|
1300 |
* |
|
12005 | 1301 |
* @param index the position of the attribute |
1302 |
* @return true if this is a default attribute |
|
1303 |
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE |
|
1304 |
*/ |
|
1305 |
public boolean isAttributeSpecified(int index) { |
|
1306 |
//check that current state should be either START_ELEMENT or ATTRIBUTE |
|
42802 | 1307 |
if ((fEventType == XMLEvent.START_ELEMENT) || (fEventType == XMLEvent.ATTRIBUTE)) { |
1308 |
return fScanner.getAttributeIterator().isSpecified(index); |
|
1309 |
} else { |
|
12005 | 1310 |
throw new IllegalStateException("Current state is not among the states " |
42802 | 1311 |
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , " |
1312 |
+ getEventTypeString(XMLEvent.ATTRIBUTE) |
|
1313 |
+ "valid for isAttributeSpecified()"); |
|
12005 | 1314 |
} |
1315 |
} |
|
1316 |
||
42802 | 1317 |
/** |
1318 |
* Returns true if the cursor points to a character data event |
|
1319 |
* |
|
12005 | 1320 |
* @return true if the cursor points to character data, false otherwise |
1321 |
*/ |
|
1322 |
public boolean isCharacters() { |
|
42802 | 1323 |
return fEventType == XMLEvent.CHARACTERS; |
12005 | 1324 |
} |
1325 |
||
42802 | 1326 |
/** |
1327 |
* Skips any insignificant events (COMMENT and PROCESSING_INSTRUCTION) until |
|
1328 |
* a START_ELEMENT or END_ELEMENT is reached. If other than space characters |
|
1329 |
* are encountered, an exception is thrown. This method should be used when |
|
1330 |
* processing element-only content because the parser is not able to |
|
1331 |
* recognize ignorable whitespace if then DTD is missing or not interpreted. |
|
1332 |
* |
|
12005 | 1333 |
* @return the event type of the element read |
1334 |
* @throws XMLStreamException if the current event is not white space |
|
1335 |
*/ |
|
1336 |
public int nextTag() throws XMLStreamException { |
|
1337 |
||
1338 |
int eventType = next(); |
|
42802 | 1339 |
while ((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace |
1340 |
|| (eventType == XMLStreamConstants.CDATA && isWhiteSpace()) |
|
1341 |
// skip whitespace |
|
1342 |
|| eventType == XMLStreamConstants.SPACE |
|
1343 |
|| eventType == XMLStreamConstants.PROCESSING_INSTRUCTION |
|
1344 |
|| eventType == XMLStreamConstants.COMMENT) { |
|
12005 | 1345 |
eventType = next(); |
1346 |
} |
|
1347 |
||
1348 |
if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) { |
|
1349 |
throw new XMLStreamException( |
|
1350 |
"found: " + getEventTypeString(eventType) |
|
1351 |
+ ", expected " + getEventTypeString(XMLStreamConstants.START_ELEMENT) |
|
1352 |
+ " or " + getEventTypeString(XMLStreamConstants.END_ELEMENT), |
|
1353 |
getLocation()); |
|
1354 |
} |
|
1355 |
||
1356 |
return eventType; |
|
1357 |
} |
|
1358 |
||
42802 | 1359 |
/** |
1360 |
* Checks if standalone was set in the document |
|
1361 |
* |
|
12005 | 1362 |
* @return true if standalone was set in the document, or false otherwise |
1363 |
*/ |
|
1364 |
public boolean standaloneSet() { |
|
1365 |
//xxx: it requires if the standalone was set in the document ? This is different that if the document |
|
1366 |
// is standalone |
|
42802 | 1367 |
return fScanner.standaloneSet(); |
12005 | 1368 |
} |
1369 |
||
1370 |
/** |
|
1371 |
* @param qname |
|
1372 |
* @return |
|
1373 |
*/ |
|
42802 | 1374 |
public javax.xml.namespace.QName convertXNIQNametoJavaxQName( |
1375 |
com.sun.org.apache.xerces.internal.xni.QName qname) { |
|
1376 |
if (qname == null) { |
|
1377 |
return null; |
|
1378 |
} |
|
12005 | 1379 |
//xxx: prefix definition ? |
42802 | 1380 |
if (qname.prefix == null) { |
1381 |
return new javax.xml.namespace.QName(qname.uri, qname.localpart); |
|
1382 |
} else { |
|
1383 |
return new javax.xml.namespace.QName(qname.uri, qname.localpart, qname.prefix); |
|
12005 | 1384 |
} |
1385 |
} |
|
1386 |
||
42802 | 1387 |
/** |
1388 |
* Return the uri for the given prefix. The uri returned depends on the |
|
1389 |
* current state of the processor. |
|
12005 | 1390 |
* |
42802 | 1391 |
* <p> |
1392 |
* <strong>NOTE:</strong>The 'xml' prefix is bound as defined in |
|
1393 |
* <a href="http://www.w3.org/TR/REC-xml-names/#ns-using">Namespaces in |
|
1394 |
* XML</a> |
|
12005 | 1395 |
* specification to "http://www.w3.org/XML/1998/namespace". |
1396 |
* |
|
42802 | 1397 |
* <p> |
1398 |
* <strong>NOTE:</strong> The 'xmlns' prefix must be resolved to following |
|
1399 |
* namespace |
|
12005 | 1400 |
* <a href="http://www.w3.org/2000/xmlns/">http://www.w3.org/2000/xmlns/</a> |
42802 | 1401 |
* |
12005 | 1402 |
* @return the uri bound to the given prefix or null if it is not bound |
1403 |
* @param prefix The prefix to lookup, may not be null |
|
1404 |
* @throws IllegalStateException - if the prefix is null |
|
1405 |
*/ |
|
1406 |
public String getNamespaceURI(String prefix) { |
|
42802 | 1407 |
if (prefix == null) { |
1408 |
throw new java.lang.IllegalArgumentException("prefix cannot be null."); |
|
1409 |
} |
|
12005 | 1410 |
|
1411 |
//first add the string to symbol table.. since internally identity comparisons are done. |
|
42802 | 1412 |
return fScanner.getNamespaceContext().getURI(fSymbolTable.addSymbol(prefix)); |
12005 | 1413 |
} |
1414 |
||
1415 |
//xxx: this function is not being used. |
|
42802 | 1416 |
protected void setPropertyManager(PropertyManager propertyManager) { |
1417 |
fPropertyManager = propertyManager; |
|
12005 | 1418 |
//REVISIT: we were supplying hashmap ealier |
42802 | 1419 |
fScanner.setProperty("stax-properties", propertyManager); |
1420 |
fScanner.setPropertyManager(propertyManager); |
|
12005 | 1421 |
} |
1422 |
||
1423 |
/** |
|
1424 |
* @return returns the reference to property manager. |
|
1425 |
*/ |
|
42802 | 1426 |
protected PropertyManager getPropertyManager() { |
1427 |
return fPropertyManager; |
|
12005 | 1428 |
} |
1429 |
||
1430 |
static void pr(String str) { |
|
42802 | 1431 |
System.out.println(str); |
12005 | 1432 |
} |
1433 |
||
42802 | 1434 |
protected List<EntityDeclaration> getEntityDecls() { |
1435 |
if (fEventType == XMLStreamConstants.DTD) { |
|
12005 | 1436 |
XMLEntityStorage entityStore = fEntityManager.getEntityStore(); |
42802 | 1437 |
ArrayList<EntityDeclaration> list = null; |
1438 |
Map<String, Entity> entities = entityStore.getEntities(); |
|
1439 |
if (entities.size() > 0) { |
|
12005 | 1440 |
EntityDeclarationImpl decl = null; |
42802 | 1441 |
list = new ArrayList<>(entities.size()); |
1442 |
for (Map.Entry<String, Entity> entry : entities.entrySet()) { |
|
1443 |
String key = entry.getKey(); |
|
1444 |
Entity en = entry.getValue(); |
|
12005 | 1445 |
decl = new EntityDeclarationImpl(); |
1446 |
decl.setEntityName(key); |
|
42802 | 1447 |
if (en.isExternal()) { |
1448 |
decl.setXMLResourceIdentifier(((Entity.ExternalEntity) en).entityLocation); |
|
1449 |
decl.setNotationName(((Entity.ExternalEntity) en).notation); |
|
1450 |
} else { |
|
1451 |
decl.setEntityReplacementText(((Entity.InternalEntity) en).text); |
|
12005 | 1452 |
} |
1453 |
list.add(decl); |
|
1454 |
} |
|
1455 |
} |
|
1456 |
return list; |
|
1457 |
} |
|
1458 |
return null; |
|
1459 |
} |
|
1460 |
||
42802 | 1461 |
protected List<NotationDeclaration> getNotationDecls() { |
1462 |
if (fEventType == XMLStreamConstants.DTD) { |
|
1463 |
if (fScanner.fDTDScanner == null) { |
|
1464 |
return null; |
|
1465 |
} |
|
1466 |
DTDGrammar grammar = ((XMLDTDScannerImpl) (fScanner.fDTDScanner)).getGrammar(); |
|
1467 |
if (grammar == null) { |
|
1468 |
return null; |
|
1469 |
} |
|
1470 |
List<XMLNotationDecl> notations = grammar.getNotationDecls(); |
|
1471 |
ArrayList<NotationDeclaration> list = new ArrayList<>(); |
|
1472 |
for (XMLNotationDecl notation : notations) { |
|
1473 |
if (notation != null) { |
|
1474 |
list.add(new NotationDeclarationImpl(notation)); |
|
12005 | 1475 |
} |
1476 |
} |
|
1477 |
return list; |
|
1478 |
} |
|
1479 |
return null; |
|
1480 |
} |
|
1481 |
||
1482 |
}//XMLReaderImpl |