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