# HG changeset patch
# User František Kučera <franta-hg@frantovo.cz>
# Date 1401973430 -7200
# Node ID f56a5369245ee2972db62527cccd64f7ab545b45
# Parent  f40af5368823baeeb90b9890521cfe8276f302fb
rozdělení na více projektů: přesun tříd

diff -r f40af5368823 -r f56a5369245e java/alt2xml-bin/nbproject/project.properties
--- a/java/alt2xml-bin/nbproject/project.properties	Thu Jun 05 14:45:15 2014 +0200
+++ b/java/alt2xml-bin/nbproject/project.properties	Thu Jun 05 15:03:50 2014 +0200
@@ -30,7 +30,6 @@
 includes=**
 jar.compress=false
 javac.classpath=\
-    ${libs.json-simple.classpath}:\
     ${reference.alt2xml-lib.jar}
 # Space-separated list of extra javac options
 javac.compilerargs=
diff -r f40af5368823 -r f56a5369245e java/alt2xml-bin/src/cz/frantovo/alt2xml/vstup/JsonSimpleContentHandler.java
--- a/java/alt2xml-bin/src/cz/frantovo/alt2xml/vstup/JsonSimpleContentHandler.java	Thu Jun 05 14:45:15 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,135 +0,0 @@
-package cz.frantovo.alt2xml.vstup;
-
-import java.io.IOException;
-import java.util.Stack;
-import org.json.simple.parser.ParseException;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-
-/**
- *
- * @author fiki
- */
-public class JsonSimpleContentHandler implements org.json.simple.parser.ContentHandler {
-
-	/** Sem vypisujeme XML události */
-	private ContentHandler saxVýstup;
-	/** Musíme si pamatovat polohu v XML stromu, abychom věděli, kterou značku kdy uzavřít */
-	private Stack<String> poloha = new Stack<>();
-	/**
-	 * Po textových uzlech vkládáme konce elementů rovnou,
-	 * ale pokud jeden element končí hned po jiném, 
-	 * vložíme mezi ně ještě konec řádku a odsazení.
-	 */
-	private boolean zalomitŘádek = false;
-
-	public JsonSimpleContentHandler(ContentHandler saxVýstup) {
-		this.saxVýstup = saxVýstup;
-	}
-
-	private void začniElement(String název) throws IOException {
-		try {
-			vložOdsazení();
-			saxVýstup.startElement(null, null, název, null);
-			poloha.push(název);
-		} catch (SAXException e) {
-			throw new IOException("Chyba při začátku elementu.", e);
-		}
-	}
-
-	private void ukončiElement() throws IOException {
-		try {
-			String značka = poloha.pop();
-			if (zalomitŘádek) {
-				vložOdsazení();
-			}
-			zalomitŘádek = true;
-			saxVýstup.endElement(null, null, značka);
-		} catch (SAXException e) {
-			throw new IOException("Chyba při ukončování elementu.", e);
-		}
-	}
-
-	private void vložOdsazení() throws IOException {
-		/**
-		 * TODO: ignorableWhitespace() ?
-		 */
-		vložText("\n");
-		for (int i = 0; i < poloha.size(); i++) {
-			vložText("\t");
-		}
-	}
-
-	private void vložText(String text) throws IOException {
-		try {
-			saxVýstup.characters(text.toCharArray(), 0, text.length());
-		} catch (SAXException e) {
-			throw new IOException("Chyba při vkládání textu.", e);
-		}
-	}
-
-	@Override
-	public void startJSON() throws ParseException, IOException {
-		try {
-			saxVýstup.startDocument();
-			začniElement("objekt");
-		} catch (SAXException e) {
-			throw new IOException("Chyba při začátku dokumentu.", e);
-		}
-	}
-
-	@Override
-	public void endJSON() throws ParseException, IOException {
-		try {
-			ukončiElement();
-			vložText("\n");
-			saxVýstup.endDocument();
-		} catch (SAXException e) {
-			throw new IOException(e);
-		}
-	}
-
-	@Override
-	public boolean startObject() throws ParseException, IOException {
-		// System.err.println("startObject");
-		return true;
-	}
-
-	@Override
-	public boolean endObject() throws ParseException, IOException {
-		// System.err.println("endObject");
-		return true;
-	}
-
-	@Override
-	public boolean startObjectEntry(String key) throws ParseException, IOException {
-		začniElement(key);
-		return true;
-	}
-
-	@Override
-	public boolean endObjectEntry() throws ParseException, IOException {
-		ukončiElement();
-		// System.err.println("endObjectEntry");
-		return true;
-	}
-
-	@Override
-	public boolean startArray() throws ParseException, IOException {
-		// System.err.println("startArray");
-		return true;
-	}
-
-	@Override
-	public boolean endArray() throws ParseException, IOException {
-		// System.err.println("endArray");
-		return true;
-	}
-
-	@Override
-	public boolean primitive(Object value) throws ParseException, IOException {
-		vložText(String.valueOf(value));
-		zalomitŘádek = false;
-		return true;
-	}
-}
diff -r f40af5368823 -r f56a5369245e java/alt2xml-bin/src/cz/frantovo/alt2xml/vstup/SuperReader.java
--- a/java/alt2xml-bin/src/cz/frantovo/alt2xml/vstup/SuperReader.java	Thu Jun 05 14:45:15 2014 +0200
+++ b/java/alt2xml-bin/src/cz/frantovo/alt2xml/vstup/SuperReader.java	Thu Jun 05 15:03:50 2014 +0200
@@ -4,8 +4,8 @@
 import java.io.InputStreamReader;
 import java.util.HashMap;
 import java.util.Map;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
