Search in sources :

Example 6 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project violations-plugin by jenkinsci.

the class ParseTypeXML method parse.

/**
     * Parse a xml violation file.
     * @param model the model to store the violations in.
     * @param projectPath the project path used for resolving paths.
     * @param xmlFile the xml file to parse.
     * @param typeParser the parser to use.
     * @param sourcePaths a list of source paths to resolve classes against
     * @throws IOException if there is an error.
     */
public void parse(FullBuildModel model, File projectPath, String xmlFile, String[] sourcePaths, AbstractTypeParser typeParser) throws IOException {
    LOG.info("Parsing " + xmlFile);
    InputStream in = null;
    boolean success = false;
    try {
        in = projectPath == null ? new FileInputStream(new File(xmlFile)) : new FileInputStream(new File(projectPath, xmlFile));
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser parser = factory.newPullParser();
        parser.setInput(in, null);
        typeParser.setProjectPath(projectPath);
        typeParser.setModel(model);
        typeParser.setParser(parser);
        typeParser.setSourcePaths(sourcePaths);
        typeParser.execute();
        success = true;
    } catch (IOException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new IOException2(ex);
    } finally {
        CloseUtil.close(in, !success);
    }
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) IOException2(hudson.util.IOException2)

Example 7 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project violations-plugin by jenkinsci.

the class ParseXML method parse.

/**
     * Parse an Input stream using a parser object.
     * @param in the stream to parse.
     * @param xmlParser the parser object.
     * @throws IOException if there is a problem.
     */
public static void parse(InputStream in, AbstractParser xmlParser) throws IOException {
    try {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser parser = factory.newPullParser();
        parser.setInput(new XmlReader(in));
        xmlParser.setParser(parser);
        xmlParser.execute();
    } catch (IOException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new IOException2(ex);
    }
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) XmlPullParser(org.xmlpull.v1.XmlPullParser) IOException(java.io.IOException) IOException(java.io.IOException) IOException2(hudson.util.IOException2)

Example 8 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project Talon-for-Twitter by klinker24.

the class NearbyTweets method getLocationFromYahoo.

private double[] getLocationFromYahoo(int woeid) {
    double[] loc = new double[] { -1, -1 };
    try {
        String url = "http://where.yahooapis.com/v1/place/" + woeid + "?appid=.DuZKdDV34EQ.TNLpvgTtFuMf5VruNTzx4Ti7F60XHVyV2zEbulKVjZKvRWBAiYZ";
        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
        XmlPullParserFactory factory = null;
        try {
            factory = XmlPullParserFactory.newInstance();
            factory.setNamespaceAware(true);
        } catch (XmlPullParserException e) {
        }
        XmlPullParser xpp = factory.newPullParser();
        xpp.setInput(new InputStreamReader(connection.getInputStream()));
        int eventType = xpp.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG && "latitude".equals(xpp.getName()) && loc[0] == -1) {
                try {
                    loc[0] = Double.parseDouble(xpp.nextText());
                } catch (Exception e) {
                }
            } else if (eventType == XmlPullParser.START_TAG && "longitude".equals(xpp.getName()) && loc[1] == -1) {
                try {
                    loc[1] = Double.parseDouble(xpp.nextText());
                } catch (Exception e) {
                }
            }
            eventType = xpp.next();
        }
    } catch (Exception e) {
        e.printStackTrace();
        loc[0] = -1;
        loc[1] = -1;
    }
    Log.v("talon_loc", "lat: " + loc[0] + " long: " + loc[1]);
    return loc;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) InputStreamReader(java.io.InputStreamReader) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) URL(java.net.URL) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 9 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project k-9 by k9mail.

the class SettingsImporter method parseSettings.

@VisibleForTesting
static Imported parseSettings(InputStream inputStream, boolean globalSettings, List<String> accountUuids, boolean overview) throws SettingsImportExportException {
    if (!overview && accountUuids == null) {
        throw new IllegalArgumentException("Argument 'accountUuids' must not be null.");
    }
    try {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        //factory.setNamespaceAware(true);
        XmlPullParser xpp = factory.newPullParser();
        InputStreamReader reader = new InputStreamReader(inputStream);
        xpp.setInput(reader);
        Imported imported = null;
        int eventType = xpp.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                if (SettingsExporter.ROOT_ELEMENT.equals(xpp.getName())) {
                    imported = parseRoot(xpp, globalSettings, accountUuids, overview);
                } else {
                    Timber.w("Unexpected start tag: %s", xpp.getName());
                }
            }
            eventType = xpp.next();
        }
        if (imported == null || (overview && imported.globalSettings == null && imported.accounts == null)) {
            throw new SettingsImportExportException("Invalid import data");
        }
        return imported;
    } catch (Exception e) {
        throw new SettingsImportExportException(e);
    }
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) InputStreamReader(java.io.InputStreamReader) XmlPullParser(org.xmlpull.v1.XmlPullParser) InvalidSettingValueException(com.fsck.k9.preferences.Settings.InvalidSettingValueException) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 10 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project KeepScore by nolanlawson.

the class XmlHelper method loadData.

public static XmlPullParser loadData(String xmlData) throws XmlPullParserException {
    XmlPullParserFactory parserFactory = XmlPullParserFactory.newInstance();
    XmlPullParser parser = parserFactory.newPullParser();
    parser.setInput(new StringReader(xmlData));
    return parser;
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) XmlPullParser(org.xmlpull.v1.XmlPullParser) StringReader(java.io.StringReader)

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