KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nu > xom > xslt > XOMReader


1 /* Copyright 2004 Elliotte Rusty Harold
2    
3    This library is free software; you can redistribute it and/or modify
4    it under the terms of version 2.1 of the GNU Lesser General Public
5    License as published by the Free Software Foundation.
6    
7    This library is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10    GNU Lesser General Public License for more details.
11    
12    You should have received a copy of the GNU Lesser General Public
13    License along with this library; if not, write to the
14    Free Software Foundation, Inc., 59 Temple Place, Suite 330,
15    Boston, MA 02111-1307 USA
16    
17    You can contact Elliotte Rusty Harold by sending e-mail to
18    elharo@metalab.unc.edu. Please include the word "XOM" in the
19    subject line. The XOM home page is located at http://www.xom.nu/
20 */

21
22 package nu.xom.xslt;
23
24 import java.io.IOException JavaDoc;
25
26 import nu.xom.converters.SAXConverter;
27
28 import org.xml.sax.ContentHandler JavaDoc;
29 import org.xml.sax.DTDHandler JavaDoc;
30 import org.xml.sax.EntityResolver JavaDoc;
31 import org.xml.sax.ErrorHandler JavaDoc;
32 import org.xml.sax.InputSource JavaDoc;
33 import org.xml.sax.SAXException JavaDoc;
34 import org.xml.sax.SAXNotRecognizedException JavaDoc;
35 import org.xml.sax.SAXNotSupportedException JavaDoc;
36 import org.xml.sax.XMLReader JavaDoc;
37 import org.xml.sax.ext.LexicalHandler JavaDoc;
38
39 /**
40  *
41  * <p>
42  * This is just for XSLTransform, and implements only the functionality
43  * that class requires. Other classes should not use this.
44  * It is far from a conformant implementation of XMLReader.
45  * </p>
46  *
47  * @author Elliotte Rusty Harold
48  * @version 1.0
49  *
50  */

51 class XOMReader implements XMLReader JavaDoc {
52
53     private SAXConverter converter;
54         
55     public boolean getFeature(String JavaDoc uri)
56       throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
57         
58         if ("http://xml.org/sax/features/namespace-prefixes".equals(uri)
59           || "http://xml.org/sax/features/namespaces".equals(uri)) {
60             return true;
61         }
62         throw new SAXNotRecognizedException JavaDoc("XOMReader doesn't support features");
63         
64     }
65
66     
67     public void setFeature(String JavaDoc uri, boolean value)
68       throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
69
70     }
71
72     
73     public Object JavaDoc getProperty(String JavaDoc uri) throws SAXNotRecognizedException JavaDoc,
74             SAXNotSupportedException JavaDoc {
75         
76         if ("http://xml.org/sax/properties/lexical-handler".equals(uri)) {
77             return converter.getLexicalHandler();
78         }
79         else {
80             throw new SAXNotRecognizedException JavaDoc("XOMReader doesn't support features");
81         }
82         
83     }
84
85     
86     public void setProperty(String JavaDoc uri, Object JavaDoc value)
87       throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
88
89         if ("http://xml.org/sax/properties/lexical-handler".equals(uri)) {
90             LexicalHandler JavaDoc handler = (LexicalHandler JavaDoc) value;
91             converter.setLexicalHandler(handler);
92         }
93         else {
94             throw new SAXNotRecognizedException JavaDoc(
95               "XOMReader doesn't support " + uri);
96         }
97
98     }
99
100     
101     public void setEntityResolver(EntityResolver JavaDoc resolver) {
102         throw new UnsupportedOperationException JavaDoc();
103     }
104
105     
106     public EntityResolver JavaDoc getEntityResolver() {
107         return null;
108     }
109
110     
111     public void setDTDHandler(DTDHandler JavaDoc handler) {
112         // throw new UnsupportedOperationException();
113
}
114
115     
116     public DTDHandler JavaDoc getDTDHandler() {
117         return null;
118     }
119
120     
121     public void setContentHandler(ContentHandler JavaDoc handler) {
122         converter = new SAXConverter(handler);
123     }
124
125     
126     public ContentHandler JavaDoc getContentHandler() {
127         return null;
128     }
129
130     
131     public void setErrorHandler(ErrorHandler JavaDoc handler) {
132     }
133
134     
135     public ErrorHandler JavaDoc getErrorHandler() {
136         return null;
137     }
138
139     
140     public void parse(InputSource JavaDoc source)
141       throws IOException JavaDoc, SAXException JavaDoc {
142         
143         XOMInputSource xis = (XOMInputSource) source;
144         converter.convert(xis.getNodes());
145         
146     }
147
148     
149     public void parse(String JavaDoc url) throws IOException JavaDoc, SAXException JavaDoc {
150         throw new UnsupportedOperationException JavaDoc();
151     }
152
153     
154 }
155
Popular Tags