java/alt2xml-in-json/src/cz/frantovo/alt2xml/in/json/Reader.java
author František Kučera <franta-hg@frantovo.cz>
Sat, 14 Jun 2014 22:54:26 +0200
changeset 41 efc293b2082c
parent 17 64358dd0999f
child 111 e4900596abdb
permissions -rw-r--r--
optimalizace .hgignore – regulární výrazy
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@11
     7
 * the Free Software Foundation, either version 3 of the License, or
franta-hg@11
     8
 * (at your option) any later version.
franta-hg@11
     9
 *
franta-hg@11
    10
 * This program is distributed in the hope that it will be useful,
franta-hg@11
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@11
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@11
    13
 * GNU General Public License for more details.
franta-hg@11
    14
 *
franta-hg@11
    15
 * You should have received a copy of the GNU General Public License
franta-hg@11
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@11
    17
 */
franta-hg@14
    18
package cz.frantovo.alt2xml.in.json;
franta-hg@2
    19
franta-hg@17
    20
import cz.frantovo.alt2xml.AbstractAlt2XmlReader;
franta-hg@2
    21
import java.io.IOException;
franta-hg@2
    22
import java.io.InputStreamReader;
franta-hg@2
    23
import org.json.simple.parser.JSONParser;
franta-hg@2
    24
import org.json.simple.parser.ParseException;
franta-hg@2
    25
import org.xml.sax.InputSource;
franta-hg@2
    26
import org.xml.sax.SAXException;
franta-hg@2
    27
franta-hg@2
    28
/**
franta-hg@2
    29
 *
franta-hg@17
    30
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@2
    31
 */
franta-hg@17
    32
public class Reader extends AbstractAlt2XmlReader {
franta-hg@13
    33
franta-hg@2
    34
	@Override
franta-hg@6
    35
	public void parse(InputSource input) throws IOException, SAXException {
franta-hg@6
    36
		JSONParser p = new JSONParser();
franta-hg@6
    37
		InputStreamReader vstup = new InputStreamReader(input.getByteStream());
franta-hg@6
    38
		JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler);
franta-hg@6
    39
franta-hg@6
    40
		try {
franta-hg@6
    41
			p.parse(vstup, handler);
franta-hg@6
    42
		} catch (ParseException e) {
franta-hg@17
    43
			throw new SAXException("Unable to parse JSON: " + input.getSystemId(), e);
franta-hg@6
    44
		}
franta-hg@6
    45
	}
franta-hg@2
    46
}