use of org.xmlpull.v1.XmlPullParserFactory in project android_frameworks_base by ResurrectionRemix.
the class DaylightHeaderProvider method loadHeaders.
private void loadHeaders() throws XmlPullParserException, IOException {
mHeadersList = new ArrayList<DaylightHeaderInfo>();
InputStream in = null;
XmlPullParser parser = null;
try {
if (mHeaderName == null) {
if (DEBUG)
Log.i(TAG, "Load header pack config daylight_header.xml");
in = mRes.getAssets().open("daylight_header.xml");
} else {
int idx = mHeaderName.lastIndexOf(".");
String headerConfigFile = mHeaderName.substring(idx + 1) + ".xml";
if (DEBUG)
Log.i(TAG, "Load header pack config " + headerConfigFile);
in = mRes.getAssets().open(headerConfigFile);
}
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
parser = factory.newPullParser();
parser.setInput(in, "UTF-8");
loadResourcesFromXmlParser(parser);
} finally {
// Cleanup resources
if (parser instanceof XmlResourceParser) {
((XmlResourceParser) parser).close();
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
}
use of org.xmlpull.v1.XmlPullParserFactory in project AntennaPod by AntennaPod.
the class TypeGetter method getType.
public Type getType(Feed feed) throws UnsupportedFeedtypeException {
XmlPullParserFactory factory;
if (feed.getFile_url() != null) {
Reader reader = null;
try {
factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
reader = createReader(feed);
xpp.setInput(reader);
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
String tag = xpp.getName();
switch(tag) {
case ATOM_ROOT:
feed.setType(Feed.TYPE_ATOM1);
Log.d(TAG, "Recognized type Atom");
String strLang = xpp.getAttributeValue("http://www.w3.org/XML/1998/namespace", "lang");
if (strLang != null) {
feed.setLanguage(strLang);
}
return Type.ATOM;
case RSS_ROOT:
String strVersion = xpp.getAttributeValue(null, "version");
if (strVersion != null) {
if (strVersion.equals("2.0")) {
feed.setType(Feed.TYPE_RSS2);
Log.d(TAG, "Recognized type RSS 2.0");
return Type.RSS20;
} else if (strVersion.equals("0.91") || strVersion.equals("0.92")) {
Log.d(TAG, "Recognized type RSS 0.91/0.92");
return Type.RSS091;
}
}
throw new UnsupportedFeedtypeException(Type.INVALID);
default:
Log.d(TAG, "Type is invalid");
throw new UnsupportedFeedtypeException(Type.INVALID, tag);
}
} else {
eventType = xpp.next();
}
}
} catch (XmlPullParserException e) {
e.printStackTrace();
// XML document might actually be a HTML document -> try to parse as HTML
String rootElement = null;
try {
if (Jsoup.parse(new File(feed.getFile_url()), null) != null) {
rootElement = "html";
}
} catch (IOException e1) {
e1.printStackTrace();
}
throw new UnsupportedFeedtypeException(Type.INVALID, rootElement);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Log.d(TAG, "Type is invalid");
throw new UnsupportedFeedtypeException(Type.INVALID);
}
use of org.xmlpull.v1.XmlPullParserFactory in project android_frameworks_base by DirtyUnicorns.
the class DaylightHeaderProvider method loadHeaders.
private void loadHeaders() throws XmlPullParserException, IOException {
mHeadersList = new ArrayList<DaylightHeaderInfo>();
InputStream in = null;
XmlPullParser parser = null;
try {
if (mHeaderName == null) {
in = mRes.getAssets().open("daylight_header.xml");
} else {
int idx = mHeaderName.lastIndexOf(".");
String headerConfigFile = mHeaderName.substring(idx + 1) + ".xml";
in = mRes.getAssets().open(headerConfigFile);
}
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
parser = factory.newPullParser();
parser.setInput(in, "UTF-8");
loadResourcesFromXmlParser(parser);
} finally {
// Cleanup resources
if (parser instanceof XmlResourceParser) {
((XmlResourceParser) parser).close();
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
}
use of org.xmlpull.v1.XmlPullParserFactory in project android-maps-utils by googlemaps.
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 Mindroid.java by Himmele.
the class Configuration method read.
public static Configuration read(File configurationFile) throws Exception {
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(configurationFile);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
parser.setInput((InputStream) inputStream, "UTF-8");
parser.require(XmlPullParser.START_DOCUMENT, null, null);
parser.nextTag();
parser.require(XmlPullParser.START_TAG, null, ROOT_TAG);
Configuration configuration = new Configuration();
for (int eventType = parser.nextTag(); !parser.getName().equals(ROOT_TAG) && eventType != XmlPullParser.END_TAG; eventType = parser.nextTag()) {
if (parser.getName().equals(PLUGINS_TAG)) {
parsePlugins(parser, configuration);
} else {
String tag = parser.getName();
skipSubTree(parser);
parser.require(XmlPullParser.END_TAG, null, tag);
}
}
parser.require(XmlPullParser.END_TAG, null, ROOT_TAG);
parser.next();
parser.require(XmlPullParser.END_DOCUMENT, null, null);
return configuration;
} catch (Exception e) {
throw e;
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
}
}
}
}
Aggregations