# HG changeset patch # User František Kučera # Date 1414509249 -3600 # Node ID 5e22fa13e016e5b153b45405e4793d58d9c37e26 # Parent a7f7b9094cc30b1793a08356b4d5997029425f8f in-fs: basics diff -r a7f7b9094cc3 -r 5e22fa13e016 java/alt2xml-in-fs/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-in-fs/build.xml Tue Oct 28 16:14:09 2014 +0100 @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project alt2xml-in-fs. + + + diff -r a7f7b9094cc3 -r 5e22fa13e016 java/alt2xml-in-fs/config/META-INF/services/cz.frantovo.alt2xml.Alt2XmlReaderFactory --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-in-fs/config/META-INF/services/cz.frantovo.alt2xml.Alt2XmlReaderFactory Tue Oct 28 16:14:09 2014 +0100 @@ -0,0 +1,1 @@ +cz.frantovo.alt2xml.in.fs.ReaderFactory diff -r a7f7b9094cc3 -r 5e22fa13e016 java/alt2xml-in-fs/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-in-fs/nbproject/build-impl.xml Tue Oct 28 16:14:09 2014 +0100 @@ -0,0 +1,1438 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set src.config.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 a7f7b9094cc3 -r 5e22fa13e016 java/alt2xml-in-fs/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-in-fs/nbproject/genfiles.properties Tue Oct 28 16:14:09 2014 +0100 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=f3bd0cda +build.xml.script.CRC32=c648bf07 +build.xml.stylesheet.CRC32=8064a381@1.75.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=f3bd0cda +nbproject/build-impl.xml.script.CRC32=7d9f3106 +nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48 diff -r a7f7b9094cc3 -r 5e22fa13e016 java/alt2xml-in-fs/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-in-fs/nbproject/project.properties Tue Oct 28 16:14:09 2014 +0100 @@ -0,0 +1,77 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=alt2xml-in-fs +application.vendor=fiki +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-in-fs.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath=\ + ${reference.alt2xml-lib-input.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= +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=true +platform.active=default_platform +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} +# 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.config.dir=config +src.dir=src +test.src.dir=test diff -r a7f7b9094cc3 -r 5e22fa13e016 java/alt2xml-in-fs/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-in-fs/nbproject/project.xml Tue Oct 28 16:14:09 2014 +0100 @@ -0,0 +1,26 @@ + + + org.netbeans.modules.java.j2seproject + + + alt2xml-in-fs + + + + + + + + + + + alt2xml-lib-input + jar + + jar + clean + jar + + + + diff -r a7f7b9094cc3 -r 5e22fa13e016 java/alt2xml-in-fs/src/cz/frantovo/alt2xml/in/fs/Reader.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-in-fs/src/cz/frantovo/alt2xml/in/fs/Reader.java Tue Oct 28 16:14:09 2014 +0100 @@ -0,0 +1,107 @@ +/** + * 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.in.fs; + +import cz.frantovo.alt2xml.AbstractAlt2XmlReader; +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.logging.Logger; +import org.xml.sax.Attributes; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +/** + * Reads filesystem – hierarchical structure of directories and files. + * + * @author Ing. František Kučera (frantovo.cz) + */ +public class Reader extends AbstractAlt2XmlReader { + + public static final String ROOT_ELEMENT = "fs"; + public static final String DIR_ELEMENT = "dir"; + public static final String FILE_ELEMENT = "file"; + public static final String ROOT_ATTRIBUTE = "root"; + public static final String NAME_ATTRIBUTE = "name"; + private static final Logger log = Logger.getLogger(Reader.class.getName()); + + @Override + public void parse(InputSource input) throws IOException, SAXException { + File dir = getFile(input.getSystemId()); + + outputStart(dir); + outputDir(dir); + outputEnd(); + } + + private File getFile(String systemId) throws IOException { + try { + return new File(new URI(systemId)); + } catch (URISyntaxException e) { + throw new IOException("Invalid dir URI", e); + } + } + + private Attributes singleAttribute(String name, String value) { + AttributesImpl attributes = new AttributesImpl(); + attributes.addAttribute(null, name, name, "xs:string", value); + return attributes; + } + + private void outputStart(File root) throws SAXException { + contentHandler.startDocument(); + contentHandler.lineBreak(); + contentHandler.startElement(null, null, ROOT_ELEMENT, singleAttribute(ROOT_ATTRIBUTE, root.getAbsolutePath())); + contentHandler.lineBreak(); + } + + private void outputEnd() throws SAXException { + contentHandler.endElement(null, null, ROOT_ELEMENT); + contentHandler.lineBreak(); + contentHandler.endDocument(); + } + + private void outputFile(File file) throws SAXException { + contentHandler.startElement(null, null, FILE_ELEMENT, singleAttribute(NAME_ATTRIBUTE, file.getName())); + contentHandler.lineBreak(); + + //contentHandler.characters(file.getName()); + + contentHandler.endElement(null, null, FILE_ELEMENT); + contentHandler.lineBreak(); + } + + private void outputDir(File dir) throws SAXException { + + contentHandler.startElement(null, null, DIR_ELEMENT, singleAttribute(NAME_ATTRIBUTE, dir.getName())); + contentHandler.lineBreak(); + + for (File file : dir.listFiles()) { + if (file.isDirectory()) { + outputDir(file); + } else { + outputFile(file); + } + } + + contentHandler.endElement(null, null, DIR_ELEMENT); + contentHandler.lineBreak(); + } +} diff -r a7f7b9094cc3 -r 5e22fa13e016 java/alt2xml-in-fs/src/cz/frantovo/alt2xml/in/fs/ReaderFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-in-fs/src/cz/frantovo/alt2xml/in/fs/ReaderFactory.java Tue Oct 28 16:14:09 2014 +0100 @@ -0,0 +1,41 @@ +/** + * 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.in.fs; + +import cz.frantovo.alt2xml.Alt2XmlRegexReaderFactory; +import java.util.regex.Pattern; +import org.xml.sax.XMLReader; + +/** + * + * @author Ing. František Kučera (frantovo.cz) + */ +public class ReaderFactory extends Alt2XmlRegexReaderFactory { + + private static final Pattern pattern = Pattern.compile("^file:.*/$"); + + @Override + protected Pattern getSystemIdPattern() { + return pattern; + } + + @Override + public XMLReader getReader() { + return new Reader(); + } +} diff -r a7f7b9094cc3 -r 5e22fa13e016 scripts/alt2xml.sh --- a/scripts/alt2xml.sh Tue Oct 28 00:33:17 2014 +0100 +++ b/scripts/alt2xml.sh Tue Oct 28 16:14:09 2014 +0100 @@ -11,6 +11,7 @@ INPUT_PLUGINS=( "$DIR/java/alt2xml-in-properties/dist/alt2xml-in-properties.jar" "$DIR/java/alt2xml-in-ini/dist/alt2xml-in-ini.jar" + "$DIR/java/alt2xml-in-fs/dist/alt2xml-in-fs.jar" "$DIR/java/alt2xml-in-json/dist/alt2xml-in-json.jar" "$DIR/../temp/lib/json_simple-1.1.jar"