Přehlednější struktura tříd/balíčků.
1 package cz.frantovo.alt2xml.vstup;
3 import java.io.IOException;
4 import java.io.InputStreamReader;
5 import java.util.logging.Level;
6 import java.util.logging.Logger;
7 import org.json.simple.parser.JSONParser;
8 import org.json.simple.parser.ParseException;
9 import org.xml.sax.ContentHandler;
10 import org.xml.sax.DTDHandler;
11 import org.xml.sax.EntityResolver;
12 import org.xml.sax.ErrorHandler;
13 import org.xml.sax.InputSource;
14 import org.xml.sax.SAXException;
15 import org.xml.sax.SAXNotRecognizedException;
16 import org.xml.sax.SAXNotSupportedException;
17 import org.xml.sax.XMLReader;
23 public class SuperReader implements XMLReader {
25 private static final Logger log = Logger.getLogger(SuperReader.class.getName());
26 private ContentHandler contentHandler;
29 public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
31 log.log(Level.FINE, "getFeature: {0}", name);
36 public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
38 log.log(Level.FINE, "setFeature: {0} = {1}", new Object[]{name, value});
42 public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
44 log.log(Level.FINE, "getProperty: {0}", name);
49 public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
51 log.log(Level.FINE, "setProperty: {0} = {1}", new Object[]{name, value});
55 public void setEntityResolver(EntityResolver resolver) {
57 log.log(Level.FINE, "setEntityResolver: {0}", resolver);
61 public EntityResolver getEntityResolver() {
63 log.log(Level.FINE, "getEntityResolver");
68 public void setDTDHandler(DTDHandler handler) {
70 log.log(Level.FINE, "setDTDHandler: {0}", handler);
74 public DTDHandler getDTDHandler() {
76 log.log(Level.FINE, "getDTDHandler");
81 public void setContentHandler(ContentHandler handler) {
83 contentHandler = handler;
87 public ContentHandler getContentHandler() {
89 return contentHandler;
93 public void setErrorHandler(ErrorHandler handler) {
95 log.log(Level.FINE, "setErrorHandler: {0}", handler);
99 public ErrorHandler getErrorHandler() {
101 log.log(Level.FINE, "getErrorHandler");
106 public void parse(InputSource input) throws IOException, SAXException {
108 * TODO: rozpornat formát vstupu a podle toho delegovat
111 JSONParser p = new JSONParser();
112 InputStreamReader vstup = new InputStreamReader(input.getByteStream());
113 JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler);
116 p.parse(vstup, handler);
117 } catch (ParseException e) {
118 throw new SAXException("Chyba při načítání JSONu", e);
123 public void parse(String systemId) throws IOException, SAXException {
125 throw new UnsupportedOperationException("Zatím není podporované.");