# HG changeset patch # User František Kučera # Date 1402233061 -7200 # Node ID 4afb00b7b1a9cdca2a1a834ab048a0d9c6242e75 # Parent a5020340362b5445a6df40e9e090140dd86e73a6 move EchoContentHandler to alt2xml-lib-output diff -r a5020340362b -r 4afb00b7b1a9 java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java --- a/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java Sun Jun 08 15:00:19 2014 +0200 +++ b/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java Sun Jun 08 15:11:01 2014 +0200 @@ -17,6 +17,7 @@ */ package cz.frantovo.alt2xml.cli; +import cz.frantovo.alt2xml.out.EchoContentHandler; import java.io.File; import java.io.OutputStream; import java.util.Arrays; diff -r a5020340362b -r 4afb00b7b1a9 java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/EchoContentHandler.java --- a/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/EchoContentHandler.java Sun Jun 08 15:00:19 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.cli; - -import java.util.logging.Logger; -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 Ing. František Kučera (frantovo.cz) - */ -public class EchoContentHandler extends DefaultHandler { - - private static final Logger log = Logger.getLogger(EchoContentHandler.class.getName()); - 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); - } - } - - /** - * LexicalHandler methods - * - * @Override - * public void startDTD(String name, String publicId, String systemId) throws SAXException { - * log.log(Level.WARNING, "Start of DTD: {0} | {1} | {2}", new Object[]{name, publicId, - * systemId}); - * } - * - * @Override - * public void endDTD() throws SAXException { - * log.log(Level.WARNING, "End of DTD"); - * } - * - * @Override - * public void startEntity(String name) throws SAXException { - * log.log(Level.WARNING, "Start of Entity: {0}", name); - * } - * - * @Override - * public void endEntity(String name) throws SAXException { - * log.log(Level.WARNING, "End of Entity: {0}", name); - * } - * - * @Override - * public void startCDATA() throws SAXException { - * log.log(Level.WARNING, "Start of CDATA"); - * } - * - * @Override - * public void endCDATA() throws SAXException { - * log.log(Level.WARNING, "End of CDATA"); - * } - * - * @Override - * public void comment(char[] ch, int start, int length) throws SAXException { - * try { - * w.writeComment(new String(ch, start, length)); - * w.flush(); - * } catch (XMLStreamException e) { - * throw new SAXException(e); - * } - * } - */ -} diff -r a5020340362b -r 4afb00b7b1a9 java/alt2xml-lib-output/src/cz/frantovo/alt2xml/out/EchoContentHandler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-lib-output/src/cz/frantovo/alt2xml/out/EchoContentHandler.java Sun Jun 08 15:11:01 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.out; + +import java.util.logging.Logger; +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 Ing. František Kučera (frantovo.cz) + */ +public class EchoContentHandler extends DefaultHandler { + + private static final Logger log = Logger.getLogger(EchoContentHandler.class.getName()); + 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); + } + } + + /** + * LexicalHandler methods + * + * @Override + * public void startDTD(String name, String publicId, String systemId) throws SAXException { + * log.log(Level.WARNING, "Start of DTD: {0} | {1} | {2}", new Object[]{name, publicId, + * systemId}); + * } + * + * @Override + * public void endDTD() throws SAXException { + * log.log(Level.WARNING, "End of DTD"); + * } + * + * @Override + * public void startEntity(String name) throws SAXException { + * log.log(Level.WARNING, "Start of Entity: {0}", name); + * } + * + * @Override + * public void endEntity(String name) throws SAXException { + * log.log(Level.WARNING, "End of Entity: {0}", name); + * } + * + * @Override + * public void startCDATA() throws SAXException { + * log.log(Level.WARNING, "Start of CDATA"); + * } + * + * @Override + * public void endCDATA() throws SAXException { + * log.log(Level.WARNING, "End of CDATA"); + * } + * + * @Override + * public void comment(char[] ch, int start, int length) throws SAXException { + * try { + * w.writeComment(new String(ch, start, length)); + * w.flush(); + * } catch (XMLStreamException e) { + * throw new SAXException(e); + * } + * } + */ +} diff -r a5020340362b -r 4afb00b7b1a9 scripts/alt2xml.sh --- a/scripts/alt2xml.sh Sun Jun 08 15:00:19 2014 +0200 +++ b/scripts/alt2xml.sh Sun Jun 08 15:11:01 2014 +0200 @@ -5,6 +5,7 @@ STANDARD_JARS=( "$DIR/java/alt2xml-cli/dist/alt2xml-cli.jar" "$DIR/java/alt2xml-lib-input/dist/alt2xml-lib-input.jar" + "$DIR/java/alt2xml-lib-output/dist/alt2xml-lib-output.jar" ); PLUGINS=(