java/alt2xml-lib-input/src/cz/frantovo/alt2xml/in/Alt2ContentHandler.java
changeset 75 ed9ec17aa67f
child 78 afcb4ccc6594
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/in/Alt2ContentHandler.java	Sat Sep 06 17:17:37 2014 +0200
     1.3 @@ -0,0 +1,113 @@
     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.in;
    1.22 +
    1.23 +import org.xml.sax.Attributes;
    1.24 +import org.xml.sax.ContentHandler;
    1.25 +import org.xml.sax.Locator;
    1.26 +import org.xml.sax.SAXException;
    1.27 +
    1.28 +/**
    1.29 + * Improved wrapper for SAX ContentHandler.
    1.30 + *
    1.31 + * @author Ing. František Kučera (frantovo.cz)
    1.32 + */
    1.33 +public class Alt2ContentHandler implements ContentHandler {
    1.34 +
    1.35 +	private final ContentHandler handler;
    1.36 +
    1.37 +	public Alt2ContentHandler(ContentHandler handler) {
    1.38 +		this.handler = handler;
    1.39 +	}
    1.40 +
    1.41 +	public void lineBreak() throws SAXException {
    1.42 +		// TODO: ignorableWhitespace()
    1.43 +		characters("\n");
    1.44 +	}
    1.45 +
    1.46 +	public void indentation(int level) throws SAXException {
    1.47 +		for (int i = 0; i < level; i++) {
    1.48 +			// TODO: ignorableWhitespace()
    1.49 +			characters("\t");
    1.50 +		}
    1.51 +	}
    1.52 +
    1.53 +	public void characters(String text) throws SAXException {
    1.54 +		handler.characters(text.toCharArray(), 0, text.length());
    1.55 +	}
    1.56 +
    1.57 +	public void ignorableWhitespace(String text) throws SAXException {
    1.58 +		handler.ignorableWhitespace(text.toCharArray(), 0, text.length());
    1.59 +	}
    1.60 +
    1.61 +	// ---------------------------------------------------------------------------------------------
    1.62 +	@Override
    1.63 +	public void setDocumentLocator(Locator locator) {
    1.64 +		handler.setDocumentLocator(locator);
    1.65 +	}
    1.66 +
    1.67 +	@Override
    1.68 +	public void startDocument() throws SAXException {
    1.69 +		handler.startDocument();
    1.70 +	}
    1.71 +
    1.72 +	@Override
    1.73 +	public void endDocument() throws SAXException {
    1.74 +		handler.endDocument();
    1.75 +	}
    1.76 +
    1.77 +	@Override
    1.78 +	public void startPrefixMapping(String prefix, String uri) throws SAXException {
    1.79 +		handler.startPrefixMapping(prefix, uri);
    1.80 +	}
    1.81 +
    1.82 +	@Override
    1.83 +	public void endPrefixMapping(String prefix) throws SAXException {
    1.84 +		handler.endPrefixMapping(prefix);
    1.85 +	}
    1.86 +
    1.87 +	@Override
    1.88 +	public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
    1.89 +		handler.startElement(uri, localName, qName, atts);
    1.90 +	}
    1.91 +
    1.92 +	@Override
    1.93 +	public void endElement(String uri, String localName, String qName) throws SAXException {
    1.94 +		handler.endElement(uri, localName, qName);
    1.95 +	}
    1.96 +
    1.97 +	@Override
    1.98 +	public void characters(char[] ch, int start, int length) throws SAXException {
    1.99 +		handler.characters(ch, start, length);
   1.100 +	}
   1.101 +
   1.102 +	@Override
   1.103 +	public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
   1.104 +		handler.ignorableWhitespace(ch, start, length);
   1.105 +	}
   1.106 +
   1.107 +	@Override
   1.108 +	public void processingInstruction(String target, String data) throws SAXException {
   1.109 +		handler.processingInstruction(target, data);
   1.110 +	}
   1.111 +
   1.112 +	@Override
   1.113 +	public void skippedEntity(String name) throws SAXException {
   1.114 +		handler.skippedEntity(name);
   1.115 +	}
   1.116 +}