1.1 --- a/java/alt2xml-in-json/src/cz/frantovo/alt2xml/in/json/Reader.java Sat Jun 07 10:49:42 2014 +0200
1.2 +++ b/java/alt2xml-in-json/src/cz/frantovo/alt2xml/in/json/Reader.java Sat Jun 07 11:23:58 2014 +0200
1.3 @@ -17,39 +17,22 @@
1.4 */
1.5 package cz.frantovo.alt2xml.in.json;
1.6
1.7 +import cz.frantovo.alt2xml.AbstractAlt2XmlReader;
1.8 import java.io.IOException;
1.9 import java.io.InputStreamReader;
1.10 -import java.util.HashMap;
1.11 -import java.util.Map;
1.12 import org.json.simple.parser.JSONParser;
1.13 import org.json.simple.parser.ParseException;
1.14 -import org.xml.sax.ContentHandler;
1.15 -import org.xml.sax.DTDHandler;
1.16 -import org.xml.sax.EntityResolver;
1.17 -import org.xml.sax.ErrorHandler;
1.18 import org.xml.sax.InputSource;
1.19 import org.xml.sax.SAXException;
1.20 -import org.xml.sax.SAXNotRecognizedException;
1.21 -import org.xml.sax.SAXNotSupportedException;
1.22 -import org.xml.sax.XMLReader;
1.23
1.24 /**
1.25 *
1.26 - * @author fiki
1.27 + * @author Ing. František Kučera (frantovo.cz)
1.28 */
1.29 -public class Reader implements XMLReader {
1.30 -
1.31 - private ContentHandler contentHandler;
1.32 - private ErrorHandler errorHandler;
1.33 - private DTDHandler dtdHandler;
1.34 - private EntityResolver entityResolver;
1.35 - private Map<String, Object> konfigurace = new HashMap<>();
1.36 +public class Reader extends AbstractAlt2XmlReader {
1.37
1.38 @Override
1.39 public void parse(InputSource input) throws IOException, SAXException {
1.40 - /**
1.41 - * TODO: rozpornat formát vstupu a podle toho delegovat
1.42 - */
1.43 JSONParser p = new JSONParser();
1.44 InputStreamReader vstup = new InputStreamReader(input.getByteStream());
1.45 JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler);
1.46 @@ -57,78 +40,7 @@
1.47 try {
1.48 p.parse(vstup, handler);
1.49 } catch (ParseException e) {
1.50 - throw new SAXException("Chyba při načítání JSONu", e);
1.51 + throw new SAXException("Unable to parse JSON: " + input.getSystemId(), e);
1.52 }
1.53 }
1.54 -
1.55 - @Override
1.56 - public void parse(String systemId) throws IOException, SAXException {
1.57 - parse(new InputSource(systemId));
1.58 - }
1.59 -
1.60 - @Override
1.61 - public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
1.62 - /**
1.63 - * TODO:
1.64 - * All XMLReaders are required to recognize
1.65 - * the http://xml.org/sax/features/namespaces
1.66 - * and the http://xml.org/sax/features/namespace-prefixes feature names.
1.67 - */
1.68 - throw new SAXNotSupportedException("Zatím není podporováno.");
1.69 - }
1.70 -
1.71 - @Override
1.72 - public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
1.73 - throw new SAXNotSupportedException("Zatím není podporováno.");
1.74 - }
1.75 -
1.76 - @Override
1.77 - public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
1.78 - return konfigurace.get(name);
1.79 - }
1.80 -
1.81 - @Override
1.82 - public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
1.83 - konfigurace.put(name, value);
1.84 - }
1.85 -
1.86 - @Override
1.87 - public void setEntityResolver(EntityResolver entityResolver) {
1.88 - this.entityResolver = entityResolver;
1.89 - }
1.90 -
1.91 - @Override
1.92 - public EntityResolver getEntityResolver() {
1.93 - return entityResolver;
1.94 - }
1.95 -
1.96 - @Override
1.97 - public void setDTDHandler(DTDHandler dtdHandler) {
1.98 - this.dtdHandler = dtdHandler;
1.99 - }
1.100 -
1.101 - @Override
1.102 - public DTDHandler getDTDHandler() {
1.103 - return dtdHandler;
1.104 - }
1.105 -
1.106 - @Override
1.107 - public void setContentHandler(ContentHandler contentHandler) {
1.108 - this.contentHandler = contentHandler;
1.109 - }
1.110 -
1.111 - @Override
1.112 - public ContentHandler getContentHandler() {
1.113 - return contentHandler;
1.114 - }
1.115 -
1.116 - @Override
1.117 - public void setErrorHandler(ErrorHandler errorHandler) {
1.118 - this.errorHandler = errorHandler;
1.119 - }
1.120 -
1.121 - @Override
1.122 - public ErrorHandler getErrorHandler() {
1.123 - return errorHandler;
1.124 - }
1.125 }