Java Code Examples for org.xmlpull.v1.XmlPullParser#require()

The following examples show how to use org.xmlpull.v1.XmlPullParser#require() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SELinuxMMAC.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Loop over a package element looking for seinfo child tags. If found return the
 * value attribute of the seinfo tag, otherwise return null. All other tags encountered
 * will be skipped.
 *
 * @param parser an XmlPullParser object representing a package element.
 * @param pb a Policy.PolicyBuilder instance to build
 * @throws IOException
 * @throws XmlPullParserException
 * @throws IllegalArgumentException if any of the validation checks fail while
 *         parsing tag values.
 * @throws IllegalStateException if there is a duplicate seinfo tag for the current
 *         package tag.
 */
private static void readPackageOrThrow(XmlPullParser parser, Policy.PolicyBuilder pb) throws
        IOException, XmlPullParserException {
    parser.require(XmlPullParser.START_TAG, null, "package");
    String pkgName = parser.getAttributeValue(null, "name");

    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }

        String tagName = parser.getName();
        if ("seinfo".equals(tagName)) {
            String seinfo = parser.getAttributeValue(null, "value");
            pb.addInnerPackageMapOrThrow(pkgName, seinfo);
            readSeinfo(parser);
        } else {
            skip(parser);
        }
    }
}
 
Example 2
Source File: WISPAccessGatewayParam.java    From WiFiAfterConnect with Apache License 2.0 6 votes vote down vote up
private void parseRedirect (XmlPullParser parser) throws XmlPullParserException, IOException {
	parser.require(XmlPullParser.START_TAG, ns, "Redirect");
    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String name = parser.getName();
        if (name.equals("AccessProcedure")) {
        	accessProcedure = parseSimpleTag (parser, "AccessProcedure");
        } else if (name.equals("AccessLocation")) {
        	accessLocation = parseSimpleTag (parser, "AccessLocation");
        } else if (name.equals("LocationName")) {
        	locationName = parseSimpleTag (parser, "LocationName");
        } else if (name.equals("LoginURL")) {
        	loginURL = parseSimpleTag (parser, "LoginURL");
        } else if (name.equals("MessageType")) {
        	messageType = parseSimpleTag (parser, "MessageType");
        } else if (name.equals("ResponseCode")) {
        	responseCode = parseSimpleTag (parser, "ResponseCode");
        } else {
            skip(parser);
        }
    }
}
 
Example 3
Source File: KeyChainSnapshotDeserializer.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private static byte[] readBlobTag(XmlPullParser parser, String tagName)
        throws IOException, XmlPullParserException, KeyChainSnapshotParserException {
    parser.require(XmlPullParser.START_TAG, NAMESPACE, tagName);
    String text = readText(parser);
    parser.require(XmlPullParser.END_TAG, NAMESPACE, tagName);

    try {
        return Base64.decode(text, /*flags=*/ Base64.DEFAULT);
    } catch (IllegalArgumentException e) {
        throw new KeyChainSnapshotParserException(
                String.format(
                        Locale.US,
                        "%s expected base64 encoded bytes but got '%s'",
                        tagName, text), e);
    }
}
 
Example 4
Source File: KeyChainSnapshotDeserializer.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static int readIntTag(XmlPullParser parser, String tagName)
        throws IOException, XmlPullParserException, KeyChainSnapshotParserException {
    parser.require(XmlPullParser.START_TAG, NAMESPACE, tagName);
    String text = readText(parser);
    parser.require(XmlPullParser.END_TAG, NAMESPACE, tagName);
    try {
        return Integer.valueOf(text);
    } catch (NumberFormatException e) {
        throw new KeyChainSnapshotParserException(
                String.format(
                        Locale.US, "%s expected int but got '%s'", tagName, text), e);
    }
}
 
Example 5
Source File: PreferenceParser.java    From Aegis with GNU General Public License v3.0 5 votes vote down vote up
private static XmlEntry parseEntry(XmlPullParser parser) throws IOException, XmlPullParserException {
    parser.require(XmlPullParser.START_TAG, null, "string");
    String name = parser.getAttributeValue(null, "name");
    String value = parseText(parser);
    parser.require(XmlPullParser.END_TAG, null, "string");

    XmlEntry entry = new XmlEntry();
    entry.Name = name;
    entry.Value = value;
    return entry;
}
 
Example 6
Source File: EmoticonFileUtils.java    From imsdk-android with MIT License 5 votes vote down vote up
private  String readFileName(XmlPullParser parser) throws IOException, XmlPullParserException {
    parser.require(XmlPullParser.START_TAG,ns,"FILE_FIXED");
    String result = "";
    if(parser.next()== XmlPullParser.TEXT)
    {
        result = parser.getText();
        parser.nextTag();
    }
    parser.require(XmlPullParser.END_TAG,ns,"FILE_FIXED");
    return result;
}
 
