Search in sources :

Example 11 with XMLReaderPool

use of org.exist.util.XMLReaderPool in project exist by eXist-db.

the class Utils method nodeFromString.

public static NodeImpl nodeFromString(XQueryContext context, String source) throws IOException {
    SAXAdapter adapter = new SAXAdapter(context);
    final XMLReaderPool parserPool = context.getBroker().getBrokerPool().getParserPool();
    XMLReader xr = null;
    try {
        try {
            xr = parserPool.borrowXMLReader();
            xr.setContentHandler(adapter);
            xr.setProperty(Namespaces.SAX_LEXICAL_HANDLER, adapter);
        } catch (Exception e) {
            throw new IOException(e);
        }
        try {
            InputSource src = new InputSource(new StringReader(source));
            xr.parse(src);
            return (NodeImpl) adapter.getDocument();
        } catch (SAXException e) {
            throw new IOException(e);
        }
    } finally {
        if (xr != null) {
            parserPool.returnXMLReader(xr);
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) NodeImpl(org.exist.dom.memtree.NodeImpl) StringReader(java.io.StringReader) SAXAdapter(org.exist.dom.memtree.SAXAdapter) IOException(java.io.IOException) XMLReaderPool(org.exist.util.XMLReaderPool) XMLReader(org.xml.sax.XMLReader) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

XMLReaderPool (org.exist.util.XMLReaderPool)11 XMLReader (org.xml.sax.XMLReader)10 InputSource (org.xml.sax.InputSource)8 IOException (java.io.IOException)7 SAXAdapter (org.exist.dom.memtree.SAXAdapter)6 SAXException (org.xml.sax.SAXException)4 StringReader (java.io.StringReader)3 InputStream (java.io.InputStream)2 EXistInputSource (org.exist.util.EXistInputSource)2 BufferedInputStream (java.io.BufferedInputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1 SQLRecoverableException (java.sql.SQLRecoverableException)1 SQLXML (java.sql.SQLXML)1