# HG changeset patch # User František Kučera # Date 1402171772 -7200 # Node ID ecc2731a5a4695359ef7134c76b91e3cc92130d1 # Parent c9f1e497132e8d1f517ca1a8035da3071e4dd2e8 rename: alt2xml-lib → alt2xml-lib-input diff -r c9f1e497132e -r ecc2731a5a46 .hgignore --- a/.hgignore Sat Jun 07 21:57:50 2014 +0200 +++ b/.hgignore Sat Jun 07 22:09:32 2014 +0200 @@ -2,9 +2,13 @@ java/alt2xml-cli/build/* java/alt2xml-cli/nbproject/private/* -java/alt2xml-lib/dist/* -java/alt2xml-lib/build/* -java/alt2xml-lib/nbproject/private/* +java/alt2xml-lib-input/dist/* +java/alt2xml-lib-input/build/* +java/alt2xml-lib-input/nbproject/private/* + +java/alt2xml-lib-output/dist/* +java/alt2xml-lib-output/build/* +java/alt2xml-lib-output/nbproject/private/* java/alt2xml-in-json/dist/* java/alt2xml-in-json/build/* diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-cli/nbproject/genfiles.properties --- a/java/alt2xml-cli/nbproject/genfiles.properties Sat Jun 07 21:57:50 2014 +0200 +++ b/java/alt2xml-cli/nbproject/genfiles.properties Sat Jun 07 22:09:32 2014 +0200 @@ -1,4 +1,4 @@ -build.xml.data.CRC32=97b0f0d3 +build.xml.data.CRC32=43f6f692 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. @@ -6,6 +6,6 @@ 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.data.CRC32=43f6f692 nbproject/groovy-build.xml.script.CRC32=66297360 nbproject/groovy-build.xml.stylesheet.CRC32=28d0e1f2@1.7.1 diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-cli/nbproject/project.properties --- a/java/alt2xml-cli/nbproject/project.properties Sat Jun 07 21:57:50 2014 +0200 +++ b/java/alt2xml-cli/nbproject/project.properties Sat Jun 07 22:09:32 2014 +0200 @@ -29,8 +29,7 @@ excludes= includes=** jar.compress=false -javac.classpath=\ - ${reference.alt2xml-lib.jar} +javac.classpath= # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false @@ -59,8 +58,6 @@ meta.inf.dir=${src.dir}/META-INF mkdist.disabled=true 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} diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-cli/nbproject/project.xml --- a/java/alt2xml-cli/nbproject/project.xml Sat Jun 07 21:57:50 2014 +0200 +++ b/java/alt2xml-cli/nbproject/project.xml Sat Jun 07 22:09:32 2014 +0200 @@ -16,15 +16,6 @@ - - - alt2xml-lib - jar - - jar - clean - jar - - + diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-in-json/nbproject/build-impl.xml --- a/java/alt2xml-in-json/nbproject/build-impl.xml Sat Jun 07 21:57:50 2014 +0200 +++ b/java/alt2xml-in-json/nbproject/build-impl.xml Sat Jun 07 22:09:32 2014 +0200 @@ -900,8 +900,8 @@ - - + + @@ -1400,8 +1400,8 @@ - - + + diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-in-json/nbproject/genfiles.properties --- a/java/alt2xml-in-json/nbproject/genfiles.properties Sat Jun 07 21:57:50 2014 +0200 +++ b/java/alt2xml-in-json/nbproject/genfiles.properties Sat Jun 07 22:09:32 2014 +0200 @@ -1,8 +1,8 @@ -build.xml.data.CRC32=eaa6670b +build.xml.data.CRC32=36d981c5 build.xml.script.CRC32=85cc1c66 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=eaa6670b -nbproject/build-impl.xml.script.CRC32=fae42019 +nbproject/build-impl.xml.data.CRC32=36d981c5 +nbproject/build-impl.xml.script.CRC32=5b826399 nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.74.2.48 diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-in-json/nbproject/project.properties --- a/java/alt2xml-in-json/nbproject/project.properties Sat Jun 07 21:57:50 2014 +0200 +++ b/java/alt2xml-in-json/nbproject/project.properties Sat Jun 07 22:09:32 2014 +0200 @@ -32,8 +32,8 @@ includes=** jar.compress=false javac.classpath=\ - ${reference.alt2xml-lib.jar}:\ - ${libs.json-simple.classpath} + ${libs.json-simple.classpath}:\ + ${reference.alt2xml-lib-input.jar} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false @@ -60,8 +60,8 @@ meta.inf.dir=${src.dir}/META-INF mkdist.disabled=true platform.active=default_platform -project.alt2xml-lib=../alt2xml-lib -reference.alt2xml-lib.jar=${project.alt2xml-lib}/dist/alt2xml-lib.jar +project.alt2xml-lib-input=../alt2xml-lib-input +reference.alt2xml-lib-input.jar=${project.alt2xml-lib-input}/dist/alt2xml-lib-input.jar run.classpath=\ ${javac.classpath}:\ ${build.classes.dir} diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-in-json/nbproject/project.xml --- a/java/alt2xml-in-json/nbproject/project.xml Sat Jun 07 21:57:50 2014 +0200 +++ b/java/alt2xml-in-json/nbproject/project.xml Sat Jun 07 22:09:32 2014 +0200 @@ -14,7 +14,7 @@ - alt2xml-lib + alt2xml-lib-input jar jar diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-in-properties/nbproject/build-impl.xml --- a/java/alt2xml-in-properties/nbproject/build-impl.xml Sat Jun 07 21:57:50 2014 +0200 +++ b/java/alt2xml-in-properties/nbproject/build-impl.xml Sat Jun 07 22:09:32 2014 +0200 @@ -900,8 +900,8 @@ - - + + @@ -1400,8 +1400,8 @@ - - + + diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-in-properties/nbproject/genfiles.properties --- a/java/alt2xml-in-properties/nbproject/genfiles.properties Sat Jun 07 21:57:50 2014 +0200 +++ b/java/alt2xml-in-properties/nbproject/genfiles.properties Sat Jun 07 22:09:32 2014 +0200 @@ -1,8 +1,8 @@ -build.xml.data.CRC32=1573d3a6 +build.xml.data.CRC32=d90e5067 build.xml.script.CRC32=462baf93 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=1573d3a6 -nbproject/build-impl.xml.script.CRC32=4e81b18f +nbproject/build-impl.xml.data.CRC32=d90e5067 +nbproject/build-impl.xml.script.CRC32=a04fd84f nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.74.2.48 diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-in-properties/nbproject/project.properties --- a/java/alt2xml-in-properties/nbproject/project.properties Sat Jun 07 21:57:50 2014 +0200 +++ b/java/alt2xml-in-properties/nbproject/project.properties Sat Jun 07 22:09:32 2014 +0200 @@ -32,7 +32,7 @@ includes=** jar.compress=false javac.classpath=\ - ${reference.alt2xml-lib.jar} + ${reference.alt2xml-lib-input.jar} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false @@ -59,8 +59,8 @@ meta.inf.dir=${src.dir}/META-INF mkdist.disabled=true platform.active=default_platform -project.alt2xml-lib=../alt2xml-lib -reference.alt2xml-lib.jar=${project.alt2xml-lib}/dist/alt2xml-lib.jar +project.alt2xml-lib-input=../alt2xml-lib-input +reference.alt2xml-lib-input.jar=${project.alt2xml-lib-input}/dist/alt2xml-lib-input.jar run.classpath=\ ${javac.classpath}:\ ${build.classes.dir} diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-in-properties/nbproject/project.xml --- a/java/alt2xml-in-properties/nbproject/project.xml Sat Jun 07 21:57:50 2014 +0200 +++ b/java/alt2xml-in-properties/nbproject/project.xml Sat Jun 07 22:09:32 2014 +0200 @@ -14,7 +14,7 @@ - alt2xml-lib + alt2xml-lib-input jar jar diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib-input/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-lib-input/build.xml Sat Jun 07 22:09:32 2014 +0200 @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project alt2xml-lib-input. + + + diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib-input/dist/alt2xml-lib-input.jar Binary file java/alt2xml-lib-input/dist/alt2xml-lib-input.jar has changed diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib-input/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-lib-input/nbproject/build-impl.xml Sat Jun 07 22:09:32 2014 +0200 @@ -0,0 +1,1413 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 -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 c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib-input/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-lib-input/nbproject/genfiles.properties Sat Jun 07 22:09:32 2014 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=0525abf5 +build.xml.script.CRC32=4245728b +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=0525abf5 +nbproject/build-impl.xml.script.CRC32=9bda5398 +nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.74.2.48 diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib-input/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-lib-input/nbproject/project.properties Sat Jun 07 22:09:32 2014 +0200 @@ -0,0 +1,71 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# 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} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/alt2xml-lib-input.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# 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= +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=true +platform.active=default_platform +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. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib-input/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-lib-input/nbproject/project.xml Sat Jun 07 22:09:32 2014 +0200 @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + alt2xml-lib-input + + + + + + + + + diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib-input/src/cz/frantovo/alt2xml/AbstractAlt2XmlReader.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/AbstractAlt2XmlReader.java Sat Jun 07 22:09:32 2014 +0200 @@ -0,0 +1,116 @@ +/** + * 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.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; + +/** + * Recommended base class for all alternative format readers. + * + * @author Ing. František Kučera (frantovo.cz) + */ +public abstract class AbstractAlt2XmlReader implements XMLReader { + + protected ContentHandler contentHandler; + protected ErrorHandler errorHandler; + protected DTDHandler dtdHandler; + protected EntityResolver entityResolver; + protected Map properties = new HashMap<>(); + + @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 properties.get(name); + } + + @Override + public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { + properties.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 c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib-input/src/cz/frantovo/alt2xml/Alt2XmlReaderFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/Alt2XmlReaderFactory.java Sat Jun 07 22:09:32 2014 +0200 @@ -0,0 +1,35 @@ +/** + * 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 org.xml.sax.XMLReader; + +/** + * + * @author Ing. František Kučera (frantovo.cz) + */ +public interface Alt2XmlReaderFactory { + + /** + * @param systemId system ID of the document to be read + * @return whether this alternative format is supported + */ + public boolean canRead(String systemId); + + public XMLReader getReader(); +} diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib-input/src/cz/frantovo/alt2xml/Alt2XmlRegexReaderFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/Alt2XmlRegexReaderFactory.java Sat Jun 07 22:09:32 2014 +0200 @@ -0,0 +1,36 @@ +/** + * 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.regex.Pattern; + +/** + * Factory for XMLReaders that can read documents with systemId defined by given pattern (typically + * file extension like .ini, .properties etc.) + * + * @author Ing. František Kučera (frantovo.cz) + */ +public abstract class Alt2XmlRegexReaderFactory implements Alt2XmlReaderFactory { + + protected abstract Pattern getSystemIdPattern(); + + @Override + public boolean canRead(String systemId) { + return getSystemIdPattern().matcher(systemId).matches(); + } +} diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib-input/src/cz/frantovo/alt2xml/AltInputSource.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/AltInputSource.java Sat Jun 07 22:09:32 2014 +0200 @@ -0,0 +1,127 @@ +/** + * 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.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +/** + * + * @author Ing. František Kučera (frantovo.cz) + */ +public class AltInputSource extends InputSource { + + private final EntityResolver entityResolver; + private final InputSource originalSource; + + private static final Logger log = Logger.getLogger(AltInputSource.class.getName()); + + public AltInputSource(EntityResolver entityResolver, InputSource originalSource) { + this.entityResolver = entityResolver; + this.originalSource = originalSource; + } + + @Override + public InputStream getByteStream() { + InputStream originalStream = originalSource.getByteStream(); + + if (originalStream == null) { + + InputSource source = originalSource; + + if (entityResolver != null) { + try { + InputSource resolvedSource = entityResolver.resolveEntity(originalSource.getSystemId(), originalSource.getSystemId()); + if (resolvedSource != null) { + source = resolvedSource; + } + } catch (IOException | SAXException e) { + log.log(Level.WARNING, "Error while resolving InputSource – publicId: " + originalSource.getPublicId() + " systemId: " + originalSource.getSystemId(), e); + } + } + + InputStream resolvedStream = source.getByteStream(); + + if (resolvedStream == null) { + + try { + URL url = new URL(source.getSystemId()); + return url.openStream(); + } catch (MalformedURLException e) { + log.log(Level.WARNING, "Invalid SystemId URL syntax: " + originalSource.getSystemId(), e); + return null; + } catch (IOException e) { + log.log(Level.WARNING, "Unable to open stream for systemId: " + originalSource.getSystemId(), e); + return null; + } + } else { + return resolvedStream; + } + + } else { + return originalStream; + } + } + + @Override + public Reader getCharacterStream() { + Reader originalStream = originalSource.getCharacterStream(); + + if (originalStream == null) { + String encoding = getEncoding(); + + if (encoding == null) { + return new InputStreamReader(getByteStream()); + } else { + try { + return new InputStreamReader(getByteStream(), encoding); + } catch (UnsupportedEncodingException e) { + log.log(Level.WARNING, "Invalid encoding: " + encoding, e); + return null; + } + } + } else { + return originalStream; + } + } + + @Override + public String getEncoding() { + return originalSource.getEncoding(); + } + + @Override + public String getPublicId() { + return originalSource.getPublicId(); + } + + @Override + public String getSystemId() { + return originalSource.getSystemId(); + } +} diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib-input/src/cz/frantovo/alt2xml/ParserFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/ParserFactory.java Sat Jun 07 22:09:32 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 Ing. František Kučera (frantovo.cz) + */ +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 c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib-input/src/cz/frantovo/alt2xml/ReaderFinder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/ReaderFinder.java Sat Jun 07 22:09:32 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 c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib-input/src/cz/frantovo/alt2xml/SuperReader.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/SuperReader.java Sat Jun 07 22:09:32 2014 +0200 @@ -0,0 +1,148 @@ +/** + * 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.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +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 Ing. František Kučera (frantovo.cz) + */ +public class SuperReader implements XMLReader { + + private ContentHandler contentHandler; + private ErrorHandler errorHandler; + private DTDHandler dtdHandler; + private EntityResolver entityResolver; + private final Map properties = new HashMap<>(); + private final Map features = new HashMap<>(); + private final ReaderFinder readerFinder; + + public SuperReader(ReaderFinder readerFinder) { + this.readerFinder = readerFinder; + } + + @Override + public void parse(InputSource input) throws IOException, SAXException { + + input = new AltInputSource(entityResolver, input); + + XMLReader reader = readerFinder.findReader(input.getSystemId()); + + reader.setContentHandler(contentHandler); + reader.setDTDHandler(dtdHandler); + reader.setEntityResolver(entityResolver); + reader.setErrorHandler(errorHandler); + + for (Entry e : properties.entrySet()) { + reader.setProperty(e.getKey(), e.getValue()); + } + + for (Entry e : features.entrySet()) { + reader.setFeature(e.getKey(), e.getValue()); + } + + reader.parse(input); + } + + @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. + */ + return features.get(name); + } + + @Override + public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { + /** + * TODO: filtrovat – povolit jen náš jmenný prostor + */ + features.put(name, value); + } + + @Override + public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException { + return properties.get(name); + } + + @Override + public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { + properties.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 c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib/build.xml --- a/java/alt2xml-lib/build.xml Sat Jun 07 21:57:50 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ - - - - - - - - - - - Builds, tests, and runs the project alt2xml-lib. - - - diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib/nbproject/build-impl.xml --- a/java/alt2xml-lib/nbproject/build-impl.xml Sat Jun 07 21:57:50 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1413 +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 -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 c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib/nbproject/genfiles.properties --- a/java/alt2xml-lib/nbproject/genfiles.properties Sat Jun 07 21:57:50 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -build.xml.data.CRC32=cbc99b8c -build.xml.script.CRC32=b9c31994 -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=cbc99b8c -nbproject/build-impl.xml.script.CRC32=a496a745 -nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.74.2.48 diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib/nbproject/project.properties --- a/java/alt2xml-lib/nbproject/project.properties Sat Jun 07 21:57:50 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.processor.options= -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# 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} -# Files in build.classes.dir which should be excluded from distribution jar -dist.archive.excludes= -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/alt2xml-lib.jar -dist.javadoc.dir=${dist.dir}/javadoc -excludes= -includes=** -jar.compress=false -javac.classpath= -# 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= -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=true -platform.active=default_platform -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. -# To set system properties for unit tests define test-sys-prop.name=value: -run.jvmargs= -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -source.encoding=UTF-8 -src.dir=src -test.src.dir=test diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib/nbproject/project.xml --- a/java/alt2xml-lib/nbproject/project.xml Sat Jun 07 21:57:50 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ - - - org.netbeans.modules.java.j2seproject - - - alt2xml-lib - - - - - - - - - diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib/src/cz/frantovo/alt2xml/AbstractAlt2XmlReader.java --- a/java/alt2xml-lib/src/cz/frantovo/alt2xml/AbstractAlt2XmlReader.java Sat Jun 07 21:57:50 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +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 java.io.IOException; -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; - -/** - * Recommended base class for all alternative format readers. - * - * @author Ing. František Kučera (frantovo.cz) - */ -public abstract class AbstractAlt2XmlReader implements XMLReader { - - protected ContentHandler contentHandler; - protected ErrorHandler errorHandler; - protected DTDHandler dtdHandler; - protected EntityResolver entityResolver; - protected Map properties = new HashMap<>(); - - @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 properties.get(name); - } - - @Override - public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { - properties.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 c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib/src/cz/frantovo/alt2xml/Alt2XmlReaderFactory.java --- a/java/alt2xml-lib/src/cz/frantovo/alt2xml/Alt2XmlReaderFactory.java Sat Jun 07 21:57:50 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +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 org.xml.sax.XMLReader; - -/** - * - * @author Ing. František Kučera (frantovo.cz) - */ -public interface Alt2XmlReaderFactory { - - /** - * @param systemId system ID of the document to be read - * @return whether this alternative format is supported - */ - public boolean canRead(String systemId); - - public XMLReader getReader(); -} diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib/src/cz/frantovo/alt2xml/Alt2XmlRegexReaderFactory.java --- a/java/alt2xml-lib/src/cz/frantovo/alt2xml/Alt2XmlRegexReaderFactory.java Sat Jun 07 21:57:50 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +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 java.util.regex.Pattern; - -/** - * Factory for XMLReaders that can read documents with systemId defined by given pattern (typically - * file extension like .ini, .properties etc.) - * - * @author Ing. František Kučera (frantovo.cz) - */ -public abstract class Alt2XmlRegexReaderFactory implements Alt2XmlReaderFactory { - - protected abstract Pattern getSystemIdPattern(); - - @Override - public boolean canRead(String systemId) { - return getSystemIdPattern().matcher(systemId).matches(); - } -} diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib/src/cz/frantovo/alt2xml/AltInputSource.java --- a/java/alt2xml-lib/src/cz/frantovo/alt2xml/AltInputSource.java Sat Jun 07 21:57:50 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,127 +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 java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -/** - * - * @author Ing. František Kučera (frantovo.cz) - */ -public class AltInputSource extends InputSource { - - private final EntityResolver entityResolver; - private final InputSource originalSource; - - private static final Logger log = Logger.getLogger(AltInputSource.class.getName()); - - public AltInputSource(EntityResolver entityResolver, InputSource originalSource) { - this.entityResolver = entityResolver; - this.originalSource = originalSource; - } - - @Override - public InputStream getByteStream() { - InputStream originalStream = originalSource.getByteStream(); - - if (originalStream == null) { - - InputSource source = originalSource; - - if (entityResolver != null) { - try { - InputSource resolvedSource = entityResolver.resolveEntity(originalSource.getSystemId(), originalSource.getSystemId()); - if (resolvedSource != null) { - source = resolvedSource; - } - } catch (IOException | SAXException e) { - log.log(Level.WARNING, "Error while resolving InputSource – publicId: " + originalSource.getPublicId() + " systemId: " + originalSource.getSystemId(), e); - } - } - - InputStream resolvedStream = source.getByteStream(); - - if (resolvedStream == null) { - - try { - URL url = new URL(source.getSystemId()); - return url.openStream(); - } catch (MalformedURLException e) { - log.log(Level.WARNING, "Invalid SystemId URL syntax: " + originalSource.getSystemId(), e); - return null; - } catch (IOException e) { - log.log(Level.WARNING, "Unable to open stream for systemId: " + originalSource.getSystemId(), e); - return null; - } - } else { - return resolvedStream; - } - - } else { - return originalStream; - } - } - - @Override - public Reader getCharacterStream() { - Reader originalStream = originalSource.getCharacterStream(); - - if (originalStream == null) { - String encoding = getEncoding(); - - if (encoding == null) { - return new InputStreamReader(getByteStream()); - } else { - try { - return new InputStreamReader(getByteStream(), encoding); - } catch (UnsupportedEncodingException e) { - log.log(Level.WARNING, "Invalid encoding: " + encoding, e); - return null; - } - } - } else { - return originalStream; - } - } - - @Override - public String getEncoding() { - return originalSource.getEncoding(); - } - - @Override - public String getPublicId() { - return originalSource.getPublicId(); - } - - @Override - public String getSystemId() { - return originalSource.getSystemId(); - } -} diff -r c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib/src/cz/frantovo/alt2xml/ParserFactory.java --- a/java/alt2xml-lib/src/cz/frantovo/alt2xml/ParserFactory.java Sat Jun 07 21:57:50 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,112 +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 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 Ing. František Kučera (frantovo.cz) - */ -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 c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib/src/cz/frantovo/alt2xml/ReaderFinder.java --- a/java/alt2xml-lib/src/cz/frantovo/alt2xml/ReaderFinder.java Sat Jun 07 21:57:50 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 c9f1e497132e -r ecc2731a5a46 java/alt2xml-lib/src/cz/frantovo/alt2xml/SuperReader.java --- a/java/alt2xml-lib/src/cz/frantovo/alt2xml/SuperReader.java Sat Jun 07 21:57:50 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,148 +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 java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -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 Ing. František Kučera (frantovo.cz) - */ -public class SuperReader implements XMLReader { - - private ContentHandler contentHandler; - private ErrorHandler errorHandler; - private DTDHandler dtdHandler; - private EntityResolver entityResolver; - private final Map properties = new HashMap<>(); - private final Map features = new HashMap<>(); - private final ReaderFinder readerFinder; - - public SuperReader(ReaderFinder readerFinder) { - this.readerFinder = readerFinder; - } - - @Override - public void parse(InputSource input) throws IOException, SAXException { - - input = new AltInputSource(entityResolver, input); - - XMLReader reader = readerFinder.findReader(input.getSystemId()); - - reader.setContentHandler(contentHandler); - reader.setDTDHandler(dtdHandler); - reader.setEntityResolver(entityResolver); - reader.setErrorHandler(errorHandler); - - for (Entry e : properties.entrySet()) { - reader.setProperty(e.getKey(), e.getValue()); - } - - for (Entry e : features.entrySet()) { - reader.setFeature(e.getKey(), e.getValue()); - } - - reader.parse(input); - } - - @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. - */ - return features.get(name); - } - - @Override - public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { - /** - * TODO: filtrovat – povolit jen náš jmenný prostor - */ - features.put(name, value); - } - - @Override - public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException { - return properties.get(name); - } - - @Override - public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { - properties.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 c9f1e497132e -r ecc2731a5a46 scripts/alt2xml.sh --- a/scripts/alt2xml.sh Sat Jun 07 21:57:50 2014 +0200 +++ b/scripts/alt2xml.sh Sat Jun 07 22:09:32 2014 +0200 @@ -4,7 +4,7 @@ STANDARD_JARS=( "$DIR/java/alt2xml-cli/dist/alt2xml-cli.jar" - "$DIR/java/alt2xml-lib/dist/alt2xml-lib.jar" + "$DIR/java/alt2xml-lib-input/dist/alt2xml-lib-input.jar" ); PLUGINS=(