Example 7
Source File: StrategyLoader.java    From ssj with GNU General Public License v3.0 5 votes vote down vote up
public ActionAttributes(XmlPullParser xmlPullParser) throws IOException, XmlPullParserException
{
	xmlPullParser.require(XmlPullParser.START_TAG, null, "action");

	res = xmlPullParser.getAttributeValue(null, "res");
	lock = xmlPullParser.getAttributeValue(null, "lock");
	lockSelf = xmlPullParser.getAttributeValue(null, "lockSelf");
	intensity = xmlPullParser.getAttributeValue(null, "intensity");
	duration = xmlPullParser.getAttributeValue(null, "duration");
	brightness = xmlPullParser.getAttributeValue(null, "brightness");
	type = xmlPullParser.getAttributeValue(null, "type");
}
 
Example 8
Source File: firmwareEntriesParser.java    From SensorTag-CC2650 with Apache License 2.0 5 votes vote down vote up
private boolean readBoolean(XmlPullParser parser,String tag) throws XmlPullParserException, IOException {
    parser.require(XmlPullParser.START_TAG, ns, tag);
    boolean temp = false;
    if (parser.next() == XmlPullParser.TEXT) {
        temp = Boolean.getBoolean(parser.getText());
        parser.nextTag();
    }
    parser.require(XmlPullParser.END_TAG, ns, tag);
    return temp;
}
 
Example 9
Source File: XmlParser.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
/**
 * Parse changeLogVersion node
 *
 * @param parser
 * @param changeLog
 * @throws Exception
 */
protected void readChangeLogVersionNode(XmlPullParser parser, ChangeLog changeLog) throws Exception {

    if (parser == null)
        return;

    parser.require(XmlPullParser.START_TAG, null, TAG_CHANGELOGVERSION);

    // Read attributes
    String versionName = parser.getAttributeValue(null, ATTRIBUTE_VERSIONNAME);
    String changeDate = parser.getAttributeValue(null, ATTRIBUTE_CHANGEDATE);
    if (versionName == null)
        throw new ChangeLogException("VersionName required in changeLogVersion node");

    ChangeLogRowHeader row = new ChangeLogRowHeader();
    row.setVersionName(versionName);
    row.setChangeDate(changeDate);
    changeLog.addRow(row);

    Log.d(TAG, "Added rowHeader:" + row.toString());

    // Parse nested nodes
    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String tag = parser.getName();
        Log.d(TAG, "Processing tag=" + tag);

        if (tag.equals(TAG_CHANGELOGTEXT)) {
            readChangeLogRowNode(parser, changeLog, versionName);
        }
    }
}
 
Example 10
Source File: DLNAEventParser.java    From Connect-SDK-Android-Core with Apache License 2.0 5 votes vote down vote up
private JSONObject readEvent(XmlPullParser parser) throws IOException, XmlPullParserException, JSONException {
    JSONObject event = new JSONObject();

    JSONArray instanceIDs = new JSONArray();
    JSONArray queueIDs = new JSONArray();

    parser.require(XmlPullParser.START_TAG, ns, "Event");
    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String name = parser.getName();
        if (name.equals("InstanceID")) {
            instanceIDs.put(readInstanceID(parser));
        }
        else if (name.equals("QueueID")) {
            queueIDs.put(readQueueID(parser));
        }
        else {
            skip(parser);
        }
    }

    if (instanceIDs.length() > 0)
        event.put("InstanceID", instanceIDs);
    if (queueIDs.length() > 0)
        event.put("QueueID", queueIDs);

    return event;
}
 
Example 11
Source File: WISPAccessGatewayParam.java    From WiFiAfterConnect with Apache License 2.0 5 votes vote down vote up
private static String parseSimpleTag(XmlPullParser parser, String name) throws XmlPullParserException, IOException {
	String result = "";
	parser.require(XmlPullParser.START_TAG, ns, name);
    result = readText(parser);
    parser.require(XmlPullParser.END_TAG, ns, name);
	return result;
}
 
Example 12
Source File: BluetoothXmlParser.java    From EFRConnect-android with Apache License 2.0 4 votes vote down vote up
private long readMaximum(XmlPullParser parser) throws NumberFormatException, XmlPullParserException, IOException {
    parser.require(XmlPullParser.START_TAG, ns, Consts.TAG_MAXIMUM);
    long maximum = readLong(parser);
    parser.require(XmlPullParser.END_TAG, ns, Consts.TAG_MAXIMUM);
    return maximum;
}
 
