Search in sources :

Example 36 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 37 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 38 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)

Example 39 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 40 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)

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