Search in sources :

Example 51 with XmlPullParserFactory

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

the class ArchiveMetricsFileExporter method writeManifest.

private void writeManifest(ZipOutputStream zipOut, boolean includeTaskLists) throws IOException {
    zipOut.putNextEntry(new ZipEntry(MANIFEST_FILE_NAME));
    XmlSerializer xml = null;
    try {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        xml = factory.newSerializer();
    } catch (XmlPullParserException xppe) {
        throw new RuntimeException("Couldn't obtain xml serializer", xppe);
    }
    xml.setOutput(zipOut, ENCODING);
    xml.startDocument(ENCODING, Boolean.TRUE);
    xml.ignorableWhitespace(NEWLINE + NEWLINE);
    xml.startTag(null, ARCHIVE_ELEM);
    xml.attribute(null, TYPE_ATTR, FILE_TYPE_ARCHIVE);
    xml.ignorableWhitespace(NEWLINE);
    writeManifestMetaData(xml);
    writeManifestFileEntry(xml, DATA_FILE_NAME, FILE_TYPE_METRICS, "1");
    writeManifestFileEntry(xml, DEFECT_FILE_NAME, FILE_TYPE_DEFECTS, "1");
    writeManifestFileEntry(xml, TIME_FILE_NAME, FILE_TYPE_TIME_LOG, "1");
    if (includeTaskLists)
        writeManifestFileEntry(xml, EV_FILE_NAME, FILE_TYPE_EARNED_VALUE, "1");
    if (additionalEntries != null)
        for (Iterator i = additionalEntries.iterator(); i.hasNext(); ) {
            ExportFileEntry file = (ExportFileEntry) i.next();
            writeManifestFileEntry(xml, file.getFilename(), file.getType(), file.getVersion());
        }
    xml.endTag(null, ARCHIVE_ELEM);
    xml.ignorableWhitespace(NEWLINE);
    xml.endDocument();
    zipOut.closeEntry();
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) ZipEntry(java.util.zip.ZipEntry) Iterator(java.util.Iterator) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) ExportFileEntry(net.sourceforge.processdash.tool.export.mgr.ExportFileEntry) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 52 with XmlPullParserFactory

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

the class DataImporterXMLv1 method handle.

public void handle(ArchiveMetricsFileImporter caller, InputStream in, String type, String version) throws Exception {
    Map defns = caller.getDefns();
    if (shouldImportRootValuesOnly(caller))
        defns.put(ROOT_VALUES_ONLY_TAG, "true");
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    XmlPullParser parser = factory.newPullParser();
    parser.setInput(in, ENCODING);
    parser.nextTag();
    parser.require(XmlPullParser.START_TAG, null, DATA_ELEM);
    importData(parser, defns, null);
    parser.require(XmlPullParser.END_TAG, null, DATA_ELEM);
    defns.remove(ROOT_VALUES_ONLY_TAG);
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) XmlPullParser(org.xmlpull.v1.XmlPullParser) HashMap(java.util.HashMap) Map(java.util.Map)

Example 53 with XmlPullParserFactory

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

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)

Example 54 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project Taskbar by farmerbb.

the class IconPack method load.

private void load(Context mContext) {
    if (!mIsLoading) {
        mIsLoading = true;
        SharedPreferences pref = U.getSharedPreferences(mContext);
        boolean loadMasks = pref.getBoolean("icon_pack_use_mask", false);
        // Load appfilter.xml from the icon pack package
        try {
            XmlPullParser xpp = null;
            int appfilterid = getResources(mContext).getIdentifier("appfilter", "xml", packageName);
            if (appfilterid > 0) {
                xpp = getResources(mContext).getXml(appfilterid);
            } else {
                // No resource found, try to open it from assets folder
                try {
                    InputStream appfilterstream = getResources(mContext).getAssets().open("appfilter.xml");
                    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
                    factory.setNamespaceAware(true);
                    xpp = factory.newPullParser();
                    xpp.setInput(appfilterstream, "utf-8");
                } catch (IOException e) {
                /* Gracefully fail */
                }
            }
            if (xpp != null) {
                int eventType = xpp.getEventType();
                while (eventType != XmlPullParser.END_DOCUMENT) {
                    if (eventType == XmlPullParser.START_TAG) {
                        if (loadMasks) {
                            if (xpp.getName().equals("iconback")) {
                                for (int i = 0; i < xpp.getAttributeCount(); i++) {
                                    if (xpp.getAttributeName(i).startsWith("img")) {
                                        String drawableName = xpp.getAttributeValue(i);
                                        Bitmap iconback = loadBitmap(mContext, drawableName);
                                        if (iconback != null)
                                            mBackImages.add(iconback);
                                    }
                                }
                            } else if (xpp.getName().equals("iconmask")) {
                                if (xpp.getAttributeCount() > 0 && xpp.getAttributeName(0).equals("img1")) {
                                    String drawableName = xpp.getAttributeValue(0);
                                    mMaskImage = loadBitmap(mContext, drawableName);
                                }
                            } else if (xpp.getName().equals("iconupon")) {
                                if (xpp.getAttributeCount() > 0 && xpp.getAttributeName(0).equals("img1")) {
                                    String drawableName = xpp.getAttributeValue(0);
                                    mFrontImage = loadBitmap(mContext, drawableName);
                                }
                            } else if (xpp.getName().equals("scale")) {
                                if (xpp.getAttributeCount() > 0 && xpp.getAttributeName(0).equals("factor")) {
                                    mFactor = Float.valueOf(xpp.getAttributeValue(0));
                                }
                            }
                        }
                        if (xpp.getName().equals("item")) {
                            String componentName = null;
                            String drawableName = null;
                            for (int i = 0; i < xpp.getAttributeCount(); i++) {
                                if (xpp.getAttributeName(i).equals("component")) {
                                    componentName = xpp.getAttributeValue(i);
                                } else if (xpp.getAttributeName(i).equals("drawable")) {
                                    drawableName = xpp.getAttributeValue(i);
                                }
                            }
                            if (!mPackagesDrawables.containsKey(componentName)) {
                                mPackagesDrawables.put(componentName, drawableName);
                                totalIcons = totalIcons + 1;
                            }
                        }
                    }
                    eventType = xpp.next();
                }
            }
            mLoaded = true;
        } catch (XmlPullParserException | IOException e) {
        /* Gracefully fail */
        }
        mIsLoading = false;
    }
}
Also used : Bitmap(android.graphics.Bitmap) XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) SharedPreferences(android.content.SharedPreferences) InputStream(java.io.InputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) Paint(android.graphics.Paint)

Example 55 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project LibreraReader by foobnix.

the class XmlParser method buildPullParser.

public static XmlPullParser buildPullParser() throws XmlPullParserException {
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setValidating(false);
    factory.setFeature(Xml.FEATURE_RELAXED, true);
    // factory.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, false);
    // factory.setFeature(XmlPullParser.FEATURE_VALIDATION, false);
    XmlPullParser newPullParser = factory.newPullParser();
    return newPullParser;
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) XmlPullParser(org.xmlpull.v1.XmlPullParser)

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