Search in sources :

Example 1 with Tag

use of org.jivesoftware.smackx.iot.discovery.element.Tag in project Smack by igniterealtime.

the class IoTRegisterProvider method parse.

@Override
public IoTRegister parse(XmlPullParser parser, int initialDepth) throws Exception {
    boolean selfOwned = ParserUtils.getBooleanAttribute(parser, "selfOwned", false);
    NodeInfo nodeInfo = NodeInfoParser.parse(parser);
    List<Tag> tags = new ArrayList<>();
    while (parser.getDepth() != initialDepth) {
        int event = parser.next();
        if (event != XmlPullParser.START_TAG) {
            continue;
        }
        final String element = parser.getName();
        Tag.Type type = null;
        switch(element) {
            case "str":
                type = Tag.Type.str;
                break;
            case "num":
                type = Tag.Type.num;
                break;
        }
        if (type == null) {
            continue;
        }
        String name = parser.getAttributeValue(null, "name");
        String value = parser.getAttributeValue(null, "value");
        tags.add(new Tag(name, type, value));
    }
    return new IoTRegister(tags, nodeInfo, selfOwned);
}
Also used : NodeInfo(org.jivesoftware.smackx.iot.element.NodeInfo) ArrayList(java.util.ArrayList) Tag(org.jivesoftware.smackx.iot.discovery.element.Tag) IoTRegister(org.jivesoftware.smackx.iot.discovery.element.IoTRegister)

Example 2 with Tag

use of org.jivesoftware.smackx.iot.discovery.element.Tag in project Smack by igniterealtime.

the class Thing method toString.

@SuppressWarnings("ObjectToString")
@Override
public String toString() {
    if (toStringCache == null) {
        StringBuilder sb = new StringBuilder();
        sb.append("Thing " + nodeInfo + " [");
        Iterator<Tag> it = metaTags.values().iterator();
        while (it.hasNext()) {
            Tag tag = it.next();
            sb.append(tag);
            if (it.hasNext()) {
                sb.append(' ');
            }
        }
        sb.append(']');
        toStringCache = sb.toString();
    }
    return toStringCache;
}
Also used : Tag(org.jivesoftware.smackx.iot.discovery.element.Tag)

Example 3 with Tag

use of org.jivesoftware.smackx.iot.discovery.element.Tag in project Smack by igniterealtime.

the class IoTRegisterProvider method parse.

@Override
public IoTRegister parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
    boolean selfOwned = ParserUtils.getBooleanAttribute(parser, "selfOwned", false);
    NodeInfo nodeInfo = NodeInfoParser.parse(parser);
    List<Tag> tags = new ArrayList<>();
    while (parser.getDepth() != initialDepth) {
        XmlPullParser.Event event = parser.next();
        if (event != XmlPullParser.Event.START_ELEMENT) {
            continue;
        }
        final String element = parser.getName();
        Tag.Type type = null;
        switch(element) {
            case "str":
                type = Tag.Type.str;
                break;
            case "num":
                type = Tag.Type.num;
                break;
        }
        if (type == null) {
            continue;
        }
        String name = parser.getAttributeValue(null, "name");
        String value = parser.getAttributeValue(null, "value");
        tags.add(new Tag(name, type, value));
    }
    return new IoTRegister(tags, nodeInfo, selfOwned);
}
Also used : NodeInfo(org.jivesoftware.smackx.iot.element.NodeInfo) ArrayList(java.util.ArrayList) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Tag(org.jivesoftware.smackx.iot.discovery.element.Tag) IoTRegister(org.jivesoftware.smackx.iot.discovery.element.IoTRegister)

Aggregations

Tag (org.jivesoftware.smackx.iot.discovery.element.Tag)3 ArrayList (java.util.ArrayList)2 IoTRegister (org.jivesoftware.smackx.iot.discovery.element.IoTRegister)2 NodeInfo (org.jivesoftware.smackx.iot.element.NodeInfo)2 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)1