Class XmlWriter<SELF extends XmlWriter<SELF>>

java.lang.Object
java.io.Writer
org.apache.juneau.marshall.serializer.SerializerWriter<SELF>
org.apache.juneau.marshall.xml.XmlWriter<SELF>
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable
Direct Known Subclasses:
BasicXmlWriter, HtmlWriter

public abstract class XmlWriter<SELF extends XmlWriter<SELF>> extends SerializerWriter<SELF>
Specialized writer for serializing XML.
Notes:
  • This class is not intended for external use.
See Also:
  • Constructor Details

    • XmlWriter

      protected XmlWriter(Writer out, boolean useWhitespace, int maxIndent, boolean trimStrings, char quoteChar, UriResolver uriResolver, boolean enableNs, Namespace defaultNamespace)
      Constructor.
      Parameters:
      out - The wrapped writer.
      useWhitespace - If true XML elements will be indented.
      maxIndent - The maximum indentation level.
      trimStrings - If true, strings should be trimmed before they're serialized.
      quoteChar - The quote character to use for attributes. Should be '\'' or '"'.
      uriResolver - The URI resolver for resolving URIs to absolute or root-relative form.
      enableNs - Flag to indicate if XML namespaces are enabled.
      defaultNamespace - The default namespace if XML namespaces are enabled.
    • XmlWriter

      protected XmlWriter(XmlWriter<?> w)
      Copy constructor.
      Parameters:
      w - Writer being copied.
  • Method Details

    • attr

      public SELF attr(Namespace ns, String name, Object value)
      Same as attr(String, String, Object), except pass in a Namespace object for the namespace.
      Parameters:
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The attribute name.
      value - The attribute value. Encoded as described in attr(String, String, Object, boolean).
      Returns:
      This object.
    • attr

      public SELF attr(String name, Object value)
      Shortcut for attr(null, name, value, true);
      Parameters:
      name - The attribute name.
      value - The attribute value. Encoded as described in attr(String, String, Object, boolean).
      Returns:
      This object.
    • attr

      public SELF attr(String name, Object value, boolean valNeedsEncoding)
      Shortcut for attr(null, name, value, valNeedsEncoding);
      Parameters:
      name - The attribute name.
      value - The attribute value.
      valNeedsEncoding - If true, the attribute value will be encoded.
      Returns:
      This object.
    • attr

      public SELF attr(String ns, String name, Object value)
      Shortcut for attr(ns, name, value, true);
      Parameters:
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The attribute name.
      value - The attribute value. Encoded as described in attr(String, String, Object, boolean).
      Returns:
      This object.
    • attr

      public SELF attr(String ns, String name, Object value, boolean valNeedsEncoding)
      Writes an attribute to the output: ns:name='value'

      Encoding defends against markup injection: an unencoded value containing a quote character terminates the attribute early and lets the remainder of the value be interpreted as markup. Pass false only for values that are already known to be safe attribute text.

      Parameters:
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The attribute name.
      value - The attribute value.
      valNeedsEncoding - If true, the attribute value will be encoded.
      Returns:
      This object.
    • attrUri

      public SELF attrUri(Namespace ns, String name, Object value)
      Writes an attribute with a URI value to the output: ns:name='uri-value'
      Parameters:
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The attribute name.
      value - The attribute value, convertible to a URI via toString()
      Returns:
      This object.
    • attrUri

      public SELF attrUri(String name, Object value)
      Append an attribute with a URI value.
      Parameters:
      name - The attribute name.
      value - The attribute value. Can be any object whose toString() method returns a URI.
      Returns:
      This object.
    • attrUri

      public SELF attrUri(String ns, String name, Object value)
      Writes an attribute with a URI value to the output: ns:name='uri-value'
      Parameters:
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The attribute name.
      value - The attribute value, convertible to a URI via toString()
      Returns:
      This object.
    • ceTag

      public SELF ceTag()
      Closes an empty tag.

      Shortcut for append('/').append('->');

      Returns:
      This object.
    • cTag

      public SELF cTag()
      Closes a tag.

      Shortcut for append('->');

      Returns:
      This object.
    • eTag

      public SELF eTag(int indent, String name)
      Shortcut for i(indent).eTag(null, name, false);
      Parameters:
      indent - The number of prefix tabs to add.
      name - The element name.
      Returns:
      This object.
    • eTag

      public SELF eTag(int indent, String ns, String name)
      Shortcut for i(indent).eTag(ns, name, false);
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The element name.
      Returns:
      This object.
    • eTag

      public SELF eTag(int indent, String ns, String name, boolean needsEncoding)
      Shortcut for i(indent).eTag(ns, name, needsEncoding);
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • eTag

      public SELF eTag(String name)
      Shortcut for eTag(null, name, false);
      Parameters:
      name - The element name.
      Returns:
      This object.
    • eTag

      public SELF eTag(String ns, String name)
      Shortcut for eTag(ns, name, false);
      Parameters:
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The element name.
      Returns:
      This object.
    • eTag

      public SELF eTag(String ns, String name, boolean needsEncoding)
      Writes an end tag to the output: </ns:name>
      Parameters:
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • oAttr

      public SELF oAttr(Namespace ns, String name)
      Writes an open-ended attribute to the output: ns:name=
      Parameters:
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The attribute name.
      Returns:
      This object.
    • oAttr

      public SELF oAttr(String ns, String name)
      Writes an open-ended attribute to the output: ns:name=
      Parameters:
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The attribute name.
      Returns:
      This object.
    • oTag

      public SELF oTag(int indent, String name)
      Shortcut for i(indent).oTag(null, name, false);
      Parameters:
      indent - The number of prefix tabs to add.
      name - The element name.
      Returns:
      This object.
    • oTag

      public SELF oTag(int indent, String ns, String name)
      Shortcut for i(indent).oTag(ns, name, false);
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The element name.
      Returns:
      This object.
    • oTag

      public SELF oTag(int indent, String ns, String name, boolean needsEncoding)
      Shortcut for i(indent).oTag(ns, name, needsEncoding);
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • oTag

      public SELF oTag(String name)
      Shortcut for oTag(null, name, false);
      Parameters:
      name - The element name.
      Returns:
      This object.
    • oTag

      public SELF oTag(String ns, String name)
      Shortcut for oTag(ns, name, false);
      Parameters:
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The element name.
      Returns:
      This object.
    • oTag

      public SELF oTag(String ns, String name, boolean needsEncoding)
      Writes an opening tag to the output: <ns:name
      Parameters:
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • sTag

      public SELF sTag(int indent, String name)
      Shortcut for i(indent).sTag(null, name, false);
      Parameters:
      indent - The number of prefix tabs to add.
      name - The element name.
      Returns:
      This object.
    • sTag

      public SELF sTag(int indent, String ns, String name)
      Shortcut for i(indent).sTag(ns, name, false);
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The element name.
      Returns:
      This object.
    • sTag

      public SELF sTag(int indent, String ns, String name, boolean needsEncoding)
      Shortcut for i(indent).sTag(ns, name, needsEncoding);
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • sTag

      public SELF sTag(String name)
      Shortcut for sTag(null, name, false);
      Parameters:
      name - The element name.
      Returns:
      This object.
    • sTag

      public SELF sTag(String ns, String name)
      Shortcut for sTag(ns, name, false);
      Parameters:
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The element name.
      Returns:
      This object.
    • sTag

      public SELF sTag(String ns, String name, boolean needsEncoding)
      Writes a start tag to the output: <ns:name>
      Parameters:
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • tag

      public SELF tag(int indent, String name)
      Shortcut for i(indent).tag(null, name, false);
      Parameters:
      indent - The number of prefix tabs to add.
      name - The element name.
      Returns:
      This object.
    • tag

      public SELF tag(int indent, String ns, String name)
      Shortcut for i(indent).tag(ns, name, false);
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The element name.
      Returns:
      This object.
    • tag

      public SELF tag(int indent, String ns, String name, boolean needsEncoding)
      Shortcut for i(indent).tag(ns, name, needsEncoding);
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • tag

      public SELF tag(String name)
      Shortcut for tag(null, name, false);
      Parameters:
      name - The element name.
      Returns:
      This object.
    • tag

      public SELF tag(String ns, String name)
      Shortcut for tag(ns, name, false);
      Parameters:
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The element name.
      Returns:
      This object.
    • tag

      public SELF tag(String ns, String name, boolean needsEncoding)
      Writes a closed tag to the output: <ns:name/>
      Parameters:
      ns - The namespace. Can be null (no namespace prefix is written).
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • text

      public SELF text(Object value)
      Shortcut for calling text(o, false);
      Parameters:
      value - The object being serialized.
      Returns:
      This object.
    • text

      public SELF text(Object value, boolean preserveWhitespace)
      Serializes and encodes the specified object as valid XML text.
      Parameters:
      value - The object being serialized.
      preserveWhitespace - If true, then we're serializing XmlFormat.MIXED_PWS or XmlFormat.TEXT_PWS content.
      Returns:
      This object.
    • textUri

      public SELF textUri(Object value)
      Same as text(Object) but treats the value as a URL to resolved then serialized.
      Parameters:
      value - The object being serialized.
      Returns:
      This object.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • attrValue

      protected SELF attrValue(Object value, boolean needsEncoding)
      Writes an attribute value to the output, optionally encoding it.
      Parameters:
      value - The attribute value. URI and URL values are resolved against the URI resolver first.
      needsEncoding - If true, the value is encoded via XmlUtils.encodeAttrValue(Writer, Object, boolean).
      Returns:
      This object.