1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2016 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.
26
26
import org .xml .sax .ext .LexicalHandler ;
27
27
28
28
/**
29
- * Abstract base class for SAX {@code XMLReader} implementations. Contains properties as defined in {@link
30
- * XMLReader}, and does not recognize any features.
29
+ * Abstract base class for SAX {@code XMLReader} implementations.
30
+ * Contains properties as defined in {@link XMLReader}, and does not recognize any features.
31
31
*
32
32
* @author Arjen Poutsma
33
+ * @author Juergen Hoeller
34
+ * @since 3.0
33
35
* @see #setContentHandler(org.xml.sax.ContentHandler)
34
36
* @see #setDTDHandler(org.xml.sax.DTDHandler)
35
37
* @see #setEntityResolver(org.xml.sax.EntityResolver)
36
38
* @see #setErrorHandler(org.xml.sax.ErrorHandler)
37
- * @since 3.0
38
39
*/
39
40
abstract class AbstractXMLReader implements XMLReader {
40
41
@@ -48,29 +49,25 @@ abstract class AbstractXMLReader implements XMLReader {
48
49
49
50
private LexicalHandler lexicalHandler ;
50
51
51
- @ Override
52
- public ContentHandler getContentHandler () {
53
- return contentHandler ;
54
- }
55
52
56
53
@ Override
57
54
public void setContentHandler (ContentHandler contentHandler ) {
58
55
this .contentHandler = contentHandler ;
59
56
}
60
57
61
58
@ Override
62
- public void setDTDHandler ( DTDHandler dtdHandler ) {
63
- this .dtdHandler = dtdHandler ;
59
+ public ContentHandler getContentHandler ( ) {
60
+ return this .contentHandler ;
64
61
}
65
62
66
63
@ Override
67
- public DTDHandler getDTDHandler ( ) {
68
- return dtdHandler ;
64
+ public void setDTDHandler ( DTDHandler dtdHandler ) {
65
+ this . dtdHandler = dtdHandler ;
69
66
}
70
67
71
68
@ Override
72
- public EntityResolver getEntityResolver () {
73
- return entityResolver ;
69
+ public DTDHandler getDTDHandler () {
70
+ return this . dtdHandler ;
74
71
}
75
72
76
73
@ Override
@@ -79,38 +76,55 @@ public void setEntityResolver(EntityResolver entityResolver) {
79
76
}
80
77
81
78
@ Override
82
- public ErrorHandler getErrorHandler () {
83
- return errorHandler ;
79
+ public EntityResolver getEntityResolver () {
80
+ return this . entityResolver ;
84
81
}
85
82
86
83
@ Override
87
84
public void setErrorHandler (ErrorHandler errorHandler ) {
88
85
this .errorHandler = errorHandler ;
89
86
}
90
87
88
+ @ Override
89
+ public ErrorHandler getErrorHandler () {
90
+ return this .errorHandler ;
91
+ }
92
+
91
93
protected LexicalHandler getLexicalHandler () {
92
- return lexicalHandler ;
94
+ return this . lexicalHandler ;
93
95
}
94
96
97
+
95
98
/**
96
- * Throws a {@code SAXNotRecognizedException} exception.
97
- *
98
- * @throws org.xml.sax.SAXNotRecognizedException
99
- * always
99
+ * This implementation throws a {@code SAXNotRecognizedException} exception
100
+ * for any feature outside of the "http://xml.org/sax/features/" namespace
101
+ * and returns {@code false} for any feature within.
100
102
*/
101
103
@ Override
102
104
public boolean getFeature (String name ) throws SAXNotRecognizedException , SAXNotSupportedException {
103
- throw new SAXNotRecognizedException (name );
105
+ if (name .startsWith ("http://xml.org/sax/features/" )) {
106
+ return false ;
107
+ }
108
+ else {
109
+ throw new SAXNotRecognizedException (name );
110
+ }
104
111
}
105
112
106
113
/**
107
- * Throws a {@code SAXNotRecognizedException} exception.
108
- *
109
- * @throws SAXNotRecognizedException always
114
+ * This implementation throws a {@code SAXNotRecognizedException} exception
115
+ * for any feature outside of the "http://xml.org/sax/features/" namespace
116
+ * and accepts a {@code false} value for any feature within.
110
117
*/
111
118
@ Override
112
119
public void setFeature (String name , boolean value ) throws SAXNotRecognizedException , SAXNotSupportedException {
113
- throw new SAXNotRecognizedException (name );
120
+ if (name .startsWith ("http://xml.org/sax/features/" )) {
121
+ if (value ) {
122
+ throw new SAXNotSupportedException (name );
123
+ }
124
+ }
125
+ else {
126
+ throw new SAXNotRecognizedException (name );
127
+ }
114
128
}
115
129
116
130
/**
@@ -120,7 +134,7 @@ public void setFeature(String name, boolean value) throws SAXNotRecognizedExcept
120
134
@ Override
121
135
public Object getProperty (String name ) throws SAXNotRecognizedException , SAXNotSupportedException {
122
136
if ("http://xml.org/sax/properties/lexical-handler" .equals (name )) {
123
- return lexicalHandler ;
137
+ return this . lexicalHandler ;
124
138
}
125
139
else {
126
140
throw new SAXNotRecognizedException (name );
@@ -134,10 +148,11 @@ public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotS
134
148
@ Override
135
149
public void setProperty (String name , Object value ) throws SAXNotRecognizedException , SAXNotSupportedException {
136
150
if ("http://xml.org/sax/properties/lexical-handler" .equals (name )) {
137
- lexicalHandler = (LexicalHandler ) value ;
151
+ this . lexicalHandler = (LexicalHandler ) value ;
138
152
}
139
153
else {
140
154
throw new SAXNotRecognizedException (name );
141
155
}
142
156
}
157
+
143
158
}
0 commit comments