Search in sources :

Example 46 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 47 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 48 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)

Example 49 with XmlPullParserFactory

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

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

use of org.xmlpull.v1.XmlPullParserFactory in project processdash by dtuma.

the class ArchiveMetricsFileImporter method readAndProcessArchive.

private void readAndProcessArchive() throws IOException, XmlPullParserException {
    shouldDeleteArchiveFileOnCompletion = false;
    zipFile = new ZipFile(file);
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    XmlPullParser parser = factory.newPullParser();
    InputStream manifestIn = openEntry(zipFile, MANIFEST_FILE_NAME);
    parser.setInput(manifestIn, ENCODING);
    parser.nextTag();
    parser.require(XmlPullParser.START_TAG, null, ARCHIVE_ELEM);
    if (!FILE_TYPE_ARCHIVE.equals(parser.getAttributeValue(null, TYPE_ATTR)))
        error("expected archive of type " + FILE_TYPE_ARCHIVE);
    parser.nextTag();
    parser.require(XmlPullParser.START_TAG, null, EXPORTED_TAG);
    owner = parser.getAttributeValue(null, OWNER_ATTR);
    exportTimestamp = XMLUtils.parseDate(parser.getAttributeValue(null, WHEN_ATTR));
    ImportedDefectManager.closeDefects(prefix);
    ImportedTimeLogManager.getInstance().closeTimeLogs(prefix);
    ImportedEVManager.getInstance().closeTaskLists(prefix);
    defns = new HashMap();
    Map<String, String> packageIDs = new HashMap<String, String>();
    while (parser.next() != XmlPullParser.END_DOCUMENT) {
        if (parser.getEventType() == XmlPullParser.START_TAG) {
            if (PACKAGE_ELEM.equals(parser.getName())) {
                String id = parser.getAttributeValue(null, PACKAGE_ID_ATTR);
                String version = parser.getAttributeValue(null, VERSION_ATTR);
                packageIDs.put(id, version);
            } else if (FROM_DATASET_TAG.equals(parser.getName())) {
                srcDatasetID = parser.getAttributeValue(null, FROM_DATASET_ID_ATTR);
            } else if (FILE_ELEM.equals(parser.getName())) {
                String name = parser.getAttributeValue(null, FILE_NAME_ATTR);
                String type = parser.getAttributeValue(null, TYPE_ATTR);
                String version = parser.getAttributeValue(null, VERSION_ATTR);
                readFile(zipFile, name, type, version);
            }
        }
    }
    // make a note of the individual who exported this data
    recordKnownPerson();
    // Protect this data from being viewed via external http requests.
    defns.put("_Password_", ImmutableDoubleData.READ_ONLY_ZERO);
    // Save metadata about the import
    addImportMetadata(packageIDs);
    try {
        data.mountImportedData(prefix, defns);
    } catch (InvalidDatafileFormat idf) {
    }
}
Also used : ZipFile(java.util.zip.ZipFile) XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) HashMap(java.util.HashMap) InputStream(java.io.InputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) InvalidDatafileFormat(net.sourceforge.processdash.data.repository.InvalidDatafileFormat)

Aggregations

XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)71 XmlPullParser (org.xmlpull.v1.XmlPullParser)56 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)30 IOException (java.io.IOException)24 InputStream (java.io.InputStream)16 InputStreamReader (java.io.InputStreamReader)10 StringReader (java.io.StringReader)10 FileInputStream (java.io.FileInputStream)8 XmlSerializer (org.xmlpull.v1.XmlSerializer)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 File (java.io.File)5 XmlResourceParser (android.content.res.XmlResourceParser)4 IOException2 (hudson.util.IOException2)4 BufferedReader (java.io.BufferedReader)4 Reader (java.io.Reader)4 Map (java.util.Map)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 StringWriter (java.io.StringWriter)2