Search in sources :

Example 11 with SAXParser

use of javax.xml.parsers.SAXParser in project AndEngine by nicolasgramlich.

the class AnimationPackLoader method load.

public AnimationPack load(final InputStream pInputStream, final String pAssetBasePath) throws AnimationPackParseException {
    try {
        final SAXParserFactory spf = SAXParserFactory.newInstance();
        final SAXParser sp = spf.newSAXParser();
        final XMLReader xr = sp.getXMLReader();
        final AnimationPackParser animationPackParser = new AnimationPackParser(this.mAssetManager, pAssetBasePath, this.mTextureManager);
        xr.setContentHandler(animationPackParser);
        xr.parse(new InputSource(new BufferedInputStream(pInputStream)));
        return animationPackParser.getAnimationPack();
    } catch (final SAXException e) {
        throw new AnimationPackParseException(e);
    } catch (final ParserConfigurationException pe) {
        /* Doesn't happen. */
        return null;
    } catch (final IOException e) {
        throw new AnimationPackParseException(e);
    } finally {
        StreamUtils.close(pInputStream);
    }
}
Also used : InputSource(org.xml.sax.InputSource) BufferedInputStream(java.io.BufferedInputStream) AnimationPackParseException(org.andengine.util.animationpack.exception.AnimationPackParseException) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 12 with SAXParser

use of javax.xml.parsers.SAXParser in project orientdb by orientechnologies.

the class StopSAXParser method parse.

/**
   * @param is
   *          - xml file to be validated
   * @param handler
   * @return handler for chained calls
   * @throws ParserConfigurationException
   * @throws SAXException
   * @throws IOException
   */
protected static <T extends DefaultHandler> T parse(InputStream is, T handler) throws ParserConfigurationException, SAXException, IOException {
    try {
        SAXParser parser = parserFactory.newSAXParser();
        parser.parse(is, handler);
    } catch (StopSAXParser e) {
    // This is not really an exception, but a way to work out which
    // version of the persistence schema to use in validation
    }
    return handler;
}
Also used : SAXParser(javax.xml.parsers.SAXParser)

Example 13 with SAXParser

use of javax.xml.parsers.SAXParser in project jforum2 by rafaelsteil.

the class BBCodeHandler method parse.

public BBCodeHandler parse() {
    try {
        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
        BBCodeHandler bbParser = new BBCodeHandler();
        String path = SystemGlobals.getValue(ConfigKeys.CONFIG_DIR) + "/bb_config.xml";
        File fileInput = new File(path);
        if (fileInput.exists()) {
            parser.parse(fileInput, bbParser);
        } else {
            InputSource input = new InputSource(path);
            parser.parse(input, bbParser);
        }
        return bbParser;
    } catch (Exception e) {
        throw new ForumException(e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) ForumException(net.jforum.exceptions.ForumException) SAXParser(javax.xml.parsers.SAXParser) File(java.io.File) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException) ForumException(net.jforum.exceptions.ForumException)

Example 14 with SAXParser

use of javax.xml.parsers.SAXParser in project jforum2 by rafaelsteil.

the class ConfigLoader method getConfig.

public ClickstreamConfig getConfig() {
    if (this.config != null) {
        return this.config;
    }
    synchronized (instance) {
        this.config = new ClickstreamConfig();
        try {
            SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
            String path = SystemGlobals.getValue(ConfigKeys.CLICKSTREAM_CONFIG);
            if (path != null) {
                if (log.isInfoEnabled()) {
                    log.info("Loading clickstream config from " + path);
                }
                File fileInput = new File(path);
                if (fileInput.exists()) {
                    parser.parse(fileInput, new ConfigHandler());
                } else {
                    parser.parse(new InputSource(path), new ConfigHandler());
                }
            }
            return config;
        } catch (SAXException e) {
            log.error("Could not parse clickstream XML", e);
            throw new RuntimeException(e.getMessage());
        } catch (IOException e) {
            log.error("Could not read clickstream config from stream", e);
            throw new RuntimeException(e.getMessage());
        } catch (ParserConfigurationException e) {
            log.fatal("Could not obtain SAX parser", e);
            throw new RuntimeException(e.getMessage());
        } catch (RuntimeException e) {
            log.fatal("RuntimeException", e);
            throw e;
        } catch (Throwable e) {
            log.fatal("Exception", e);
            throw new RuntimeException(e.getMessage());
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAXParser(javax.xml.parsers.SAXParser) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) SAXException(org.xml.sax.SAXException)

Example 15 with SAXParser

use of javax.xml.parsers.SAXParser in project robovm by robovm.

the class SimpleParserTest method testWorkingFile1.

public void testWorkingFile1() throws Exception {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(false);
    factory.setNamespaceAware(true);
    SAXParser parser = factory.newSAXParser();
    parser.getXMLReader().setContentHandler(contentHandler);
    parser.parse(getClass().getResourceAsStream("/SimpleParserTest.xml"), (DefaultHandler) null);
    assertEquals("The:quick,brown:fox", instructions.toString());
    assertEquals("stuff,nestedStuff,nestedStuff,nestedStuff", elements1.toString());
    assertEquals("Some text here,some more here...", text.toString());
    assertEquals("eins", attributes1.get("one"));
    assertEquals("zwei", attributes1.get("two"));
    assertEquals("drei", attributes1.get("three"));
    assertEquals("http://www.foobar.org", namespaces1.get("stuff"));
}
Also used : SAXParser(javax.xml.parsers.SAXParser) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

SAXParser (javax.xml.parsers.SAXParser)235 SAXParserFactory (javax.xml.parsers.SAXParserFactory)142 SAXException (org.xml.sax.SAXException)112 InputSource (org.xml.sax.InputSource)95 IOException (java.io.IOException)80 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)71 DefaultHandler (org.xml.sax.helpers.DefaultHandler)37 XMLReader (org.xml.sax.XMLReader)36 File (java.io.File)35 ByteArrayInputStream (java.io.ByteArrayInputStream)28 StringReader (java.io.StringReader)27 InputStream (java.io.InputStream)24 Attributes (org.xml.sax.Attributes)22 SAXSource (javax.xml.transform.sax.SAXSource)17 SAXParseException (org.xml.sax.SAXParseException)17 ArrayList (java.util.ArrayList)13 JAXBContext (javax.xml.bind.JAXBContext)12 Unmarshaller (javax.xml.bind.Unmarshaller)12 FileNotFoundException (java.io.FileNotFoundException)10 ValidationEvent (javax.xml.bind.ValidationEvent)9