Java Code Examples for org.jivesoftware.smack.util.XmlStringBuilder#element()
The following examples show how to use
org.jivesoftware.smack.util.XmlStringBuilder#element() .
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 |
@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: MUCLightElements.java From Smack with Apache License 2.0 | 6 votes |
@Override public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { XmlStringBuilder xml = new XmlStringBuilder(this); xml.rightAngleBracket(); xml.optElement("prev-version", prevVersion); xml.optElement("version", version); xml.optElement("roomname", roomName); xml.optElement("subject", subject); if (customConfigs != null) { Iterator<Map.Entry<String, String>> it = customConfigs.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> pair = it.next(); xml.element(pair.getKey(), pair.getValue()); } } xml.closeElement(this); return xml; }
Example 3
Source File: MUCLightElements.java From Smack with Apache License 2.0 | 6 votes |
@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: JingleFileTransferChild.java From Smack with Apache License 2.0 | 6 votes |
@Override public XmlStringBuilder toXML(XmlEnvironment enclosingNamespace) { XmlStringBuilder sb = new XmlStringBuilder(this, enclosingNamespace); sb.rightAngleBracket(); sb.optElement(ELEM_DATE, date); sb.optElement(ELEM_DESC, desc); sb.optElement(ELEM_MEDIA_TYPE, mediaType); sb.optElement(ELEM_NAME, name); sb.optElement(range); if (size > 0) { sb.element(ELEM_SIZE, Integer.toString(size)); } sb.optElement(hash); sb.closeElement(this); return sb; }
Example 5
Source File: PublishPostExtension.java From mangosta-android with Apache License 2.0 | 5 votes |
@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 6
Source File: DataForm.java From Smack with Apache License 2.0 | 5 votes |
@Override public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) { XmlStringBuilder buf = new XmlStringBuilder(this, xmlEnvironment); buf.attribute("type", getType()); buf.rightAngleBracket(); xmlEnvironment = buf.getXmlEnvironment(); buf.optElement("title", getTitle()); for (String instruction : getInstructions()) { buf.element("instructions", instruction); } // Append the list of fields returned from a search buf.optElement(getReportedData()); // Loop through all the items returned from a search and append them to the string buffer buf.append(getItems()); // Add all form fields. // We do not need to include the type for data forms of the type submit. boolean includeType = getType() != Type.submit; for (FormField formField : getFields()) { buf.append(formField.toXML(xmlEnvironment, includeType)); } buf.append(getExtensionElements()); buf.closeElement(this); return buf; }
Example 7
Source File: FormField.java From Smack with Apache License 2.0 | 5 votes |
@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 8
Source File: Mechanisms.java From Smack with Apache License 2.0 | 5 votes |
@Override public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { XmlStringBuilder xml = new XmlStringBuilder(this); xml.rightAngleBracket(); for (String mechanism : mechanisms) { xml.element("mechanism", mechanism); } xml.closeElement(this); return xml; }
Example 9
Source File: Presence.java From Smack with Apache License 2.0 | 5 votes |
@Override public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { XmlStringBuilder buf = new XmlStringBuilder(this, enclosingNamespace); addCommonAttributes(buf); if (type != Type.available) { buf.attribute("type", type); } List<ExtensionElement> extensions = getExtensions(); if (status == null && priority == null && (mode == null || mode == Mode.available) && extensions.isEmpty() && getError() == null) { return buf.closeEmptyElement(); } buf.rightAngleBracket(); buf.optElement("status", status); buf.optElement("priority", priority); if (mode != null && mode != Mode.available) { buf.element("show", mode); } buf.append(extensions); // Add the error sub-packet, if there is one. appendErrorIfExists(buf); buf.closeElement(ELEMENT); return buf; }
Example 10
Source File: Compress.java From Smack with Apache License 2.0 | 5 votes |
@Override public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { XmlStringBuilder xml = new XmlStringBuilder(this); xml.rightAngleBracket(); for (String method : methods) { xml.element("method", method); } xml.closeElement(this); return xml; }
Example 11
Source File: Compress.java From Smack with Apache License 2.0 | 5 votes |
@Override public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace); xml.rightAngleBracket(); xml.element("method", method); xml.closeElement(this); return xml; }
Example 12
Source File: MamElements.java From Smack with Apache License 2.0 | 5 votes |
@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 13
Source File: MamElements.java From Smack with Apache License 2.0 | 5 votes |
@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 14
Source File: FileTooLargeError.java From Smack with Apache License 2.0 | 5 votes |
@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 15
Source File: CustomPresence.java From League-of-Legends-XMPP-Chat-Library with MIT License | 5 votes |
@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 16
Source File: PublishCommentExtension.java From mangosta-android with Apache License 2.0 | 5 votes |
@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 17
Source File: ValidateElement.java From Smack with Apache License 2.0 | 4 votes |
@Override protected void appendXML(XmlStringBuilder buf) { buf.element("regex", getRegex()); }
Example 18
Source File: JivePropertiesExtension.java From Smack with Apache License 2.0 | 4 votes |
@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; }