Search in sources :

Example 1 with XMLReader

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

the class XmlParser method parse.

/* ------------------------------------------------------------ */
/**
     * Parse InputStream.
     * @param in the input stream of the xml to parse
     * @return the root node of the xml
     * @throws IOException if unable to load the xml
     * @throws SAXException if unable to parse the xml
     */
public synchronized Node parse(InputStream in) throws IOException, SAXException {
    _dtd = null;
    Handler handler = new Handler();
    XMLReader reader = _parser.getXMLReader();
    reader.setContentHandler(handler);
    reader.setErrorHandler(handler);
    reader.setEntityResolver(handler);
    _parser.parse(new InputSource(in), handler);
    if (handler._error != null)
        throw handler._error;
    Node doc = (Node) handler._top.get(0);
    handler.clear();
    return doc;
}
Also used : InputSource(org.xml.sax.InputSource) ContentHandler(org.xml.sax.ContentHandler) DefaultHandler(org.xml.sax.helpers.DefaultHandler) XMLReader(org.xml.sax.XMLReader)

Example 2 with XMLReader

use of org.xml.sax.XMLReader in project jmonkeyengine by jMonkeyEngine.

the class SceneMaterialLoader method load.

public MaterialList load(AssetManager assetManager, String folderName, InputStream in) throws IOException {
    try {
        this.assetManager = assetManager;
        this.folderName = folderName;
        reset();
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XMLReader xr = factory.newSAXParser().getXMLReader();
        xr.setContentHandler(this);
        xr.setErrorHandler(this);
        InputStreamReader r = null;
        try {
            r = new InputStreamReader(in);
            xr.parse(new InputSource(r));
        } finally {
            if (r != null) {
                r.close();
            }
        }
        return materialList;
    } catch (SAXException ex) {
        IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
        ioEx.initCause(ex);
        throw ioEx;
    } catch (ParserConfigurationException ex) {
        IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
        ioEx.initCause(ex);
        throw ioEx;
    }
}
Also used : InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 3 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 4 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 5 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)

Aggregations

XMLReader (org.xml.sax.XMLReader)441 InputSource (org.xml.sax.InputSource)317 SAXException (org.xml.sax.SAXException)178 IOException (java.io.IOException)164 SAXParserFactory (javax.xml.parsers.SAXParserFactory)103 SAXParser (javax.xml.parsers.SAXParser)89 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)80 SAXSource (javax.xml.transform.sax.SAXSource)79 StringReader (java.io.StringReader)69 InputStream (java.io.InputStream)61 ByteArrayInputStream (java.io.ByteArrayInputStream)33 TransformerException (javax.xml.transform.TransformerException)33 ContentHandler (org.xml.sax.ContentHandler)33 SAXParseException (org.xml.sax.SAXParseException)30 URL (java.net.URL)24 ExpatReader (org.apache.harmony.xml.ExpatReader)24 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)23 StreamSource (javax.xml.transform.stream.StreamSource)23 Source (javax.xml.transform.Source)21 InputStreamReader (java.io.InputStreamReader)20