+//import org.json.simple.parser.JSONParser;
+//import org.json.simple.parser.ParseException;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.DTDHandler;
 import org.xml.sax.EntityResolver;
@@ -33,15 +33,17 @@
 		/**
 		 * TODO: rozpornat formát vstupu a podle toho delegovat
 		 */
-		JSONParser p = new JSONParser();
+		//JSONParser p = new JSONParser();
 		InputStreamReader vstup = new InputStreamReader(input.getByteStream());
-		JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler);
+		//JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler);
 
+		/*
 		try {
 			p.parse(vstup, handler);
 		} catch (ParseException e) {
 			throw new SAXException("Chyba při načítání JSONu", e);
 		}
+		*/
 	}
 
 	@Override
diff -r f40af5368823 -r f56a5369245e java/alt2xml-in-json/nbproject/project.properties
--- a/java/alt2xml-in-json/nbproject/project.properties	Thu Jun 05 14:45:15 2014 +0200
+++ b/java/alt2xml-in-json/nbproject/project.properties	Thu Jun 05 15:03:50 2014 +0200
@@ -30,7 +30,8 @@
 includes=**
 jar.compress=false
 javac.classpath=\
-    ${reference.alt2xml-lib.jar}
+    ${reference.alt2xml-lib.jar}:\
+    ${libs.json-simple.classpath}
 # Space-separated list of extra javac options
 javac.compilerargs=
 javac.deprecation=false
