Search in sources :

Example 36 with XMLReader

use of org.xml.sax.XMLReader in project AndEngine by nicolasgramlich.

the class TexturePackLoader method load.

public TexturePack load(final InputStream pInputStream, final String pAssetBasePath) throws TexturePackParseException {
    try {
        final SAXParserFactory spf = SAXParserFactory.newInstance();
        final SAXParser sp = spf.newSAXParser();
        final XMLReader xr = sp.getXMLReader();
        final TexturePackParser texturePackParser = new TexturePackParser(this.mAssetManager, pAssetBasePath, this.mTextureManager);
        xr.setContentHandler(texturePackParser);
        xr.parse(new InputSource(new BufferedInputStream(pInputStream)));
        return texturePackParser.getTexturePack();
    } catch (final SAXException e) {
        throw new TexturePackParseException(e);
    } catch (final ParserConfigurationException pe) {
        /* Doesn't happen. */
        return null;
    } catch (final IOException e) {
        throw new TexturePackParseException(e);
    } finally {
        StreamUtils.close(pInputStream);
    }
}
Also used : InputSource(org.xml.sax.InputSource) BufferedInputStream(java.io.BufferedInputStream) SAXParser(javax.xml.parsers.SAXParser) TexturePackParseException(org.andengine.util.texturepack.exception.TexturePackParseException) 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 37 with XMLReader

use of org.xml.sax.XMLReader 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 38 with XMLReader

use of org.xml.sax.XMLReader in project che by eclipse.

the class RefactoringSessionReader method createParser.

/**
	 * Creates a new parser from the specified factory.
	 *
	 * @param factory
	 *            the parser factoring to use
	 * @return the created parser
	 * @throws ParserConfigurationException
	 *             if no parser is available with the given configuration
	 * @throws SAXException
	 *             if an error occurs while creating the parser
	 */
private SAXParser createParser(final SAXParserFactory factory) throws ParserConfigurationException, SAXException {
    final SAXParser parser = factory.newSAXParser();
    final XMLReader reader = parser.getXMLReader();
    try {
        //$NON-NLS-1$
        reader.setFeature("http://xml.org/sax/features/validation", false);
        //$NON-NLS-1$
        reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    } catch (SAXNotRecognizedException exception) {
    // Do nothing
    } catch (SAXNotSupportedException exception) {
    // Do nothing
    }
    return parser;
}
Also used : SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXParser(javax.xml.parsers.SAXParser) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) XMLReader(org.xml.sax.XMLReader)

Example 39 with XMLReader

use of org.xml.sax.XMLReader in project android_frameworks_base by ResurrectionRemix.

the class Xml method parse.

/**
     * Parses xml from the given input stream and fires events on the given SAX
     * handler.
     */
public static void parse(InputStream in, Encoding encoding, ContentHandler contentHandler) throws IOException, SAXException {
    XMLReader reader = new ExpatReader();
    reader.setContentHandler(contentHandler);
    InputSource source = new InputSource(in);
    source.setEncoding(encoding.expatName);
    reader.parse(source);
}
Also used : InputSource(org.xml.sax.InputSource) ExpatReader(org.apache.harmony.xml.ExpatReader) XMLReader(org.xml.sax.XMLReader)

Example 40 with XMLReader

use of org.xml.sax.XMLReader in project intellij-community by JetBrains.

the class UnsupportedFeaturesUtil method fillTestCaseMethods.

private static void fillTestCaseMethods() throws IOException {
    final Logger log = Logger.getInstance(UnsupportedFeaturesUtil.class.getName());
    final FileReader reader = new FileReader(PythonHelpersLocator.getHelperPath("/tools/class_method_versions.xml"));
    try {
        final XMLReader xr = XMLReaderFactory.createXMLReader();
        final ClassMethodsParser parser = new ClassMethodsParser();
        xr.setContentHandler(parser);
        xr.parse(new InputSource(reader));
    } catch (SAXException e) {
        log.error("Improperly formed \"class_method_versions.xml\". " + e.getMessage());
    } finally {
        reader.close();
    }
}
Also used : InputSource(org.xml.sax.InputSource) FileReader(java.io.FileReader) Logger(com.intellij.openapi.diagnostic.Logger) XMLReader(org.xml.sax.XMLReader) SAXException(org.xml.sax.SAXException)

Aggregations

XMLReader (org.xml.sax.XMLReader)234 InputSource (org.xml.sax.InputSource)186 SAXException (org.xml.sax.SAXException)82 IOException (java.io.IOException)75 SAXParserFactory (javax.xml.parsers.SAXParserFactory)51 SAXSource (javax.xml.transform.sax.SAXSource)48 SAXParser (javax.xml.parsers.SAXParser)42 StringReader (java.io.StringReader)37 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)35 InputStream (java.io.InputStream)28 ExpatReader (org.apache.harmony.xml.ExpatReader)24 ContentHandler (org.xml.sax.ContentHandler)20 TransformerException (javax.xml.transform.TransformerException)19 DOMSource (javax.xml.transform.dom.DOMSource)18 StreamSource (javax.xml.transform.stream.StreamSource)17 ByteArrayInputStream (java.io.ByteArrayInputStream)16 FileReader (java.io.FileReader)16 InputStreamReader (java.io.InputStreamReader)12 SAXParseException (org.xml.sax.SAXParseException)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10