use of javax.xml.parsers.SAXParser in project AndEngine by nicolasgramlich.
the class AnimationPackLoader method load.
public AnimationPack load(final InputStream pInputStream, final String pAssetBasePath) throws AnimationPackParseException {
try {
final SAXParserFactory spf = SAXParserFactory.newInstance();
final SAXParser sp = spf.newSAXParser();
final XMLReader xr = sp.getXMLReader();
final AnimationPackParser animationPackParser = new AnimationPackParser(this.mAssetManager, pAssetBasePath, this.mTextureManager);
xr.setContentHandler(animationPackParser);
xr.parse(new InputSource(new BufferedInputStream(pInputStream)));
return animationPackParser.getAnimationPack();
} catch (final SAXException e) {
throw new AnimationPackParseException(e);
} catch (final ParserConfigurationException pe) {
/* Doesn't happen. */
return null;
} catch (final IOException e) {
throw new AnimationPackParseException(e);
} finally {
StreamUtils.close(pInputStream);
}
}
use of javax.xml.parsers.SAXParser in project orientdb by orientechnologies.
the class StopSAXParser method parse.
/**
* @param is
* - xml file to be validated
* @param handler
* @return handler for chained calls
* @throws ParserConfigurationException
* @throws SAXException
* @throws IOException
*/
protected static <T extends DefaultHandler> T parse(InputStream is, T handler) throws ParserConfigurationException, SAXException, IOException {
try {
SAXParser parser = parserFactory.newSAXParser();
parser.parse(is, handler);
} catch (StopSAXParser e) {
// This is not really an exception, but a way to work out which
// version of the persistence schema to use in validation
}
return handler;
}
use of javax.xml.parsers.SAXParser in project jforum2 by rafaelsteil.
the class BBCodeHandler method parse.
public BBCodeHandler parse() {
try {
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
BBCodeHandler bbParser = new BBCodeHandler();
String path = SystemGlobals.getValue(ConfigKeys.CONFIG_DIR) + "/bb_config.xml";
File fileInput = new File(path);
if (fileInput.exists()) {
parser.parse(fileInput, bbParser);
} else {
InputSource input = new InputSource(path);
parser.parse(input, bbParser);
}
return bbParser;
} catch (Exception e) {
throw new ForumException(e);
}
}
use of javax.xml.parsers.SAXParser in project jforum2 by rafaelsteil.
the class ConfigLoader method getConfig.
public ClickstreamConfig getConfig() {
if (this.config != null) {
return this.config;
}
synchronized (instance) {
this.config = new ClickstreamConfig();
try {
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
String path = SystemGlobals.getValue(ConfigKeys.CLICKSTREAM_CONFIG);
if (path != null) {
if (log.isInfoEnabled()) {
log.info("Loading clickstream config from " + path);
}
File fileInput = new File(path);
if (fileInput.exists()) {
parser.parse(fileInput, new ConfigHandler());
} else {
parser.parse(new InputSource(path), new ConfigHandler());
}
}
return config;
} catch (SAXException e) {
log.error("Could not parse clickstream XML", e);
throw new RuntimeException(e.getMessage());
} catch (IOException e) {
log.error("Could not read clickstream config from stream", e);
throw new RuntimeException(e.getMessage());
} catch (ParserConfigurationException e) {
log.fatal("Could not obtain SAX parser", e);
throw new RuntimeException(e.getMessage());
} catch (RuntimeException e) {
log.fatal("RuntimeException", e);
throw e;
} catch (Throwable e) {
log.fatal("Exception", e);
throw new RuntimeException(e.getMessage());
}
}
}
use of javax.xml.parsers.SAXParser in project robovm by robovm.
the class SimpleParserTest method testWorkingFile1.
public void testWorkingFile1() throws Exception {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(true);
SAXParser parser = factory.newSAXParser();
parser.getXMLReader().setContentHandler(contentHandler);
parser.parse(getClass().getResourceAsStream("/SimpleParserTest.xml"), (DefaultHandler) null);
assertEquals("The:quick,brown:fox", instructions.toString());
assertEquals("stuff,nestedStuff,nestedStuff,nestedStuff", elements1.toString());
assertEquals("Some text here,some more here...", text.toString());
assertEquals("eins", attributes1.get("one"));
assertEquals("zwei", attributes1.get("two"));
assertEquals("drei", attributes1.get("three"));
assertEquals("http://www.foobar.org", namespaces1.get("stuff"));
}
Aggregations