java/alt2xml-lib-input/src/cz/frantovo/alt2xml/in/Alt2ContentHandler.java
author František Kučera <franta-hg@frantovo.cz>
Sat, 06 Sep 2014 18:29:44 +0200
changeset 78 afcb4ccc6594
parent 75 ed9ec17aa67f
child 111 e4900596abdb
permissions -rw-r--r--
in-ini: first working version
     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 	public void textElement(String text, String uri, String localName, String qName, Attributes atts) throws SAXException {
    59 		startElement(uri, localName, qName, atts);
    60 		characters(text);
    61 		endElement(uri, localName, qName);
    62 	}
    63 
    64 	// ---------------------------------------------------------------------------------------------
    65 	@Override
    66 	public void setDocumentLocator(Locator locator) {
    67 		handler.setDocumentLocator(locator);
    68 	}
    69 
    70 	@Override
    71 	public void startDocument() throws SAXException {
    72 		handler.startDocument();
    73 	}
    74 
    75 	@Override
    76 	public void endDocument() throws SAXException {
    77 		handler.endDocument();
    78 	}
    79 
    80 	@Override
    81 	public void startPrefixMapping(String prefix, String uri) throws SAXException {
    82 		handler.startPrefixMapping(prefix, uri);
    83 	}
    84 
    85 	@Override
    86 	public void endPrefixMapping(String prefix) throws SAXException {
    87 		handler.endPrefixMapping(prefix);
    88 	}
    89 
    90 	@Override
    91 	public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
    92 		handler.startElement(uri, localName, qName, atts);
    93 	}
    94 
    95 	@Override
    96 	public void endElement(String uri, String localName, String qName) throws SAXException {
    97 		handler.endElement(uri, localName, qName);
    98 	}
    99 
   100 	@Override
   101 	public void characters(char[] ch, int start, int length) throws SAXException {
   102 		handler.characters(ch, start, length);
   103 	}
   104 
   105 	@Override
   106 	public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
   107 		handler.ignorableWhitespace(ch, start, length);
   108 	}
   109 
   110 	@Override
   111 	public void processingInstruction(String target, String data) throws SAXException {
   112 		handler.processingInstruction(target, data);
   113 	}
   114 
   115 	@Override
   116 	public void skippedEntity(String name) throws SAXException {
   117 		handler.skippedEntity(name);
   118 	}
   119 }