1 package cz.frantovo.alt2xml.vstup;
3 import java.io.IOException;
4 import java.io.InputStreamReader;
5 import java.util.HashMap;
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 ContentHandler contentHandler;
26 private ErrorHandler errorHandler;
27 private DTDHandler dtdHandler;
28 private EntityResolver entityResolver;
29 private Map<String, Object> konfigurace = new HashMap<>();
32 public void parse(InputSource input) throws IOException, SAXException {
34 * TODO: rozpornat formát vstupu a podle toho delegovat
36 JSONParser p = new JSONParser();
37 InputStreamReader vstup = new InputStreamReader(input.getByteStream());
38 JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler);
41 p.parse(vstup, handler);
42 } catch (ParseException e) {
43 throw new SAXException("Chyba při načítání JSONu", e);
48 public void parse(String systemId) throws IOException, SAXException {
49 parse(new InputSource(systemId));
53 public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
56 * All XMLReaders are required to recognize
57 * the http://xml.org/sax/features/namespaces
58 * and the http://xml.org/sax/features/namespace-prefixes feature names.
60 throw new SAXNotSupportedException("Zatím není podporováno.");
64 public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
65 throw new SAXNotSupportedException("Zatím není podporováno.");
69 public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
70 return konfigurace.get(name);
74 public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
75 konfigurace.put(name, value);
79 public void setEntityResolver(EntityResolver entityResolver) {
80 this.entityResolver = entityResolver;
84 public EntityResolver getEntityResolver() {
85 return entityResolver;
89 public void setDTDHandler(DTDHandler dtdHandler) {
90 this.dtdHandler = dtdHandler;
94 public DTDHandler getDTDHandler() {
99 public void setContentHandler(ContentHandler contentHandler) {
100 this.contentHandler = contentHandler;
104 public ContentHandler getContentHandler() {
105 return contentHandler;
109 public void setErrorHandler(ErrorHandler errorHandler) {
110 this.errorHandler = errorHandler;
114 public ErrorHandler getErrorHandler() {