diff -r 6d1fc2895273 -r ed9ec17aa67f java/alt2xml-lib-input/src/cz/frantovo/alt2xml/in/Alt2ContentHandler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/in/Alt2ContentHandler.java Sat Sep 06 17:17:37 2014 +0200 @@ -0,0 +1,113 @@ +/** + * 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.in; + +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; + +/** + * Improved wrapper for SAX ContentHandler. + * + * @author Ing. František Kučera (frantovo.cz) + */ +public class Alt2ContentHandler implements ContentHandler { + + private final ContentHandler handler; + + public Alt2ContentHandler(ContentHandler handler) { + this.handler = handler; + } + + public void lineBreak() throws SAXException { + // TODO: ignorableWhitespace() + characters("\n"); + } + + public void indentation(int level) throws SAXException { + for (int i = 0; i < level; i++) { + // TODO: ignorableWhitespace() + characters("\t"); + } + } + + public void characters(String text) throws SAXException { + handler.characters(text.toCharArray(), 0, text.length()); + } + + public void ignorableWhitespace(String text) throws SAXException { + handler.ignorableWhitespace(text.toCharArray(), 0, text.length()); + } + + // --------------------------------------------------------------------------------------------- + @Override + public void setDocumentLocator(Locator locator) { + handler.setDocumentLocator(locator); + } + + @Override + public void startDocument() throws SAXException { + handler.startDocument(); + } + + @Override + public void endDocument() throws SAXException { + handler.endDocument(); + } + + @Override + public void startPrefixMapping(String prefix, String uri) throws SAXException { + handler.startPrefixMapping(prefix, uri); + } + + @Override + public void endPrefixMapping(String prefix) throws SAXException { + handler.endPrefixMapping(prefix); + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { + handler.startElement(uri, localName, qName, atts); + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + handler.endElement(uri, localName, qName); + } + + @Override + public void characters(char[] ch, int start, int length) throws SAXException { + handler.characters(ch, start, length); + } + + @Override + public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { + handler.ignorableWhitespace(ch, start, length); + } + + @Override + public void processingInstruction(String target, String data) throws SAXException { + handler.processingInstruction(target, data); + } + + @Override + public void skippedEntity(String name) throws SAXException { + handler.skippedEntity(name); + } +}