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

The following examples show how to use org.jivesoftware.smack.util.XmlStringBuilder#optAttribute() . 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: Range.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 sb =  new XmlStringBuilder(this);

    sb.optAttribute(ATTR_OFFSET, offset);
    sb.optAttribute(ATTR_LENGTH, length);

    if (hash != null) {
        sb.rightAngleBracket();
        sb.append(hash);
        sb.closeElement(this);
    } else {
        sb.closeEmptyElement();
    }
    return sb;
}
 
Example 2
Source File: StreamOpen.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
public XmlStringBuilder toXML(XmlEnvironment enclosingXmlEnvironment) {
    XmlStringBuilder xml = new XmlStringBuilder();
    xml.halfOpenElement(getElementName());

    String namespace = CLIENT_NAMESPACE;
    // We always want to state 'xmlns' for stream open tags.
    if (enclosingXmlEnvironment != null) {
        namespace = enclosingXmlEnvironment.getEffectiveNamespaceOrUse(CLIENT_NAMESPACE);
    }
    xml.attribute("xmlns", namespace);

    xml.attribute("to", to);
    xml.attribute("xmlns:stream", "http://etherx.jabber.org/streams");
    xml.attribute("version", VERSION);
    xml.optAttribute("from", from);
    xml.optAttribute("id", id);
    xml.xmllangAttribute(lang);
    xml.rightAngleBracket();
    return xml;
}
 
Example 3
Source File: RosterPacket.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, enclosingNamespace);
    xml.attribute("jid", jid);
    xml.optAttribute("name", name);
    xml.optAttribute("subscription", itemType);
    if (subscriptionPending) {
        xml.append(" ask='subscribe'");
    }
    xml.optBooleanAttribute("approved", approved);
    xml.rightAngleBracket();

    for (String groupName : groupNames) {
        xml.openElement(GROUP).escape(groupName).closeElement(GROUP);
    }
    xml.closeElement(this);
    return xml;
}
 
Example 4
Source File: Subscription.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
protected void addXml(XmlStringBuilder xml) {
    xml.attribute("jid", jid);
    xml.optAttribute("subid", id);
    xml.optAttribute("subscription", state);
    xml.closeEmptyElement();
}
 
Example 5
Source File: JingleS5BTransportCandidate.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(ATTR_CID, cid);
    xml.attribute(ATTR_HOST, host);
    xml.attribute(ATTR_JID, jid);
    if (port >= 0) {
        xml.attribute(ATTR_PORT, port);
    }
    xml.attribute(ATTR_PRIORITY, priority);
    xml.optAttribute(ATTR_TYPE, type);

    xml.closeEmptyElement();
    return xml;
}
 
Example 6
Source File: PayloadItem.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
protected void addXml(XmlStringBuilder xml) {
    xml.optAttribute("id", getId());
    xml.rightAngleBracket();
    xml.append(payload);
    xml.closeElement(this);
}
 
Example 7
Source File: DeliveryReceipt.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("id", id);
    xml.closeEmptyElement();
    return xml;
}
 
Example 8
Source File: FormField.java    From Smack with Apache License 2.0 5 votes vote down vote up
public final XmlStringBuilder toXML(XmlEnvironment enclosingNamespace, boolean includeType) {
    XmlStringBuilder buf = new XmlStringBuilder(this, enclosingNamespace);
    // Add attributes
    buf.optAttribute("label", getLabel());
    buf.optAttribute("var", getFieldName());

    if (includeType) {
        // If no 'type' is specified, the default is "text-single";
        buf.attribute("type", getType(), Type.text_single);
    }

    if (extraXmlChildElements == null) {
        // If extraXmlChildElements is null, see if they should be populated.
        populateExtraXmlChildElements();
    }

    if (formFieldChildElements.isEmpty() && extraXmlChildElements == null) {
        buf.closeEmptyElement();
    } else {
        buf.rightAngleBracket();

        buf.optAppend(extraXmlChildElements);
        buf.append(formFieldChildElements);

        buf.closeElement(this);
    }
    return buf;
}
 
Example 9
Source File: DiscoverInfo.java    From Smack with Apache License 2.0 5 votes vote down vote up
public XmlStringBuilder toXML() {
    XmlStringBuilder xml = new XmlStringBuilder();
    xml.halfOpenElement("identity");
    xml.xmllangAttribute(lang);
    xml.attribute("category", category);
    xml.optAttribute("name", name);
    xml.optAttribute("type", type);
    xml.closeEmptyElement();
    return xml;
}
 
Example 10
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 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.optAttribute("to", getTo());
    xml.optAttribute("from", getFrom());
    xml.rightAngleBracket();
    xml.optElement("reason", getReason());
    xml.closeElement(this);
    return xml;
}
 
Example 12
Source File: FormField.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);
    // Add attribute
    xml.optAttribute("label", getLabel());
    xml.rightAngleBracket();

    // Add element
    xml.element("value", getValueString());

    xml.closeElement(this);
    return xml;
}
 
Example 13
Source File: DelayInformation.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.attribute("stamp", XmppDateTime.formatXEP0082Date(stamp));
    xml.optAttribute("from", from);
    xml.optTextChild(reason, this);
    return xml;
}
 
Example 14
Source File: DataLayout.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);
    buf.optAttribute("label", getLabel());
    buf.rightAngleBracket();

    buf.append(getSectionLayout());

    buf.closeElement(ELEMENT);
    return buf;
}
 
Example 15
Source File: ValidateElement.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(XmlEnvironment enclosingXmlEnvironment) {
    XmlStringBuilder buf = new XmlStringBuilder(this, enclosingXmlEnvironment);
    buf.optAttribute("min", getMin());
    buf.optAttribute("max", getMax());
    buf.closeEmptyElement();
    return buf;
}
 
Example 16
Source File: MamElements.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("queryid", getQueryId());
    xml.optAttribute("id", getId());
    xml.rightAngleBracket();

    xml.append(getForwarded());

    xml.closeElement(this);
    return xml;
}
 
Example 17
Source File: DiscoverItems.java    From Smack with Apache License 2.0 5 votes vote down vote up
public XmlStringBuilder toXML() {
    XmlStringBuilder xml = new XmlStringBuilder();
    xml.halfOpenElement("item");
    xml.attribute("jid", entityID);
    xml.optAttribute("name", name);
    xml.optAttribute("node", node);
    xml.optAttribute("action", action);
    xml.closeEmptyElement();
    return xml;
}
 
Example 18
Source File: JingleS5BTransport.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Override
protected void addExtraAttributes(XmlStringBuilder xml) {
    xml.optAttribute(ATTR_DSTADDR, dstAddr);
    xml.optAttribute(ATTR_MODE, mode);
    xml.attribute(ATTR_SID, streamId);
}
 
Example 19
Source File: UnsubscribeExtension.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Override
protected void addXml(XmlStringBuilder xml) {
    xml.attribute("jid", jid);
    xml.optAttribute("subid", id);
    xml.closeEmptyElement();
}
 
Example 20
Source File: GetItemsRequest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Override
protected void addXml(XmlStringBuilder xml) {
    xml.optAttribute("subid", getSubscriptionId());
    xml.optIntAttribute("max_items", getMaxItems());
    xml.closeEmptyElement();
}