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