move EchoContentHandler to alt2xml-lib-output
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 08 Jun 2014 15:11:01 +0200
changeset 404afb00b7b1a9
parent 39 a5020340362b
child 41 efc293b2082c
move EchoContentHandler to alt2xml-lib-output
java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java
java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/EchoContentHandler.java
java/alt2xml-lib-output/src/cz/frantovo/alt2xml/out/EchoContentHandler.java
scripts/alt2xml.sh
     1.1 --- a/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java	Sun Jun 08 15:00:19 2014 +0200
     1.2 +++ b/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java	Sun Jun 08 15:11:01 2014 +0200
     1.3 @@ -17,6 +17,7 @@
     1.4   */
     1.5  package cz.frantovo.alt2xml.cli;
     1.6  
     1.7 +import cz.frantovo.alt2xml.out.EchoContentHandler;
     1.8  import java.io.File;
     1.9  import java.io.OutputStream;
    1.10  import java.util.Arrays;
     2.1 --- a/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/EchoContentHandler.java	Sun Jun 08 15:00:19 2014 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,148 +0,0 @@
     2.4 -/**
     2.5 - * Alt2XML
     2.6 - * Copyright © 2014 František Kučera (frantovo.cz)
     2.7 - *
     2.8 - * This program is free software: you can redistribute it and/or modify
     2.9 - * it under the terms of the GNU General Public License as published by
    2.10 - * the Free Software Foundation, either version 3 of the License, or
    2.11 - * (at your option) any later version.
    2.12 - *
    2.13 - * This program is distributed in the hope that it will be useful,
    2.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    2.16 - * GNU General Public License for more details.
    2.17 - *
    2.18 - * You should have received a copy of the GNU General Public License
    2.19 - * along with this program. If not, see <http://www.gnu.org/licenses/>.
    2.20 - */
    2.21 -package cz.frantovo.alt2xml.cli;
    2.22 -
    2.23 -import java.util.logging.Logger;
    2.24 -import javax.xml.stream.XMLStreamException;
    2.25 -import javax.xml.stream.XMLStreamWriter;
    2.26 -import org.xml.sax.Attributes;
    2.27 -import org.xml.sax.SAXException;
    2.28 -import org.xml.sax.helpers.DefaultHandler;
    2.29 -
    2.30 -/**
    2.31 - * Slouží k převodu právě parsovaného XML zpět na XML.
    2.32 - * Určen pro testování a ladění a pro použití s neobvyklými „XML“ parsery,
    2.33 - * které nečtou XML ale jiný jazyk (např. JSON, INI atd.), ale používají stejné rozhraní (SAX).
    2.34 - *
    2.35 - * TODO: další typy uzlů a jmenné prostory.
    2.36 - *
    2.37 - * @author Ing. František Kučera (frantovo.cz)
    2.38 - */
    2.39 -public class EchoContentHandler extends DefaultHandler {
    2.40 -
    2.41 -	private static final Logger log = Logger.getLogger(EchoContentHandler.class.getName());
    2.42 -	private XMLStreamWriter w;
    2.43 -
    2.44 -	/**
    2.45 -	 * @param writer kam se bude vypisovat XML.
    2.46 -	 */
    2.47 -	public EchoContentHandler(XMLStreamWriter writer) {
    2.48 -		w = writer;
    2.49 -	}
    2.50 -
    2.51 -	@Override
    2.52 -	public void startDocument() throws SAXException {
    2.53 -		try {
    2.54 -			w.writeStartDocument();
    2.55 -		} catch (XMLStreamException e) {
    2.56 -			throw new SAXException(e);
    2.57 -		}
    2.58 -	}
    2.59 -
    2.60 -	@Override
    2.61 -	public void endDocument() throws SAXException {
    2.62 -		try {
    2.63 -			w.writeEndDocument();
    2.64 -			w.close();
    2.65 -		} catch (XMLStreamException e) {
    2.66 -			throw new SAXException(e);
    2.67 -		}
    2.68 -	}
    2.69 -
    2.70 -	@Override
    2.71 -	public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    2.72 -		try {
    2.73 -			w.writeStartElement(qName);
    2.74 -
    2.75 -			if (attributes != null) {
    2.76 -				for (int i = 0; i < attributes.getLength(); i++) {
    2.77 -					w.writeAttribute(attributes.getQName(i), attributes.getValue(i));
    2.78 -				}
    2.79 -			}
    2.80 -
    2.81 -			w.flush();
    2.82 -		} catch (XMLStreamException e) {
    2.83 -			throw new SAXException(e);
    2.84 -		}
    2.85 -	}
    2.86 -
    2.87 -	@Override
    2.88 -	public void endElement(String uri, String localName, String qName) throws SAXException {
    2.89 -		try {
    2.90 -			w.writeEndElement();
    2.91 -			w.flush();
    2.92 -		} catch (XMLStreamException e) {
    2.93 -			throw new SAXException(e);
    2.94 -		}
    2.95 -	}
    2.96 -
    2.97 -	@Override
    2.98 -	public void characters(char[] ch, int start, int length) throws SAXException {
    2.99 -		try {
   2.100 -			w.writeCharacters(ch, start, length);
   2.101 -			w.flush();
   2.102 -		} catch (XMLStreamException e) {
   2.103 -			throw new SAXException(e);
   2.104 -		}
   2.105 -	}
   2.106 -
   2.107 -	/**
   2.108 -	 * LexicalHandler methods
   2.109 -	 *
   2.110 -	 * @Override
   2.111 -	 * public void startDTD(String name, String publicId, String systemId) throws SAXException {
   2.112 -	 * log.log(Level.WARNING, "Start of DTD: {0} | {1} | {2}", new Object[]{name, publicId,
   2.113 -	 * systemId});
   2.114 -	 * }
   2.115 -	 *
   2.116 -	 * @Override
   2.117 -	 * public void endDTD() throws SAXException {
   2.118 -	 * log.log(Level.WARNING, "End of DTD");
   2.119 -	 * }
   2.120 -	 *
   2.121 -	 * @Override
   2.122 -	 * public void startEntity(String name) throws SAXException {
   2.123 -	 * log.log(Level.WARNING, "Start of Entity: {0}", name);
   2.124 -	 * }
   2.125 -	 *
   2.126 -	 * @Override
   2.127 -	 * public void endEntity(String name) throws SAXException {
   2.128 -	 * log.log(Level.WARNING, "End of Entity: {0}", name);
   2.129 -	 * }
   2.130 -	 *
   2.131 -	 * @Override
   2.132 -	 * public void startCDATA() throws SAXException {
   2.133 -	 * log.log(Level.WARNING, "Start of CDATA");
   2.134 -	 * }
   2.135 -	 *
   2.136 -	 * @Override
   2.137 -	 * public void endCDATA() throws SAXException {
   2.138 -	 * log.log(Level.WARNING, "End of CDATA");
   2.139 -	 * }
   2.140 -	 *
   2.141 -	 * @Override
   2.142 -	 * public void comment(char[] ch, int start, int length) throws SAXException {
   2.143 -	 * try {
   2.144 -	 * w.writeComment(new String(ch, start, length));
   2.145 -	 * w.flush();
   2.146 -	 * } catch (XMLStreamException e) {
   2.147 -	 * throw new SAXException(e);
   2.148 -	 * }
   2.149 -	 * }
   2.150 -	 */
   2.151 -}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/java/alt2xml-lib-output/src/cz/frantovo/alt2xml/out/EchoContentHandler.java	Sun Jun 08 15:11:01 2014 +0200
     3.3 @@ -0,0 +1,148 @@
     3.4 +/**
     3.5 + * Alt2XML
     3.6 + * Copyright © 2014 František Kučera (frantovo.cz)
     3.7 + *
     3.8 + * This program is free software: you can redistribute it and/or modify
     3.9 + * it under the terms of the GNU General Public License as published by
    3.10 + * the Free Software Foundation, either version 3 of the License, or
    3.11 + * (at your option) any later version.
    3.12 + *
    3.13 + * This program is distributed in the hope that it will be useful,
    3.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    3.16 + * GNU General Public License for more details.
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License
    3.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    3.20 + */
    3.21 +package cz.frantovo.alt2xml.out;
    3.22 +
    3.23 +import java.util.logging.Logger;
    3.24 +import javax.xml.stream.XMLStreamException;
    3.25 +import javax.xml.stream.XMLStreamWriter;
    3.26 +import org.xml.sax.Attributes;
    3.27 +import org.xml.sax.SAXException;
    3.28 +import org.xml.sax.helpers.DefaultHandler;
    3.29 +
    3.30 +/**
    3.31 + * Slouží k převodu právě parsovaného XML zpět na XML.
    3.32 + * Určen pro testování a ladění a pro použití s neobvyklými „XML“ parsery,
    3.33 + * které nečtou XML ale jiný jazyk (např. JSON, INI atd.), ale používají stejné rozhraní (SAX).
    3.34 + *
    3.35 + * TODO: další typy uzlů a jmenné prostory.
    3.36 + *
    3.37 + * @author Ing. František Kučera (frantovo.cz)
    3.38 + */
    3.39 +public class EchoContentHandler extends DefaultHandler {
    3.40 +
    3.41 +	private static final Logger log = Logger.getLogger(EchoContentHandler.class.getName());
    3.42 +	private XMLStreamWriter w;
    3.43 +
    3.44 +	/**
    3.45 +	 * @param writer kam se bude vypisovat XML.
    3.46 +	 */
    3.47 +	public EchoContentHandler(XMLStreamWriter writer) {
    3.48 +		w = writer;
    3.49 +	}
    3.50 +
    3.51 +	@Override
    3.52 +	public void startDocument() throws SAXException {
    3.53 +		try {
    3.54 +			w.writeStartDocument();
    3.55 +		} catch (XMLStreamException e) {
    3.56 +			throw new SAXException(e);
    3.57 +		}
    3.58 +	}
    3.59 +
    3.60 +	@Override
    3.61 +	public void endDocument() throws SAXException {
    3.62 +		try {
    3.63 +			w.writeEndDocument();
    3.64 +			w.close();
    3.65 +		} catch (XMLStreamException e) {
    3.66 +			throw new SAXException(e);
    3.67 +		}
    3.68 +	}
    3.69 +
    3.70 +	@Override
    3.71 +	public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    3.72 +		try {
    3.73 +			w.writeStartElement(qName);
    3.74 +
    3.75 +			if (attributes != null) {
    3.76 +				for (int i = 0; i < attributes.getLength(); i++) {
    3.77 +					w.writeAttribute(attributes.getQName(i), attributes.getValue(i));
    3.78 +				}
    3.79 +			}
    3.80 +
    3.81 +			w.flush();
    3.82 +		} catch (XMLStreamException e) {
    3.83 +			throw new SAXException(e);
    3.84 +		}
    3.85 +	}
    3.86 +
    3.87 +	@Override
    3.88 +	public void endElement(String uri, String localName, String qName) throws SAXException {
    3.89 +		try {
    3.90 +			w.writeEndElement();
    3.91 +			w.flush();
    3.92 +		} catch (XMLStreamException e) {
    3.93 +			throw new SAXException(e);
    3.94 +		}
    3.95 +	}
    3.96 +
    3.97 +	@Override
    3.98 +	public void characters(char[] ch, int start, int length) throws SAXException {
    3.99 +		try {
   3.100 +			w.writeCharacters(ch, start, length);
   3.101 +			w.flush();
   3.102 +		} catch (XMLStreamException e) {
   3.103 +			throw new SAXException(e);
   3.104 +		}
   3.105 +	}
   3.106 +
   3.107 +	/**
   3.108 +	 * LexicalHandler methods
   3.109 +	 *
   3.110 +	 * @Override
   3.111 +	 * public void startDTD(String name, String publicId, String systemId) throws SAXException {
   3.112 +	 * log.log(Level.WARNING, "Start of DTD: {0} | {1} | {2}", new Object[]{name, publicId,
   3.113 +	 * systemId});
   3.114 +	 * }
   3.115 +	 *
   3.116 +	 * @Override
   3.117 +	 * public void endDTD() throws SAXException {
   3.118 +	 * log.log(Level.WARNING, "End of DTD");
   3.119 +	 * }
   3.120 +	 *
   3.121 +	 * @Override
   3.122 +	 * public void startEntity(String name) throws SAXException {
   3.123 +	 * log.log(Level.WARNING, "Start of Entity: {0}", name);
   3.124 +	 * }
   3.125 +	 *
   3.126 +	 * @Override
   3.127 +	 * public void endEntity(String name) throws SAXException {
   3.128 +	 * log.log(Level.WARNING, "End of Entity: {0}", name);
   3.129 +	 * }
   3.130 +	 *
   3.131 +	 * @Override
   3.132 +	 * public void startCDATA() throws SAXException {
   3.133 +	 * log.log(Level.WARNING, "Start of CDATA");
   3.134 +	 * }
   3.135 +	 *
   3.136 +	 * @Override
   3.137 +	 * public void endCDATA() throws SAXException {
   3.138 +	 * log.log(Level.WARNING, "End of CDATA");
   3.139 +	 * }
   3.140 +	 *
   3.141 +	 * @Override
   3.142 +	 * public void comment(char[] ch, int start, int length) throws SAXException {
   3.143 +	 * try {
   3.144 +	 * w.writeComment(new String(ch, start, length));
   3.145 +	 * w.flush();
   3.146 +	 * } catch (XMLStreamException e) {
   3.147 +	 * throw new SAXException(e);
   3.148 +	 * }
   3.149 +	 * }
   3.150 +	 */
   3.151 +}
     4.1 --- a/scripts/alt2xml.sh	Sun Jun 08 15:00:19 2014 +0200
     4.2 +++ b/scripts/alt2xml.sh	Sun Jun 08 15:11:01 2014 +0200
     4.3 @@ -5,6 +5,7 @@
     4.4  STANDARD_JARS=(
     4.5  	"$DIR/java/alt2xml-cli/dist/alt2xml-cli.jar"
     4.6  	"$DIR/java/alt2xml-lib-input/dist/alt2xml-lib-input.jar"
     4.7 +	"$DIR/java/alt2xml-lib-output/dist/alt2xml-lib-output.jar"
     4.8  );
     4.9  
    4.10  PLUGINS=(