Search in sources :

Example 11 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project freeline by alibaba.

the class GradleDependencyEntity method parse.

/**
     * xml解析为对象
     *
     * @param text
     * @return
     */
public static GradleDependencyEntity parse(String text) {
    GradleDependencyEntity entity = new GradleDependencyEntity();
    XmlPullParserFactory f = null;
    try {
        f = XmlPullParserFactory.newInstance();
        f.setNamespaceAware(true);
        XmlPullParser xmlPullParser = f.newPullParser();
        xmlPullParser.setInput(new InputStreamReader(new ByteArrayInputStream(text.getBytes())));
        int eventType = xmlPullParser.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_DOCUMENT) {
            } else if (eventType == XmlPullParser.START_TAG) {
                String name = xmlPullParser.getName();
                if (name.equals("groupId")) {
                    entity.setGroupId(xmlPullParser.nextText());
                } else if (name.equals("artifactId")) {
                    entity.setArtifactId(xmlPullParser.nextText());
                } else if (name.equals("version")) {
                    String version = xmlPullParser.nextText();
                    entity.setVersion(version);
                } else if (name.equals("lastUpdated")) {
                    entity.setUpdateTime(xmlPullParser.nextText());
                }
            } else if (eventType == XmlPullParser.END_TAG) {
            } else if (eventType == XmlPullParser.TEXT) {
            }
            eventType = xmlPullParser.next();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return entity;
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) ParseException(java.text.ParseException)

Example 12 with XmlPullParserFactory

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;
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) InputStream(java.io.InputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser)

Example 13 with XmlPullParserFactory

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) {
            }
        }
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) InputStream(java.io.InputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) IOException(java.io.IOException)

Example 14 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project android_frameworks_base by AOSPA.

the class TtmlRenderingWidget method loadParser.

private void loadParser(String ttmlFragment) throws XmlPullParserException {
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(false);
    mParser = factory.newPullParser();
    StringReader in = new StringReader(ttmlFragment);
    mParser.setInput(in);
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) StringReader(java.io.StringReader)

Example 15 with XmlPullParserFactory

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) {
            }
        }
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) InputStream(java.io.InputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) IOException(java.io.IOException)

Aggregations

XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)40 XmlPullParser (org.xmlpull.v1.XmlPullParser)28 IOException (java.io.IOException)15 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)15 InputStream (java.io.InputStream)11 StringReader (java.io.StringReader)7 InputStreamReader (java.io.InputStreamReader)6 XmlSerializer (org.xmlpull.v1.XmlSerializer)5 XmlResourceParser (android.content.res.XmlResourceParser)4 IOException2 (hudson.util.IOException2)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 HashMap (java.util.HashMap)3 Reader (java.io.Reader)2 Iterator (java.util.Iterator)2 ParseConfigurationFileException (org.litepal.exceptions.ParseConfigurationFileException)2 PackageManager (android.content.pm.PackageManager)1 Resources (android.content.res.Resources)1 NonNull (android.support.annotation.NonNull)1 VisibleForTesting (android.support.annotation.VisibleForTesting)1