|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| package nu.xom.xslt; |
|
23 |
| |
|
24 |
| import java.io.IOException; |
|
25 |
| |
|
26 |
| import nu.xom.converters.SAXConverter; |
|
27 |
| |
|
28 |
| import org.xml.sax.ContentHandler; |
|
29 |
| import org.xml.sax.DTDHandler; |
|
30 |
| import org.xml.sax.EntityResolver; |
|
31 |
| import org.xml.sax.ErrorHandler; |
|
32 |
| import org.xml.sax.InputSource; |
|
33 |
| import org.xml.sax.SAXException; |
|
34 |
| import org.xml.sax.SAXNotRecognizedException; |
|
35 |
| import org.xml.sax.SAXNotSupportedException; |
|
36 |
| import org.xml.sax.XMLReader; |
|
37 |
| import org.xml.sax.ext.LexicalHandler; |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| class XOMReader implements XMLReader { |
|
52 |
| |
|
53 |
| private SAXConverter converter; |
|
54 |
| |
|
55 |
0
| public boolean getFeature(String uri)
|
|
56 |
| throws SAXNotRecognizedException, SAXNotSupportedException { |
|
57 |
| |
|
58 |
0
| if ("http://xml.org/sax/features/namespace-prefixes".equals(uri)
|
|
59 |
| || "http://xml.org/sax/features/namespaces".equals(uri)) { |
|
60 |
0
| return true;
|
|
61 |
| } |
|
62 |
0
| throw new SAXNotRecognizedException("XOMReader doesn't support features");
|
|
63 |
| |
|
64 |
| } |
|
65 |
| |
|
66 |
| |
|
67 |
433
| public void setFeature(String uri, boolean value)
|
|
68 |
| throws SAXNotRecognizedException, SAXNotSupportedException { |
|
69 |
| |
|
70 |
| } |
|
71 |
| |
|
72 |
| |
|
73 |
0
| public Object getProperty(String uri) throws SAXNotRecognizedException,
|
|
74 |
| SAXNotSupportedException { |
|
75 |
| |
|
76 |
0
| if ("http://xml.org/sax/properties/lexical-handler".equals(uri)) {
|
|
77 |
0
| return converter.getLexicalHandler();
|
|
78 |
| } |
|
79 |
| else { |
|
80 |
0
| throw new SAXNotRecognizedException("XOMReader doesn't support features");
|
|
81 |
| } |
|
82 |
| |
|
83 |
| } |
|
84 |
| |
|
85 |
| |
|
86 |
433
| public void setProperty(String uri, Object value)
|
|
87 |
| throws SAXNotRecognizedException, SAXNotSupportedException { |
|
88 |
| |
|
89 |
433
| if ("http://xml.org/sax/properties/lexical-handler".equals(uri)) {
|
|
90 |
433
| LexicalHandler handler = (LexicalHandler) value;
|
|
91 |
433
| converter.setLexicalHandler(handler);
|
|
92 |
| } |
|
93 |
| else { |
|
94 |
0
| throw new SAXNotRecognizedException(
|
|
95 |
| "XOMReader doesn't support " + uri); |
|
96 |
| } |
|
97 |
| |
|
98 |
| } |
|
99 |
| |
|
100 |
| |
|
101 |
0
| public void setEntityResolver(EntityResolver resolver) {
|
|
102 |
0
| throw new UnsupportedOperationException();
|
|
103 |
| } |
|
104 |
| |
|
105 |
| |
|
106 |
0
| public EntityResolver getEntityResolver() {
|
|
107 |
0
| return null;
|
|
108 |
| } |
|
109 |
| |
|
110 |
| |
|
111 |
433
| public void setDTDHandler(DTDHandler handler) {
|
|
112 |
| |
|
113 |
| } |
|
114 |
| |
|
115 |
| |
|
116 |
0
| public DTDHandler getDTDHandler() {
|
|
117 |
0
| return null;
|
|
118 |
| } |
|
119 |
| |
|
120 |
| |
|
121 |
972
| public void setContentHandler(ContentHandler handler) {
|
|
122 |
972
| converter = new SAXConverter(handler);
|
|
123 |
| |
|
124 |
972
| converter.setContentHandler(new XSLTHandler(null));
|
|
125 |
| } |
|
126 |
| |
|
127 |
| |
|
128 |
0
| public ContentHandler getContentHandler() {
|
|
129 |
0
| return null;
|
|
130 |
| } |
|
131 |
| |
|
132 |
| |
|
133 |
433
| public void setErrorHandler(ErrorHandler handler) {
|
|
134 |
| } |
|
135 |
| |
|
136 |
| |
|
137 |
433
| public ErrorHandler getErrorHandler() {
|
|
138 |
433
| return null;
|
|
139 |
| } |
|
140 |
| |
|
141 |
| |
|
142 |
972
| public void parse(InputSource source)
|
|
143 |
| throws IOException, SAXException { |
|
144 |
| |
|
145 |
972
| XOMInputSource xis = (XOMInputSource) source;
|
|
146 |
972
| converter.convert(xis.getNodes());
|
|
147 |
| |
|
148 |
| } |
|
149 |
| |
|
150 |
| |
|
151 |
0
| public void parse(String url) throws IOException, SAXException {
|
|
152 |
0
| throw new UnsupportedOperationException();
|
|
153 |
| } |
|
154 |
| |
|
155 |
| |
|
156 |
| } |