1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2013 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
51
51
* an {@code XMLEventReader}, and calls the corresponding methods on the SAX callback interfaces.
52
52
*
53
53
* @author Arjen Poutsma
54
+ * @since 3.0
54
55
* @see XMLEventReader
55
56
* @see #setContentHandler(org.xml.sax.ContentHandler)
56
57
* @see #setDTDHandler(org.xml.sax.DTDHandler)
57
58
* @see #setEntityResolver(org.xml.sax.EntityResolver)
58
59
* @see #setErrorHandler(org.xml.sax.ErrorHandler)
59
- * @since 3.0
60
60
*/
61
61
class StaxEventXMLReader extends AbstractStaxXMLReader {
62
62
@@ -70,11 +70,11 @@ class StaxEventXMLReader extends AbstractStaxXMLReader {
70
70
71
71
private String encoding ;
72
72
73
+
73
74
/**
74
75
* Constructs a new instance of the {@code StaxEventXmlReader} that reads from the given
75
76
* {@code XMLEventReader}. The supplied event reader must be in {@code XMLStreamConstants.START_DOCUMENT} or
76
77
* {@code XMLStreamConstants.START_ELEMENT} state.
77
- *
78
78
* @param reader the {@code XMLEventReader} to read from
79
79
* @throws IllegalStateException if the reader is not at the start of a document or element
80
80
*/
@@ -89,17 +89,17 @@ class StaxEventXMLReader extends AbstractStaxXMLReader {
89
89
catch (XMLStreamException ex ) {
90
90
throw new IllegalStateException ("Could not read first element: " + ex .getMessage ());
91
91
}
92
-
93
92
this .reader = reader ;
94
93
}
95
94
95
+
96
96
@ Override
97
97
protected void parseInternal () throws SAXException , XMLStreamException {
98
98
boolean documentStarted = false ;
99
99
boolean documentEnded = false ;
100
100
int elementDepth = 0 ;
101
- while (reader .hasNext () && elementDepth >= 0 ) {
102
- XMLEvent event = reader .nextEvent ();
101
+ while (this . reader .hasNext () && elementDepth >= 0 ) {
102
+ XMLEvent event = this . reader .nextEvent ();
103
103
if (!event .isStartDocument () && !event .isEndDocument () && !documentStarted ) {
104
104
handleStartDocument (event );
105
105
documentStarted = true ;
@@ -165,42 +165,34 @@ private void handleStartDocument(final XMLEvent event) throws SAXException {
165
165
this .encoding = startDocument .getCharacterEncodingScheme ();
166
166
}
167
167
}
168
-
169
168
if (getContentHandler () != null ) {
170
169
final Location location = event .getLocation ();
171
170
getContentHandler ().setDocumentLocator (new Locator2 () {
172
-
173
171
@ Override
174
172
public int getColumnNumber () {
175
- return location != null ? location .getColumnNumber () : -1 ;
173
+ return ( location != null ? location .getColumnNumber () : -1 ) ;
176
174
}
177
-
178
175
@ Override
179
176
public int getLineNumber () {
180
- return location != null ? location .getLineNumber () : -1 ;
177
+ return ( location != null ? location .getLineNumber () : -1 ) ;
181
178
}
182
-
183
179
@ Override
184
180
public String getPublicId () {
185
- return location != null ? location .getPublicId () : null ;
181
+ return ( location != null ? location .getPublicId () : null ) ;
186
182
}
187
-
188
183
@ Override
189
184
public String getSystemId () {
190
- return location != null ? location .getSystemId () : null ;
185
+ return ( location != null ? location .getSystemId () : null ) ;
191
186
}
192
-
193
187
@ Override
194
188
public String getXMLVersion () {
195
189
return xmlVersion ;
196
190
}
197
-
198
191
@ Override
199
192
public String getEncoding () {
200
193
return encoding ;
201
194
}
202
195
});
203
-
204
196
getContentHandler ().startDocument ();
205
197
}
206
198
}
@@ -317,7 +309,6 @@ private void handleEntityReference(EntityReference reference) throws SAXExceptio
317
309
318
310
private Attributes getAttributes (StartElement event ) {
319
311
AttributesImpl attributes = new AttributesImpl ();
320
-
321
312
for (Iterator i = event .getAttributes (); i .hasNext ();) {
322
313
Attribute attribute = (Attribute ) i .next ();
323
314
QName qName = attribute .getName ();
@@ -329,8 +320,7 @@ private Attributes getAttributes(StartElement event) {
329
320
if (type == null ) {
330
321
type = "CDATA" ;
331
322
}
332
- attributes
333
- .addAttribute (namespace , qName .getLocalPart (), toQualifiedName (qName ), type , attribute .getValue ());
323
+ attributes .addAttribute (namespace , qName .getLocalPart (), toQualifiedName (qName ), type , attribute .getValue ());
334
324
}
335
325
if (hasNamespacePrefixesFeature ()) {
336
326
for (Iterator i = event .getNamespaces (); i .hasNext ();) {
0 commit comments