Package org.jivesoftware.smack.util
Class XmlStringBuilder
- java.lang.Object
-
- org.jivesoftware.smack.util.XmlStringBuilder
-
- All Implemented Interfaces:
java.lang.Appendable
,java.lang.CharSequence
,Element
- Direct Known Subclasses:
IQ.IQChildElementXmlStringBuilder
public class XmlStringBuilder extends java.lang.Object implements java.lang.Appendable, java.lang.CharSequence, Element
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
RIGHT_ANGLE_BRACKET
-
Constructor Summary
Constructors Constructor Description XmlStringBuilder()
XmlStringBuilder(java.lang.String elementName, java.lang.String xmlNs, java.lang.String xmlLang, XmlEnvironment enclosingXmlEnvironment)
XmlStringBuilder(ExtensionElement pe)
XmlStringBuilder(FullyQualifiedElement element, XmlEnvironment enclosingXmlEnvironment)
XmlStringBuilder(NamedElement e)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description XmlStringBuilder
append(char c)
XmlStringBuilder
append(java.lang.CharSequence csq)
XmlStringBuilder
append(java.lang.CharSequence csq, int start, int end)
XmlStringBuilder
append(java.util.Collection<? extends Element> elements)
XmlStringBuilder
append(Element element)
XmlStringBuilder
append(XmlStringBuilder xsb)
XmlStringBuilder
attribute(java.lang.String name, boolean bool)
XmlStringBuilder
attribute(java.lang.String name, int value)
XmlStringBuilder
attribute(java.lang.String name, long value)
<E extends java.lang.Enum<?>>
XmlStringBuilderattribute(java.lang.String name, E value, E implicitDefault)
XmlStringBuilder
attribute(java.lang.String name, java.lang.CharSequence value)
XmlStringBuilder
attribute(java.lang.String name, java.lang.Enum<?> value)
XmlStringBuilder
attribute(java.lang.String name, java.lang.String value)
Does nothing if value is null.XmlStringBuilder
attribute(java.lang.String name, java.util.Date value)
Add a new attribute to this builder, with theDate
instance as its value, which will get formatted withXmppDateTime.formatXEP0082Date(Date)
.char
charAt(int index)
XmlStringBuilder
closeElement(java.lang.String name)
XmlStringBuilder
closeElement(NamedElement e)
XmlStringBuilder
closeEmptyElement()
XmlStringBuilder
condAttribute(boolean condition, java.lang.String name, java.lang.String value)
XmlStringBuilder
condEmptyElement(boolean condition, java.lang.String element)
XmlStringBuilder
element(java.lang.String name, java.lang.CharSequence content)
Add a new element to this builder.XmlStringBuilder
element(java.lang.String name, java.lang.Enum<?> content)
XmlStringBuilder
element(java.lang.String name, java.lang.String content)
Add a new element to this builder.XmlStringBuilder
element(java.lang.String name, java.util.Date content)
Add a new element to this builder, with theDate
instance as its content, which will get formatted withXmppDateTime.formatXEP0082Date(Date)
.XmlStringBuilder
element(Element element)
Deprecated.useappend(Element)
instead.XmlStringBuilder
emptyElement(java.lang.Enum<?> element)
XmlStringBuilder
emptyElement(java.lang.String element)
boolean
equals(java.lang.Object other)
XmlStringBuilder
escape(java.lang.CharSequence text)
XmlStringBuilder
escape(java.lang.String text)
XmlStringBuilder
escapeAttributeValue(java.lang.String value)
XmlStringBuilder
escapedElement(java.lang.String name, java.lang.String escapedContent)
XmlEnvironment
getXmlEnvironment()
XmlStringBuilder
halfOpenElement(java.lang.String name)
XmlStringBuilder
halfOpenElement(NamedElement namedElement)
int
hashCode()
int
length()
XmlStringBuilder
openElement(java.lang.String name)
XmlStringBuilder
optAppend(java.util.Collection<? extends Element> elements)
XmlStringBuilder
optAppend(Element element)
XmlStringBuilder
optAttribute(java.lang.String name, java.lang.CharSequence value)
XmlStringBuilder
optAttribute(java.lang.String name, java.lang.Enum<?> value)
XmlStringBuilder
optAttribute(java.lang.String name, java.lang.Long value)
XmlStringBuilder
optAttribute(java.lang.String name, java.lang.Number number)
XmlStringBuilder
optAttribute(java.lang.String name, java.lang.String value)
XmlStringBuilder
optAttribute(java.lang.String name, java.util.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
.XmlStringBuilder
optAttributeCs(java.lang.String name, java.lang.CharSequence value)
Same asoptAttribute(String, CharSequence)
, but with a different method name.XmlStringBuilder
optBooleanAttribute(java.lang.String name, boolean bool)
XmlStringBuilder
optBooleanAttributeDefaultTrue(java.lang.String name, boolean bool)
XmlStringBuilder
optElement(java.lang.String name, java.lang.CharSequence content)
XmlStringBuilder
optElement(java.lang.String name, java.lang.Enum<?> content)
XmlStringBuilder
optElement(java.lang.String name, java.lang.Object object)
XmlStringBuilder
optElement(java.lang.String name, java.lang.String content)
XmlStringBuilder
optElement(java.lang.String name, java.util.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
.XmlStringBuilder
optElement(Element element)
XmlStringBuilder
optEscape(java.lang.CharSequence text)
XmlStringBuilder
optIntAttribute(java.lang.String name, int value)
Add the given attribute ifvalue => 0
.XmlStringBuilder
optIntAttribute(java.lang.String name, java.lang.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.XmlStringBuilder
optIntElement(java.lang.String name, int value)
XmlStringBuilder
optLongAttribute(java.lang.String name, java.lang.Long value)
Add the given attribute if value not null andvalue => 0
.XmlStringBuilder
optTextChild(java.lang.CharSequence sqc, NamedElement parentElement)
XmlStringBuilder
optXmlLangAttribute(java.lang.String lang)
protected XmlStringBuilder
prelude(java.lang.String elementName, java.lang.String namespace)
protected XmlStringBuilder
prelude(FullyQualifiedElement pe)
XmlStringBuilder
rightAngleBracket()
Add a right angle bracket '>'.java.lang.CharSequence
subSequence(int start, int end)
XmlStringBuilder
text(java.lang.CharSequence text)
java.util.List<java.lang.CharSequence>
toList(XmlEnvironment enclosingXmlEnvironment)
java.lang.String
toString()
java.lang.StringBuilder
toXML(XmlEnvironment enclosingXmlEnvironment)
void
write(java.io.Writer writer, XmlEnvironment enclosingXmlEnvironment)
Write the contents of thisXmlStringBuilder
to aWriter
.XmlStringBuilder
xmllangAttribute(java.lang.String value)
XmlStringBuilder
xmlnsAttribute(java.lang.String value)
-
-
-
Field Detail
-
RIGHT_ANGLE_BRACKET
public static final java.lang.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(java.lang.String elementName, java.lang.String xmlNs, java.lang.String xmlLang, XmlEnvironment enclosingXmlEnvironment)
-
-
Method Detail
-
getXmlEnvironment
public XmlEnvironment getXmlEnvironment()
-
escapedElement
public XmlStringBuilder escapedElement(java.lang.String name, java.lang.String escapedContent)
-
element
public XmlStringBuilder element(java.lang.String name, java.lang.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(java.lang.String name, java.util.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(java.lang.String name, java.lang.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(java.lang.String name, java.lang.Enum<?> content)
-
element
@Deprecated public XmlStringBuilder element(Element element)
Deprecated.useappend(Element)
instead.Deprecated.- Parameters:
element
- deprecated.- Returns:
- deprecated.
-
optElement
public XmlStringBuilder optElement(java.lang.String name, java.lang.String content)
-
optElement
public XmlStringBuilder optElement(java.lang.String name, java.util.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(java.lang.String name, java.lang.CharSequence content)
-
optElement
public XmlStringBuilder optElement(Element element)
-
optElement
public XmlStringBuilder optElement(java.lang.String name, java.lang.Enum<?> content)
-
optElement
public XmlStringBuilder optElement(java.lang.String name, java.lang.Object object)
-
optIntElement
public XmlStringBuilder optIntElement(java.lang.String name, int value)
-
halfOpenElement
public XmlStringBuilder halfOpenElement(java.lang.String name)
-
halfOpenElement
public XmlStringBuilder halfOpenElement(NamedElement namedElement)
-
openElement
public XmlStringBuilder openElement(java.lang.String name)
-
closeElement
public XmlStringBuilder closeElement(java.lang.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(java.lang.String name, java.lang.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(java.lang.String name, boolean bool)
-
attribute
public XmlStringBuilder attribute(java.lang.String name, java.util.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(java.lang.String name, java.lang.CharSequence value)
-
attribute
public XmlStringBuilder attribute(java.lang.String name, java.lang.Enum<?> value)
-
attribute
public <E extends java.lang.Enum<?>> XmlStringBuilder attribute(java.lang.String name, E value, E implicitDefault)
-
attribute
public XmlStringBuilder attribute(java.lang.String name, int value)
-
attribute
public XmlStringBuilder attribute(java.lang.String name, long value)
-
optAttribute
public XmlStringBuilder optAttribute(java.lang.String name, java.lang.String value)
-
optAttribute
public XmlStringBuilder optAttribute(java.lang.String name, java.lang.Long value)
-
optAttribute
public XmlStringBuilder optAttribute(java.lang.String name, java.util.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(java.lang.String name, java.lang.CharSequence value)
-
optAttribute
public XmlStringBuilder optAttribute(java.lang.String name, java.lang.Enum<?> value)
-
optAttribute
public XmlStringBuilder optAttribute(java.lang.String name, java.lang.Number number)
-
optAttributeCs
public XmlStringBuilder optAttributeCs(java.lang.String name, java.lang.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(java.lang.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(java.lang.String name, java.lang.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(java.lang.String name, java.lang.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(java.lang.String name, boolean bool)
-
optBooleanAttributeDefaultTrue
public XmlStringBuilder optBooleanAttributeDefaultTrue(java.lang.String name, boolean bool)
-
xmlnsAttribute
public XmlStringBuilder xmlnsAttribute(java.lang.String value)
-
xmllangAttribute
public XmlStringBuilder xmllangAttribute(java.lang.String value)
-
optXmlLangAttribute
public XmlStringBuilder optXmlLangAttribute(java.lang.String lang)
-
text
public XmlStringBuilder text(java.lang.CharSequence text)
-
escape
public XmlStringBuilder escape(java.lang.String text)
-
escapeAttributeValue
public XmlStringBuilder escapeAttributeValue(java.lang.String value)
-
optEscape
public XmlStringBuilder optEscape(java.lang.CharSequence text)
-
escape
public XmlStringBuilder escape(java.lang.CharSequence text)
-
prelude
protected XmlStringBuilder prelude(FullyQualifiedElement pe)
-
prelude
protected XmlStringBuilder prelude(java.lang.String elementName, java.lang.String namespace)
-
optAppend
public XmlStringBuilder optAppend(Element element)
-
optAppend
public XmlStringBuilder optAppend(java.util.Collection<? extends Element> elements)
-
optTextChild
public XmlStringBuilder optTextChild(java.lang.CharSequence sqc, NamedElement parentElement)
-
append
public XmlStringBuilder append(XmlStringBuilder xsb)
-
append
public XmlStringBuilder append(Element element)
-
append
public XmlStringBuilder append(java.util.Collection<? extends Element> elements)
-
emptyElement
public XmlStringBuilder emptyElement(java.lang.Enum<?> element)
-
emptyElement
public XmlStringBuilder emptyElement(java.lang.String element)
-
condEmptyElement
public XmlStringBuilder condEmptyElement(boolean condition, java.lang.String element)
-
condAttribute
public XmlStringBuilder condAttribute(boolean condition, java.lang.String name, java.lang.String value)
-
append
public XmlStringBuilder append(java.lang.CharSequence csq)
- Specified by:
append
in interfacejava.lang.Appendable
-
append
public XmlStringBuilder append(java.lang.CharSequence csq, int start, int end)
- Specified by:
append
in interfacejava.lang.Appendable
-
append
public XmlStringBuilder append(char c)
- Specified by:
append
in interfacejava.lang.Appendable
-
length
public int length()
- Specified by:
length
in interfacejava.lang.CharSequence
-
charAt
public char charAt(int index)
- Specified by:
charAt
in interfacejava.lang.CharSequence
-
subSequence
public java.lang.CharSequence subSequence(int start, int end)
- Specified by:
subSequence
in interfacejava.lang.CharSequence
-
toString
public java.lang.String toString()
- Specified by:
toString
in interfacejava.lang.CharSequence
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
write
public void write(java.io.Writer writer, XmlEnvironment enclosingXmlEnvironment) throws java.io.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:
java.io.IOException
- if an I/O error occurred.
-
toList
public java.util.List<java.lang.CharSequence> toList(XmlEnvironment enclosingXmlEnvironment)
-
toXML
public java.lang.StringBuilder toXML(XmlEnvironment enclosingXmlEnvironment)
-
-