Search in sources :

Example 31 with XMLReader

use of org.xml.sax.XMLReader in project OpenNotebook by jaltekruse.

the class OldReader method readFile.

public Document readFile(InputStreamReader file) throws SAXException, IOException {
    attributeNameInError = null;
    attributeValueInError = null;
    objectWithError = null;
    XMLReader reader = XMLReaderFactory.createXMLReader();
    reader.setContentHandler(this);
    reader.setErrorHandler(this);
    reader.parse(new InputSource(file));
    if (doc == null) {
        if (DEBUG) {
            System.out.println("error 1");
        }
        throw new IOException("improper document format");
    }
    if (hadAttributeError) {
        if (DEBUG) {
            System.out.println("error 2");
        }
        throw new IOException("improper document format, error with attribute '" + attributeNameInError + "' with a value of '" + attributeValueInError + "'" + " in object '" + objectWithError + "'");
    }
    return doc;
}
Also used : InputSource(org.xml.sax.InputSource) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader)

Example 32 with XMLReader

use of org.xml.sax.XMLReader in project hadoop by apache.

the class OfflineEditsXmlLoader method loadEdits.

/**
   * Loads edits file, uses visitor to process all elements
   */
@Override
public void loadEdits() throws IOException {
    try {
        XMLReader xr = XMLReaderFactory.createXMLReader();
        xr.setContentHandler(this);
        xr.setErrorHandler(this);
        xr.setDTDHandler(null);
        xr.parse(new InputSource(fileReader));
        visitor.close(null);
    } catch (SAXParseException e) {
        System.out.println("XML parsing error: " + "\n" + "Line:    " + e.getLineNumber() + "\n" + "URI:     " + e.getSystemId() + "\n" + "Message: " + e.getMessage());
        visitor.close(e);
        throw new IOException(e.toString());
    } catch (SAXException e) {
        visitor.close(e);
        throw new IOException(e.toString());
    } catch (RuntimeException e) {
        visitor.close(e);
        throw e;
    } finally {
        fileReader.close();
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAXParseException(org.xml.sax.SAXParseException) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader) SAXException(org.xml.sax.SAXException)

Example 33 with XMLReader

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

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 34 with XMLReader

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

the class Xml method parse.

/**
     * Parses the given xml string and fires events on the given SAX handler.
     */
public static void parse(String xml, ContentHandler contentHandler) throws SAXException {
    try {
        XMLReader reader = new ExpatReader();
        reader.setContentHandler(contentHandler);
        reader.parse(new InputSource(new StringReader(xml)));
    } catch (IOException e) {
        throw new AssertionError(e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) ExpatReader(org.apache.harmony.xml.ExpatReader) StringReader(java.io.StringReader) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader)

Example 35 with XMLReader

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

the class LevelLoader method loadLevelFromStream.

public void loadLevelFromStream(final InputStream pInputStream) throws IOException {
    try {
        final SAXParserFactory spf = SAXParserFactory.newInstance();
        final SAXParser sp = spf.newSAXParser();
        final XMLReader xr = sp.getXMLReader();
        this.onBeforeLoadLevel();
        final LevelParser levelParser = new LevelParser(this.mDefaultEntityLoader, this.mEntityLoaders);
        xr.setContentHandler(levelParser);
        xr.parse(new InputSource(new BufferedInputStream(pInputStream)));
        this.onAfterLoadLevel();
    } catch (final SAXException se) {
        Debug.e(se);
    /* Doesn't happen. */
    } catch (final ParserConfigurationException pe) {
        Debug.e(pe);
    /* Doesn't happen. */
    } finally {
        StreamUtils.close(pInputStream);
    }
}
Also used : InputSource(org.xml.sax.InputSource) BufferedInputStream(java.io.BufferedInputStream) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory) 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