franta-hg@11: /** franta-hg@11: * Alt2XML franta-hg@11: * Copyright © 2014 František Kučera (frantovo.cz) franta-hg@11: * franta-hg@11: * This program is free software: you can redistribute it and/or modify franta-hg@11: * it under the terms of the GNU General Public License as published by franta-hg@11: * the Free Software Foundation, either version 3 of the License, or franta-hg@11: * (at your option) any later version. franta-hg@11: * franta-hg@11: * This program is distributed in the hope that it will be useful, franta-hg@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of franta-hg@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the franta-hg@11: * GNU General Public License for more details. franta-hg@11: * franta-hg@11: * You should have received a copy of the GNU General Public License franta-hg@11: * along with this program. If not, see . franta-hg@11: */ franta-hg@14: package cz.frantovo.alt2xml.in.json; franta-hg@2: franta-hg@17: import cz.frantovo.alt2xml.AbstractAlt2XmlReader; franta-hg@2: import java.io.IOException; franta-hg@2: import java.io.InputStreamReader; franta-hg@2: import org.json.simple.parser.JSONParser; franta-hg@2: import org.json.simple.parser.ParseException; franta-hg@2: import org.xml.sax.InputSource; franta-hg@2: import org.xml.sax.SAXException; franta-hg@2: franta-hg@2: /** franta-hg@2: * franta-hg@17: * @author Ing. František Kučera (frantovo.cz) franta-hg@2: */ franta-hg@17: public class Reader extends AbstractAlt2XmlReader { franta-hg@13: franta-hg@2: @Override franta-hg@6: public void parse(InputSource input) throws IOException, SAXException { franta-hg@6: JSONParser p = new JSONParser(); franta-hg@6: InputStreamReader vstup = new InputStreamReader(input.getByteStream()); franta-hg@6: JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler); franta-hg@6: franta-hg@6: try { franta-hg@6: p.parse(vstup, handler); franta-hg@6: } catch (ParseException e) { franta-hg@17: throw new SAXException("Unable to parse JSON: " + input.getSystemId(), e); franta-hg@6: } franta-hg@6: } franta-hg@2: }