Java Code Examples for org.jivesoftware.smack.util.XmlStringBuilder

The following examples show how to use org.jivesoftware.smack.util.XmlStringBuilder. These examples are extracted from open source projects. 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 Project: mangosta-android   Source File: PostEntryExtension.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public CharSequence toXML() {
    XmlStringBuilder xml = new XmlStringBuilder(this);
    xml.rightAngleBracket();

    xml.halfOpenElement("title");
    xml.attribute("type", "text");
    xml.rightAngleBracket();
    xml.escape(title);
    xml.closeElement("title");

    String timeStamp = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(published);
    String idTag = "tag:" + XMPPSession.getInstance().getXMPPConnection().getUser().getDomain() + "," + timeStamp + ":posts-" + id;
    xml.element("id", idTag);

    xml.element("published", published);

    xml.element("updated", updated);

    xml.closeElement(this);
    return xml;
}
 
Example 2
Source Project: Smack   Source File: StreamOpen.java    License: 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 Project: Smack   Source File: OmemoBundleElement.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder sb = new XmlStringBuilder(this, enclosingNamespace).rightAngleBracket();

    sb.halfOpenElement(SIGNED_PRE_KEY_PUB).attribute(SIGNED_PRE_KEY_ID, signedPreKeyId).rightAngleBracket()
            .append(signedPreKeyB64).closeElement(SIGNED_PRE_KEY_PUB);

    sb.openElement(SIGNED_PRE_KEY_SIG).append(signedPreKeySignatureB64).closeElement(SIGNED_PRE_KEY_SIG);

    sb.openElement(IDENTITY_KEY).append(identityKeyB64).closeElement(IDENTITY_KEY);

    sb.openElement(PRE_KEYS);
    for (Map.Entry<Integer, String> p : this.preKeysB64.entrySet()) {
        sb.halfOpenElement(PRE_KEY_PUB).attribute(PRE_KEY_ID, p.getKey()).rightAngleBracket()
                .append(p.getValue()).closeElement(PRE_KEY_PUB);
    }
    sb.closeElement(PRE_KEYS);

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

    String tag = isRoom ? "room" : "user";
    xml.halfOpenElement(tag);

    String action = allow ? "allow" : "deny";
    xml.attribute("action", action);
    xml.rightAngleBracket();

    xml.escape(jid);

    xml.closeElement(tag);
    return xml;
}
 
Example 5
Source Project: Smack   Source File: Range.java    License: 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 6
Source Project: Smack   Source File: ReferenceElement.java    License: 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)
            .optIntAttribute(ATTR_BEGIN, begin != null ? begin : -1)
            .optIntAttribute(ATTR_END, end != null ? end : -1)
            .attribute(ATTR_TYPE, type.toString())
            .optAttribute(ATTR_ANCHOR, anchor)
            .optAttribute(ATTR_URI, uri != null ? uri.toString() : null);

    if (child == null) {
        return xml.closeEmptyElement();
    } else {
        return xml.rightAngleBracket()
                .append(child.toXML())
                .closeElement(this);
    }
}
 
Example 7
Source Project: Smack   Source File: IdleElement.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    return new XmlStringBuilder(this)
            .attribute(ATTR_SINCE, since)
            .closeEmptyElement();
}
 
Example 8
Source Project: Smack   Source File: JingleS5BTransportCandidate.java    License: 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 9
Source Project: Smack   Source File: SubscriptionsExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void addXml(XmlStringBuilder xml) {
    if ((items == null) || (items.size() == 0)) {
        xml.closeEmptyElement();
        return;
    }
    xml.rightAngleBracket();
    xml.append(items);
    xml.closeElement(this);
}
 
Example 10
Source Project: Smack   Source File: StreamManagement.java    License: Apache License 2.0 5 votes vote down vote up
protected void maybeAddResumeAttributeTo(XmlStringBuilder xml) {
    if (resume) {
        // XEP 198 never mentions the case where resume='false', it's either set to true or
        // not set at all. We reflect this in this code part
        xml.attribute("resume", "true");
    }
}
 
Example 11
Source Project: Smack   Source File: Destroy.java    License: 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 12
Source Project: Smack   Source File: StreamManagement.java    License: 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, enclosingNamespace);
    xml.optAttribute("id", id);
    maybeAddResumeAttributeTo(xml);
    xml.optAttribute("location", location);
    maybeAddMaxAttributeTo(xml);
    xml.closeEmptyElement();
    return xml;
}
 
Example 13
Source Project: Smack   Source File: ValidateElement.java    License: 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("datatype", datatype);
    buf.rightAngleBracket();
    appendXML(buf);
    buf.optAppend(getListRange());
    buf.closeElement(this);
    return buf;
}
 
