# HG changeset patch # User František Kučera # Date 1401955654 -7200 # Node ID 9107f7df660cf9c66be95068783e3aa2f1ee7615 # Parent 5cfb685d8eec4bc3f0e6d5b44ff463ba86ce9a2e přejmenování alt2xml → alt2xml-bin diff -r 5cfb685d8eec -r 9107f7df660c java/alt2xml-bin/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-bin/build.xml Thu Jun 05 10:07:34 2014 +0200 @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project alt2xml-bin. + + + diff -r 5cfb685d8eec -r 9107f7df660c java/alt2xml-bin/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-bin/manifest.mf Thu Jun 05 10:07:34 2014 +0200 @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff -r 5cfb685d8eec -r 9107f7df660c java/alt2xml-bin/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-bin/nbproject/build-impl.xml Thu Jun 05 10:07:34 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 5cfb685d8eec -r 9107f7df660c java/alt2xml-bin/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-bin/nbproject/genfiles.properties Thu Jun 05 10:07:34 2014 +0200 @@ -0,0 +1,11 @@ +build.xml.data.CRC32=e6d87916 +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=e6d87916 +nbproject/groovy-build.xml.script.CRC32=66297360 +nbproject/groovy-build.xml.stylesheet.CRC32=28d0e1f2@1.7.1 diff -r 5cfb685d8eec -r 9107f7df660c java/alt2xml-bin/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-bin/nbproject/project.properties Thu Jun 05 10:07:34 2014 +0200 @@ -0,0 +1,75 @@ +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=\ + ${libs.json-simple.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= +main.class=cz.frantovo.alt2xml.CLI +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +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 +# 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 5cfb685d8eec -r 9107f7df660c java/alt2xml-bin/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-bin/nbproject/project.xml Thu Jun 05 10:07:34 2014 +0200 @@ -0,0 +1,21 @@ + + + org.netbeans.modules.java.j2seproject + + + + + + + + alt2xml-bin + + + + + + + + + + diff -r 5cfb685d8eec -r 9107f7df660c java/alt2xml-bin/src/cz/frantovo/alt2xml/CLI.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-bin/src/cz/frantovo/alt2xml/CLI.java Thu Jun 05 10:07:34 2014 +0200 @@ -0,0 +1,42 @@ +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 5cfb685d8eec -r 9107f7df660c java/alt2xml-bin/src/cz/frantovo/alt2xml/SAXTovarna.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-bin/src/cz/frantovo/alt2xml/SAXTovarna.java Thu Jun 05 10:07:34 2014 +0200 @@ -0,0 +1,72 @@ +package cz.frantovo.alt2xml; + +import cz.frantovo.alt2xml.vstup.SuperReader; +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 { + + @Override + public SAXParser newSAXParser() throws ParserConfigurationException, SAXException { + return new MůjParser(new SuperReader()); + } + + @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 MůjParser extends SAXParser { + + private XMLReader xmlReader; + + public MůjParser(XMLReader xmlReader) { + this.xmlReader = xmlReader; + } + + @Override + public Parser getParser() throws SAXException { + throw new SAXException("Není podporováno."); + } + + @Override + public XMLReader getXMLReader() throws SAXException { + return xmlReader; + } + + @Override + public boolean isNamespaceAware() { + return false; + } + + @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); + } + } +} \ No newline at end of file diff -r 5cfb685d8eec -r 9107f7df660c java/alt2xml-bin/src/cz/frantovo/alt2xml/vstup/JsonSimpleContentHandler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-bin/src/cz/frantovo/alt2xml/vstup/JsonSimpleContentHandler.java Thu Jun 05 10:07:34 2014 +0200 @@ -0,0 +1,135 @@ +package cz.frantovo.alt2xml.vstup; + +import java.io.IOException; +import java.util.Stack; +import org.json.simple.parser.ParseException; +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; + +/** + * + * @author fiki + */ +public class JsonSimpleContentHandler implements org.json.simple.parser.ContentHandler { + + /** Sem vypisujeme XML události */ + private ContentHandler saxVýstup; + /** Musíme si pamatovat polohu v XML stromu, abychom věděli, kterou značku kdy uzavřít */ + private Stack poloha = new Stack<>(); + /** + * Po textových uzlech vkládáme konce elementů rovnou, + * ale pokud jeden element končí hned po jiném, + * vložíme mezi ně ještě konec řádku a odsazení. + */ + private boolean zalomitŘádek = false; + + public JsonSimpleContentHandler(ContentHandler saxVýstup) { + this.saxVýstup = saxVýstup; + } + + private void začniElement(String název) throws IOException { + try { + vložOdsazení(); + saxVýstup.startElement(null, null, název, null); + poloha.push(název); + } catch (SAXException e) { + throw new IOException("Chyba při začátku elementu.", e); + } + } + + private void ukončiElement() throws IOException { + try { + String značka = poloha.pop(); + if (zalomitŘádek) { + vložOdsazení(); + } + zalomitŘádek = true; + saxVýstup.endElement(null, null, značka); + } catch (SAXException e) { + throw new IOException("Chyba při ukončování elementu.", e); + } + } + + private void vložOdsazení() throws IOException { + /** + * TODO: ignorableWhitespace() ? + */ + vložText("\n"); + for (int i = 0; i < poloha.size(); i++) { + vložText("\t"); + } + } + + private void vložText(String text) throws IOException { + try { + saxVýstup.characters(text.toCharArray(), 0, text.length()); + } catch (SAXException e) { + throw new IOException("Chyba při vkládání textu.", e); + } + } + + @Override + public void startJSON() throws ParseException, IOException { + try { + saxVýstup.startDocument(); + začniElement("objekt"); + } catch (SAXException e) { + throw new IOException("Chyba při začátku dokumentu.", e); + } + } + + @Override + public void endJSON() throws ParseException, IOException { + try { + ukončiElement(); + vložText("\n"); + saxVýstup.endDocument(); + } catch (SAXException e) { + throw new IOException(e); + } + } + + @Override + public boolean startObject() throws ParseException, IOException { + // System.err.println("startObject"); + return true; + } + + @Override + public boolean endObject() throws ParseException, IOException { + // System.err.println("endObject"); + return true; + } + + @Override + public boolean startObjectEntry(String key) throws ParseException, IOException { + začniElement(key); + return true; + } + + @Override + public boolean endObjectEntry() throws ParseException, IOException { + ukončiElement(); + // System.err.println("endObjectEntry"); + return true; + } + + @Override + public boolean startArray() throws ParseException, IOException { + // System.err.println("startArray"); + return true; + } + + @Override + public boolean endArray() throws ParseException, IOException { + // System.err.println("endArray"); + return true; + } + + @Override + public boolean primitive(Object value) throws ParseException, IOException { + vložText(String.valueOf(value)); + zalomitŘádek = false; + return true; + } +} diff -r 5cfb685d8eec -r 9107f7df660c java/alt2xml-bin/src/cz/frantovo/alt2xml/vstup/SuperReader.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-bin/src/cz/frantovo/alt2xml/vstup/SuperReader.java Thu Jun 05 10:07:34 2014 +0200 @@ -0,0 +1,117 @@ +package cz.frantovo.alt2xml.vstup; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import org.xml.sax.ContentHandler; +import org.xml.sax.DTDHandler; +import org.xml.sax.EntityResolver; +import org.xml.sax.ErrorHandler; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; +import org.xml.sax.XMLReader; + +/** + * + * @author fiki + */ +public class SuperReader implements XMLReader { + + private ContentHandler contentHandler; + private ErrorHandler errorHandler; + private DTDHandler dtdHandler; + private EntityResolver entityResolver; + private Map konfigurace = new HashMap<>(); + + @Override + public void parse(InputSource input) throws IOException, SAXException { + /** + * TODO: rozpornat formát vstupu a podle toho delegovat + */ + JSONParser p = new JSONParser(); + InputStreamReader vstup = new InputStreamReader(input.getByteStream()); + JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler); + + try { + p.parse(vstup, handler); + } catch (ParseException e) { + throw new SAXException("Chyba při načítání JSONu", e); + } + } + + @Override + public void parse(String systemId) throws IOException, SAXException { + parse(new InputSource(systemId)); + } + + @Override + public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { + /** + * TODO: + * All XMLReaders are required to recognize + * the http://xml.org/sax/features/namespaces + * and the http://xml.org/sax/features/namespace-prefixes feature names. + */ + throw new SAXNotSupportedException("Zatím není podporováno."); + } + + @Override + public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { + throw new SAXNotSupportedException("Zatím není podporováno."); + } + + @Override + public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException { + return konfigurace.get(name); + } + + @Override + public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { + konfigurace.put(name, value); + } + + @Override + public void setEntityResolver(EntityResolver entityResolver) { + this.entityResolver = entityResolver; + } + + @Override + public EntityResolver getEntityResolver() { + return entityResolver; + } + + @Override + public void setDTDHandler(DTDHandler dtdHandler) { + this.dtdHandler = dtdHandler; + } + + @Override + public DTDHandler getDTDHandler() { + return dtdHandler; + } + + @Override + public void setContentHandler(ContentHandler contentHandler) { + this.contentHandler = contentHandler; + } + + @Override + public ContentHandler getContentHandler() { + return contentHandler; + } + + @Override + public void setErrorHandler(ErrorHandler errorHandler) { + this.errorHandler = errorHandler; + } + + @Override + public ErrorHandler getErrorHandler() { + return errorHandler; + } +} diff -r 5cfb685d8eec -r 9107f7df660c java/alt2xml-bin/src/cz/frantovo/alt2xml/výstup/EchoContentHandler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-bin/src/cz/frantovo/alt2xml/výstup/EchoContentHandler.java Thu Jun 05 10:07:34 2014 +0200 @@ -0,0 +1,83 @@ +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 5cfb685d8eec -r 9107f7df660c java/alt2xml/manifest.mf --- a/java/alt2xml/manifest.mf Tue Jan 03 14:47:22 2012 +0100 +++ /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 5cfb685d8eec -r 9107f7df660c java/alt2xml/nbproject/build-impl.xml --- a/java/alt2xml/nbproject/build-impl.xml Tue Jan 03 14:47:22 2012 +0100 +++ /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 5cfb685d8eec -r 9107f7df660c java/alt2xml/nbproject/genfiles.properties --- a/java/alt2xml/nbproject/genfiles.properties Tue Jan 03 14:47:22 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -build.xml.data.CRC32=ec5db5e3 -build.xml.script.CRC32=bb4dbef7 -build.xml.stylesheet.CRC32=28e38971@1.44.1.45 -# 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=ec5db5e3 -nbproject/build-impl.xml.script.CRC32=9cc781c1 -nbproject/build-impl.xml.stylesheet.CRC32=0ae3a408@1.44.1.45 diff -r 5cfb685d8eec -r 9107f7df660c java/alt2xml/nbproject/project.properties --- a/java/alt2xml/nbproject/project.properties Tue Jan 03 14:47:22 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -application.title=alt2xml -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} -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/alt2xml.jar -dist.javadoc.dir=${dist.dir}/javadoc -endorsed.classpath= -excludes= -includes=** -jar.compress=false -javac.classpath=\ - ${libs.json-simple.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= -main.class=cz.frantovo.alt2xml.CLI -manifest.file=manifest.mf -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=false -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 -# 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 diff -r 5cfb685d8eec -r 9107f7df660c java/alt2xml/nbproject/project.xml --- a/java/alt2xml/nbproject/project.xml Tue Jan 03 14:47:22 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ - - - org.netbeans.modules.java.j2seproject - - - alt2xml - - - - - - - - - diff -r 5cfb685d8eec -r 9107f7df660c java/alt2xml/src/cz/frantovo/alt2xml/CLI.java --- a/java/alt2xml/src/cz/frantovo/alt2xml/CLI.java Tue Jan 03 14:47:22 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -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 5cfb685d8eec -r 9107f7df660c java/alt2xml/src/cz/frantovo/alt2xml/SAXTovarna.java --- a/java/alt2xml/src/cz/frantovo/alt2xml/SAXTovarna.java Tue Jan 03 14:47:22 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -package cz.frantovo.alt2xml; - -import cz.frantovo.alt2xml.vstup.SuperReader; -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 { - - @Override - public SAXParser newSAXParser() throws ParserConfigurationException, SAXException { - return new MůjParser(new SuperReader()); - } - - @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 MůjParser extends SAXParser { - - private XMLReader xmlReader; - - public MůjParser(XMLReader xmlReader) { - this.xmlReader = xmlReader; - } - - @Override - public Parser getParser() throws SAXException { - throw new SAXException("Není podporováno."); - } - - @Override - public XMLReader getXMLReader() throws SAXException { - return xmlReader; - } - - @Override - public boolean isNamespaceAware() { - return false; - } - - @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); - } - } -} \ No newline at end of file diff -r 5cfb685d8eec -r 9107f7df660c java/alt2xml/src/cz/frantovo/alt2xml/vstup/JsonSimpleContentHandler.java --- a/java/alt2xml/src/cz/frantovo/alt2xml/vstup/JsonSimpleContentHandler.java Tue Jan 03 14:47:22 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,135 +0,0 @@ -package cz.frantovo.alt2xml.vstup; - -import java.io.IOException; -import java.util.Stack; -import org.json.simple.parser.ParseException; -import org.xml.sax.ContentHandler; -import org.xml.sax.SAXException; - -/** - * - * @author fiki - */ -public class JsonSimpleContentHandler implements org.json.simple.parser.ContentHandler { - - /** Sem vypisujeme XML události */ - private ContentHandler saxVýstup; - /** Musíme si pamatovat polohu v XML stromu, abychom věděli, kterou značku kdy uzavřít */ - private Stack poloha = new Stack<>(); - /** - * Po textových uzlech vkládáme konce elementů rovnou, - * ale pokud jeden element končí hned po jiném, - * vložíme mezi ně ještě konec řádku a odsazení. - */ - private boolean zalomitŘádek = false; - - public JsonSimpleContentHandler(ContentHandler saxVýstup) { - this.saxVýstup = saxVýstup; - } - - private void začniElement(String název) throws IOException { - try { - vložOdsazení(); - saxVýstup.startElement(null, null, název, null); - poloha.push(název); - } catch (SAXException e) { - throw new IOException("Chyba při začátku elementu.", e); - } - } - - private void ukončiElement() throws IOException { - try { - String značka = poloha.pop(); - if (zalomitŘádek) { - vložOdsazení(); - } - zalomitŘádek = true; - saxVýstup.endElement(null, null, značka); - } catch (SAXException e) { - throw new IOException("Chyba při ukončování elementu.", e); - } - } - - private void vložOdsazení() throws IOException { - /** - * TODO: ignorableWhitespace() ? - */ - vložText("\n"); - for (int i = 0; i < poloha.size(); i++) { - vložText("\t"); - } - } - - private void vložText(String text) throws IOException { - try { - saxVýstup.characters(text.toCharArray(), 0, text.length()); - } catch (SAXException e) { - throw new IOException("Chyba při vkládání textu.", e); - } - } - - @Override - public void startJSON() throws ParseException, IOException { - try { - saxVýstup.startDocument(); - začniElement("objekt"); - } catch (SAXException e) { - throw new IOException("Chyba při začátku dokumentu.", e); - } - } - - @Override - public void endJSON() throws ParseException, IOException { - try { - ukončiElement(); - vložText("\n"); - saxVýstup.endDocument(); - } catch (SAXException e) { - throw new IOException(e); - } - } - - @Override - public boolean startObject() throws ParseException, IOException { - // System.err.println("startObject"); - return true; - } - - @Override - public boolean endObject() throws ParseException, IOException { - // System.err.println("endObject"); - return true; - } - - @Override - public boolean startObjectEntry(String key) throws ParseException, IOException { - začniElement(key); - return true; - } - - @Override - public boolean endObjectEntry() throws ParseException, IOException { - ukončiElement(); - // System.err.println("endObjectEntry"); - return true; - } - - @Override - public boolean startArray() throws ParseException, IOException { - // System.err.println("startArray"); - return true; - } - - @Override - public boolean endArray() throws ParseException, IOException { - // System.err.println("endArray"); - return true; - } - - @Override - public boolean primitive(Object value) throws ParseException, IOException { - vložText(String.valueOf(value)); - zalomitŘádek = false; - return true; - } -} diff -r 5cfb685d8eec -r 9107f7df660c java/alt2xml/src/cz/frantovo/alt2xml/vstup/SuperReader.java --- a/java/alt2xml/src/cz/frantovo/alt2xml/vstup/SuperReader.java Tue Jan 03 14:47:22 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,111 +0,0 @@ -package cz.frantovo.alt2xml.vstup; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.HashMap; -import java.util.Map; -import org.json.simple.parser.JSONParser; -import org.json.simple.parser.ParseException; -import org.xml.sax.ContentHandler; -import org.xml.sax.DTDHandler; -import org.xml.sax.EntityResolver; -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.SAXNotSupportedException; -import org.xml.sax.XMLReader; - -/** - * - * @author fiki - */ -public class SuperReader implements XMLReader { - - private ContentHandler contentHandler; - private ErrorHandler errorHandler; - private DTDHandler dtdHandler; - private EntityResolver entityResolver; - private Map konfigurace = new HashMap<>(); - - @Override - public void parse(InputSource input) throws IOException, SAXException { - /** - * TODO: rozpornat formát vstupu a podle toho delegovat - */ - JSONParser p = new JSONParser(); - InputStreamReader vstup = new InputStreamReader(input.getByteStream()); - JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler); - - try { - p.parse(vstup, handler); - } catch (ParseException e) { - throw new SAXException("Chyba při načítání JSONu", e); - } - } - - @Override - public void parse(String systemId) throws IOException, SAXException { - parse(new InputSource(systemId)); - } - - @Override - public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { - 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 5cfb685d8eec -r 9107f7df660c java/alt2xml/src/cz/frantovo/alt2xml/výstup/EchoContentHandler.java --- a/java/alt2xml/src/cz/frantovo/alt2xml/výstup/EchoContentHandler.java Tue Jan 03 14:47:22 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -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); - } - } -}