1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/java/alt2xml/src/cz/frantovo/alt2xml/SuperReader.java Mon Jan 02 20:15:52 2012 +0100
1.3 @@ -0,0 +1,128 @@
1.4 +package cz.frantovo.alt2xml;
1.5 +
1.6 +import java.io.BufferedReader;
1.7 +import java.io.IOException;
1.8 +import java.io.InputStreamReader;
1.9 +import java.util.logging.Level;
1.10 +import java.util.logging.Logger;
1.11 +import org.json.simple.parser.JSONParser;
1.12 +import org.json.simple.parser.ParseException;
1.13 +import org.xml.sax.ContentHandler;
1.14 +import org.xml.sax.DTDHandler;
1.15 +import org.xml.sax.EntityResolver;
1.16 +import org.xml.sax.ErrorHandler;
1.17 +import org.xml.sax.InputSource;
1.18 +import org.xml.sax.SAXException;
1.19 +import org.xml.sax.SAXNotRecognizedException;
1.20 +import org.xml.sax.SAXNotSupportedException;
1.21 +import org.xml.sax.XMLReader;
1.22 +
1.23 +/**
1.24 + *
1.25 + * @author fiki
1.26 + */
1.27 +public class SuperReader implements XMLReader {
1.28 +
1.29 + private static final Logger log = Logger.getLogger(SuperReader.class.getName());
1.30 + private ContentHandler contentHandler;
1.31 +
1.32 + @Override
1.33 + public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
1.34 + // TODO: dopsat
1.35 + log.log(Level.FINE, "getFeature: {0}", name);
1.36 + return false;
1.37 + }
1.38 +
1.39 + @Override
1.40 + public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
1.41 + // TODO: dopsat
1.42 + log.log(Level.FINE, "setFeature: {0} = {1}", new Object[]{name, value});
1.43 + }
1.44 +
1.45 + @Override
1.46 + public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
1.47 + // TODO: dopsat
1.48 + log.log(Level.FINE, "getProperty: {0}", name);
1.49 + return null;
1.50 + }
1.51 +
1.52 + @Override
1.53 + public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
1.54 + // TODO: dopsat
1.55 + log.log(Level.FINE, "setProperty: {0} = {1}", new Object[]{name, value});
1.56 + }
1.57 +
1.58 + @Override
1.59 + public void setEntityResolver(EntityResolver resolver) {
1.60 + // TODO: dopsat
1.61 + log.log(Level.FINE, "setEntityResolver: {0}", resolver);
1.62 + }
1.63 +
1.64 + @Override
1.65 + public EntityResolver getEntityResolver() {
1.66 + // TODO: dopsat
1.67 + log.log(Level.FINE, "getEntityResolver");
1.68 + return null;
1.69 + }
1.70 +
1.71 + @Override
1.72 + public void setDTDHandler(DTDHandler handler) {
1.73 + // TODO: dopsat
1.74 + log.log(Level.FINE, "setDTDHandler: {0}", handler);
1.75 + }
1.76 +
1.77 + @Override
1.78 + public DTDHandler getDTDHandler() {
1.79 + // TODO: dopsat
1.80 + log.log(Level.FINE, "getDTDHandler");
1.81 + return null;
1.82 + }
1.83 +
1.84 + @Override
1.85 + public void setContentHandler(ContentHandler handler) {
1.86 + // TODO: dopsat
1.87 + contentHandler = handler;
1.88 + }
1.89 +
1.90 + @Override
1.91 + public ContentHandler getContentHandler() {
1.92 + // TODO: dopsat
1.93 + return contentHandler;
1.94 + }
1.95 +
1.96 + @Override
1.97 + public void setErrorHandler(ErrorHandler handler) {
1.98 + // TODO: dopsat
1.99 + log.log(Level.FINE, "setErrorHandler: {0}", handler);
1.100 + }
1.101 +
1.102 + @Override
1.103 + public ErrorHandler getErrorHandler() {
1.104 + // TODO: dopsat
1.105 + log.log(Level.FINE, "getErrorHandler");
1.106 + return null;
1.107 + }
1.108 +
1.109 + @Override
1.110 + public void parse(InputSource input) throws IOException, SAXException {
1.111 + /**
1.112 + * TODO: rozpornat formát vstupu a podle toho delegovat
1.113 + */
1.114 +
1.115 + JSONParser p = new JSONParser();
1.116 + InputStreamReader vstup = new InputStreamReader(input.getByteStream());
1.117 + JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler);
1.118 +
1.119 + try {
1.120 + p.parse(vstup, handler);
1.121 + } catch (ParseException e) {
1.122 + throw new SAXException("Chyba při načítání JSONu", e);
1.123 + }
1.124 + }
1.125 +
1.126 + @Override
1.127 + public void parse(String systemId) throws IOException, SAXException {
1.128 + // TODO: dopsat
1.129 + throw new UnsupportedOperationException("Zatím není podporované.");
1.130 + }
1.131 +}