Example 13
Source File: KmlParser.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
private static Track readLineString(XmlPullParser parser) throws IOException, XmlPullParserException {
    parser.require(XmlPullParser.START_TAG, NS, KmlFile.TAG_LINE_STRING);
    Track track = new Track();
    String coordinatesString = null;
    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String name = parser.getName();
        switch (name) {
            case KmlFile.TAG_COORDINATES:
                coordinatesString = readTextElement(parser, KmlFile.TAG_COORDINATES);
                break;
            default:
                skip(parser);
                break;
        }
    }
    parser.require(XmlPullParser.END_TAG, NS, KmlFile.TAG_LINE_STRING);
    if (coordinatesString == null)
        throw new XmlPullParserException(KmlFile.TAG_LINE_STRING + " must have coordinates", parser, null);
    String[] points = coordinatesString.split("[\\s\\n]");
    boolean continuous = false;
    for (String point : points) {
        String[] coordinates = point.split(",");
        if (coordinates.length < 2)
            continue;
        try {
            int latitudeE6 = (int) (Double.parseDouble(coordinates[1]) * 1E6);
            int longitudeE6 = (int) (Double.parseDouble(coordinates[0]) * 1E6);
            float altitude = 0f;
            if (coordinates.length == 3)
                altitude = (float) Double.parseDouble(coordinates[2]);
            track.addPointFast(continuous, latitudeE6, longitudeE6, altitude, Float.NaN, Float.NaN, Float.NaN, 0L);
        } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
            throw new XmlPullParserException("Wrong coordinates format: " + point, parser, e);
        }
        continuous = true;
    }
    return track;
}
 
Example 14
Source File: BluetoothXmlParser.java    From EFRConnect-android with Apache License 2.0 4 votes vote down vote up
private long readMinimum(XmlPullParser parser) throws XmlPullParserException, IOException {
    parser.require(XmlPullParser.START_TAG, ns, Consts.TAG_MINIMUM);
    long minimum = readLong(parser);
    parser.require(XmlPullParser.END_TAG, ns, Consts.TAG_MINIMUM);
    return minimum;
}
 
Example 15
Source File: ApplicationListParser.java    From Stringlate with MIT License 4 votes vote down vote up
private static ApplicationDetails readApplication(XmlPullParser parser)
        throws XmlPullParserException, IOException {

    String packageName, lastUpdated, name, description, iconUrl, sourceCodeUrl, webUrl, email;
    packageName = lastUpdated = name = description = iconUrl = sourceCodeUrl = webUrl = email = "";

    parser.require(XmlPullParser.START_TAG, ns, "application");
    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG)
            continue;

        switch (parser.getName()) {
            case ID:
                packageName = readText(parser);
                break;
            case LAST_UPDATED:
                lastUpdated = readText(parser);
                break;
            case NAME:
                name = readText(parser);
                break;
            case DESCRIPTION:
                description = readText(parser);
                break;
            case WEB:
                webUrl = readText(parser);
                break;
            case ICON:
                if (fdroidIconPath != null) {
                    iconUrl = fdroidIconPath + readText(parser);
                }
                break;
            case ICON_URL:
                iconUrl = readText(parser);
                break;
            case SOURCE_URL:
                sourceCodeUrl = readText(parser);
                break;
            case MAIL:
                email = readText(parser);
                break;
            default:
                skip(parser);
                break;
        }
    }
    parser.require(XmlPullParser.END_TAG, ns, "application");

    return new ApplicationDetails(packageName, lastUpdated,
            name, description, iconUrl, sourceCodeUrl, webUrl, email);
}
 
Example 16
Source File: XmlParser.java    From droidddle with Apache License 2.0 4 votes vote down vote up
/**
 * Parse changeLogVersion node
 *
 * @param parser
 * @param changeLog
 * @throws Exception
 */
protected void readChangeLogVersionNode(XmlPullParser parser, ChangeLog changeLog) throws Exception {

    if (parser == null) return;

    parser.require(XmlPullParser.START_TAG, null, TAG_CHANGELOGVERSION);

    // Read attributes
    String versionName = parser.getAttributeValue(null, ATTRIBUTE_VERSIONNAME);
    String versionCodeStr = parser.getAttributeValue(null, ATTRIBUTE_VERSIONCODE);
    int versionCode = 0;
    if (versionCodeStr != null) {
        try {
            versionCode = Integer.parseInt(versionCodeStr);
        } catch (NumberFormatException ne) {
            Log.w(TAG, "Error while parsing versionCode.It must be a numeric value. Check you file.");
        }
    }
    String changeDate = parser.getAttributeValue(null, ATTRIBUTE_CHANGEDATE);
    if (versionName == null)
        throw new ChangeLogException("VersionName required in changeLogVersion node");

    ChangeLogRowHeader row = new ChangeLogRowHeader();
    row.setVersionName(versionName);
    //row.setVersionCode(versionCode);
    row.setChangeDate(changeDate);
    changeLog.addRow(row);

    //Log.d(TAG,"Added rowHeader:"+row.toString());

    // Parse nested nodes
    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String tag = parser.getName();
        //Log.d(TAG,"Processing tag="+tag);

        if (mChangeLogTags.contains(tag)) {
            readChangeLogRowNode(parser, changeLog, versionName, versionCode);
        }
    }
}
 
