licence
authorFrantišek Kučera <franta-hg@frantovo.cz>
Thu, 05 Jun 2014 22:01:58 +0200
changeset 11aaf6648af0aa
parent 10 f56a5369245e
child 12 3770beeed252
licence
java/alt2xml-bin/src/cz/frantovo/alt2xml/CLI.java
java/alt2xml-bin/src/cz/frantovo/alt2xml/SAXTovarna.java
java/alt2xml-bin/src/cz/frantovo/alt2xml/vstup/SuperReader.java
java/alt2xml-bin/src/cz/frantovo/alt2xml/výstup/EchoContentHandler.java
java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/JsonSimpleContentHandler.java
java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/JsonXMLReader.java
java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/SuperReader.java
     1.1 --- a/java/alt2xml-bin/src/cz/frantovo/alt2xml/CLI.java	Thu Jun 05 15:03:50 2014 +0200
     1.2 +++ b/java/alt2xml-bin/src/cz/frantovo/alt2xml/CLI.java	Thu Jun 05 22:01:58 2014 +0200
     1.3 @@ -1,3 +1,20 @@
     1.4 +/**
     1.5 + * Alt2XML
     1.6 + * Copyright © 2014 František Kučera (frantovo.cz)
     1.7 + *
     1.8 + * This program is free software: you can redistribute it and/or modify
     1.9 + * it under the terms of the GNU General Public License as published by
    1.10 + * the Free Software Foundation, either version 3 of the License, or
    1.11 + * (at your option) any later version.
    1.12 + *
    1.13 + * This program is distributed in the hope that it will be useful,
    1.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    1.16 + * GNU General Public License for more details.
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License
    1.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    1.20 + */
    1.21  package cz.frantovo.alt2xml;
    1.22  
    1.23  import cz.frantovo.alt2xml.výstup.EchoContentHandler;
     2.1 --- a/java/alt2xml-bin/src/cz/frantovo/alt2xml/SAXTovarna.java	Thu Jun 05 15:03:50 2014 +0200
     2.2 +++ b/java/alt2xml-bin/src/cz/frantovo/alt2xml/SAXTovarna.java	Thu Jun 05 22:01:58 2014 +0200
     2.3 @@ -1,3 +1,20 @@
     2.4 +/**
     2.5 + * Alt2XML
     2.6 + * Copyright © 2014 František Kučera (frantovo.cz)
     2.7 + *
     2.8 + * This program is free software: you can redistribute it and/or modify
     2.9 + * it under the terms of the GNU General Public License as published by
    2.10 + * the Free Software Foundation, either version 3 of the License, or
    2.11 + * (at your option) any later version.
    2.12 + *
    2.13 + * This program is distributed in the hope that it will be useful,
    2.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    2.16 + * GNU General Public License for more details.
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License
    2.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    2.20 + */
    2.21  package cz.frantovo.alt2xml;
    2.22  
    2.23  import cz.frantovo.alt2xml.vstup.SuperReader;
    2.24 @@ -18,7 +35,7 @@
    2.25  
    2.26  	@Override
    2.27  	public SAXParser newSAXParser() throws ParserConfigurationException, SAXException {
    2.28 -		return new MůjParser(new SuperReader());
    2.29 +		return new AltSAXParser(new SuperReader());
    2.30  	}
    2.31  
    2.32  	@Override
    2.33 @@ -31,15 +48,16 @@
    2.34  		throw new SAXNotSupportedException("Zatím není podporováno.");
    2.35  	}
    2.36  
    2.37 -	private static class MůjParser extends SAXParser {
    2.38 +	private static class AltSAXParser extends SAXParser {
    2.39  
    2.40  		private XMLReader xmlReader;
    2.41  
    2.42 -		public MůjParser(XMLReader xmlReader) {
    2.43 +		public AltSAXParser(XMLReader xmlReader) {
    2.44  			this.xmlReader = xmlReader;
    2.45  		}
    2.46  
    2.47  		@Override
    2.48 +		@Deprecated
    2.49  		public Parser getParser() throws SAXException {
    2.50  			throw new SAXException("Není podporováno.");
    2.51  		}
    2.52 @@ -51,7 +69,7 @@
    2.53  
    2.54  		@Override
    2.55  		public boolean isNamespaceAware() {
    2.56 -			return false;
    2.57 +			return true;
    2.58  		}
    2.59  
    2.60  		@Override
     3.1 --- a/java/alt2xml-bin/src/cz/frantovo/alt2xml/vstup/SuperReader.java	Thu Jun 05 15:03:50 2014 +0200
     3.2 +++ b/java/alt2xml-bin/src/cz/frantovo/alt2xml/vstup/SuperReader.java	Thu Jun 05 22:01:58 2014 +0200
     3.3 @@ -1,3 +1,20 @@
     3.4 +/**
     3.5 + * Alt2XML
     3.6 + * Copyright © 2014 František Kučera (frantovo.cz)
     3.7 + *
     3.8 + * This program is free software: you can redistribute it and/or modify
     3.9 + * it under the terms of the GNU General Public License as published by
    3.10 + * the Free Software Foundation, either version 3 of the License, or
    3.11 + * (at your option) any later version.
    3.12 + *
    3.13 + * This program is distributed in the hope that it will be useful,
    3.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    3.16 + * GNU General Public License for more details.
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License
    3.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    3.20 + */
    3.21  package cz.frantovo.alt2xml.vstup;
    3.22  
    3.23  import java.io.IOException;
     4.1 --- a/java/alt2xml-bin/src/cz/frantovo/alt2xml/výstup/EchoContentHandler.java	Thu Jun 05 15:03:50 2014 +0200
     4.2 +++ b/java/alt2xml-bin/src/cz/frantovo/alt2xml/výstup/EchoContentHandler.java	Thu Jun 05 22:01:58 2014 +0200
     4.3 @@ -1,3 +1,20 @@
     4.4 +/**
     4.5 + * Alt2XML
     4.6 + * Copyright © 2014 František Kučera (frantovo.cz)
     4.7 + *
     4.8 + * This program is free software: you can redistribute it and/or modify
     4.9 + * it under the terms of the GNU General Public License as published by
    4.10 + * the Free Software Foundation, either version 3 of the License, or
    4.11 + * (at your option) any later version.
    4.12 + *
    4.13 + * This program is distributed in the hope that it will be useful,
    4.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    4.16 + * GNU General Public License for more details.
    4.17 + *
    4.18 + * You should have received a copy of the GNU General Public License
    4.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    4.20 + */
    4.21  package cz.frantovo.alt2xml.výstup;
    4.22  
    4.23  import javax.xml.stream.XMLStreamException;
     5.1 --- a/java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/JsonSimpleContentHandler.java	Thu Jun 05 15:03:50 2014 +0200
     5.2 +++ b/java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/JsonSimpleContentHandler.java	Thu Jun 05 22:01:58 2014 +0200
     5.3 @@ -1,3 +1,20 @@
     5.4 +/**
     5.5 + * Alt2XML
     5.6 + * Copyright © 2014 František Kučera (frantovo.cz)
     5.7 + *
     5.8 + * This program is free software: you can redistribute it and/or modify
     5.9 + * it under the terms of the GNU General Public License as published by
    5.10 + * the Free Software Foundation, either version 3 of the License, or
    5.11 + * (at your option) any later version.
    5.12 + *
    5.13 + * This program is distributed in the hope that it will be useful,
    5.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    5.16 + * GNU General Public License for more details.
    5.17 + *
    5.18 + * You should have received a copy of the GNU General Public License
    5.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    5.20 + */
    5.21  package cz.frantovo.alt2xml.vstup;
    5.22  
    5.23  import java.io.IOException;
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/JsonXMLReader.java	Thu Jun 05 22:01:58 2014 +0200
     6.3 @@ -0,0 +1,134 @@
     6.4 +/**
     6.5 + * Alt2XML
     6.6 + * Copyright © 2014 František Kučera (frantovo.cz)
     6.7 + *
     6.8 + * This program is free software: you can redistribute it and/or modify
     6.9 + * it under the terms of the GNU General Public License as published by
    6.10 + * the Free Software Foundation, either version 3 of the License, or
    6.11 + * (at your option) any later version.
    6.12 + *
    6.13 + * This program is distributed in the hope that it will be useful,
    6.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    6.16 + * GNU General Public License for more details.
    6.17 + *
    6.18 + * You should have received a copy of the GNU General Public License
    6.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    6.20 + */
    6.21 +package cz.frantovo.alt2xml.vstup;
    6.22 +
    6.23 +import java.io.IOException;
    6.24 +import java.io.InputStreamReader;
    6.25 +import java.util.HashMap;
    6.26 +import java.util.Map;
    6.27 +import org.json.simple.parser.JSONParser;
    6.28 +import org.json.simple.parser.ParseException;
    6.29 +import org.xml.sax.ContentHandler;
    6.30 +import org.xml.sax.DTDHandler;
    6.31 +import org.xml.sax.EntityResolver;
    6.32 +import org.xml.sax.ErrorHandler;
    6.33 +import org.xml.sax.InputSource;
    6.34 +import org.xml.sax.SAXException;
    6.35 +import org.xml.sax.SAXNotRecognizedException;
    6.36 +import org.xml.sax.SAXNotSupportedException;
    6.37 +import org.xml.sax.XMLReader;
    6.38 +
    6.39 +/**
    6.40 + *
    6.41 + * @author fiki
    6.42 + */
    6.43 +public class JsonXMLReader implements XMLReader {
    6.44 +
    6.45 +	private ContentHandler contentHandler;
    6.46 +	private ErrorHandler errorHandler;
    6.47 +	private DTDHandler dtdHandler;
    6.48 +	private EntityResolver entityResolver;
    6.49 +	private Map<String, Object> konfigurace = new HashMap<>();
    6.50 +	
    6.51 +	@Override
    6.52 +	public void parse(InputSource input) throws IOException, SAXException {
    6.53 +		/**
    6.54 +		 * TODO: rozpornat formát vstupu a podle toho delegovat
    6.55 +		 */
    6.56 +		JSONParser p = new JSONParser();
    6.57 +		InputStreamReader vstup = new InputStreamReader(input.getByteStream());
    6.58 +		JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler);
    6.59 +
    6.60 +		try {
    6.61 +			p.parse(vstup, handler);
    6.62 +		} catch (ParseException e) {
    6.63 +			throw new SAXException("Chyba při načítání JSONu", e);
    6.64 +		}
    6.65 +	}
    6.66 +
    6.67 +	@Override
    6.68 +	public void parse(String systemId) throws IOException, SAXException {
    6.69 +		parse(new InputSource(systemId));
    6.70 +	}
    6.71 +
    6.72 +	@Override
    6.73 +	public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
    6.74 +		/**
    6.75 +		 * TODO: 
    6.76 +		 * All XMLReaders are required to recognize 
    6.77 +		 * the http://xml.org/sax/features/namespaces 
    6.78 +		 * and the http://xml.org/sax/features/namespace-prefixes feature names.
    6.79 +		 */
    6.80 +		throw new SAXNotSupportedException("Zatím není podporováno.");
    6.81 +	}
    6.82 +
    6.83 +	@Override
    6.84 +	public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
    6.85 +		throw new SAXNotSupportedException("Zatím není podporováno.");
    6.86 +	}
    6.87 +
    6.88 +	@Override
    6.89 +	public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
    6.90 +		return konfigurace.get(name);
    6.91 +	}
    6.92 +
    6.93 +	@Override
    6.94 +	public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
    6.95 +		konfigurace.put(name, value);
    6.96 +	}
    6.97 +
    6.98 +	@Override
    6.99 +	public void setEntityResolver(EntityResolver entityResolver) {
   6.100 +		this.entityResolver = entityResolver;
   6.101 +	}
   6.102 +
   6.103 +	@Override
   6.104 +	public EntityResolver getEntityResolver() {
   6.105 +		return entityResolver;
   6.106 +	}
   6.107 +
   6.108 +	@Override
   6.109 +	public void setDTDHandler(DTDHandler dtdHandler) {
   6.110 +		this.dtdHandler = dtdHandler;
   6.111 +	}
   6.112 +
   6.113 +	@Override
   6.114 +	public DTDHandler getDTDHandler() {
   6.115 +		return dtdHandler;
   6.116 +	}
   6.117 +
   6.118 +	@Override
   6.119 +	public void setContentHandler(ContentHandler contentHandler) {
   6.120 +		this.contentHandler = contentHandler;
   6.121 +	}
   6.122 +
   6.123 +	@Override
   6.124 +	public ContentHandler getContentHandler() {
   6.125 +		return contentHandler;
   6.126 +	}
   6.127 +
   6.128 +	@Override
   6.129 +	public void setErrorHandler(ErrorHandler errorHandler) {
   6.130 +		this.errorHandler = errorHandler;
   6.131 +	}
   6.132 +
   6.133 +	@Override
   6.134 +	public ErrorHandler getErrorHandler() {
   6.135 +		return errorHandler;
   6.136 +	}
   6.137 +}
     7.1 --- a/java/alt2xml-in-json/src/cz/frantovo/alt2xml/vstup/SuperReader.java	Thu Jun 05 15:03:50 2014 +0200
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,117 +0,0 @@
     7.4 -package cz.frantovo.alt2xml.vstup;
     7.5 -
     7.6 -import java.io.IOException;
     7.7 -import java.io.InputStreamReader;
     7.8 -import java.util.HashMap;
     7.9 -import java.util.Map;
    7.10 -import org.json.simple.parser.JSONParser;
    7.11 -import org.json.simple.parser.ParseException;
    7.12 -import org.xml.sax.ContentHandler;
    7.13 -import org.xml.sax.DTDHandler;
    7.14 -import org.xml.sax.EntityResolver;
    7.15 -import org.xml.sax.ErrorHandler;
    7.16 -import org.xml.sax.InputSource;
    7.17 -import org.xml.sax.SAXException;
    7.18 -import org.xml.sax.SAXNotRecognizedException;
    7.19 -import org.xml.sax.SAXNotSupportedException;
    7.20 -import org.xml.sax.XMLReader;
    7.21 -
    7.22 -/**
    7.23 - *
    7.24 - * @author fiki
    7.25 - */
    7.26 -public class SuperReader implements XMLReader {
    7.27 -
    7.28 -	private ContentHandler contentHandler;
    7.29 -	private ErrorHandler errorHandler;
    7.30 -	private DTDHandler dtdHandler;
    7.31 -	private EntityResolver entityResolver;
    7.32 -	private Map<String, Object> konfigurace = new HashMap<>();
    7.33 -	
    7.34 -	@Override
    7.35 -	public void parse(InputSource input) throws IOException, SAXException {
    7.36 -		/**
    7.37 -		 * TODO: rozpornat formát vstupu a podle toho delegovat
    7.38 -		 */
    7.39 -		JSONParser p = new JSONParser();
    7.40 -		InputStreamReader vstup = new InputStreamReader(input.getByteStream());
    7.41 -		JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler);
    7.42 -
    7.43 -		try {
    7.44 -			p.parse(vstup, handler);
    7.45 -		} catch (ParseException e) {
    7.46 -			throw new SAXException("Chyba při načítání JSONu", e);
    7.47 -		}
    7.48 -	}
    7.49 -
    7.50 -	@Override
    7.51 -	public void parse(String systemId) throws IOException, SAXException {
    7.52 -		parse(new InputSource(systemId));
    7.53 -	}
    7.54 -
    7.55 -	@Override
    7.56 -	public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
    7.57 -		/**
    7.58 -		 * TODO: 
    7.59 -		 * All XMLReaders are required to recognize 
    7.60 -		 * the http://xml.org/sax/features/namespaces 
    7.61 -		 * and the http://xml.org/sax/features/namespace-prefixes feature names.
    7.62 -		 */
    7.63 -		throw new SAXNotSupportedException("Zatím není podporováno.");
    7.64 -	}
    7.65 -
    7.66 -	@Override
    7.67 -	public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
    7.68 -		throw new SAXNotSupportedException("Zatím není podporováno.");
    7.69 -	}
    7.70 -
    7.71 -	@Override
    7.72 -	public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
    7.73 -		return konfigurace.get(name);
    7.74 -	}
    7.75 -
    7.76 -	@Override
    7.77 -	public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
    7.78 -		konfigurace.put(name, value);
    7.79 -	}
    7.80 -
    7.81 -	@Override
    7.82 -	public void setEntityResolver(EntityResolver entityResolver) {
    7.83 -		this.entityResolver = entityResolver;
    7.84 -	}
    7.85 -
    7.86 -	@Override
    7.87 -	public EntityResolver getEntityResolver() {
    7.88 -		return entityResolver;
    7.89 -	}
    7.90 -
    7.91 -	@Override
    7.92 -	public void setDTDHandler(DTDHandler dtdHandler) {
    7.93 -		this.dtdHandler = dtdHandler;
    7.94 -	}
    7.95 -
    7.96 -	@Override
    7.97 -	public DTDHandler getDTDHandler() {
    7.98 -		return dtdHandler;
    7.99 -	}
   7.100 -
   7.101 -	@Override
   7.102 -	public void setContentHandler(ContentHandler contentHandler) {
   7.103 -		this.contentHandler = contentHandler;
   7.104 -	}
   7.105 -
   7.106 -	@Override
   7.107 -	public ContentHandler getContentHandler() {
   7.108 -		return contentHandler;
   7.109 -	}
   7.110 -
   7.111 -	@Override
   7.112 -	public void setErrorHandler(ErrorHandler errorHandler) {
   7.113 -		this.errorHandler = errorHandler;
   7.114 -	}
   7.115 -
   7.116 -	@Override
   7.117 -	public ErrorHandler getErrorHandler() {
   7.118 -		return errorHandler;
   7.119 -	}
   7.120 -}