Java Code Examples for org.jivesoftware.smack.util.XmlStringBuilder#optElement()

The following examples show how to use org.jivesoftware.smack.util.XmlStringBuilder#optElement() . 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: MUCLightElements.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder(this);
    xml.rightAngleBracket();

    xml.optElement("prev-version", prevVersion);
    xml.optElement("version", version);

    Iterator<Map.Entry<Jid, MUCLightAffiliation>> it = affiliations.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<Jid, MUCLightAffiliation> pair = it.next();
        xml.append(new UserWithAffiliationElement(pair.getKey(), pair.getValue()));
    }

    xml.closeElement(this);
    return xml;
}
 
Example 2
Source File: UserTuneElement.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
    XmlStringBuilder xml = new XmlStringBuilder(this);
    if (isEmptyUserTune()) {
        return xml.closeEmptyElement();
    }
    xml.rightAngleBracket();
    xml.optElement("artist", artist);
    xml.optElement("length", length);
    xml.optElement("rating", rating);
    xml.optElement("source", source);
    xml.optElement("title", title);
    xml.optElement("track", track);
    xml.optElement("uri", uri);
    return xml.closeElement(getElementName());
}
 
Example 3
Source File: JingleContentTransport.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
    XmlStringBuilder xml = new XmlStringBuilder(this, xmlEnvironment);
    addExtraAttributes(xml);

    if (candidates.isEmpty() && info == null) {
        xml.closeEmptyElement();

    } else {

        xml.rightAngleBracket();
        xml.append(candidates);
        xml.optElement(info);
        xml.closeElement(this);
    }

    return xml;
}
 
Example 4
Source File: RSMSet.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder(this);
    xml.rightAngleBracket();
    xml.optElement("after", after);
    xml.optElement("before", before);
    xml.optIntElement("count", count);
    if (firstString != null) {
        xml.halfOpenElement("first");
        xml.optIntAttribute("index", firstIndex);
        xml.rightAngleBracket();
        xml.append(firstString);
        xml.closeElement("first");
    }
    xml.optIntElement("index", index);
    xml.optElement("last", last);
    xml.optIntElement("max", max);
    xml.closeElement(this);
    return xml;
}
 
Example 5
Source File: MUCLightElements.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder();
    xml.openElement("configuration");

    xml.element("roomname", configuration.getRoomName());
    xml.optElement("subject", configuration.getSubject());

    if (configuration.getCustomConfigs() != null) {
        Iterator<Map.Entry<String, String>> it = configuration.getCustomConfigs().entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, String> pair = it.next();
            xml.element(pair.getKey(), pair.getValue());
        }
    }

    xml.closeElement("configuration");
    return xml;
}
 
Example 6
Source File: MUCLightElements.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder(this);
    xml.rightAngleBracket();

    xml.optElement("prev-version", prevVersion);
    xml.optElement("version", version);
    xml.optElement("roomname", roomName);
    xml.optElement("subject", subject);

    if (customConfigs != null) {
        Iterator<Map.Entry<String, String>> it = customConfigs.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, String> pair = it.next();
            xml.element(pair.getKey(), pair.getValue());
        }
    }

    xml.closeElement(this);
    return xml;
}
 
Example 7
Source File: Forwarded.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
    xml.rightAngleBracket();
    xml.optElement(getDelayInformation());
    xml.append(forwardedPacket);
    xml.closeElement(this);
    return xml;
}
 
Example 8
Source File: Failure.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
    xml.rightAngleBracket();

    xml.emptyElement(compressFailureError);
    xml.optElement(stanzaError);

    xml.closeElement(this);
    return xml;
}
 
Example 9
Source File: Presence.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder buf = new XmlStringBuilder(this, enclosingNamespace);
    addCommonAttributes(buf);
    if (type != Type.available) {
        buf.attribute("type", type);
    }

    List<ExtensionElement> extensions = getExtensions();
    if (status == null
                    && priority == null
                    && (mode == null || mode == Mode.available)
                    && extensions.isEmpty()
                    && getError() == null) {
        return buf.closeEmptyElement();
    }

    buf.rightAngleBracket();

    buf.optElement("status", status);
    buf.optElement("priority", priority);
    if (mode != null && mode != Mode.available) {
        buf.element("show", mode);
    }

    buf.append(extensions);

    // Add the error sub-packet, if there is one.
    appendErrorIfExists(buf);

    buf.closeElement(ELEMENT);

    return buf;
}
 
Example 10
Source File: Bookmarks.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the XML representation of the PrivateData.
 *
 * @return the private data as XML.
 */
@Override
public XmlStringBuilder toXML() {
    XmlStringBuilder buf = new XmlStringBuilder();
    buf.halfOpenElement(ELEMENT).xmlnsAttribute(NAMESPACE).rightAngleBracket();

    for (BookmarkedURL urlStorage : getBookmarkedURLS()) {
        if (urlStorage.isShared()) {
            continue;
        }
        buf.halfOpenElement("url").attribute("name", urlStorage.getName()).attribute("url", urlStorage.getURL());
        buf.condAttribute(urlStorage.isRss(), "rss", "true");
        buf.closeEmptyElement();
    }

    // Add Conference additions
    for (BookmarkedConference conference : getBookmarkedConferences()) {
        if (conference.isShared()) {
            continue;
        }
        buf.halfOpenElement("conference");
        buf.attribute("name", conference.getName());
        buf.attribute("autojoin", Boolean.toString(conference.isAutoJoin()));
        buf.attribute("jid", conference.getJid());
        buf.rightAngleBracket();

        buf.optElement("nick", conference.getNickname());
        buf.optElement("password", conference.getPassword());

        buf.closeElement("conference");
    }

    buf.closeElement(ELEMENT);
    return buf;
}
 