diff -r f40af5368823 -r f56a5369245e java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/JsonSimpleContentHandler.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/JsonSimpleContentHandler.java	Thu Jun 05 15:03:50 2014 +0200
@@ -0,0 +1,135 @@
+package cz.frantovo.alt2xml.vstup;
+
+import java.io.IOException;
+import java.util.Stack;
+import org.json.simple.parser.ParseException;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+/**
+ *
+ * @author fiki
+ */
+public class JsonSimpleContentHandler implements org.json.simple.parser.ContentHandler {
+
+	/** Sem vypisujeme XML události */
+	private ContentHandler saxVýstup;
+	/** Musíme si pamatovat polohu v XML stromu, abychom věděli, kterou značku kdy uzavřít */
+	private Stack<String> poloha = new Stack<>();
+	/**
+	 * Po textových uzlech vkládáme konce elementů rovnou,
+	 * ale pokud jeden element končí hned po jiném, 
+	 * vložíme mezi ně ještě konec řádku a odsazení.
+	 */
+	private boolean zalomitŘádek = false;
+
+	public JsonSimpleContentHandler(ContentHandler saxVýstup) {
+		this.saxVýstup = saxVýstup;
+	}
+
+	private void začniElement(String název) throws IOException {
+		try {
+			vložOdsazení();
+			saxVýstup.startElement(null, null, název, null);
+			poloha.push(název);
+		} catch (SAXException e) {
+			throw new IOException("Chyba při začátku elementu.", e);
+		}
+	}
+
+	private void ukončiElement() throws IOException {
+		try {
+			String značka = poloha.pop();
+			if (zalomitŘádek) {
+				vložOdsazení();
+			}
+			zalomitŘádek = true;
+			saxVýstup.endElement(null, null, značka);
+		} catch (SAXException e) {
+			throw new IOException("Chyba při ukončování elementu.", e);
+		}
+	}
+
+	private void vložOdsazení() throws IOException {
+		/**
+		 * TODO: ignorableWhitespace() ?
+		 */
+		vložText("\n");
+		for (int i = 0; i < poloha.size(); i++) {
+			vložText("\t");
+		}
+	}
+
+	private void vložText(String text) throws IOException {
+		try {
+			saxVýstup.characters(text.toCharArray(), 0, text.length());
+		} catch (SAXException e) {
+			throw new IOException("Chyba při vkládání textu.", e);
+		}
+	}
+
+	@Override
+	public void startJSON() throws ParseException, IOException {
+		try {
+			saxVýstup.startDocument();
+			začniElement("objekt");
+		} catch (SAXException e) {
+			throw new IOException("Chyba při začátku dokumentu.", e);
+		}
+	}
+
+	@Override
+	public void endJSON() throws ParseException, IOException {
+		try {
+			ukončiElement();
+			vložText("\n");
+			saxVýstup.endDocument();
+		} catch (SAXException e) {
+			throw new IOException(e);
+		}
+	}
+
+	@Override
+	public boolean startObject() throws ParseException, IOException {
+		// System.err.println("startObject");
+		return true;
+	}
+
+	@Override
+	public boolean endObject() throws ParseException, IOException {
+		// System.err.println("endObject");
+		return true;
+	}
+
+	@Override
+	public boolean startObjectEntry(String key) throws ParseException, IOException {
+		začniElement(key);
+		return true;
+	}
+
+	@Override
+	public boolean endObjectEntry() throws ParseException, IOException {
+		ukončiElement();
+		// System.err.println("endObjectEntry");
+		return true;
+	}
+
+	@Override
+	public boolean startArray() throws ParseException, IOException {
+		// System.err.println("startArray");
+		return true;
+	}
+
+	@Override
+	public boolean endArray() throws ParseException, IOException {
+		// System.err.println("endArray");
+		return true;
+	}
+
+	@Override
+	public boolean primitive(Object value) throws ParseException, IOException {
+		vložText(String.valueOf(value));
+		zalomitŘádek = false;
+		return true;
+	}
+}
diff -r f40af5368823 -r f56a5369245e java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/SuperReader.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/SuperReader.java	Thu Jun 05 15:03:50 2014 +0200
@@ -0,0 +1,117 @@
+package cz.frantovo.alt2xml.vstup;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.Map;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.DTDHandler;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.XMLReader;
+
+/**
+ *
+ * @author fiki
+ */
+public class SuperReader implements XMLReader {
+
+	private ContentHandler contentHandler;
+	private ErrorHandler errorHandler;
+	private DTDHandler dtdHandler;
+	private EntityResolver entityResolver;
+	private Map<String, Object> konfigurace = new HashMap<>();
+	
+	@Override
+	public void parse(InputSource input) throws IOException, SAXException {
+		/**
+		 * TODO: rozpornat formát vstupu a podle toho delegovat
+		 */
+		JSONParser p = new JSONParser();
+		InputStreamReader vstup = new InputStreamReader(input.getByteStream());
+		JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler);
+
+		try {
+			p.parse(vstup, handler);
+		} catch (ParseException e) {
+			throw new SAXException("Chyba při načítání JSONu", e);
+		}
+	}
+
+	@Override
+	public void parse(String systemId) throws IOException, SAXException {
+		parse(new InputSource(systemId));
+	}
+
+	@Override
+	public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
+		/**
+		 * TODO: 
+		 * All XMLReaders are required to recognize 
+		 * the http://xml.org/sax/features/namespaces 
+		 * and the http://xml.org/sax/features/namespace-prefixes feature names.
+		 */
+		throw new SAXNotSupportedException("Zatím není podporováno.");
+	}
+
+	@Override
+	public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
+		throw new SAXNotSupportedException("Zatím není podporováno.");
+	}
+
+	@Override
+	public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
+		return konfigurace.get(name);
+	}
+
+	@Override
+	public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
+		konfigurace.put(name, value);
+	}
+
+	@Override
+	public void setEntityResolver(EntityResolver entityResolver) {
+		this.entityResolver = entityResolver;
+	}
+
+	@Override
+	public EntityResolver getEntityResolver() {
+		return entityResolver;
+	}
+
+	@Override
+	public void setDTDHandler(DTDHandler dtdHandler) {
+		this.dtdHandler = dtdHandler;
+	}
+
+	@Override
+	public DTDHandler getDTDHandler() {
+		return dtdHandler;
+	}
+
+	@Override
+	public void setContentHandler(ContentHandler contentHandler) {
+		this.contentHandler = contentHandler;
+	}
+
+	@Override
+	public ContentHandler getContentHandler() {
+		return contentHandler;
+	}
+
+	@Override
+	public void setErrorHandler(ErrorHandler errorHandler) {
+		this.errorHandler = errorHandler;
+	}
+
+	@Override
+	public ErrorHandler getErrorHandler() {
+		return errorHandler;
+	}
+}