use of javax.xml.parsers.SAXParserFactory in project GCViewer by chewiebug.
the class DataReaderIBM_J9_5_0 method read.
public GCModel read() throws IOException {
if (getLogger().isLoggable(Level.INFO))
getLogger().info("Reading IBM J9 5.0 format...");
try (InputStream inStream = this.inputStream) {
final GCModel model = new GCModel();
model.setFormat(GCModel.Format.IBM_VERBOSE_GC);
DefaultHandler handler = new IBMJ9SAXHandler(gcResource, model);
// Use the default (non-validating) parser
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
javax.xml.parsers.SAXParser saxParser;
try {
saxParser = factory.newSAXParser();
saxParser.parse(inStream, handler);
} catch (ParserConfigurationException e) {
final IOException exception = new IOException(e.toString());
exception.initCause(e);
throw exception;
} catch (SAXException e) {
// TODO: if(e.getMessage().startsWith("XML document structures must start and end within the same entity")) {
if (e instanceof SAXParseException && ((SAXParseException) e).getColumnNumber() == 1) {
// ignore. this just means a xml tag terminated.
} else {
final IOException exception = new IOException(e.toString());
exception.initCause(e);
throw exception;
}
}
return model;
} finally {
if (getLogger().isLoggable(Level.INFO))
getLogger().info("Done reading.");
}
}
use of javax.xml.parsers.SAXParserFactory in project Fling by entertailion.
the class RampClient method parseXml.
private void parseXml(Reader reader) {
try {
InputSource inStream = new org.xml.sax.InputSource();
inStream.setCharacterStream(reader);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
AppHandler appHandler = new AppHandler();
xr.setContentHandler(appHandler);
xr.parse(inStream);
connectionServiceUrl = appHandler.getConnectionServiceUrl();
state = appHandler.getState();
protocol = appHandler.getProtocol();
} catch (Exception e) {
Log.e(LOG_TAG, "parse device description", e);
}
}
use of javax.xml.parsers.SAXParserFactory in project Fling by entertailion.
the class FlingFrame method onBroadcastFound.
public void onBroadcastFound(final BroadcastAdvertisement advert) {
if (advert.getLocation() != null) {
new Thread(new Runnable() {
public void run() {
Log.d(LOG_TAG, "location=" + advert.getLocation());
HttpResponse response = new HttpRequestHelper().sendHttpGet(advert.getLocation());
if (response != null) {
String appsUrl = null;
Header header = response.getLastHeader(HEADER_APPLICATION_URL);
if (header != null) {
appsUrl = header.getValue();
if (!appsUrl.endsWith("/")) {
appsUrl = appsUrl + "/";
}
Log.d(LOG_TAG, "appsUrl=" + appsUrl);
}
try {
InputStream inputStream = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
InputSource inStream = new org.xml.sax.InputSource();
inStream.setCharacterStream(reader);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
BroadcastHandler broadcastHandler = new BroadcastHandler();
xr.setContentHandler(broadcastHandler);
xr.parse(inStream);
Log.d(LOG_TAG, "modelName=" + broadcastHandler.getDialServer().getModelName());
// devices like ChromeCast devices
if (broadcastHandler.getDialServer().getModelName().equals(CHROME_CAST_MODEL_NAME)) {
Log.d(LOG_TAG, "ChromeCast device found: " + advert.getIpAddress().getHostAddress());
DialServer dialServer = new DialServer(advert.getLocation(), advert.getIpAddress(), advert.getPort(), appsUrl, broadcastHandler.getDialServer().getFriendlyName(), broadcastHandler.getDialServer().getUuid(), broadcastHandler.getDialServer().getManufacturer(), broadcastHandler.getDialServer().getModelName());
trackedServers.add(dialServer);
}
} catch (Exception e) {
Log.e(LOG_TAG, "parse device description", e);
}
}
}
}).start();
}
}
use of javax.xml.parsers.SAXParserFactory in project iosched by google.
the class SVGParser method parse.
static SVG parse(InputSource data, SVGHandler handler) throws SVGParseException {
try {
final Picture picture = new Picture();
handler.setPicture(picture);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
xr.setContentHandler(handler);
xr.setFeature("http://xml.org/sax/features/validation", false);
if (DISALLOW_DOCTYPE_DECL) {
try {
xr.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
} catch (SAXNotRecognizedException e) {
DISALLOW_DOCTYPE_DECL = false;
}
}
xr.parse(data);
SVG result = new SVG(picture, handler.bounds);
// Skip bounds if it was an empty pic
if (!Float.isInfinite(handler.limits.top)) {
result.setLimits(handler.limits);
}
return result;
} catch (Exception e) {
Log.e(TAG, "Failed to parse SVG.", e);
throw new SVGParseException(e);
}
}
use of javax.xml.parsers.SAXParserFactory in project groovy-core by groovy.
the class XmlUtil method newSAXParser.
private static SAXParser newSAXParser(boolean namespaceAware, boolean validating, Schema schema1) throws ParserConfigurationException, SAXException {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(validating);
factory.setNamespaceAware(namespaceAware);
factory.setSchema(schema1);
return factory.newSAXParser();
}
Aggregations