# HG changeset patch # User František Kučera # Date 1402130982 -7200 # Node ID b2fbb3570ae1316172cf1bd5cc039d0dab4a08b0 # Parent b890783e4043067db2030c5030cbe6fb8fe9c539 přesun tříd do správných projektů/balíčků diff -r b890783e4043 -r b2fbb3570ae1 .hgignore --- a/.hgignore Sat Jun 07 10:38:31 2014 +0200 +++ b/.hgignore Sat Jun 07 10:49:42 2014 +0200 @@ -1,6 +1,6 @@ -java/alt2xml-bin/dist/* -java/alt2xml-bin/build/* -java/alt2xml-bin/nbproject/private/* +java/alt2xml-cli/dist/* +java/alt2xml-cli/build/* +java/alt2xml-cli/nbproject/private/* java/alt2xml-lib/dist/* java/alt2xml-lib/build/* diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-bin/build.xml --- a/java/alt2xml-bin/build.xml Sat Jun 07 10:38:31 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ - - - - - - - - - - - Builds, tests, and runs the project alt2xml-bin. - - - diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-bin/manifest.mf --- a/java/alt2xml-bin/manifest.mf Sat Jun 07 10:38:31 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -X-COMMENT: Main-Class will be added automatically by build - diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-bin/nbproject/build-impl.xml --- a/java/alt2xml-bin/nbproject/build-impl.xml Sat Jun 07 10:38:31 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1042 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set src.dir - Must set test.src.dir - Must set build.dir - Must set dist.dir - Must set build.classes.dir - Must set dist.javadoc.dir - Must set build.test.classes.dir - Must set build.test.results.dir - Must set build.classes.excludes - Must set dist.jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set JVM to use for profiling in profiler.info.jvm - Must set profiler agent JVM arguments in profiler.info.jvmargs.agent - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - - - - - - java -cp "${run.classpath.with.dist.jar}" ${main.class} - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - java -jar "${dist.jar.resolved}" - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - Must select one file in the IDE or set run.class - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set debug.class - - - - - Must select one file in the IDE or set debug.class - - - - - Must set fix.includes - - - - - - - - - - - - - - - - - Must select one file in the IDE or set profile.class - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - Some tests failed; see details above. - - - - - - - - - Must select some files in the IDE or set test.includes - - - - Some tests failed; see details above. - - - - - Must select one file in the IDE or set test.class - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-bin/nbproject/build-impl.xml.orig --- a/java/alt2xml-bin/nbproject/build-impl.xml.orig Sat Jun 07 10:38:31 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1411 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set src.dir - Must set test.src.dir - Must set build.dir - Must set dist.dir - Must set build.classes.dir - Must set dist.javadoc.dir - Must set build.test.classes.dir - Must set build.test.results.dir - Must set build.classes.excludes - Must set dist.jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - No tests executed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set JVM to use for profiling in profiler.info.jvm - Must set profiler agent JVM arguments in profiler.info.jvmargs.agent - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - - - - - - java -cp "${run.classpath.with.dist.jar}" ${main.class} - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - java -jar "${dist.jar.resolved}" - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - Must select one file in the IDE or set run.class - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set debug.class - - - - - Must select one file in the IDE or set debug.class - - - - - Must set fix.includes - - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - Must select one file in the IDE or set profile.class - This target only works when run from inside the NetBeans IDE. - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - - - Must select some files in the IDE or set test.includes - - - - - Must select one file in the IDE or set run.class - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - Some tests failed; see details above. - - - - - - - - - Must select some files in the IDE or set test.includes - - - - Some tests failed; see details above. - - - - Must select some files in the IDE or set test.class - Must select some method in the IDE or set test.method - - - - Some tests failed; see details above. - - - - - Must select one file in the IDE or set test.class - - - - Must select one file in the IDE or set test.class - Must select some method in the IDE or set test.method - - - - - - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-bin/nbproject/genfiles.properties --- a/java/alt2xml-bin/nbproject/genfiles.properties Sat Jun 07 10:38:31 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -build.xml.data.CRC32=00ae4836 -build.xml.script.CRC32=98793cfd -build.xml.stylesheet.CRC32=8064a381@1.74.2.48 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=31175c28 -nbproject/build-impl.xml.script.CRC32=aa79723f -nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46 -nbproject/groovy-build.xml.data.CRC32=00ae4836 -nbproject/groovy-build.xml.script.CRC32=66297360 -nbproject/groovy-build.xml.stylesheet.CRC32=28d0e1f2@1.7.1 diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-bin/nbproject/groovy-build.xml --- a/java/alt2xml-bin/nbproject/groovy-build.xml Sat Jun 07 10:38:31 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set javac.includes - - - - - - - - - - - - - - - - - Some tests failed; see details above. - - - - Must select some files in the IDE or set test.includes - - - - Some tests failed; see details above. - - - - Must select some files in the IDE or set test.binarytestincludes - - - - Some tests failed; see details above. - - - diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-bin/nbproject/project.properties --- a/java/alt2xml-bin/nbproject/project.properties Sat Jun 07 10:38:31 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=true -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -application.title=alt2xml-bin -application.vendor=fiki -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form,**/*.groovy -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -# Uncomment to specify the preferred debugger connection transport: -#debug.transport=dt_socket -debug.classpath=\ - ${run.classpath} -debug.test.classpath=\ - ${run.test.classpath} -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/alt2xml-bin.jar -dist.javadoc.dir=${dist.dir}/javadoc -endorsed.classpath= -excludes= -includes=** -jar.compress=false -javac.classpath=\ - ${reference.alt2xml-lib.jar} -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=false -javac.processorpath=\ - ${javac.classpath} -javac.source=1.7 -javac.target=1.7 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -main.class=cz.frantovo.alt2xml.CLI -manifest.file=manifest.mf -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=false -platform.active=default_platform -project.alt2xml-lib=../alt2xml-lib -reference.alt2xml-lib.jar=${project.alt2xml-lib}/dist/alt2xml-lib.jar -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project -# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value -# or test-sys-prop.name=value to set system properties for unit tests): -run.jvmargs= -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -source.encoding=UTF-8 -src.dir=src -test.src.dir=test -compile.on.save.unsupported.groovy=true diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-bin/nbproject/project.xml --- a/java/alt2xml-bin/nbproject/project.xml Sat Jun 07 10:38:31 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ - - - org.netbeans.modules.java.j2seproject - - - - - - - - alt2xml-bin - - - - - - - - - - alt2xml-lib - jar - - jar - clean - jar - - - - diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-bin/src/cz/frantovo/alt2xml/CLI.java --- a/java/alt2xml-bin/src/cz/frantovo/alt2xml/CLI.java Sat Jun 07 10:38:31 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/** - * 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; -import java.io.InputStream; -import java.io.OutputStream; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamWriter; -import org.xml.sax.helpers.DefaultHandler; - -/** - * - * @author fiki - */ -public class CLI { - - public static void main(String[] args) throws Exception { - /** - * Použijeme standardní vstup a výstup: - */ - InputStream vstup = System.in; - OutputStream výstup = System.out; - - /** - * Serializujeme data do XML. - * To normálně vůbec není potřeba – data se do tvaru proudu obsahujícího ostré závorky - * vůbec nedostanou – zpracováváme události (volání javovských metod – začátky a konce elementů atd.) - * a z nich např. deserializujeme nějaké naše objekty, provádíme nějaké akce, nebo třeba stavíme DOM. - */ - XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory(); - XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(výstup); - DefaultHandler h = new EchoContentHandler(w); - - /** - * Parsujeme JSON a děláme z něj XML: - */ - SAXParserFactory t = SAXParserFactory.newInstance(SAXTovarna.class.getName(), null); - SAXParser p = t.newSAXParser(); - p.parse(vstup, h); - } -} diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-bin/src/cz/frantovo/alt2xml/ReaderFinder.java --- a/java/alt2xml-bin/src/cz/frantovo/alt2xml/ReaderFinder.java Sat Jun 07 10:38:31 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package cz.frantovo.alt2xml; - -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; - -/** - * - * @author Ing. František Kučera (frantovo.cz) - */ -public interface ReaderFinder { - - /** - * - * @param systemId systemId of the document which should be parsed - * @return XMLReader appropriate for this document - * @throws org.xml.sax.SAXException if we have no reader for given systemId - */ - public XMLReader findReader(String systemId) throws SAXException; - -} diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-bin/src/cz/frantovo/alt2xml/SAXTovarna.java --- a/java/alt2xml-bin/src/cz/frantovo/alt2xml/SAXTovarna.java Sat Jun 07 10:38:31 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -/** - * 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; -import java.util.Deque; -import java.util.LinkedList; -import java.util.ServiceLoader; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import org.xml.sax.Parser; -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.SAXNotSupportedException; -import org.xml.sax.XMLReader; - -/** - * - * @author fiki - */ -public class SAXTovarna extends SAXParserFactory implements ReaderFinder { - - private final Deque readerFactories = new LinkedList(); - - public SAXTovarna() { - super(); - for (Alt2XmlReaderFactory f : ServiceLoader.load(Alt2XmlReaderFactory.class)) { - readerFactories.add(f); - } - - } - - @Override - public XMLReader findReader(String systemId) throws SAXException { - for (Alt2XmlReaderFactory f : readerFactories) { - if (f.canRead(systemId)) { - return f.getReader(); - } - } - throw new SAXException("Iterated over " + readerFactories.size() + " and was unable to find XMLReader for SystemId: " + systemId); - } - - @Override - public SAXParser newSAXParser() throws ParserConfigurationException, SAXException { - return new AltSAXParser(new SuperReader(this)); - } - - @Override - public void setFeature(String name, boolean value) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException { - throw new SAXNotSupportedException("Zatím není podporováno."); - } - - @Override - public boolean getFeature(String name) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException { - throw new SAXNotSupportedException("Zatím není podporováno."); - } - - private static class AltSAXParser extends SAXParser { - - private XMLReader xmlReader; - - public AltSAXParser(XMLReader xmlReader) { - this.xmlReader = xmlReader; - } - - @Override - @Deprecated - public Parser getParser() throws SAXException { - throw new SAXException("Není podporováno."); - } - - @Override - public XMLReader getXMLReader() throws SAXException { - return xmlReader; - } - - @Override - public boolean isNamespaceAware() { - return true; - } - - @Override - public boolean isValidating() { - return false; - } - - @Override - public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { - xmlReader.setProperty(name, value); - } - - @Override - public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException { - return xmlReader.getProperty(name); - } - } -} diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-bin/src/cz/frantovo/alt2xml/vstup/SuperReader.java --- a/java/alt2xml-bin/src/cz/frantovo/alt2xml/vstup/SuperReader.java Sat Jun 07 10:38:31 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,140 +0,0 @@ -/** - * 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 cz.frantovo.alt2xml.ReaderFinder; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.HashMap; -import java.util.Map; -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<>(); - private final ReaderFinder readerFinder; - - public SuperReader(ReaderFinder readerFinder) { - this.readerFinder = readerFinder; - } - - @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 b890783e4043 -r b2fbb3570ae1 java/alt2xml-bin/src/cz/frantovo/alt2xml/výstup/EchoContentHandler.java --- a/java/alt2xml-bin/src/cz/frantovo/alt2xml/výstup/EchoContentHandler.java Sat Jun 07 10:38:31 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -/** - * 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; -import javax.xml.stream.XMLStreamWriter; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -/** - * Slouží k převodu právě parsovaného XML zpět na XML. - * Určen pro testování a ladění a pro použití s neobvyklými „XML“ parsery, - * které nečtou XML ale jiný jazyk (např. JSON, INI atd.), ale používají stejné rozhraní (SAX). - * - * TODO: další typy uzlů a jmenné prostory. - * @author fiki - */ -public class EchoContentHandler extends DefaultHandler { - - private XMLStreamWriter w; - - /** - * @param writer kam se bude vypisovat XML. - */ - public EchoContentHandler(XMLStreamWriter writer) { - w = writer; - } - - @Override - public void startDocument() throws SAXException { - try { - w.writeStartDocument(); - } catch (XMLStreamException e) { - throw new SAXException(e); - } - } - - @Override - public void endDocument() throws SAXException { - try { - w.writeEndDocument(); - w.close(); - } catch (XMLStreamException e) { - throw new SAXException(e); - } - } - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - try { - w.writeStartElement(qName); - - if (attributes != null) { - for (int i = 0; i < attributes.getLength(); i++) { - w.writeAttribute(attributes.getQName(i), attributes.getValue(i)); - } - } - - w.flush(); - } catch (XMLStreamException e) { - throw new SAXException(e); - } - } - - @Override - public void endElement(String uri, String localName, String qName) throws SAXException { - try { - w.writeEndElement(); - w.flush(); - } catch (XMLStreamException e) { - throw new SAXException(e); - } - } - - @Override - public void characters(char[] ch, int start, int length) throws SAXException { - try { - w.writeCharacters(ch, start, length); - w.flush(); - } catch (XMLStreamException e) { - throw new SAXException(e); - } - } -} diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-cli/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-cli/build.xml Sat Jun 07 10:49:42 2014 +0200 @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project alt2xml-cli. + + + diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-cli/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-cli/manifest.mf Sat Jun 07 10:49:42 2014 +0200 @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-cli/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-cli/nbproject/build-impl.xml Sat Jun 07 10:49:42 2014 +0200 @@ -0,0 +1,1042 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-cli/nbproject/build-impl.xml.orig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-cli/nbproject/build-impl.xml.orig Sat Jun 07 10:49:42 2014 +0200 @@ -0,0 +1,1411 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-cli/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-cli/nbproject/genfiles.properties Sat Jun 07 10:49:42 2014 +0200 @@ -0,0 +1,11 @@ +build.xml.data.CRC32=97b0f0d3 +build.xml.script.CRC32=c0ec96ea +build.xml.stylesheet.CRC32=8064a381@1.74.2.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=31175c28 +nbproject/build-impl.xml.script.CRC32=aa79723f +nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46 +nbproject/groovy-build.xml.data.CRC32=97b0f0d3 +nbproject/groovy-build.xml.script.CRC32=66297360 +nbproject/groovy-build.xml.stylesheet.CRC32=28d0e1f2@1.7.1 diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-cli/nbproject/groovy-build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-cli/nbproject/groovy-build.xml Sat Jun 07 10:49:42 2014 +0200 @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.binarytestincludes + + + + Some tests failed; see details above. + + + diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-cli/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-cli/nbproject/project.properties Sat Jun 07 10:49:42 2014 +0200 @@ -0,0 +1,77 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=true +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=alt2xml-cli +application.vendor=fiki +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form,**/*.groovy +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/alt2xml-cli.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath=\ + ${reference.alt2xml-lib.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=cz.frantovo.alt2xml.CLI +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +project.alt2xml-lib=../alt2xml-lib +reference.alt2xml-lib.jar=${project.alt2xml-lib}/dist/alt2xml-lib.jar +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test +compile.on.save.unsupported.groovy=true diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-cli/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-cli/nbproject/project.xml Sat Jun 07 10:49:42 2014 +0200 @@ -0,0 +1,30 @@ + + + org.netbeans.modules.java.j2seproject + + + + + + + + alt2xml-cli + + + + + + + + + + alt2xml-lib + jar + + jar + clean + jar + + + + diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java Sat Jun 07 10:49:42 2014 +0200 @@ -0,0 +1,61 @@ +/** + * 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.cli; + +import cz.frantovo.alt2xml.ParserFactory; +import java.io.InputStream; +import java.io.OutputStream; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamWriter; +import org.xml.sax.helpers.DefaultHandler; + +/** + * + * @author fiki + */ +public class CLI { + + public static void main(String[] args) throws Exception { + /** + * Použijeme standardní vstup a výstup: + */ + InputStream vstup = System.in; + OutputStream výstup = System.out; + + /** + * Serializujeme data do XML. + * To normálně vůbec není potřeba – data se do tvaru proudu obsahujícího ostré závorky + * vůbec nedostanou – zpracováváme události (volání javovských metod – začátky a konce + * elementů atd.) + * a z nich např. deserializujeme nějaké naše objekty, provádíme nějaké akce, nebo třeba + * stavíme DOM. + */ + XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory(); + XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(výstup); + DefaultHandler h = new EchoContentHandler(w); + + /** + * Parsujeme JSON a děláme z něj XML: + */ + SAXParserFactory t = SAXParserFactory.newInstance(ParserFactory.class.getName(), null); + SAXParser p = t.newSAXParser(); + p.parse(vstup, h); + } +} diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/EchoContentHandler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/EchoContentHandler.java Sat Jun 07 10:49:42 2014 +0200 @@ -0,0 +1,100 @@ +/** + * 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.cli; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * Slouží k převodu právě parsovaného XML zpět na XML. + * Určen pro testování a ladění a pro použití s neobvyklými „XML“ parsery, + * které nečtou XML ale jiný jazyk (např. JSON, INI atd.), ale používají stejné rozhraní (SAX). + * + * TODO: další typy uzlů a jmenné prostory. + * @author fiki + */ +public class EchoContentHandler extends DefaultHandler { + + private XMLStreamWriter w; + + /** + * @param writer kam se bude vypisovat XML. + */ + public EchoContentHandler(XMLStreamWriter writer) { + w = writer; + } + + @Override + public void startDocument() throws SAXException { + try { + w.writeStartDocument(); + } catch (XMLStreamException e) { + throw new SAXException(e); + } + } + + @Override + public void endDocument() throws SAXException { + try { + w.writeEndDocument(); + w.close(); + } catch (XMLStreamException e) { + throw new SAXException(e); + } + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + try { + w.writeStartElement(qName); + + if (attributes != null) { + for (int i = 0; i < attributes.getLength(); i++) { + w.writeAttribute(attributes.getQName(i), attributes.getValue(i)); + } + } + + w.flush(); + } catch (XMLStreamException e) { + throw new SAXException(e); + } + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + try { + w.writeEndElement(); + w.flush(); + } catch (XMLStreamException e) { + throw new SAXException(e); + } + } + + @Override + public void characters(char[] ch, int start, int length) throws SAXException { + try { + w.writeCharacters(ch, start, length); + w.flush(); + } catch (XMLStreamException e) { + throw new SAXException(e); + } + } +} diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-lib/src/cz/frantovo/alt2xml/ParserFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-lib/src/cz/frantovo/alt2xml/ParserFactory.java Sat Jun 07 10:49:42 2014 +0200 @@ -0,0 +1,112 @@ +/** + * 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 java.util.Deque; +import java.util.LinkedList; +import java.util.ServiceLoader; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import org.xml.sax.Parser; +import org.xml.sax.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; +import org.xml.sax.XMLReader; + +/** + * + * @author fiki + */ +public class ParserFactory extends SAXParserFactory implements ReaderFinder { + + private final Deque readerFactories = new LinkedList(); + + public ParserFactory() { + super(); + for (Alt2XmlReaderFactory f : ServiceLoader.load(Alt2XmlReaderFactory.class)) { + readerFactories.add(f); + } + + } + + @Override + public XMLReader findReader(String systemId) throws SAXException { + for (Alt2XmlReaderFactory f : readerFactories) { + if (f.canRead(systemId)) { + return f.getReader(); + } + } + throw new SAXException("Iterated over " + readerFactories.size() + " and was unable to find XMLReader for SystemId: " + systemId); + } + + @Override + public SAXParser newSAXParser() throws ParserConfigurationException, SAXException { + return new AltSAXParser(new SuperReader(this)); + } + + @Override + public void setFeature(String name, boolean value) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException { + throw new SAXNotSupportedException("Zatím není podporováno."); + } + + @Override + public boolean getFeature(String name) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException { + throw new SAXNotSupportedException("Zatím není podporováno."); + } + + private static class AltSAXParser extends SAXParser { + + private XMLReader xmlReader; + + public AltSAXParser(XMLReader xmlReader) { + this.xmlReader = xmlReader; + } + + @Override + @Deprecated + public Parser getParser() throws SAXException { + throw new SAXException("Není podporováno."); + } + + @Override + public XMLReader getXMLReader() throws SAXException { + return xmlReader; + } + + @Override + public boolean isNamespaceAware() { + return true; + } + + @Override + public boolean isValidating() { + return false; + } + + @Override + public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { + xmlReader.setProperty(name, value); + } + + @Override + public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException { + return xmlReader.getProperty(name); + } + } +} diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-lib/src/cz/frantovo/alt2xml/ReaderFinder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-lib/src/cz/frantovo/alt2xml/ReaderFinder.java Sat Jun 07 10:49:42 2014 +0200 @@ -0,0 +1,20 @@ +package cz.frantovo.alt2xml; + +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; + +/** + * + * @author Ing. František Kučera (frantovo.cz) + */ +public interface ReaderFinder { + + /** + * + * @param systemId systemId of the document which should be parsed + * @return XMLReader appropriate for this document + * @throws org.xml.sax.SAXException if we have no reader for given systemId + */ + public XMLReader findReader(String systemId) throws SAXException; + +} diff -r b890783e4043 -r b2fbb3570ae1 java/alt2xml-lib/src/cz/frantovo/alt2xml/SuperReader.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-lib/src/cz/frantovo/alt2xml/SuperReader.java Sat Jun 07 10:49:42 2014 +0200 @@ -0,0 +1,139 @@ +/** + * 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 java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; +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<>(); + private final ReaderFinder readerFinder; + + public SuperReader(ReaderFinder readerFinder) { + this.readerFinder = readerFinder; + } + + @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; + } +}