Search in sources :

Example 1 with OsmXmlHandler

use of uk.me.parabola.mkgmap.reader.osm.xml.OsmXmlHandler in project mkgmap by openstreetmap.

the class StyleTester method runTest.

private static void runTest(String stylefile, String mapfile) {
    PrintingMapCollector collector = new PrintingMapCollector();
    OsmConverter normal;
    try {
        normal = new StyleTester(stylefile, collector, reference);
    } catch (FileNotFoundException e) {
        System.err.println("Could not open style file " + stylefile);
        return;
    }
    try {
        InputStream is = Utils.openFile(mapfile);
        SAXParserFactory parserFactory = SAXParserFactory.newInstance();
        parserFactory.setXIncludeAware(true);
        parserFactory.setNamespaceAware(true);
        SAXParser parser = parserFactory.newSAXParser();
        try {
            EnhancedProperties props = new EnhancedProperties();
            props.put("preserve-element-order", "1");
            ElementSaver saver = new ElementSaver(props);
            OsmXmlHandler handler = new OsmXmlHandler();
            SaxHandler saxHandler = handler.new SaxHandler();
            handler.setElementSaver(saver);
            parser.parse(is, saxHandler);
            saver.finishLoading();
            saver.convert(normal);
            System.err.println("Conversion time " + (System.currentTimeMillis() - collector.getStart()) + "ms");
        } catch (IOException e) {
            throw new FormatException("Error reading file", e);
        }
    } catch (SAXException e) {
        throw new FormatException("Error parsing file", e);
    } catch (ParserConfigurationException e) {
        throw new FormatException("Internal error configuring xml parser", e);
    } catch (FileNotFoundException e) {
        System.err.println("Cannot open file " + mapfile);
    }
}
Also used : InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) SaxHandler(uk.me.parabola.mkgmap.reader.osm.xml.OsmXmlHandler.SaxHandler) FormatException(uk.me.parabola.imgfmt.FormatException) SAXException(org.xml.sax.SAXException) EnhancedProperties(uk.me.parabola.util.EnhancedProperties) ElementSaver(uk.me.parabola.mkgmap.reader.osm.ElementSaver) SAXParser(javax.xml.parsers.SAXParser) OsmConverter(uk.me.parabola.mkgmap.reader.osm.OsmConverter) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) OsmXmlHandler(uk.me.parabola.mkgmap.reader.osm.xml.OsmXmlHandler) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXParser (javax.xml.parsers.SAXParser)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 SAXException (org.xml.sax.SAXException)1 FormatException (uk.me.parabola.imgfmt.FormatException)1 ElementSaver (uk.me.parabola.mkgmap.reader.osm.ElementSaver)1 OsmConverter (uk.me.parabola.mkgmap.reader.osm.OsmConverter)1 OsmXmlHandler (uk.me.parabola.mkgmap.reader.osm.xml.OsmXmlHandler)1 SaxHandler (uk.me.parabola.mkgmap.reader.osm.xml.OsmXmlHandler.SaxHandler)1 EnhancedProperties (uk.me.parabola.util.EnhancedProperties)1