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

The following examples show how to use org.jivesoftware.smack.util.XmlStringBuilder#openElement() . 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: UserLocationExtension.java    From Yahala-Messenger with MIT License 6 votes vote down vote up
public CharSequence toXML() {
    XmlStringBuilder xml = new XmlStringBuilder(this);
    xml.rightAngelBracket();

    xml.openElement("lon");

    xml.escape(location.lon + "");
    xml.closeElement("lon");


    xml.openElement("lat");

    xml.escape(location.lat + "");
    xml.closeElement("lat");
    xml.closeElement(this);
    return xml;
}
 
Example 2
Source File: OmemoBundleElement.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 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 3
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 4
Source File: BoBExtension.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.halfOpenElement(Message.BODY);
    xml.xmlnsAttribute(XHTMLText.NAMESPACE);
    xml.rightAngleBracket();

    xml.openElement(XHTMLText.P);
    xml.optEscape(paragraph);

    xml.halfOpenElement(XHTMLText.IMG);
    xml.optAttribute("alt", alt);
    xml.attribute("src", bobHash.toSrc());
    xml.closeEmptyElement();

    xml.closeElement(XHTMLText.P);
    xml.closeElement(Message.BODY);
    xml.closeElement(this);
    return xml;
}
 
Example 5
Source File: PublishCommentExtension.java    From mangosta-android with Apache License 2.0 5 votes vote down vote up
@Override
public CharSequence toXML() {
    XmlStringBuilder xml = new XmlStringBuilder(this);
    xml.attribute("node", NODE + "/" + blogPostId);
    xml.rightAngleBracket();

    xml.halfOpenElement("item");
    xml.attribute("id", id);
    xml.rightAngleBracket();

    xml.halfOpenElement("entry");
    xml.xmlnsAttribute("http://www.w3.org/2005/Atom");
    xml.rightAngleBracket();

    xml.openElement("author");
    xml.element("name", authorName);
    xml.element("uri", "xmpp:" + authorJid);
    xml.closeElement("author");

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

    xml.element("published", published);

    xml.closeElement("entry");
    xml.closeElement("item");
    xml.closeElement(this);
    return xml;
}
 
Example 6
Source File: MUCLightElements.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();
    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 7
Source File: MamElements.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();
    xml.openElement("always");

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

    xml.closeElement("always");
    return xml;
}
 
Example 8
Source File: MamElements.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();
    xml.openElement("never");

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

    xml.closeElement("never");
    return xml;
}
 
Example 9
Source File: OpenPgpContentElement.java    From Smack with Apache License 2.0 5 votes vote down vote up
protected void addCommonXml(XmlStringBuilder xml) {
    for (Jid toJid : to != null ? to : Collections.<Jid>emptySet()) {
        xml.halfOpenElement(ELEM_TO).attribute(ATTR_JID, toJid).closeEmptyElement();
    }

    ensureTimestampStringSet();
    xml.halfOpenElement(ELEM_TIME).attribute(ATTR_STAMP, timestampString).closeEmptyElement();

    xml.openElement(ELEM_PAYLOAD);
    for (ExtensionElement element : payload.values()) {
        xml.append(element.toXML(getNamespace()));
    }
    xml.closeElement(ELEM_PAYLOAD);
}
 
Example 10
Source File: StreamError.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();
    xml.openElement(ELEMENT);
    xml.halfOpenElement(condition.toString()).xmlnsAttribute(NAMESPACE).closeEmptyElement();
    addDescriptiveTextsAndExtensions(xml);
    xml.closeElement(ELEMENT);
    return xml;
}
 
Example 11
Source File: JingleReason.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.openElement(reason.asString);
    xml.openElement(SID);
    xml.append(sessionId);
    xml.closeElement(SID);
    xml.closeElement(reason.asString);

    xml.closeElement(this);
    return xml;
}
 
Example 12
Source File: JivePropertiesExtension.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Override
public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder(this);
    xml.rightAngleBracket();
    // Loop through all properties and write them out.
    for (String name : getPropertyNames()) {
        Object value = getProperty(name);
        xml.openElement("property");
        xml.element("name", name);
        xml.halfOpenElement("value");

        String type;
        String valueStr;
        if (value instanceof Integer) {
            type = "integer";
            valueStr = Integer.toString((Integer) value);
        }
        else if (value instanceof Long) {
            type = "long";
            valueStr = Long.toString((Long) value);
        }
        else if (value instanceof Float) {
            type = "float";
            valueStr = Float.toString((Float) value);
        }
        else if (value instanceof Double) {
            type = "double";
            valueStr = Double.toString((Double) value);
        }
        else if (value instanceof Boolean) {
            type = "boolean";
            valueStr = Boolean.toString((Boolean) value);
        }
        else if (value instanceof String) {
            type = "string";
            valueStr = (String) value;
        }
        // Otherwise, it's a generic Serializable object. Serialized objects are in
        // a binary format, which won't work well inside of XML. Therefore, we base-64
        // encode the binary data before adding it.
        else {
            try (
                ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream(byteStream);
                ) {
                out.writeObject(value);
                type = "java-object";
                valueStr = Base64.encodeToString(byteStream.toByteArray());
            }
            catch (Exception e) {
                LOGGER.log(Level.SEVERE, "Error encoding java object", e);
                type = "java-object";
                valueStr = "Serializing error: " + e.getMessage();
            }
        }
        xml.attribute("type", type);
        xml.rightAngleBracket();
        xml.escape(valueStr);
        xml.closeElement("value");
        xml.closeElement("property");
    }
    xml.closeElement(this);

    return xml;
}