Example 14
Source Project: Smack   Source File: OmemoKeyElement.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(XmlEnvironment enclosingXmlEnvironment) {
    XmlStringBuilder sb = new XmlStringBuilder(this, enclosingXmlEnvironment);

    if (isPreKey()) {
        sb.attribute(ATTR_PREKEY, true);
    }

    sb.attribute(ATTR_RID, getId());
    sb.rightAngleBracket();
    sb.append(Base64.encodeToString(getData()));
    sb.closeElement(this);
    return sb;
}
 
Example 15
Source Project: Smack   Source File: OmemoElement.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder sb = new XmlStringBuilder(this, enclosingNamespace).rightAngleBracket();

    sb.append(header);

    if (payload != null) {
        sb.openElement(ATTR_PAYLOAD).append(Base64.encodeToString(payload)).closeElement(ATTR_PAYLOAD);
    }

    sb.closeElement(this);
    return sb;
}
 
Example 16
Source Project: Smack   Source File: MUCUser.java    License: 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 17
Source Project: Smack   Source File: FileTooLargeError.java    License: 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.element("max-file-size", String.valueOf(maxFileSize));
    xml.closeElement(this);
    return xml;
}
 
Example 18
Source Project: Smack   Source File: Bookmarks.java    License: 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 19
Source Project: Smack   Source File: Session.java    License: 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);
    if (optional) {
        xml.rightAngleBracket();
        xml.emptyElement(OPTIONAL_ELEMENT);
        xml.closeElement(this);
    } else {
        xml.closeEmptyElement();
    }
    return xml;
}
 
Example 20
Source Project: Smack   Source File: DataLayout.java    License: 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);
    buf.optAttribute("label", getLabel());
    buf.rightAngleBracket();

    buf.append(getPageLayout());

    buf.closeElement(this);

    return buf;
}
 
Example 21
Source Project: Smack   Source File: MUCLightElements.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder();
    xml.openElement("occupants");

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

    xml.closeElement("occupants");
    return xml;
}
 
Example 22
Source Project: Smack   Source File: IQ.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Append the sub-element XML section of the IQ stanza.
 *
 * @param xml the XmlStringBuilder to append to.
 */
private void appendInnerXml(XmlStringBuilder xml) {
    if (type == Type.error) {
        // Add the error sub-packet, if there is one.
        appendErrorIfExists(xml);
        return;
    }
    if (childElementName == null) {
        return;
    }

    // Add the query section if there is one.
    IQChildElementXmlStringBuilder iqChildElement = getIQChildElementBuilder(
                    new IQChildElementXmlStringBuilder(this));
    // TOOD: Document the cases where iqChildElement is null but childElementName not. And if there are none, change
    // the logic.
    if (iqChildElement == null) {
        return;
    }

    xml.append(iqChildElement);

    List<ExtensionElement> extensionsXml = getExtensions();
    if (iqChildElement.isEmptyElement) {
        if (extensionsXml.isEmpty()) {
            xml.closeEmptyElement();
            return;
        }

        xml.rightAngleBracket();
    }

    xml.append(extensionsXml);
    xml.closeElement(iqChildElement.element);
}
 
Example 23
Source Project: Smack   Source File: CarbonExtension.java    License: 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.append(fwd.toXML());
    xml.closeElement(this);
    return xml;
}
 
Example 24
Source Project: Smack   Source File: MamElements.java    License: 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 25
Source Project: Smack   Source File: MamElements.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder();
    xml.openElement("always");

    for (Jid jid : alwaysJids) {
        xml.element("jid", jid);
    }

    xml.closeElement("always");
    return xml;
}
 
Example 26
Source Project: Smack   Source File: MamElements.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder();
    xml.openElement("never");

    for (Jid jid : neverJids) {
        xml.element("jid", jid);
    }

    xml.closeElement("never");
    return xml;
}
 
Example 27
Source Project: Smack   Source File: HashElement.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder sb = new XmlStringBuilder(this);
    sb.attribute(ATTR_ALGO, algorithm.toString());
    sb.rightAngleBracket();
    sb.append(hashB64);
    sb.closeElement(this);
    return sb;
}
 
Example 28
Source Project: Smack   Source File: MUCUser.java    License: 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.attribute("code", getCode());
    xml.closeEmptyElement();
    return xml;
}
 
Example 29
Source Project: Smack   Source File: DeliveryReceipt.java    License: 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 30
Source Project: Smack   Source File: SaslNonza.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
    XmlStringBuilder xml = new XmlStringBuilder(this, xmlEnvironment);
    xml.attribute("mechanism", mechanism).rightAngleBracket();
    xml.escape(authenticationText);
    xml.closeElement(this);
    return xml;
}