Package org.jivesoftware.smack.util
Class XmlStringBuilder
- java.lang.Object
-
- org.jivesoftware.smack.util.XmlStringBuilder
-
- All Implemented Interfaces:
Appendable
,CharSequence
,Element
- Direct Known Subclasses:
IQ.IQChildElementXmlStringBuilder
public class XmlStringBuilder extends Object implements Appendable, CharSequence, Element
-
-
Field Summary
Fields Modifier and Type Field Description static String
RIGHT_ANGLE_BRACKET
-
Constructor Summary
Constructors Constructor Description XmlStringBuilder()
XmlStringBuilder(String elementName, String xmlNs, String xmlLang, XmlEnvironment enclosingXmlEnvironment)
XmlStringBuilder(ExtensionElement pe)
XmlStringBuilder(FullyQualifiedElement element, XmlEnvironment enclosingXmlEnvironment)
XmlStringBuilder(NamedElement e)
-
Method Summary
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.CharSequence
chars, codePoints
-
-
-
-
Field Detail
-
RIGHT_ANGLE_BRACKET
public static final String RIGHT_ANGLE_BRACKET
-
-
Constructor Detail
-
XmlStringBuilder
public XmlStringBuilder()
-
XmlStringBuilder
public XmlStringBuilder(ExtensionElement pe)
-
XmlStringBuilder
public XmlStringBuilder(NamedElement e)
-
XmlStringBuilder
public XmlStringBuilder(FullyQualifiedElement element, XmlEnvironment enclosingXmlEnvironment)
-
XmlStringBuilder
public XmlStringBuilder(String elementName, String xmlNs, String xmlLang, XmlEnvironment enclosingXmlEnvironment)
-
-
Method Detail
-
getXmlEnvironment
public XmlEnvironment getXmlEnvironment()
-
escapedElement
public XmlStringBuilder escapedElement(String name, String escapedContent)
-
element
public XmlStringBuilder element(String name, String content)
Add a new element to this builder.- Parameters:
name
- TODO javadoc me pleasecontent
- TODO javadoc me please- Returns:
- the XmlStringBuilder
-
element
public XmlStringBuilder element(String name, Date content)
Add a new element to this builder, with theDate
instance as its content, which will get formatted withXmppDateTime.formatXEP0082Date(Date)
.- Parameters:
name
- element namecontent
- content of element- Returns:
- this XmlStringBuilder
-
element
public XmlStringBuilder element(String name, CharSequence content)
Add a new element to this builder.- Parameters:
name
- TODO javadoc me pleasecontent
- TODO javadoc me please- Returns:
- the XmlStringBuilder
-
element
public XmlStringBuilder element(String name, Enum<?> content)
-
element
@Deprecated public XmlStringBuilder element(Element element)
Deprecated.useappend(Element)
instead.Deprecated.- Parameters:
element
- deprecated.- Returns:
- deprecated.
-
optElement
public XmlStringBuilder optElement(String name, String content)
-
optElement
public XmlStringBuilder optElement(String name, Date content)
Add a new element to this builder, with theDate
instance as its content, which will get formatted withXmppDateTime.formatXEP0082Date(Date)
ifDate
instance is notnull
.- Parameters:
name
- element namecontent
- content of element- Returns:
- this XmlStringBuilder
-
optElement
public XmlStringBuilder optElement(String name, CharSequence content)
-
optElement
public XmlStringBuilder optElement(Element element)
-
optElement
public XmlStringBuilder optElement(String name, Enum<?> content)
-
optElement
public XmlStringBuilder optElement(String name, Object object)
-
optIntElement
public XmlStringBuilder optIntElement(String name, int value)
-
halfOpenElement
public XmlStringBuilder halfOpenElement(String name)
-
halfOpenElement
public XmlStringBuilder halfOpenElement(NamedElement namedElement)
-
openElement
public XmlStringBuilder openElement(String name)
-
closeElement
public XmlStringBuilder closeElement(String name)
-
closeElement
public XmlStringBuilder closeElement(NamedElement e)
-
closeEmptyElement
public XmlStringBuilder closeEmptyElement()
-
rightAngleBracket
public XmlStringBuilder rightAngleBracket()
Add a right angle bracket '>'.- Returns:
- a reference to this object.
-
attribute
public XmlStringBuilder attribute(String name, String value)
Does nothing if value is null.- Parameters:
name
- TODO javadoc me pleasevalue
- TODO javadoc me please- Returns:
- the XmlStringBuilder
-
attribute
public XmlStringBuilder attribute(String name, boolean bool)
-
attribute
public XmlStringBuilder attribute(String name, Date value)
Add a new attribute to this builder, with theDate
instance as its value, which will get formatted withXmppDateTime.formatXEP0082Date(Date)
.- Parameters:
name
- name of attributevalue
- value of attribute- Returns:
- this XmlStringBuilder
-
attribute
public XmlStringBuilder attribute(String name, CharSequence value)
-
attribute
public XmlStringBuilder attribute(String name, Enum<?> value)
-
attribute
public <E extends Enum<?>> XmlStringBuilder attribute(String name, E value, E implicitDefault)
-
attribute
public XmlStringBuilder attribute(String name, int value)
-
attribute
public XmlStringBuilder attribute(String name, long value)
-
optAttribute
public XmlStringBuilder optAttribute(String name, String value)
-
optAttribute
public XmlStringBuilder optAttribute(String name, Long value)
-
optAttribute
public XmlStringBuilder optAttribute(String name, Date value)
Add a new attribute to this builder, with theDate
instance as its value, which will get formatted withXmppDateTime.formatXEP0082Date(Date)
ifDate
instance is notnull
.- Parameters:
name
- attribute namevalue
- value of this attribute- Returns:
- this XmlStringBuilder
-
optAttribute
public XmlStringBuilder optAttribute(String name, CharSequence value)
-
optAttribute
public XmlStringBuilder optAttribute(String name, Enum<?> value)
-
optAttribute
public XmlStringBuilder optAttribute(String name, Number number)
-
optAttributeCs
public XmlStringBuilder optAttributeCs(String name, CharSequence value)
Same asoptAttribute(String, CharSequence)
, but with a different method name. This method can be used if the provided attribute value argument type causes ambiguity in method overloading. For example if the type is a subclass of Number and CharSequence.- Parameters:
name
- the name of the attribute.value
- the value of the attribute.- Returns:
- a reference to this object.
- Since:
- 4.5
-
optIntAttribute
public XmlStringBuilder optIntAttribute(String name, int value)
Add the given attribute ifvalue => 0
.- Parameters:
name
- TODO javadoc me pleasevalue
- TODO javadoc me please- Returns:
- a reference to this object
-
optIntAttribute
public XmlStringBuilder optIntAttribute(String name, Integer value)
If the provided Integer argument is not null, then add a new XML attribute with the given name and the Integer as value.- Parameters:
name
- the XML attribute name.value
- the optional integer to use as the attribute's value.- Returns:
- a reference to this object.
- Since:
- 4.4.1
-
optLongAttribute
public XmlStringBuilder optLongAttribute(String name, Long value)
Add the given attribute if value not null andvalue => 0
.- Parameters:
name
- TODO javadoc me pleasevalue
- TODO javadoc me please- Returns:
- a reference to this object
-
optBooleanAttribute
public XmlStringBuilder optBooleanAttribute(String name, boolean bool)
-
optBooleanAttributeDefaultTrue
public XmlStringBuilder optBooleanAttributeDefaultTrue(String name, boolean bool)
-
xmlnsAttribute
public XmlStringBuilder xmlnsAttribute(String value)
-
xmllangAttribute
public XmlStringBuilder xmllangAttribute(String value)
-
optXmlLangAttribute
public XmlStringBuilder optXmlLangAttribute(String lang)
-
text
public XmlStringBuilder text(CharSequence text)
-
escape
public XmlStringBuilder escape(String text)
-
escapeAttributeValue
public XmlStringBuilder escapeAttributeValue(String value)
-
optEscape
public XmlStringBuilder optEscape(CharSequence text)
-
escape
public XmlStringBuilder escape(CharSequence text)
-
prelude
protected XmlStringBuilder prelude(FullyQualifiedElement pe)
-
prelude
protected XmlStringBuilder prelude(String elementName, String namespace)
-
optAppend
public XmlStringBuilder optAppend(Element element)
-
optAppend
public XmlStringBuilder optAppend(Collection<? extends Element> elements)
-
optTextChild
public XmlStringBuilder optTextChild(CharSequence sqc, NamedElement parentElement)
-
append
public XmlStringBuilder append(XmlStringBuilder xsb)
-
append
public XmlStringBuilder append(Element element)
-
append
public XmlStringBuilder append(Collection<? extends Element> elements)
-
emptyElement
public XmlStringBuilder emptyElement(Enum<?> element)
-
emptyElement
public XmlStringBuilder emptyElement(String element)
-
condEmptyElement
public XmlStringBuilder condEmptyElement(boolean condition, String element)
-
condAttribute
public XmlStringBuilder condAttribute(boolean condition, String name, String value)
-
append
public XmlStringBuilder append(CharSequence csq)
- Specified by:
append
in interfaceAppendable
-
append
public XmlStringBuilder append(CharSequence csq, int start, int end)
- Specified by:
append
in interfaceAppendable
-
append
public XmlStringBuilder append(char c)
- Specified by:
append
in interfaceAppendable
-
length
public int length()
- Specified by:
length
in interfaceCharSequence
-
charAt
public char charAt(int index)
- Specified by:
charAt
in interfaceCharSequence
-
subSequence
public CharSequence subSequence(int start, int end)
- Specified by:
subSequence
in interfaceCharSequence
-
toString
public String toString()
- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-
write
public void write(Writer writer, XmlEnvironment enclosingXmlEnvironment) throws IOException
Write the contents of thisXmlStringBuilder
to aWriter
. This will write the single parts one-by-one, avoiding allocation of a big continuous memory block holding the XmlStringBuilder contents.- Parameters:
writer
- TODO javadoc me pleaseenclosingXmlEnvironment
- the enclosing XML environment.- Throws:
IOException
- if an I/O error occurred.
-
toList
public List<CharSequence> toList(XmlEnvironment enclosingXmlEnvironment)
-
toXML
public StringBuilder toXML(XmlEnvironment enclosingXmlEnvironment)
-
-