franta-hg@11: /**
franta-hg@11: * Alt2XML
franta-hg@11: * Copyright © 2014 František Kučera (frantovo.cz)
franta-hg@11: *
franta-hg@11: * This program is free software: you can redistribute it and/or modify
franta-hg@11: * it under the terms of the GNU General Public License as published by
franta-hg@11: * the Free Software Foundation, either version 3 of the License, or
franta-hg@11: * (at your option) any later version.
franta-hg@11: *
franta-hg@11: * This program is distributed in the hope that it will be useful,
franta-hg@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@11: * GNU General Public License for more details.
franta-hg@11: *
franta-hg@11: * You should have received a copy of the GNU General Public License
franta-hg@11: * along with this program. If not, see .
franta-hg@11: */
franta-hg@16: package cz.frantovo.alt2xml;
franta-hg@2:
franta-hg@2: import java.io.IOException;
franta-hg@2: import java.io.InputStreamReader;
franta-hg@4: import java.util.HashMap;
franta-hg@4: import java.util.Map;
franta-hg@2: import org.xml.sax.ContentHandler;
franta-hg@2: import org.xml.sax.DTDHandler;
franta-hg@2: import org.xml.sax.EntityResolver;
franta-hg@2: import org.xml.sax.ErrorHandler;
franta-hg@2: import org.xml.sax.InputSource;
franta-hg@2: import org.xml.sax.SAXException;
franta-hg@2: import org.xml.sax.SAXNotRecognizedException;
franta-hg@2: import org.xml.sax.SAXNotSupportedException;
franta-hg@2: import org.xml.sax.XMLReader;
franta-hg@2:
franta-hg@2: /**
franta-hg@2: *
franta-hg@2: * @author fiki
franta-hg@2: */
franta-hg@2: public class SuperReader implements XMLReader {
franta-hg@2:
franta-hg@2: private ContentHandler contentHandler;
franta-hg@4: private ErrorHandler errorHandler;
franta-hg@4: private DTDHandler dtdHandler;
franta-hg@4: private EntityResolver entityResolver;
franta-hg@4: private Map konfigurace = new HashMap<>();
franta-hg@15: private final ReaderFinder readerFinder;
franta-hg@15:
franta-hg@15: public SuperReader(ReaderFinder readerFinder) {
franta-hg@15: this.readerFinder = readerFinder;
franta-hg@15: }
franta-hg@15:
franta-hg@2: @Override
franta-hg@6: public void parse(InputSource input) throws IOException, SAXException {
franta-hg@6: /**
franta-hg@6: * TODO: rozpornat formát vstupu a podle toho delegovat
franta-hg@6: */
franta-hg@10: //JSONParser p = new JSONParser();
franta-hg@6: InputStreamReader vstup = new InputStreamReader(input.getByteStream());
franta-hg@10: //JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler);
franta-hg@6:
franta-hg@10: /*
franta-hg@15: try {
franta-hg@15: p.parse(vstup, handler);
franta-hg@15: } catch (ParseException e) {
franta-hg@15: throw new SAXException("Chyba při načítání JSONu", e);
franta-hg@15: }
franta-hg@15: */
franta-hg@6: }
franta-hg@6:
franta-hg@6: @Override
franta-hg@6: public void parse(String systemId) throws IOException, SAXException {
franta-hg@6: parse(new InputSource(systemId));
franta-hg@6: }
franta-hg@6:
franta-hg@6: @Override
franta-hg@2: public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
franta-hg@7: /**
franta-hg@15: * TODO:
franta-hg@15: * All XMLReaders are required to recognize
franta-hg@15: * the http://xml.org/sax/features/namespaces
franta-hg@7: * and the http://xml.org/sax/features/namespace-prefixes feature names.
franta-hg@7: */
franta-hg@4: throw new SAXNotSupportedException("Zatím není podporováno.");
franta-hg@2: }
franta-hg@2:
franta-hg@2: @Override
franta-hg@2: public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
franta-hg@4: throw new SAXNotSupportedException("Zatím není podporováno.");
franta-hg@2: }
franta-hg@2:
franta-hg@2: @Override
franta-hg@2: public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
franta-hg@4: return konfigurace.get(name);
franta-hg@2: }
franta-hg@2:
franta-hg@2: @Override
franta-hg@2: public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
franta-hg@4: konfigurace.put(name, value);
franta-hg@2: }
franta-hg@2:
franta-hg@2: @Override
franta-hg@4: public void setEntityResolver(EntityResolver entityResolver) {
franta-hg@4: this.entityResolver = entityResolver;
franta-hg@2: }
franta-hg@2:
franta-hg@2: @Override
franta-hg@2: public EntityResolver getEntityResolver() {
franta-hg@4: return entityResolver;
franta-hg@2: }
franta-hg@2:
franta-hg@2: @Override
franta-hg@4: public void setDTDHandler(DTDHandler dtdHandler) {
franta-hg@4: this.dtdHandler = dtdHandler;
franta-hg@2: }
franta-hg@2:
franta-hg@2: @Override
franta-hg@2: public DTDHandler getDTDHandler() {
franta-hg@4: return dtdHandler;
franta-hg@2: }
franta-hg@2:
franta-hg@2: @Override
franta-hg@4: public void setContentHandler(ContentHandler contentHandler) {
franta-hg@4: this.contentHandler = contentHandler;
franta-hg@2: }
franta-hg@2:
franta-hg@2: @Override
franta-hg@2: public ContentHandler getContentHandler() {
franta-hg@2: return contentHandler;
franta-hg@2: }
franta-hg@2:
franta-hg@2: @Override
franta-hg@4: public void setErrorHandler(ErrorHandler errorHandler) {
franta-hg@4: this.errorHandler = errorHandler;
franta-hg@2: }
franta-hg@2:
franta-hg@2: @Override
franta-hg@2: public ErrorHandler getErrorHandler() {
franta-hg@4: return errorHandler;
franta-hg@2: }
franta-hg@2: }