java/alt2xml-in-json/src/cz/frantovo/alt2xml/in/json/Reader.java
author František Kučera <franta-hg@frantovo.cz>
Thu, 24 Oct 2019 21:56:03 +0200
changeset 111 e4900596abdb
parent 17 64358dd0999f
permissions -rw-r--r--
fix license version: GNU GPLv3
franta-hg@11
     1
/**
franta-hg@11
     2
 * Alt2XML
franta-hg@11
     3
 * Copyright © 2014 František Kučera (frantovo.cz)
franta-hg@11
     4
 *
franta-hg@11
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@11
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@111
     7
 * the Free Software Foundation, version 3 of the License.
franta-hg@11
     8
 *
franta-hg@11
     9
 * This program is distributed in the hope that it will be useful,
franta-hg@11
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@11
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@11
    12
 * GNU General Public License for more details.
franta-hg@11
    13
 *
franta-hg@11
    14
 * You should have received a copy of the GNU General Public License
franta-hg@11
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@11
    16
 */
franta-hg@14
    17
package cz.frantovo.alt2xml.in.json;
franta-hg@2
    18
franta-hg@17
    19
import cz.frantovo.alt2xml.AbstractAlt2XmlReader;
franta-hg@2
    20
import java.io.IOException;
franta-hg@2
    21
import java.io.InputStreamReader;
franta-hg@2
    22
import org.json.simple.parser.JSONParser;
franta-hg@2
    23
import org.json.simple.parser.ParseException;
franta-hg@2
    24
import org.xml.sax.InputSource;
franta-hg@2
    25
import org.xml.sax.SAXException;
franta-hg@2
    26
franta-hg@2
    27
/**
franta-hg@2
    28
 *
franta-hg@17
    29
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@2
    30
 */
franta-hg@17
    31
public class Reader extends AbstractAlt2XmlReader {
franta-hg@13
    32
franta-hg@2
    33
	@Override
franta-hg@6
    34
	public void parse(InputSource input) throws IOException, SAXException {
franta-hg@6
    35
		JSONParser p = new JSONParser();
franta-hg@6
    36
		InputStreamReader vstup = new InputStreamReader(input.getByteStream());
franta-hg@6
    37
		JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler);
franta-hg@6
    38
franta-hg@6
    39
		try {
franta-hg@6
    40
			p.parse(vstup, handler);
franta-hg@6
    41
		} catch (ParseException e) {
franta-hg@17
    42
			throw new SAXException("Unable to parse JSON: " + input.getSystemId(), e);
franta-hg@6
    43
		}
franta-hg@6
    44
	}
franta-hg@2
    45
}