Class 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 Detail

      • RIGHT_ANGLE_BRACKET

        public static final java.lang.String RIGHT_ANGLE_BRACKET
    • Method Detail

      • 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 please
        content - 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 the Date instance as its content, which will get formatted with XmppDateTime.formatXEP0082Date(Date).
        Parameters:
        name - element name
        content - 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 please
        content - TODO javadoc me please
        Returns:
        the XmlStringBuilder
      • element

        public XmlStringBuilder element​(java.lang.String name,
                                        java.lang.Enum<?> content)
      • 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 the Date instance as its content, which will get formatted with XmppDateTime.formatXEP0082Date(Date) if Date instance is not null.
        Parameters:
        name - element name
        content - content of element
        Returns:
        this XmlStringBuilder
      • optElement

        public XmlStringBuilder optElement​(java.lang.String name,
                                           java.lang.CharSequence content)
      • 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)
      • closeElement

        public XmlStringBuilder closeElement​(java.lang.String name)
      • 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 please
        value - 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 the Date instance as its value, which will get formatted with XmppDateTime.formatXEP0082Date(Date).
        Parameters:
        name - name of attribute
        value - 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 the Date instance as its value, which will get formatted with XmppDateTime.formatXEP0082Date(Date) if Date instance is not null.
        Parameters:
        name - attribute name
        value - 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 as optAttribute(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 if value => 0.
        Parameters:
        name - TODO javadoc me please
        value - 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 and value => 0.
        Parameters:
        name - TODO javadoc me please
        value - 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)
      • escapeAttributeValue

        public XmlStringBuilder escapeAttributeValue​(java.lang.String value)
      • optEscape

        public XmlStringBuilder optEscape​(java.lang.CharSequence text)
      • prelude

        protected XmlStringBuilder prelude​(java.lang.String elementName,
                                           java.lang.String namespace)
      • 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 interface java.lang.Appendable
      • append

        public XmlStringBuilder append​(java.lang.CharSequence csq,
                                       int start,
                                       int end)
        Specified by:
        append in interface java.lang.Appendable
      • append

        public XmlStringBuilder append​(char c)
        Specified by:
        append in interface java.lang.Appendable
      • length

        public int length()
        Specified by:
        length in interface java.lang.CharSequence
      • charAt

        public char charAt​(int index)
        Specified by:
        charAt in interface java.lang.CharSequence
      • subSequence

        public java.lang.CharSequence subSequence​(int start,
                                                  int end)
        Specified by:
        subSequence in interface java.lang.CharSequence
      • toString

        public java.lang.String toString()
        Specified by:
        toString in interface java.lang.CharSequence
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • write

        public void write​(java.io.Writer writer,
                          XmlEnvironment enclosingXmlEnvironment)
                   throws java.io.IOException
        Write the contents of this XmlStringBuilder to a Writer. 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 please
        enclosingXmlEnvironment - 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)
        Specified by:
        toXML in interface Element