File tree Expand file tree Collapse file tree 9 files changed +160
-10
lines changed Expand file tree Collapse file tree 9 files changed +160
-10
lines changed Original file line number Diff line number Diff line change 24
24
package nu .validator .htmlparser .impl ;
25
25
26
26
import org .xml .sax .Locator ;
27
+ import org .xml .sax .ext .Locator2 ;
27
28
28
- public class LocatorImpl implements Locator {
29
+ public class LocatorImpl implements Locator , Locator2 {
29
30
30
31
private final String systemId ;
31
32
32
33
private final String publicId ;
33
34
35
+ private final String encoding ;
36
+
34
37
private final int column ;
35
38
36
39
private final int line ;
37
40
41
+ /**
42
+ * Create a new Locator with default values
43
+ */
44
+ public LocatorImpl () {
45
+ this .systemId = this .publicId = this .encoding = null ;
46
+ this .column = this .line = 0 ;
47
+ }
48
+
38
49
public LocatorImpl (Locator locator ) {
39
50
this .systemId = locator .getSystemId ();
40
51
this .publicId = locator .getPublicId ();
41
52
this .column = locator .getColumnNumber ();
42
53
this .line = locator .getLineNumber ();
54
+ if (locator instanceof Locator2 ) {
55
+ this .encoding = ((Locator2 )locator ).getEncoding ();
56
+ } else {
57
+ this .encoding = null ;
58
+ }
43
59
}
44
60
45
61
public final int getColumnNumber () {
@@ -57,4 +73,12 @@ public final String getPublicId() {
57
73
public final String getSystemId () {
58
74
return systemId ;
59
75
}
76
+
77
+ public final String getXMLVersion () {
78
+ return "1.0" ;
79
+ }
80
+
81
+ public final String getEncoding () {
82
+ return encoding ;
83
+ }
60
84
}
Original file line number Diff line number Diff line change 37
37
38
38
import org .xml .sax .ErrorHandler ;
39
39
import org .xml .sax .Locator ;
40
+ import org .xml .sax .ext .Locator2 ;
40
41
import org .xml .sax .SAXException ;
41
42
import org .xml .sax .SAXParseException ;
42
43
66
67
* @version $Id$
67
68
* @author hsivonen
68
69
*/
69
- public class Tokenizer implements Locator {
70
+ public class Tokenizer implements Locator , Locator2 {
70
71
71
72
private static final int DATA_AND_RCDATA_MASK = ~1 ;
72
73
@@ -864,6 +865,24 @@ public String getSystemId() {
864
865
return systemId ;
865
866
}
866
867
868
+ /**
869
+ * @see org.xml.sax.ext.Locator2#getXMLVersion()
870
+ */
871
+ public String getXMLVersion () {
872
+ return "1.0" ;
873
+ }
874
+
875
+ /**
876
+ * @see org.xml.sax.ext.Locator2#getXMLVersion()
877
+ */
878
+ public String getEncoding () {
879
+ try {
880
+ return encodingDeclarationHandler == null ? null : encodingDeclarationHandler .getCharacterEncoding ();
881
+ } catch (SAXException e ) {
882
+ return null ;
883
+ }
884
+ }
885
+
867
886
// end Locator impl
868
887
869
888
// end public API
Original file line number Diff line number Diff line change @@ -579,7 +579,7 @@ public void setXmlnsPolicy(XmlViolationPolicy xmlnsPolicy) {
579
579
}
580
580
581
581
public String getCharacterEncoding () throws SAXException {
582
- return characterEncoding .getCanonName ();
582
+ return characterEncoding == null ? null : characterEncoding .getCanonName ();
583
583
}
584
584
585
585
public Locator getDocumentLocator () {
Original file line number Diff line number Diff line change 42
42
43
43
import org .xml .sax .ErrorHandler ;
44
44
import org .xml .sax .Locator ;
45
+ import org .xml .sax .ext .Locator2 ;
45
46
import org .xml .sax .SAXException ;
46
47
import org .xml .sax .SAXParseException ;
47
48
58
59
* @author hsivonen
59
60
*/
60
61
public final class HtmlInputStreamReader extends Reader implements
61
- ByteReadable , Locator {
62
+ ByteReadable , Locator , Locator2 {
62
63
63
64
private static final int SNIFFING_LIMIT = 1024 ;
64
65
@@ -452,6 +453,20 @@ public String getSystemId() {
452
453
return null ;
453
454
}
454
455
456
+ public String getXMLVersion () {
457
+ if (tokenizer != null ) {
458
+ return tokenizer .getXMLVersion ();
459
+ }
460
+ return null ;
461
+ }
462
+
463
+ public String getEncoding () {
464
+ if (tokenizer != null ) {
465
+ return tokenizer .getEncoding ();
466
+ }
467
+ return null ;
468
+ }
469
+
455
470
/**
456
471
* @param string
457
472
* @throws SAXException
Original file line number Diff line number Diff line change 30
30
31
31
import org .xml .sax .ErrorHandler ;
32
32
import org .xml .sax .Locator ;
33
+ import org .xml .sax .ext .Locator2 ;
33
34
import org .xml .sax .SAXException ;
34
35
import org .xml .sax .SAXParseException ;
35
36
36
- public class MetaSniffer extends MetaScanner implements Locator {
37
+ public class MetaSniffer extends MetaScanner implements Locator , Locator2 {
37
38
38
39
private Encoding characterEncoding = null ;
39
40
@@ -142,6 +143,20 @@ public String getSystemId() {
142
143
}
143
144
return null ;
144
145
}
146
+
147
+ public String getXMLVersion () {
148
+ if (locator != null ) {
149
+ return ((Locator2 )locator ).getXMLVersion ();
150
+ }
151
+ return null ;
152
+ }
153
+
154
+ public String getEncoding () {
155
+ if (locator != null ) {
156
+ return ((Locator2 )locator ).getEncoding ();
157
+ }
158
+ return null ;
159
+ }
145
160
146
161
protected boolean tryCharset (String encoding ) throws SAXException {
147
162
encoding = Encoding .toAsciiLowerCase (encoding );
Original file line number Diff line number Diff line change 23
23
24
24
package nu .validator .saxtree ;
25
25
26
- import org . xml . sax . helpers .LocatorImpl ;
26
+ import nu . validator . htmlparser . impl .LocatorImpl ;
27
27
28
28
/**
29
29
* A document fragment.
Original file line number Diff line number Diff line change 24
24
package nu .validator .saxtree ;
25
25
26
26
import org .xml .sax .Locator ;
27
+ import org .xml .sax .ext .Locator2 ;
27
28
28
29
/**
29
30
* A locator implementation.
30
31
* @version $Id$
31
32
* @author hsivonen
32
33
*/
33
- public final class LocatorImpl implements Locator {
34
+ public final class LocatorImpl implements Locator , Locator2 {
34
35
35
36
/**
36
37
* The system id.
@@ -42,6 +43,11 @@ public final class LocatorImpl implements Locator {
42
43
*/
43
44
private final String publicId ;
44
45
46
+ /**
47
+ * The encoding.
48
+ */
49
+ private final String encoding ;
50
+
45
51
/**
46
52
* The column.
47
53
*/
@@ -62,11 +68,17 @@ public LocatorImpl(Locator locator) {
62
68
this .publicId = null ;
63
69
this .column = -1 ;
64
70
this .line = -1 ;
71
+ this .encoding = null ;
65
72
} else {
66
73
this .systemId = locator .getSystemId ();
67
74
this .publicId = locator .getPublicId ();
68
75
this .column = locator .getColumnNumber ();
69
76
this .line = locator .getLineNumber ();
77
+ if (locator instanceof Locator2 ) {
78
+ this .encoding = ((Locator2 )locator ).getEncoding ();
79
+ } else {
80
+ this .encoding = null ;
81
+ }
70
82
}
71
83
}
72
84
@@ -101,4 +113,21 @@ public String getPublicId() {
101
113
public String getSystemId () {
102
114
return systemId ;
103
115
}
116
+
117
+ /**
118
+ *
119
+ * @see org.xml.sax.ext.Locator2#getXMLVersion()
120
+ */
121
+ public String getXMLVersion () {
122
+ return "1.0" ;
123
+ }
124
+
125
+ /**
126
+ *
127
+ * @see org.xml.sax.ext.Locator2#getEncoding()
128
+ */
129
+ public String getEncoding () {
130
+ return encoding ;
131
+ }
132
+
104
133
}
Original file line number Diff line number Diff line change 27
27
28
28
import org .xml .sax .Attributes ;
29
29
import org .xml .sax .Locator ;
30
+ import org .xml .sax .ext .Locator2 ;
30
31
import org .xml .sax .SAXException ;
31
32
32
33
/**
33
34
* The common node superclass.
34
35
* @version $Id$
35
36
* @author hsivonen
36
37
*/
37
- public abstract class Node implements Locator {
38
+ public abstract class Node implements Locator , Locator2 {
38
39
39
40
/**
40
41
* The system id.
@@ -45,6 +46,11 @@ public abstract class Node implements Locator {
45
46
* The public id.
46
47
*/
47
48
private final String publicId ;
49
+
50
+ /**
51
+ * The encoding.
52
+ */
53
+ private final String encoding ;
48
54
49
55
/**
50
56
* The column.
@@ -75,13 +81,19 @@ public abstract class Node implements Locator {
75
81
if (locator == null ) {
76
82
this .systemId = null ;
77
83
this .publicId = null ;
84
+ this .encoding = null ;
78
85
this .column = -1 ;
79
86
this .line = -1 ;
80
87
} else {
81
88
this .systemId = locator .getSystemId ();
82
89
this .publicId = locator .getPublicId ();
83
90
this .column = locator .getColumnNumber ();
84
91
this .line = locator .getLineNumber ();
92
+ if (locator instanceof Locator2 ) {
93
+ this .encoding = ((Locator2 )locator ).getEncoding ();
94
+ } else {
95
+ this .encoding = null ;
96
+ }
85
97
}
86
98
}
87
99
@@ -117,6 +129,20 @@ public String getSystemId() {
117
129
return systemId ;
118
130
}
119
131
132
+ /**
133
+ * @see org.xml.sax.ext.Locator2#getXMLVersion()
134
+ */
135
+ public String getXMLVersion () {
136
+ return "1.0" ;
137
+ }
138
+
139
+ /**
140
+ * @see org.xml.sax.ext.Locator2#getEncoding
141
+ */
142
+ public String getEncoding () {
143
+ return encoding ;
144
+ }
145
+
120
146
/**
121
147
* Visit the node.
122
148
*
Original file line number Diff line number Diff line change 26
26
import org .xml .sax .Attributes ;
27
27
import org .xml .sax .ContentHandler ;
28
28
import org .xml .sax .Locator ;
29
+ import org .xml .sax .ext .Locator2 ;
29
30
import org .xml .sax .SAXException ;
30
31
import org .xml .sax .ext .LexicalHandler ;
31
32
34
35
* @version $Id$
35
36
* @author hsivonen
36
37
*/
37
- public final class TreeParser implements Locator {
38
+ public final class TreeParser implements Locator , Locator2 {
38
39
39
40
/**
40
41
* The content handler.
@@ -283,7 +284,6 @@ public String getPublicId() {
283
284
if (locatorDelegate == null ) {
284
285
return null ;
285
286
} else {
286
-
287
287
return locatorDelegate .getPublicId ();
288
288
}
289
289
}
@@ -298,4 +298,26 @@ public String getSystemId() {
298
298
return locatorDelegate .getSystemId ();
299
299
}
300
300
}
301
+
302
+ /**
303
+ * @see org.xml.sax.Locator#getSystemId()
304
+ */
305
+ public String getXMLVersion () {
306
+ if (!(locatorDelegate instanceof Locator2 )) {
307
+ return null ;
308
+ } else {
309
+ return ((Locator2 )locatorDelegate ).getXMLVersion ();
310
+ }
311
+ }
312
+
313
+ /**
314
+ * @see org.xml.sax.Locator#getSystemId()
315
+ */
316
+ public String getEncoding () {
317
+ if (!(locatorDelegate instanceof Locator2 )) {
318
+ return null ;
319
+ } else {
320
+ return ((Locator2 )locatorDelegate ).getEncoding ();
321
+ }
322
+ }
301
323
}
You can’t perform that action at this time.
0 commit comments