use of org.xmlpull.v1.XmlPullParserFactory in project violations-plugin by jenkinsci.
the class ParseTypeXML method parse.
/**
* Parse a xml violation file.
* @param model the model to store the violations in.
* @param projectPath the project path used for resolving paths.
* @param xmlFile the xml file to parse.
* @param typeParser the parser to use.
* @param sourcePaths a list of source paths to resolve classes against
* @throws IOException if there is an error.
*/
public void parse(FullBuildModel model, File projectPath, String xmlFile, String[] sourcePaths, AbstractTypeParser typeParser) throws IOException {
LOG.info("Parsing " + xmlFile);
InputStream in = null;
boolean success = false;
try {
in = projectPath == null ? new FileInputStream(new File(xmlFile)) : new FileInputStream(new File(projectPath, xmlFile));
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
parser.setInput(in, null);
typeParser.setProjectPath(projectPath);
typeParser.setModel(model);
typeParser.setParser(parser);
typeParser.setSourcePaths(sourcePaths);
typeParser.execute();
success = true;
} catch (IOException ex) {
throw ex;
} catch (Exception ex) {
throw new IOException2(ex);
} finally {
CloseUtil.close(in, !success);
}
}
use of org.xmlpull.v1.XmlPullParserFactory in project violations-plugin by jenkinsci.
the class ParseXML method parse.
/**
* Parse an Input stream using a parser object.
* @param in the stream to parse.
* @param xmlParser the parser object.
* @throws IOException if there is a problem.
*/
public static void parse(InputStream in, AbstractParser xmlParser) throws IOException {
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
parser.setInput(new XmlReader(in));
xmlParser.setParser(parser);
xmlParser.execute();
} catch (IOException ex) {
throw ex;
} catch (Exception ex) {
throw new IOException2(ex);
}
}
use of org.xmlpull.v1.XmlPullParserFactory in project Talon-for-Twitter by klinker24.
the class NearbyTweets method getLocationFromYahoo.
private double[] getLocationFromYahoo(int woeid) {
double[] loc = new double[] { -1, -1 };
try {
String url = "http://where.yahooapis.com/v1/place/" + woeid + "?appid=.DuZKdDV34EQ.TNLpvgTtFuMf5VruNTzx4Ti7F60XHVyV2zEbulKVjZKvRWBAiYZ";
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
XmlPullParserFactory factory = null;
try {
factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
} catch (XmlPullParserException e) {
}
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new InputStreamReader(connection.getInputStream()));
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG && "latitude".equals(xpp.getName()) && loc[0] == -1) {
try {
loc[0] = Double.parseDouble(xpp.nextText());
} catch (Exception e) {
}
} else if (eventType == XmlPullParser.START_TAG && "longitude".equals(xpp.getName()) && loc[1] == -1) {
try {
loc[1] = Double.parseDouble(xpp.nextText());
} catch (Exception e) {
}
}
eventType = xpp.next();
}
} catch (Exception e) {
e.printStackTrace();
loc[0] = -1;
loc[1] = -1;
}
Log.v("talon_loc", "lat: " + loc[0] + " long: " + loc[1]);
return loc;
}
use of org.xmlpull.v1.XmlPullParserFactory in project k-9 by k9mail.
the class SettingsImporter method parseSettings.
@VisibleForTesting
static Imported parseSettings(InputStream inputStream, boolean globalSettings, List<String> accountUuids, boolean overview) throws SettingsImportExportException {
if (!overview && accountUuids == null) {
throw new IllegalArgumentException("Argument 'accountUuids' must not be null.");
}
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
//factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
InputStreamReader reader = new InputStreamReader(inputStream);
xpp.setInput(reader);
Imported imported = null;
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
if (SettingsExporter.ROOT_ELEMENT.equals(xpp.getName())) {
imported = parseRoot(xpp, globalSettings, accountUuids, overview);
} else {
Timber.w("Unexpected start tag: %s", xpp.getName());
}
}
eventType = xpp.next();
}
if (imported == null || (overview && imported.globalSettings == null && imported.accounts == null)) {
throw new SettingsImportExportException("Invalid import data");
}
return imported;
} catch (Exception e) {
throw new SettingsImportExportException(e);
}
}
use of org.xmlpull.v1.XmlPullParserFactory in project KeepScore by nolanlawson.
the class XmlHelper method loadData.
public static XmlPullParser loadData(String xmlData) throws XmlPullParserException {
XmlPullParserFactory parserFactory = XmlPullParserFactory.newInstance();
XmlPullParser parser = parserFactory.newPullParser();
parser.setInput(new StringReader(xmlData));
return parser;
}
Aggregations