java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/EchoContentHandler.java
changeset 40 4afb00b7b1a9
parent 39 a5020340362b
child 41 efc293b2082c
     1.1 --- a/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/EchoContentHandler.java	Sun Jun 08 15:00:19 2014 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,148 +0,0 @@
     1.4 -/**
     1.5 - * Alt2XML
     1.6 - * Copyright © 2014 František Kučera (frantovo.cz)
     1.7 - *
     1.8 - * This program is free software: you can redistribute it and/or modify
     1.9 - * it under the terms of the GNU General Public License as published by
    1.10 - * the Free Software Foundation, either version 3 of the License, or
    1.11 - * (at your option) any later version.
    1.12 - *
    1.13 - * This program is distributed in the hope that it will be useful,
    1.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    1.16 - * GNU General Public License for more details.
    1.17 - *
    1.18 - * You should have received a copy of the GNU General Public License
    1.19 - * along with this program. If not, see <http://www.gnu.org/licenses/>.
    1.20 - */
    1.21 -package cz.frantovo.alt2xml.cli;
    1.22 -
    1.23 -import java.util.logging.Logger;
    1.24 -import javax.xml.stream.XMLStreamException;
    1.25 -import javax.xml.stream.XMLStreamWriter;
    1.26 -import org.xml.sax.Attributes;
    1.27 -import org.xml.sax.SAXException;
    1.28 -import org.xml.sax.helpers.DefaultHandler;
    1.29 -
    1.30 -/**
    1.31 - * Slouží k převodu právě parsovaného XML zpět na XML.
    1.32 - * Určen pro testování a ladění a pro použití s neobvyklými „XML“ parsery,
    1.33 - * které nečtou XML ale jiný jazyk (např. JSON, INI atd.), ale používají stejné rozhraní (SAX).
    1.34 - *
    1.35 - * TODO: další typy uzlů a jmenné prostory.
    1.36 - *
    1.37 - * @author Ing. František Kučera (frantovo.cz)
    1.38 - */
    1.39 -public class EchoContentHandler extends DefaultHandler {
    1.40 -
    1.41 -	private static final Logger log = Logger.getLogger(EchoContentHandler.class.getName());
    1.42 -	private XMLStreamWriter w;
    1.43 -
    1.44 -	/**
    1.45 -	 * @param writer kam se bude vypisovat XML.
    1.46 -	 */
    1.47 -	public EchoContentHandler(XMLStreamWriter writer) {
    1.48 -		w = writer;
    1.49 -	}
    1.50 -
    1.51 -	@Override
    1.52 -	public void startDocument() throws SAXException {
    1.53 -		try {
    1.54 -			w.writeStartDocument();
    1.55 -		} catch (XMLStreamException e) {
    1.56 -			throw new SAXException(e);
    1.57 -		}
    1.58 -	}
    1.59 -
    1.60 -	@Override
    1.61 -	public void endDocument() throws SAXException {
    1.62 -		try {
    1.63 -			w.writeEndDocument();
    1.64 -			w.close();
    1.65 -		} catch (XMLStreamException e) {
    1.66 -			throw new SAXException(e);
    1.67 -		}
    1.68 -	}
    1.69 -
    1.70 -	@Override
    1.71 -	public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    1.72 -		try {
    1.73 -			w.writeStartElement(qName);
    1.74 -
    1.75 -			if (attributes != null) {
    1.76 -				for (int i = 0; i < attributes.getLength(); i++) {
    1.77 -					w.writeAttribute(attributes.getQName(i), attributes.getValue(i));
    1.78 -				}
    1.79 -			}
    1.80 -
    1.81 -			w.flush();
    1.82 -		} catch (XMLStreamException e) {
    1.83 -			throw new SAXException(e);
    1.84 -		}
    1.85 -	}
    1.86 -
    1.87 -	@Override
    1.88 -	public void endElement(String uri, String localName, String qName) throws SAXException {
    1.89 -		try {
    1.90 -			w.writeEndElement();
    1.91 -			w.flush();
    1.92 -		} catch (XMLStreamException e) {
    1.93 -			throw new SAXException(e);
    1.94 -		}
    1.95 -	}
    1.96 -
    1.97 -	@Override
    1.98 -	public void characters(char[] ch, int start, int length) throws SAXException {
    1.99 -		try {
   1.100 -			w.writeCharacters(ch, start, length);
   1.101 -			w.flush();
   1.102 -		} catch (XMLStreamException e) {
   1.103 -			throw new SAXException(e);
   1.104 -		}
   1.105 -	}
   1.106 -
   1.107 -	/**
   1.108 -	 * LexicalHandler methods
   1.109 -	 *
   1.110 -	 * @Override
   1.111 -	 * public void startDTD(String name, String publicId, String systemId) throws SAXException {
   1.112 -	 * log.log(Level.WARNING, "Start of DTD: {0} | {1} | {2}", new Object[]{name, publicId,
   1.113 -	 * systemId});
   1.114 -	 * }
   1.115 -	 *
   1.116 -	 * @Override
   1.117 -	 * public void endDTD() throws SAXException {
   1.118 -	 * log.log(Level.WARNING, "End of DTD");
   1.119 -	 * }
   1.120 -	 *
   1.121 -	 * @Override
   1.122 -	 * public void startEntity(String name) throws SAXException {
   1.123 -	 * log.log(Level.WARNING, "Start of Entity: {0}", name);
   1.124 -	 * }
   1.125 -	 *
   1.126 -	 * @Override
   1.127 -	 * public void endEntity(String name) throws SAXException {
   1.128 -	 * log.log(Level.WARNING, "End of Entity: {0}", name);
   1.129 -	 * }
   1.130 -	 *
   1.131 -	 * @Override
   1.132 -	 * public void startCDATA() throws SAXException {
   1.133 -	 * log.log(Level.WARNING, "Start of CDATA");
   1.134 -	 * }
   1.135 -	 *
   1.136 -	 * @Override
   1.137 -	 * public void endCDATA() throws SAXException {
   1.138 -	 * log.log(Level.WARNING, "End of CDATA");
   1.139 -	 * }
   1.140 -	 *
   1.141 -	 * @Override
   1.142 -	 * public void comment(char[] ch, int start, int length) throws SAXException {
   1.143 -	 * try {
   1.144 -	 * w.writeComment(new String(ch, start, length));
   1.145 -	 * w.flush();
   1.146 -	 * } catch (XMLStreamException e) {
   1.147 -	 * throw new SAXException(e);
   1.148 -	 * }
   1.149 -	 * }
   1.150 -	 */
   1.151 -}