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 Java by bottleleung.
the class XmlManager method getXmlParser.
/**
* ��ȡXML������
* @param fileName ��Ҫ������xml�ļ�·�����ļ������������������ͳһ��plist,�б�Ҫ���ģ�
* @param encode �ַ�������
* @return
*/
public static XmlPullParser getXmlParser(String fileName, String encode) {
try {
// ��ô��� xml �ļ��� XmlResourceParser ����
// XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), Thread.currentThread().getContextClassLoader().getClass());
factory.setNamespaceAware(true);
XmlPullParser xml = factory.newPullParser();
xml.setInput(new FileInputStream(fileName + ".plist"), encode);
return xml;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of org.xmlpull.v1.XmlPullParserFactory in project wigle-wifi-wardriving by wiglenet.
the class KmlParserTest 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_device_mediatek_common by MediatekDevs.
the class MtkEccList method parseEccList.
/**
* Parse Ecc List From XML File
*
* @param none.
* @return none.
* @hide
*/
private static void parseEccList() {
mCustomizedEccList.clear();
// Parse GSM ECC list
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser parser = factory.newPullParser();
if (parser == null) {
Rlog.d(LOG_TAG, "XmlPullParserFactory.newPullParser() return null");
return;
}
FileReader fileReader = new FileReader(EccEntry.ECC_LIST_PATH);
parser.setInput(fileReader);
int eventType = parser.getEventType();
EccEntry record = null;
while (eventType != XmlPullParser.END_DOCUMENT) {
switch(eventType) {
case XmlPullParser.START_TAG:
if (parser.getName().equals(EccEntry.ECC_ENTRY_TAG)) {
record = new EccEntry();
int attrNum = parser.getAttributeCount();
for (int i = 0; i < attrNum; ++i) {
String name = parser.getAttributeName(i);
String value = parser.getAttributeValue(i);
if (name.equals(EccEntry.ECC_ATTR))
record.setEcc(value);
else if (name.equals(EccEntry.CATEGORY_ATTR))
record.setCategory(value);
else if (name.equals(EccEntry.CONDITION_ATTR))
record.setCondition(value);
}
}
break;
case XmlPullParser.END_TAG:
if (parser.getName().equals(EccEntry.ECC_ENTRY_TAG) && record != null)
mCustomizedEccList.add(record);
break;
}
eventType = parser.next();
}
fileReader.close();
if (sIsCtaSet) {
String[] emergencyCTAList = { "120", "122", "110", "119" };
for (String emergencyNum : emergencyCTAList) {
record = new EccEntry();
record.setEcc(emergencyNum);
record.setCategory("0");
record.setCondition(EccEntry.ECC_FOR_MMI);
boolean bFound = false;
int nIndex = 0;
for (EccEntry eccEntry : mCustomizedEccList) {
String ecc = eccEntry.getEcc();
if (ecc.equals(emergencyNum)) {
bFound = true;
Rlog.d(LOG_TAG, "[parseEccList]" + "CTA ecc match customized ecc list, ecc=" + ecc);
break;
}
nIndex++;
}
if (bFound)
mCustomizedEccList.set(nIndex, record);
else
mCustomizedEccList.add(record);
}
}
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
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);
}
Aggregations