Example 11
Source File: MUCUser.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder(this);
    xml.rightAngleBracket();
    xml.optElement(getInvite());
    xml.optElement(getDecline());
    xml.optElement(getItem());
    xml.optElement("password", getPassword());
    xml.append(statusCodes);
    xml.optElement(getDestroy());
    xml.closeElement(this);
    return xml;
}
 
Example 12
Source File: MUCUser.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder(this);
    xml.optAttribute("to", getTo());
    xml.optAttribute("from", getFrom());
    xml.rightAngleBracket();
    xml.optElement("reason", getReason());
    xml.closeElement(this);
    return xml;
}
 
Example 13
Source File: MUCUser.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
    xml.optAttribute("to", getTo());
    xml.optAttribute("from", getFrom());
    xml.rightAngleBracket();
    xml.optElement("reason", getReason());
    xml.closeElement(this);
    return xml;
}
 
Example 14
Source File: Destroy.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder(this);
    xml.optAttribute("jid", getJid());
    xml.rightAngleBracket();
    xml.optElement("reason", getReason());
    xml.closeElement(this);
    return xml;
}
 
Example 15
Source File: MUCItem.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder(this);
    xml.optAttribute("affiliation", getAffiliation());
    xml.optAttribute("jid", getJid());
    xml.optAttribute("nick", getNick());
    xml.optAttribute("role", getRole());
    xml.rightAngleBracket();
    xml.optElement("reason", getReason());
    if (getActor() != null) {
        xml.halfOpenElement("actor").attribute("jid", getActor()).closeEmptyElement();
    }
    xml.closeElement(Stanza.ITEM);
    return xml;
}
 
Example 16
Source File: MUCInitialPresence.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder(this);
    xml.rightAngleBracket();
    xml.optElement("password", getPassword());
    xml.optElement(getHistory());
    xml.closeElement(this);
    return xml;
}
 
Example 17
Source File: GeoLocation.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder(this);
    xml.rightAngleBracket();
    xml.optElement("accuracy", accuracy);
    xml.optElement("alt", alt);
    xml.optElement("altaccuracy", altAccuracy);
    xml.optElement("area", area);
    xml.optElement("bearing", bearing);
    xml.optElement("building", building);
    xml.optElement("country", country);
    xml.optElement("countrycode", countryCode);
    xml.optElement("datum", datum);
    xml.optElement("description", description);
    xml.optElement("error", error);
    xml.optElement("floor", floor);
    xml.optElement("lat", lat);
    xml.optElement("locality", locality);
    xml.optElement("lon", lon);
    xml.optElement("postalcode", postalcode);
    xml.optElement("region", region);
    xml.optElement("room", room);
    xml.optElement("speed", speed);
    xml.optElement("street", street);
    xml.optElement("text", text);
    xml.optElement("timestamp", timestamp);
    xml.optElement("tzo", tzo);
    xml.optElement("uri", uri);
    xml.closeElement(this);
    return xml;
}
 
Example 18
Source File: JingleContent.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(XmlEnvironment enclosingXmlEnvironment) {
    XmlStringBuilder xml = new XmlStringBuilder(this, enclosingXmlEnvironment);
    xml.attribute(CREATOR_ATTRIBUTE_NAME, creator);
    xml.optAttribute(DISPOSITION_ATTRIBUTE_NAME, disposition);
    xml.attribute(NAME_ATTRIBUTE_NAME, name);
    xml.optAttribute(SENDERS_ATTRIBUTE_NAME, senders);
    xml.rightAngleBracket();

    xml.optAppend(description);
    xml.optElement(transport);

    xml.closeElement(this);
    return xml;
}
 
Example 19
Source File: DataForm.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
    XmlStringBuilder buf = new XmlStringBuilder(this, xmlEnvironment);
    buf.attribute("type", getType());
    buf.rightAngleBracket();

    xmlEnvironment = buf.getXmlEnvironment();

    buf.optElement("title", getTitle());
    for (String instruction : getInstructions()) {
        buf.element("instructions", instruction);
    }
    // Append the list of fields returned from a search
    buf.optElement(getReportedData());
    // Loop through all the items returned from a search and append them to the string buffer
    buf.append(getItems());

    // Add all form fields.
    // We do not need to include the type for data forms of the type submit.
    boolean includeType = getType() != Type.submit;
    for (FormField formField : getFields()) {
        buf.append(formField.toXML(xmlEnvironment, includeType));
    }

    buf.append(getExtensionElements());
    buf.closeElement(this);
    return buf;
}
 
Example 20
Source File: CustomPresence.java    From League-of-Legends-XMPP-Chat-Library with MIT License 5 votes vote down vote up
@Override
public XmlStringBuilder toXML() {
	final XmlStringBuilder buf = new XmlStringBuilder();
	buf.halfOpenElement("presence");
	buf.xmlnsAttribute(getXmlns());
	buf.xmllangAttribute(getLanguage());
	addCommonAttributes(buf);
	if (invisible) {
		buf.attribute("type", "invisible");
	} else if (getType() != Type.available) {
		buf.attribute("type", getType());
	}
	buf.rightAngelBracket();

	buf.optElement("status", getStatus());
	if (getPriority() != Integer.MIN_VALUE) {
		buf.element("priority", Integer.toString(getPriority()));
	}
	if (getMode() != null && getMode() != Mode.available) {
		buf.element("show", getMode());
	}
	buf.append(getExtensionsXML());

	// Add the error sub-packet, if there is one.
	final XMPPError error = getError();
	if (error != null) {
		buf.append(error.toXML());
	}
	buf.closeElement("presence");

	return buf;
}