# HG changeset patch
# User František Kučera <franta-hg@frantovo.cz>
# Date 1410016657 -7200
# Node ID ed9ec17aa67fe026e55a8d8dcb718a94ad6e999d
# Parent  6d1fc2895273f832ac5bbfc4818eeb5a58438175
lib-input: Alt2ContentHandler - extended wrapper

diff -r 6d1fc2895273 -r ed9ec17aa67f java/alt2xml-in-properties/src/cz/frantovo/alt2xml/in/properties/Reader.java
--- a/java/alt2xml-in-properties/src/cz/frantovo/alt2xml/in/properties/Reader.java	Sat Sep 06 15:06:41 2014 +0200
+++ b/java/alt2xml-in-properties/src/cz/frantovo/alt2xml/in/properties/Reader.java	Sat Sep 06 17:17:37 2014 +0200
@@ -109,11 +109,11 @@
 		contentHandler.startDocument();
 		contentHandler.startElement(null, null, "properties", null);
 
-		outputLineBreak();
+		contentHandler.lineBreak();
 	}
 
 	private void outputProperty(String key, String value) throws SAXException {
-		outputIndentation();
+		contentHandler.indentation(1);
 
 		AttributesImpl attributes = new AttributesImpl();
 		attributes.addAttribute(null, "name", "name", "xs:string", key);
@@ -122,7 +122,7 @@
 		contentHandler.characters(value.toCharArray(), 0, value.length());
 		contentHandler.endElement(null, null, "property");
 
-		outputLineBreak();
+		contentHandler.lineBreak();
 	}
 
 	private void outputProperties(Properties loadedData) throws SAXException {
@@ -133,21 +133,9 @@
 		}
 	}
 
-	private void outputIndentation() throws SAXException {
-		outputText("\t");
-	}
-
-	private void outputLineBreak() throws SAXException {
-		outputText("\n");
-	}
-
-	private void outputText(String text) throws SAXException {
-		contentHandler.characters(text.toCharArray(), 0, text.length());
-	}
-
 	private void outputEnd() throws SAXException {
 		contentHandler.endElement(null, null, "properties");
-		outputLineBreak();
+		contentHandler.lineBreak();
 		contentHandler.endDocument();
 	}
 }
diff -r 6d1fc2895273 -r ed9ec17aa67f java/alt2xml-lib-input/src/cz/frantovo/alt2xml/AbstractAlt2XmlReader.java
--- a/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/AbstractAlt2XmlReader.java	Sat Sep 06 15:06:41 2014 +0200
+++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/AbstractAlt2XmlReader.java	Sat Sep 06 17:17:37 2014 +0200
@@ -17,6 +17,7 @@
  */
 package cz.frantovo.alt2xml;
 
+import cz.frantovo.alt2xml.in.Alt2ContentHandler;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
@@ -38,7 +39,7 @@
 public abstract class AbstractAlt2XmlReader implements XMLReader {
 
 	private static final String PROPERTY_BASE_URL = "https://alt2xml.globalcode.info/sax-property/";
-	protected ContentHandler contentHandler;
+	protected Alt2ContentHandler contentHandler;
 	protected ErrorHandler errorHandler;
 	protected DTDHandler dtdHandler;
 	protected EntityResolver entityResolver;
@@ -113,11 +114,11 @@
 
 	@Override
 	public void setContentHandler(ContentHandler contentHandler) {
-		this.contentHandler = contentHandler;
+		this.contentHandler = new Alt2ContentHandler(contentHandler);
 	}
 
 	@Override
-	public ContentHandler getContentHandler() {
+	public Alt2ContentHandler getContentHandler() {
 		return contentHandler;
 	}
 
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 <http://www.gnu.org/licenses/>.
+ */
+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);
+	}
+}