Search in sources :

Example 31 with XmlPullParserFactory

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);
    }
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) ParseConfigurationFileException(org.litepal.exceptions.ParseConfigurationFileException) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 32 with XmlPullParserFactory

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

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 33 with XmlPullParserFactory

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

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 34 with XmlPullParserFactory

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

the class IconPackHelper method getIconPackResources.

private Map<String, String> getIconPackResources(Context context, String packageName) {
    if (TextUtils.isEmpty(packageName)) {
        return null;
    }
    Resources res = null;
    try {
        res = context.getPackageManager().getResourcesForApplication(packageName);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return null;
    }
    XmlPullParser parser = null;
    InputStream inputStream = null;
    Map<String, String> iconPackResources = new HashMap<String, String>();
    try {
        inputStream = res.getAssets().open("appfilter.xml");
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        parser = factory.newPullParser();
        parser.setInput(inputStream, "UTF-8");
    } catch (Exception e) {
        // Catch any exception since we want to fall back to parsing the xml/
        // resource in all cases
        int resId = res.getIdentifier("appfilter", "xml", packageName);
        if (resId != 0) {
            parser = res.getXml(resId);
        }
    }
    if (parser != null) {
        try {
            loadResourcesFromXmlParser(parser, iconPackResources);
            return iconPackResources;
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // Cleanup resources
            if (parser instanceof XmlResourceParser) {
                ((XmlResourceParser) parser).close();
            }
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                }
            }
        }
    }
    // Application uses a different theme format (most likely launcher pro)
    int arrayId = res.getIdentifier("theme_iconpack", "array", packageName);
    if (arrayId == 0) {
        arrayId = res.getIdentifier("icon_pack", "array", packageName);
    }
    if (arrayId != 0) {
        String[] iconPack = res.getStringArray(arrayId);
        for (String entry : iconPack) {
            if (TextUtils.isEmpty(entry)) {
                continue;
            }
            String icon = entry.toLowerCase();
            entry = entry.replaceAll("_", ".");
            iconPackResources.put(entry, icon);
            int activityIndex = entry.lastIndexOf(".");
            if (activityIndex <= 0 || activityIndex == entry.length() - 1) {
                continue;
            }
            String iconPackage = entry.substring(0, activityIndex);
            if (TextUtils.isEmpty(iconPackage)) {
                continue;
            }
            iconPackResources.put(iconPackage, icon);
            String iconActivity = entry.substring(activityIndex + 1);
            if (TextUtils.isEmpty(iconActivity)) {
                continue;
            }
            iconPackResources.put(iconPackage + "." + iconActivity, icon);
        }
    } else {
        loadApplicationResources(context, iconPackResources, packageName);
    }
    return iconPackResources;
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) HashMap(java.util.HashMap) InputStream(java.io.InputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) IOException(java.io.IOException) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) PackageManager(android.content.pm.PackageManager) XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources)

Example 35 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project Lightning-Browser by anthonycr.

the class GoogleSuggestionsModel method getParser.

@NonNull
private static synchronized XmlPullParser getParser() throws XmlPullParserException {
    if (sXpp == null) {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        sXpp = factory.newPullParser();
    }
    return sXpp;
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) NonNull(android.support.annotation.NonNull)

Aggregations

XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)41 XmlPullParser (org.xmlpull.v1.XmlPullParser)29 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 FileInputStream (java.io.FileInputStream)4 File (java.io.File)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