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;
}
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;
}
}
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();
}
}
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);
}
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);
}
}
Aggregations