Example 17
Source File: FeedParser.java    From Focus with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 从channel标志开始构建feed类。
 * @param parser
 * @return
 * @throws XmlPullParserException
 * @throws IOException
 */
private static Feed readChannelForFeed(XmlPullParser parser) throws XmlPullParserException, IOException {
    Feed feed = new Feed();
    feed.setUrl(feedUrl);
    List<FeedItem> feedItems = new ArrayList<>();
    parser.require(XmlPullParser.START_TAG, null, CHANNEL);
    String netFeedName = "";
    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String name = parser.getName();
        // Starts by looking for the entry tag
        switch (name) {
            case TITLE:
                //使用用户设置的title
                netFeedName = readTitle(parser);
                break;
            case LINK:
                feed.setLink(readLink(parser));
                break;
            case LAST_BUILD_DATE:
                feed.setTime(readLastBuildDate(parser));
                break;
            case DESC:
                feed.setDesc(readDesc(parser));
                break;
            case ITEM:
                //获取当前feed最新的文章列表
                FeedItem feedItem = readItemForFeedItem(parser);
                if (feedItem.isNotHaveExtractTime()){
                    feedItem.setDate(feedItem.getDate() - feedItems.size() *1000);//越往后的时间越小,保证前面的时间大,后面的时间小
                }
                feedItems.add(feedItem);//加到开头
                break;
            default:
                skip(parser);
                break;
        }

    }
    if(UserPreference.queryValueByKey(UserPreference.AUTO_SET_FEED_NAME,"0").equals("1")){//自动通过网络设置名字
        feed.setName(netFeedName);//因为在线请求的时候没有拉取Titile这个字段
    }
    feed.setFeedItemList(feedItems);
    feed.setWebsiteCategoryName("");


    return feed;
}
 
Example 18
Source File: ECBXmlParser.java    From Equate with GNU General Public License v3.0 4 votes vote down vote up
private String readSymbol(XmlPullParser parser) throws IOException, XmlPullParserException {
	parser.require(XmlPullParser.START_TAG, ns, FOURTH_ELEMENT);
	String symbol = parser.getAttributeValue(null, FOURTH_ELEMENT_ATTRIBUTE_CURR);
	return symbol;
}
 
Example 19
Source File: AtomParser.java    From Focus with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param parser
 * @return
 * @throws XmlPullParserException
 * @throws IOException
 */
public static Feed readFeedForFeed(XmlPullParser parser, String url) throws XmlPullParserException, IOException {
    Feed feed = new Feed();
    feed.setUrl(url);
    List<FeedItem> feedItems = new ArrayList<>();
    parser.require(XmlPullParser.START_TAG, null, FEED);
    String netFeedName = "";

    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String name = parser.getName();
        // Starts by looking for the entry tag
        switch (name) {
            case TITLE:
                netFeedName = readTitle(parser);
                break;
            case LINK:
                Message message = readFeedLink(parser);
                if (message.isFlag()) {//是真正的link信息
                    feed.setLink(message.getData());
                } else {
                    skip(parser);
                }
                break;
            case UPDATED:
                feed.setTime(readLastBuildDate(parser));
                break;
            case SUBTITLE:
                feed.setDesc(readSubtitle(parser));
                break;
            case ENTRY:
                //获取当前feed最新的文章列表
                FeedItem feedItem = readEntryForFeedItem(parser);
                if (feedItem.isNotHaveExtractTime()) {
                    feedItem.setDate(feedItem.getDate() - feedItems.size() * 1000);//越往后的时间越小,保证前面的时间大,后面的时间小
                }
                feedItems.add(feedItem);
                break;
            default:
                skip(parser);
                break;
        }
    }

    if (UserPreference.queryValueByKey(UserPreference.AUTO_SET_FEED_NAME, "0").equals("1")) {//自动通过网络设置名字
        feed.setName(netFeedName);//因为在线请求的时候没有拉取Titile这个字段
    }
    feed.setFeedItemList(feedItems);
    feed.setWebsiteCategoryName("");
    return feed;
}
 
Example 20
Source File: DLNANotifyParser.java    From Connect-SDK-Android-Core with Apache License 2.0 3 votes vote down vote up
private JSONObject readPropertyData(String target, XmlPullParser parser) throws IOException, XmlPullParserException, JSONException {
    JSONObject data = new JSONObject();
    String value;

    parser.require(XmlPullParser.START_TAG, ns, target);

    value = readText(parser);
    data.put(target, value);

    parser.require(XmlPullParser.END_TAG, ns, target);

    return data;
}