# HG changeset patch # User František Kučera # Date 1401998518 -7200 # Node ID aaf6648af0aa229c102033d786bb6ffd754bc531 # Parent f56a5369245ee2972db62527cccd64f7ab545b45 licence diff -r f56a5369245e -r aaf6648af0aa java/alt2xml-bin/src/cz/frantovo/alt2xml/CLI.java --- a/java/alt2xml-bin/src/cz/frantovo/alt2xml/CLI.java Thu Jun 05 15:03:50 2014 +0200 +++ b/java/alt2xml-bin/src/cz/frantovo/alt2xml/CLI.java Thu Jun 05 22:01:58 2014 +0200 @@ -1,3 +1,20 @@ +/** + * Alt2XML + * Copyright © 2014 František Kučera (frantovo.cz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package cz.frantovo.alt2xml; import cz.frantovo.alt2xml.výstup.EchoContentHandler; diff -r f56a5369245e -r aaf6648af0aa java/alt2xml-bin/src/cz/frantovo/alt2xml/SAXTovarna.java --- a/java/alt2xml-bin/src/cz/frantovo/alt2xml/SAXTovarna.java Thu Jun 05 15:03:50 2014 +0200 +++ b/java/alt2xml-bin/src/cz/frantovo/alt2xml/SAXTovarna.java Thu Jun 05 22:01:58 2014 +0200 @@ -1,3 +1,20 @@ +/** + * Alt2XML + * Copyright © 2014 František Kučera (frantovo.cz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package cz.frantovo.alt2xml; import cz.frantovo.alt2xml.vstup.SuperReader; @@ -18,7 +35,7 @@ @Override public SAXParser newSAXParser() throws ParserConfigurationException, SAXException { - return new MůjParser(new SuperReader()); + return new AltSAXParser(new SuperReader()); } @Override @@ -31,15 +48,16 @@ throw new SAXNotSupportedException("Zatím není podporováno."); } - private static class MůjParser extends SAXParser { + private static class AltSAXParser extends SAXParser { private XMLReader xmlReader; - public MůjParser(XMLReader xmlReader) { + public AltSAXParser(XMLReader xmlReader) { this.xmlReader = xmlReader; } @Override + @Deprecated public Parser getParser() throws SAXException { throw new SAXException("Není podporováno."); } @@ -51,7 +69,7 @@ @Override public boolean isNamespaceAware() { - return false; + return true; } @Override diff -r f56a5369245e -r aaf6648af0aa java/alt2xml-bin/src/cz/frantovo/alt2xml/vstup/SuperReader.java --- a/java/alt2xml-bin/src/cz/frantovo/alt2xml/vstup/SuperReader.java Thu Jun 05 15:03:50 2014 +0200 +++ b/java/alt2xml-bin/src/cz/frantovo/alt2xml/vstup/SuperReader.java Thu Jun 05 22:01:58 2014 +0200 @@ -1,3 +1,20 @@ +/** + * Alt2XML + * Copyright © 2014 František Kučera (frantovo.cz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package cz.frantovo.alt2xml.vstup; import java.io.IOException; diff -r f56a5369245e -r aaf6648af0aa java/alt2xml-bin/src/cz/frantovo/alt2xml/výstup/EchoContentHandler.java --- a/java/alt2xml-bin/src/cz/frantovo/alt2xml/výstup/EchoContentHandler.java Thu Jun 05 15:03:50 2014 +0200 +++ b/java/alt2xml-bin/src/cz/frantovo/alt2xml/výstup/EchoContentHandler.java Thu Jun 05 22:01:58 2014 +0200 @@ -1,3 +1,20 @@ +/** + * Alt2XML + * Copyright © 2014 František Kučera (frantovo.cz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package cz.frantovo.alt2xml.výstup; import javax.xml.stream.XMLStreamException; diff -r f56a5369245e -r aaf6648af0aa java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/JsonSimpleContentHandler.java --- a/java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/JsonSimpleContentHandler.java Thu Jun 05 15:03:50 2014 +0200 +++ b/java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/JsonSimpleContentHandler.java Thu Jun 05 22:01:58 2014 +0200 @@ -1,3 +1,20 @@ +/** + * Alt2XML + * Copyright © 2014 František Kučera (frantovo.cz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package cz.frantovo.alt2xml.vstup; import java.io.IOException; diff -r f56a5369245e -r aaf6648af0aa java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/JsonXMLReader.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/JsonXMLReader.java Thu Jun 05 22:01:58 2014 +0200 @@ -0,0 +1,134 @@ +/** + * Alt2XML + * Copyright © 2014 František Kučera (frantovo.cz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package cz.frantovo.alt2xml.vstup; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import org.xml.sax.ContentHandler; +import org.xml.sax.DTDHandler; +import org.xml.sax.EntityResolver; +import org.xml.sax.ErrorHandler; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; +import org.xml.sax.XMLReader; + +/** + * + * @author fiki + */ +public class JsonXMLReader implements XMLReader { + + private ContentHandler contentHandler; + private ErrorHandler errorHandler; + private DTDHandler dtdHandler; + private EntityResolver entityResolver; + private Map konfigurace = new HashMap<>(); + + @Override + public void parse(InputSource input) throws IOException, SAXException { + /** + * TODO: rozpornat formát vstupu a podle toho delegovat + */ + JSONParser p = new JSONParser(); + InputStreamReader vstup = new InputStreamReader(input.getByteStream()); + JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler); + + try { + p.parse(vstup, handler); + } catch (ParseException e) { + throw new SAXException("Chyba při načítání JSONu", e); + } + } + + @Override + public void parse(String systemId) throws IOException, SAXException { + parse(new InputSource(systemId)); + } + + @Override + public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { + /** + * TODO: + * All XMLReaders are required to recognize + * the http://xml.org/sax/features/namespaces + * and the http://xml.org/sax/features/namespace-prefixes feature names. + */ + throw new SAXNotSupportedException("Zatím není podporováno."); + } + + @Override + public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { + throw new SAXNotSupportedException("Zatím není podporováno."); + } + + @Override + public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException { + return konfigurace.get(name); + } + + @Override + public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { + konfigurace.put(name, value); + } + + @Override + public void setEntityResolver(EntityResolver entityResolver) { + this.entityResolver = entityResolver; + } + + @Override + public EntityResolver getEntityResolver() { + return entityResolver; + } + + @Override + public void setDTDHandler(DTDHandler dtdHandler) { + this.dtdHandler = dtdHandler; + } + + @Override + public DTDHandler getDTDHandler() { + return dtdHandler; + } + + @Override + public void setContentHandler(ContentHandler contentHandler) { + this.contentHandler = contentHandler; + } + + @Override + public ContentHandler getContentHandler() { + return contentHandler; + } + + @Override + public void setErrorHandler(ErrorHandler errorHandler) { + this.errorHandler = errorHandler; + } + + @Override + public ErrorHandler getErrorHandler() { + return errorHandler; + } +} diff -r f56a5369245e -r aaf6648af0aa java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/SuperReader.java --- a/java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/SuperReader.java Thu Jun 05 15:03:50 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -package cz.frantovo.alt2xml.vstup; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.HashMap; -import java.util.Map; -import org.json.simple.parser.JSONParser; -import org.json.simple.parser.ParseException; -import org.xml.sax.ContentHandler; -import org.xml.sax.DTDHandler; -import org.xml.sax.EntityResolver; -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.SAXNotSupportedException; -import org.xml.sax.XMLReader; - -/** - * - * @author fiki - */ -public class SuperReader implements XMLReader { - - private ContentHandler contentHandler; - private ErrorHandler errorHandler; - private DTDHandler dtdHandler; - private EntityResolver entityResolver; - private Map konfigurace = new HashMap<>(); - - @Override - public void parse(InputSource input) throws IOException, SAXException { - /** - * TODO: rozpornat formát vstupu a podle toho delegovat - */ - JSONParser p = new JSONParser(); - InputStreamReader vstup = new InputStreamReader(input.getByteStream()); - JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler); - - try { - p.parse(vstup, handler); - } catch (ParseException e) { - throw new SAXException("Chyba při načítání JSONu", e); - } - } - - @Override - public void parse(String systemId) throws IOException, SAXException { - parse(new InputSource(systemId)); - } - - @Override - public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { - /** - * TODO: - * All XMLReaders are required to recognize - * the http://xml.org/sax/features/namespaces - * and the http://xml.org/sax/features/namespace-prefixes feature names. - */ - throw new SAXNotSupportedException("Zatím není podporováno."); - } - - @Override - public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { - throw new SAXNotSupportedException("Zatím není podporováno."); - } - - @Override - public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException { - return konfigurace.get(name); - } - - @Override - public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { - konfigurace.put(name, value); - } - - @Override - public void setEntityResolver(EntityResolver entityResolver) { - this.entityResolver = entityResolver; - } - - @Override - public EntityResolver getEntityResolver() { - return entityResolver; - } - - @Override - public void setDTDHandler(DTDHandler dtdHandler) { - this.dtdHandler = dtdHandler; - } - - @Override - public DTDHandler getDTDHandler() { - return dtdHandler; - } - - @Override - public void setContentHandler(ContentHandler contentHandler) { - this.contentHandler = contentHandler; - } - - @Override - public ContentHandler getContentHandler() { - return contentHandler; - } - - @Override - public void setErrorHandler(ErrorHandler errorHandler) { - this.errorHandler = errorHandler; - } - - @Override - public ErrorHandler getErrorHandler() { - return errorHandler; - } -}