java/alt2xml-lib-input/src/cz/frantovo/alt2xml/in/Alt2ContentHandler.java
author František Kučera <franta-hg@frantovo.cz>
Sat, 06 Sep 2014 17:17:37 +0200
changeset 75 ed9ec17aa67f
child 78 afcb4ccc6594
permissions -rw-r--r--
lib-input: Alt2ContentHandler - extended wrapper
     1 /**
     2  * Alt2XML
     3  * Copyright © 2014 František Kučera (frantovo.cz)
     4  *
     5  * This program is free software: you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation, either version 3 of the License, or
     8  * (at your option) any later version.
     9  *
    10  * This program is distributed in the hope that it will be useful,
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  * GNU General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU General Public License
    16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    17  */
    18 package cz.frantovo.alt2xml.in;
    19 
    20 import org.xml.sax.Attributes;
    21 import org.xml.sax.ContentHandler;
    22 import org.xml.sax.Locator;
    23 import org.xml.sax.SAXException;
    24 
    25 /**
    26  * Improved wrapper for SAX ContentHandler.
    27  *
    28  * @author Ing. František Kučera (frantovo.cz)
    29  */
    30 public class Alt2ContentHandler implements ContentHandler {
    31 
    32 	private final ContentHandler handler;
    33 
    34 	public Alt2ContentHandler(ContentHandler handler) {
    35 		this.handler = handler;
    36 	}
    37 
    38 	public void lineBreak() throws SAXException {
    39 		// TODO: ignorableWhitespace()
    40 		characters("\n");
    41 	}
    42 
    43 	public void indentation(int level) throws SAXException {
    44 		for (int i = 0; i < level; i++) {
    45 			// TODO: ignorableWhitespace()
    46 			characters("\t");
    47 		}
    48 	}
    49 
    50 	public void characters(String text) throws SAXException {
    51 		handler.characters(text.toCharArray(), 0, text.length());
    52 	}
    53 
    54 	public void ignorableWhitespace(String text) throws SAXException {
    55 		handler.ignorableWhitespace(text.toCharArray(), 0, text.length());
    56 	}
    57 
    58 	// ---------------------------------------------------------------------------------------------
    59 	@Override
    60 	public void setDocumentLocator(Locator locator) {
    61 		handler.setDocumentLocator(locator);
    62 	}
    63 
    64 	@Override
    65 	public void startDocument() throws SAXException {
    66 		handler.startDocument();
    67 	}
    68 
    69 	@Override
    70 	public void endDocument() throws SAXException {
    71 		handler.endDocument();
    72 	}
    73 
    74 	@Override
    75 	public void startPrefixMapping(String prefix, String uri) throws SAXException {
    76 		handler.startPrefixMapping(prefix, uri);
    77 	}
    78 
    79 	@Override
    80 	public void endPrefixMapping(String prefix) throws SAXException {
    81 		handler.endPrefixMapping(prefix);
    82 	}
    83 
    84 	@Override
    85 	public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
    86 		handler.startElement(uri, localName, qName, atts);
    87 	}
    88 
    89 	@Override
    90 	public void endElement(String uri, String localName, String qName) throws SAXException {
    91 		handler.endElement(uri, localName, qName);
    92 	}
    93 
    94 	@Override
    95 	public void characters(char[] ch, int start, int length) throws SAXException {
    96 		handler.characters(ch, start, length);
    97 	}
    98 
    99 	@Override
   100 	public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
   101 		handler.ignorableWhitespace(ch, start, length);
   102 	}
   103 
   104 	@Override
   105 	public void processingInstruction(String target, String data) throws SAXException {
   106 		handler.processingInstruction(target, data);
   107 	}
   108 
   109 	@Override
   110 	public void skippedEntity(String name) throws SAXException {
   111 		handler.skippedEntity(name);
   112 	}
   113 }