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