use of org.xmlpull.v1.XmlPullParserFactory in project android-maps-utils by googlemaps.
the class KmlContainerParserTest method createParser.
public XmlPullParser createParser(int res) throws Exception {
InputStream stream = getInstrumentation().getContext().getResources().openRawResource(res);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
parser.setInput(stream, null);
parser.next();
return parser;
}
use of org.xmlpull.v1.XmlPullParserFactory in project android-maps-utils by googlemaps.
the class KmlFeatureParserTest method createParser.
public XmlPullParser createParser(int res) throws Exception {
InputStream stream = getInstrumentation().getContext().getResources().openRawResource(res);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
parser.setInput(stream, null);
parser.next();
return parser;
}
use of org.xmlpull.v1.XmlPullParserFactory in project violations-plugin by jenkinsci.
the class ParseXML method parse.
/**
* Parse an xml file using a parser object.
* @param xmlFile the file to parse.
* @param xmlParser the parser object.
* @throws IOException if there is a problem.
*/
public static void parse(File xmlFile, AbstractParser xmlParser) throws IOException {
InputStream in = null;
boolean seenException = false;
try {
in = new FileInputStream(xmlFile);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
parser.setInput(new XmlReader(in));
xmlParser.setParser(parser);
xmlParser.execute();
} catch (IOException ex) {
seenException = true;
throw ex;
} catch (Exception ex) {
seenException = true;
throw new IOException2(ex);
} finally {
CloseUtil.close(in, seenException);
}
}
use of org.xmlpull.v1.XmlPullParserFactory in project KeepScore by nolanlawson.
the class GamesBackupSerializer method readGamesBackupSummary.
/**
* Don't read the entire file; just read the game count and other basic, summarized information.
*
* @param backupFilename
* @return
*/
@SuppressWarnings("incomplete-switch")
public static GamesBackupSummary readGamesBackupSummary(Uri uri, Format format, ContentResolver contentResolver) {
GamesBackupSummary result = new GamesBackupSummary();
int infoReceived = 0;
try {
XmlPullParser parser = null;
BufferedReader reader = null;
int parserEvent = -1;
try {
XmlPullParserFactory parserFactory = XmlPullParserFactory.newInstance();
parser = parserFactory.newPullParser();
InputStream inputStream = contentResolver.openInputStream(uri);
if (format == Format.GZIP) {
// new, gzipped format
inputStream = new GZIPInputStream(inputStream);
}
reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 0x1000);
parser.setInput(reader);
parserEvent = parser.getEventType();
Tag tag = null;
String text = null;
while (parserEvent != XmlPullParser.END_DOCUMENT) {
parserEvent = parser.next();
switch(parserEvent) {
case XmlPullParser.START_TAG:
tag = Tag.valueOf(parser.getName());
break;
case XmlPullParser.TEXT:
text = parser.getText();
break;
case XmlPullParser.END_TAG:
switch(tag) {
case gameCount:
result.setGameCount(Integer.parseInt(text));
infoReceived++;
break;
case version:
result.setVersion(Integer.parseInt(text));
infoReceived++;
if (result.getVersion() < VERSION_TWO) {
// no automatic vs. manual distinction in version one
result.setAutomatic(false);
infoReceived++;
}
if (result.getVersion() < VERSION_THREE) {
// filename not stored in XML file itself until version three
result.setFilename(uri.getLastPathSegment());
infoReceived++;
}
break;
case automatic:
result.setAutomatic(Boolean.parseBoolean(text));
infoReceived++;
break;
case dateBackupSaved:
result.setDateSaved(Long.parseLong(text));
infoReceived++;
break;
case backupFilename:
result.setFilename(text);
infoReceived++;
break;
}
break;
}
if (infoReceived == 5) {
// this is all the info required to create a summary
return result;
}
}
} finally {
if (reader != null) {
reader.close();
}
}
} catch (NumberFormatException e) {
log.e(e, "unexpected exception for " + uri);
throw new RuntimeException(e);
} catch (IOException e) {
log.e(e, "unexpected exception for " + uri);
throw new RuntimeException(e);
} catch (XmlPullParserException e) {
log.e(e, "unexpected exception for " + uri);
throw new RuntimeException(e);
}
throw new RuntimeException("failed to find summary for " + uri);
}
use of org.xmlpull.v1.XmlPullParserFactory in project LitePal by LitePalFramework.
the class ModelListActivity method populateMappingClasses.
private void populateMappingClasses() {
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xmlPullParser = factory.newPullParser();
xmlPullParser.setInput(getInputStream(), "UTF-8");
int eventType = xmlPullParser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
String nodeName = xmlPullParser.getName();
switch(eventType) {
case XmlPullParser.START_TAG:
{
if ("mapping".equals(nodeName)) {
String className = xmlPullParser.getAttributeValue("", "class");
mList.add(className);
}
break;
}
default:
break;
}
eventType = xmlPullParser.next();
}
} catch (XmlPullParserException e) {
throw new ParseConfigurationFileException(ParseConfigurationFileException.FILE_FORMAT_IS_NOT_CORRECT);
} catch (IOException e) {
throw new ParseConfigurationFileException(ParseConfigurationFileException.IO_EXCEPTION);
}
}
Aggregations