Example usage for android.util Xml FEATURE_RELAXED

List of usage examples for android.util Xml FEATURE_RELAXED

Introduction

In this page you can find the example usage for android.util Xml FEATURE_RELAXED.

Prototype

String FEATURE_RELAXED

To view the source code for android.util Xml FEATURE_RELAXED.

Click Source Link

Document

org.xmlpull.v1.XmlPullParser "relaxed" feature name.

Usage

From source file:org.mariotaku.utwitterapi.util.OAuthPasswordAuthenticator.java

public static String readAuthenticityTokenFromHtml(final Reader in) throws IOException, XmlPullParserException {
    final XmlPullParserFactory f = XmlPullParserFactory.newInstance();
    final XmlPullParser parser = f.newPullParser();
    parser.setFeature(Xml.FEATURE_RELAXED, true);
    parser.setInput(in);/*from www .j ava  2 s .co m*/
    while (parser.next() != XmlPullParser.END_DOCUMENT) {
        final String tag = parser.getName();
        switch (parser.getEventType()) {
        case XmlPullParser.START_TAG: {
            if ("input".equals(tag) && "authenticity_token".equals(parser.getAttributeValue(null, "name")))
                return parser.getAttributeValue(null, "value");
        }
        }
    }
    return null;
}

From source file:org.mariotaku.utwitterapi.util.OAuthPasswordAuthenticator.java

public static String readCallbackUrlFromHtml(final Reader in) throws IOException, XmlPullParserException {
    final XmlPullParserFactory f = XmlPullParserFactory.newInstance();
    final XmlPullParser parser = f.newPullParser();
    parser.setFeature(Xml.FEATURE_RELAXED, true);
    parser.setInput(in);//from   w  w w . ja  va2s.c  om
    while (parser.next() != XmlPullParser.END_DOCUMENT) {
        final String tag = parser.getName();
        switch (parser.getEventType()) {
        case XmlPullParser.START_TAG: {
            if ("meta".equals(tag) && "refresh".equals(parser.getAttributeValue(null, "http-equiv"))) {
                final String content = parser.getAttributeValue(null, "content");
                int idx;
                if (!TextUtils.isEmpty(content) && (idx = content.indexOf(REFRESH_URL_PREFIX)) != -1) {
                    final String url = content.substring(idx + REFRESH_URL_PREFIX.length());
                    if (!TextUtils.isEmpty(url))
                        return url;
                }
            }
        }
        }
    }
    return null;
}

From source file:org.mariotaku.utwitterapi.util.OAuthPasswordAuthenticator.java

public static String readOAuthPINFromHtml(final Reader in) throws XmlPullParserException, IOException {
    boolean start_div = false, start_code = false;
    final XmlPullParserFactory f = XmlPullParserFactory.newInstance();
    final XmlPullParser parser = f.newPullParser();
    parser.setFeature(Xml.FEATURE_RELAXED, true);
    parser.setInput(in);//from   w ww. j a  v  a 2  s  . c o m
    while (parser.next() != XmlPullParser.END_DOCUMENT) {
        final String tag = parser.getName();
        final int type = parser.getEventType();
        if (type == XmlPullParser.START_TAG) {
            if ("div".equalsIgnoreCase(tag)) {
                start_div = "oauth_pin".equals(parser.getAttributeValue(null, "id"));
            } else if ("code".equalsIgnoreCase(tag)) {
                if (start_div) {
                    start_code = true;
                }
            }
        } else if (type == XmlPullParser.END_TAG) {
            if ("div".equalsIgnoreCase(tag)) {
                start_div = false;
            } else if ("code".equalsIgnoreCase(tag)) {
                start_code = false;
            }
        } else if (type == XmlPullParser.TEXT) {
            final String text = parser.getText();
            if (start_code && !TextUtils.isEmpty(text) && TextUtils.isDigitsOnly(text))
                return text;
        }
    }
    return null;
}

From source file:org.getlantern.firetweet.util.OAuthPasswordAuthenticator.java

public static void readInputFromHtml(final Reader in, Map<String, String> map, String... desiredNames)
        throws IOException, XmlPullParserException {
    final XmlPullParserFactory f = XmlPullParserFactory.newInstance();
    final XmlPullParser parser = f.newPullParser();
    parser.setFeature(Xml.FEATURE_RELAXED, true);
    parser.setInput(in);//ww  w  . j  av a  2  s  .  co  m
    while (parser.next() != XmlPullParser.END_DOCUMENT) {
        final String tag = parser.getName();
        switch (parser.getEventType()) {
        case XmlPullParser.START_TAG: {
            final String name = parser.getAttributeValue(null, "name");
            if ("input".equalsIgnoreCase(tag) && ArrayUtils.contains(desiredNames, name)) {
                map.put(name, parser.getAttributeValue(null, "value"));
            }
            break;
        }
        }
    }
}

From source file:org.mariotaku.twidere.util.OAuthPasswordAuthenticator.java

private static void readInputFromHtml(final Reader in, Map<String, String> map, String... desiredNames)
        throws IOException, XmlPullParserException {
    final XmlPullParserFactory f = XmlPullParserFactory.newInstance();
    final XmlPullParser parser = f.newPullParser();
    parser.setFeature(Xml.FEATURE_RELAXED, true);
    parser.setInput(in);//w  w  w.java  2  s .  co  m
    while (parser.next() != XmlPullParser.END_DOCUMENT) {
        final String tag = parser.getName();
        switch (parser.getEventType()) {
        case XmlPullParser.START_TAG: {
            final String name = parser.getAttributeValue(null, "name");
            if ("input".equalsIgnoreCase(tag) && ArrayUtils.contains(desiredNames, name)) {
                map.put(name, parser.getAttributeValue(null, "value"));
            }
            break;
        }
        }
    }
}