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

The following examples show how to use org.jivesoftware.smack.util.XmlStringBuilder#halfOpenElement() . 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: PostEntryExtension.java    From mangosta-android with 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 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 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();

    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 4
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 5
Source File: StanzaError.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
public XmlStringBuilder toXML(XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
    xml.attribute("type", type.toString());
    xml.optAttribute("by", errorGenerator);
    xml.rightAngleBracket();

    xml.halfOpenElement(condition.toString());
    xml.xmlnsAttribute(ERROR_CONDITION_AND_TEXT_NAMESPACE);
    if (conditionText != null) {
        xml.rightAngleBracket();
        xml.escape(conditionText);
        xml.closeElement(condition.toString());
    }
    else {
        xml.closeEmptyElement();
    }

    addDescriptiveTextsAndExtensions(xml);

    xml.closeElement(this);
    return xml;
}
 
Example 6
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 7
Source File: PublishPostExtension.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);
    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.halfOpenElement("title");
    xml.attribute("type", "text");
    xml.rightAngleBracket();
    xml.escape(title);
    xml.closeElement("title");

    Date today = Calendar.getInstance().getTime();
    String timeStamp = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(today);
    String idTag = "tag:" + jid.getDomain() + "," + timeStamp + ":posts-" + id;
    xml.element("id", idTag);

    xml.element("published", today);

    xml.element("updated", today);

    xml.closeElement("entry");
    xml.closeElement("item");
    xml.closeElement(this);
    return xml;
}
 
Example 8
Source File: ValidateElement.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
protected void appendXML(XmlStringBuilder buf) {
    buf.halfOpenElement(METHOD);
    buf.optAttribute("min", getMin());
    buf.optAttribute("max", getMax());
    buf.closeEmptyElement();
}
 
Example 9
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 10
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("feature");
    xml.attribute("var", variable);
    xml.closeEmptyElement();
    return xml;
}
 
Example 11
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 12
Source File: JingleS5BTransportInfo.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.halfOpenElement(this);
    xml.closeEmptyElement();
    return xml;
}
 
Example 13
Source File: JingleS5BTransportInfo.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.halfOpenElement(this);
    xml.closeEmptyElement();
    return xml;
}
 
Example 14
Source File: OptionsExtension.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
protected void addXml(XmlStringBuilder xml) {
    xml.rightAngleBracket();

    xml.halfOpenElement(getElementName());
    xml.attribute("jid", jid);
    xml.optAttribute("node", getNode());
    xml.optAttribute("subid", id);

    xml.closeEmptyElement();
    xml.closeElement(this);
}
 
Example 15
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 16
Source File: PushNotificationsElements.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.attribute("node", node);
    xml.rightAngleBracket();

    xml.halfOpenElement("affiliation");
    xml.attribute("jid", userJid);
    xml.attribute("affiliation", "none");
    xml.closeEmptyElement();

    xml.closeElement(this);
    return xml;
}
 
Example 17
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.halfOpenElement("user");
    xml.attribute("affiliation", affiliation);
    xml.rightAngleBracket();
    xml.escape(user);
    xml.closeElement("user");
    return xml;
}
 
Example 18
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;
}
 
Example 19
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 20
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;
}