34
34
* Abstract base class for SAX <code>XMLReader</code> implementations that use StAX as a basis.
35
35
*
36
36
* @author Arjen Poutsma
37
+ * @since 3.0
37
38
* @see #setContentHandler(org.xml.sax.ContentHandler)
38
39
* @see #setDTDHandler(org.xml.sax.DTDHandler)
39
40
* @see #setEntityResolver(org.xml.sax.EntityResolver)
40
41
* @see #setErrorHandler(org.xml.sax.ErrorHandler)
41
- * @since 3.0
42
42
*/
43
43
abstract class AbstractStaxXMLReader extends AbstractXMLReader {
44
44
@@ -48,23 +48,25 @@ abstract class AbstractStaxXMLReader extends AbstractXMLReader {
48
48
49
49
private static final String IS_STANDALONE_FEATURE_NAME = "http://xml.org/sax/features/is-standalone" ;
50
50
51
+
51
52
private boolean namespacesFeature = true ;
52
53
53
54
private boolean namespacePrefixesFeature = false ;
54
55
55
56
private Boolean isStandalone ;
56
57
58
+
57
59
@ Override
58
60
public boolean getFeature (String name ) throws SAXNotRecognizedException , SAXNotSupportedException {
59
61
if (NAMESPACES_FEATURE_NAME .equals (name )) {
60
- return namespacesFeature ;
62
+ return this . namespacesFeature ;
61
63
}
62
64
else if (NAMESPACE_PREFIXES_FEATURE_NAME .equals (name )) {
63
- return namespacePrefixesFeature ;
65
+ return this . namespacePrefixesFeature ;
64
66
}
65
67
else if (IS_STANDALONE_FEATURE_NAME .equals (name )) {
66
- if (isStandalone != null ) {
67
- return isStandalone ;
68
+ if (this . isStandalone != null ) {
69
+ return this . isStandalone ;
68
70
}
69
71
else {
70
72
throw new SAXNotSupportedException ("startDocument() callback not completed yet" );
@@ -88,35 +90,66 @@ else if (NAMESPACE_PREFIXES_FEATURE_NAME.equals(name)) {
88
90
}
89
91
}
90
92
91
- /** Indicates whether the SAX feature <code>http://xml.org/sax/features/namespaces</code> is turned on. */
93
+ protected void setStandalone (boolean standalone ) {
94
+ this .isStandalone = standalone ;
95
+ }
96
+
97
+ /**
98
+ * Indicates whether the SAX feature <code>http://xml.org/sax/features/namespaces</code> is turned on.
99
+ */
92
100
protected boolean hasNamespacesFeature () {
93
- return namespacesFeature ;
101
+ return this . namespacesFeature ;
94
102
}
95
103
96
- /** Indicates whether the SAX feature <code>http://xml.org/sax/features/namespaces-prefixes</code> is turned on. */
104
+ /**
105
+ * Indicates whether the SAX feature <code>http://xml.org/sax/features/namespaces-prefixes</code> is turned on.
106
+ */
97
107
protected boolean hasNamespacePrefixesFeature () {
98
- return namespacePrefixesFeature ;
108
+ return this . namespacePrefixesFeature ;
99
109
}
100
110
101
- protected void setStandalone (boolean standalone ) {
102
- isStandalone = (standalone ) ? Boolean .TRUE : Boolean .FALSE ;
111
+ /**
112
+ * Sett the SAX <code>Locator</code> based on the given StAX <code>Location</code>.
113
+ * @param location the location
114
+ * @see ContentHandler#setDocumentLocator(org.xml.sax.Locator)
115
+ */
116
+ protected void setLocator (Location location ) {
117
+ if (getContentHandler () != null ) {
118
+ getContentHandler ().setDocumentLocator (new StaxLocator (location ));
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Convert a <code>QName</code> to a qualified name, as used by DOM and SAX.
124
+ * The returned string has a format of <code>prefix:localName</code> if the
125
+ * prefix is set, or just <code>localName</code> if not.
126
+ * @param qName the <code>QName</code>
127
+ * @return the qualified name
128
+ */
129
+ protected String toQualifiedName (QName qName ) {
130
+ String prefix = qName .getPrefix ();
131
+ if (!StringUtils .hasLength (prefix )) {
132
+ return qName .getLocalPart ();
133
+ }
134
+ else {
135
+ return prefix + ":" + qName .getLocalPart ();
136
+ }
103
137
}
104
138
139
+
105
140
/**
106
- * Parses the StAX XML reader passed at construction-time. <p/> <strong>Note</strong> that the given
107
- * <code>InputSource</code> is not read, but ignored.
108
- *
141
+ * Parse the StAX XML reader passed at construction-time.
142
+ * <p><b>NOTE:</b>: The given <code>InputSource</code> is not read, but ignored.
109
143
* @param ignored is ignored
110
- * @throws SAXException A SAX exception, possibly wrapping a <code>XMLStreamException</code>
144
+ * @throws SAXException a SAX exception, possibly wrapping a <code>XMLStreamException</code>
111
145
*/
112
146
public final void parse (InputSource ignored ) throws SAXException {
113
147
parse ();
114
148
}
115
149
116
150
/**
117
- * Parses the StAX XML reader passed at construction-time. <p/> <strong>Note</strong> that the given system identifier
118
- * is not read, but ignored.
119
- *
151
+ * Parse the StAX XML reader passed at construction-time.
152
+ * <p><b>NOTE:</b>: The given system identifier is not read, but ignored.
120
153
* @param ignored is ignored
121
154
* @throws SAXException A SAX exception, possibly wrapping a <code>XMLStreamException</code>
122
155
*/
@@ -144,40 +177,13 @@ private void parse() throws SAXException {
144
177
}
145
178
146
179
/**
147
- * Sets the SAX <code>Locator</code> based on the given StAX <code>Location</code>.
148
- *
149
- * @param location the location
150
- * @see ContentHandler#setDocumentLocator(org.xml.sax.Locator)
180
+ * Template-method that parses the StAX reader passed at construction-time.
151
181
*/
152
- protected void setLocator (Location location ) {
153
- if (getContentHandler () != null ) {
154
- getContentHandler ().setDocumentLocator (new StaxLocator (location ));
155
- }
156
- }
157
-
158
- /** Template-method that parses the StAX reader passed at construction-time. */
159
182
protected abstract void parseInternal () throws SAXException , XMLStreamException ;
160
183
161
- /**
162
- * Convert a <code>QName</code> to a qualified name, as used by DOM and SAX. The returned string has a format of
163
- * <code>prefix:localName</code> if the prefix is set, or just <code>localName</code> if not.
164
- *
165
- * @param qName the <code>QName</code>
166
- * @return the qualified name
167
- */
168
- protected String toQualifiedName (QName qName ) {
169
- String prefix = qName .getPrefix ();
170
- if (!StringUtils .hasLength (prefix )) {
171
- return qName .getLocalPart ();
172
- }
173
- else {
174
- return prefix + ":" + qName .getLocalPart ();
175
- }
176
- }
177
184
178
185
/**
179
186
* Implementation of the <code>Locator</code> interface that is based on a StAX <code>Location</code>.
180
- *
181
187
* @see Locator
182
188
* @see Location
183
189
*/
@@ -205,4 +211,5 @@ public int getColumnNumber() {
205
211
return location .getColumnNumber ();
206
212
}
207
213
}
214
+
208
215
}
0 commit comments