Podpora konfigurace.
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 boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
33 throw new SAXNotSupportedException("Zatím není podporováno.");
37 public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
38 throw new SAXNotSupportedException("Zatím není podporováno.");
42 public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
43 return konfigurace.get(name);
47 public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
48 konfigurace.put(name, value);
52 public void setEntityResolver(EntityResolver entityResolver) {
53 this.entityResolver = entityResolver;
57 public EntityResolver getEntityResolver() {
58 return entityResolver;
62 public void setDTDHandler(DTDHandler dtdHandler) {
63 this.dtdHandler = dtdHandler;
67 public DTDHandler getDTDHandler() {
72 public void setContentHandler(ContentHandler contentHandler) {
73 this.contentHandler = contentHandler;
77 public ContentHandler getContentHandler() {
78 return contentHandler;
82 public void setErrorHandler(ErrorHandler errorHandler) {
83 this.errorHandler = errorHandler;
87 public ErrorHandler getErrorHandler() {
92 public void parse(InputSource input) throws IOException, SAXException {
94 * TODO: rozpornat formát vstupu a podle toho delegovat
96 JSONParser p = new JSONParser();
97 InputStreamReader vstup = new InputStreamReader(input.getByteStream());
98 JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler);
101 p.parse(vstup, handler);
102 } catch (ParseException e) {
103 throw new SAXException("Chyba při načítání JSONu", e);
108 public void parse(String systemId) throws IOException, SAXException {
110 throw new SAXException("Zatím není podporováno.");