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

The following examples show how to use org.jivesoftware.smack.util.XmlStringBuilder#escape() . 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: 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 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: 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 5
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.rightAngleBracket();
    buf.escape(getText());
    buf.closeElement(this);
    return buf;
}
 
Example 6
Source File: FormField.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
    XmlStringBuilder xml = new XmlStringBuilder(this, xmlEnvironment);
    xml.rightAngleBracket();
    xml.escape(value);
    return xml.closeElement(this);
}
 
Example 7
Source File: FormField.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
    XmlStringBuilder xml = new XmlStringBuilder(this, xmlEnvironment);
    xml.rightAngleBracket();
    xml.escape(description);
    xml.closeElement(this);
    return xml;
}
 
Example 8
Source File: MediaElement.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
    XmlStringBuilder xml = new XmlStringBuilder(this, xmlEnvironment);
    xml.attribute("type", type)
       .rightAngleBracket();
    xml.escape(uri.toString());
    xml.closeElement(this);
    return xml;
}
 
Example 9
Source File: Bytestream.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.escape(getTarget());
    xml.closeElement(this);
    return xml;
}
 
Example 10
Source File: Header.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    // Upcast to NamedElement since we don't want a xmlns attribute
    XmlStringBuilder xml = new XmlStringBuilder((NamedElement) this);
    xml.attribute("name", name);
    xml.rightAngleBracket();
    xml.escape(value);
    xml.closeElement(this);
    return xml;
}
 
Example 11
Source File: Nick.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.escape(getName());

    xml.closeElement(this);
    return xml;
}
 
Example 12
Source File: Message.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
    XmlStringBuilder xml = new XmlStringBuilder(this, xmlEnvironment);
    xml.optAttribute(PARENT_ATTRIBUTE_NAME, parent);
    xml.rightAngleBracket();
    xml.escape(thread);
    xml.closeElement(this);
    return xml;
}
 
Example 13
Source File: Message.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.rightAngleBracket();
    xml.escape(message);
    xml.closeElement(getElementName());
    return xml;
}
 
Example 14
Source File: Message.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.escape(subject);
    xml.closeElement(getElementName());
    return xml;
}
 
Example 15
Source File: AbstractTextElement.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.escape(text);
    xml.closeElement(this);
    return xml;
}
 
Example 16
Source File: AbstractError.java    From Smack with Apache License 2.0 5 votes vote down vote up
protected void addDescriptiveTextsAndExtensions(XmlStringBuilder xml) {
    for (Map.Entry<String, String> entry : descriptiveTexts.entrySet()) {
        String xmllang = entry.getKey();
        String text = entry.getValue();
        xml.halfOpenElement("text").xmlnsAttribute(textNamespace)
                .optXmlLangAttribute(xmllang)
                .rightAngleBracket();
        xml.escape(text);
        xml.closeElement("text");
    }
    xml.append(extensions);
}
 
Example 17
Source File: SaslNonza.java    From Smack with 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;
}
 
Example 18
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 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;
}