public class XmlWriterSupport extends Object
Modifier and Type | Field and Description |
---|---|
static boolean |
CLOSE
A constant for close.
|
static int |
CLOSE_TAG_DECREASE
A constant for controlling the indent function.
|
static int |
INDENT_ONLY
A constant for controlling the indent function.
|
static boolean |
OPEN
A constant for open.
|
static int |
OPEN_TAG_INCREASE
A constant for controlling the indent function.
|
Constructor and Description |
---|
XmlWriterSupport()
Default Constructor.
|
XmlWriterSupport(TagDescription safeTags,
String indentString)
Creates a new support instance.
|
XmlWriterSupport(TagDescription safeTags,
String indentString,
String lineseparator)
Create a new XmlWriterSupport instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addImpliedNamespace(String uri,
String prefix)
Adds an implied namespace to the document.
|
void |
copyNamespaces(XmlWriterSupport writerSupport)
Copies all currently declared namespaces of the given XmlWriterSupport instance as new implied namespaces into this
instance.
|
int |
getAdditionalIndent()
Returns the indent level that should be added to the automaticly computed indentation.
|
int |
getCurrentIndentLevel()
Returns the current indention level.
|
String |
getLineSeparator()
Returns the line separator.
|
Properties |
getNamespaces()
Returns all namespaces as properties-collection.
|
TagDescription |
getTagDescription()
Returns the list of safe tags.
|
void |
indent(Writer writer)
Indent the line.
|
void |
indentForClose(Writer writer)
Indent the line.
|
boolean |
isAlwaysAddNamespace()
Checks, whether the XML writer should always add a namespace prefix to the attributes.
|
boolean |
isAssumeDefaultNamespace()
Checks, whether attributes of the same namespace as the current element should be written without a prefix.
|
boolean |
isHtmlCompatiblityMode()
Checks, whether the HTML compatibility mode is enabled.
|
boolean |
isLineEmpty()
Checks, whether the currently generated line of text is empty.
|
boolean |
isNamespaceDefined(String uri)
Checks, whether the given URI is defined as valid namespace.
|
boolean |
isNamespacePrefixDefined(String prefix)
Checks, whether the given namespace prefix is defined.
|
boolean |
isWriteFinalLinebreak()
Checks, whether the written XML file should end with an empty line.
|
static String |
normalize(String s,
boolean transformNewLine)
Normalises a string, replacing certain characters with their escape sequences so that the XML text is not
corrupted.
|
String |
normalizeLocal(String s,
boolean transformNewLine)
Normalizes the given string using a shared buffer.
|
void |
setAdditionalIndent(int additionalIndent)
Defines the indent level that should be added to the automaticly computed indentation.
|
void |
setAlwaysAddNamespace(boolean alwaysAddNamespace)
Defines, whether the XML writer should always add a namespace prefix to the attributes.
|
void |
setAssumeDefaultNamespace(boolean assumeDefaultNamespace)
Defines, whether attributes of the same namespace as the current element should be written without a prefix.
|
void |
setEncoding(String encoding) |
void |
setHtmlCompatiblityMode(boolean htmlCompatiblityMode)
Enables or disables the HTML Compatibility mode.
|
void |
setLineEmpty(boolean lineEmpty)
A marker flag to track, wether the current line is empty.
|
void |
setWriteFinalLinebreak(boolean writeFinalLinebreak)
Defines, whether the written XML file should end with an empty line.
|
void |
writeCloseTag(Writer w)
Writes a closing XML tag.
|
void |
writeComment(Writer writer,
String comment)
Writes a comment into the generated xml file.
|
void |
writeNewLine(Writer writer)
Writes a linebreak to the writer.
|
void |
writeTag(Writer w,
String namespaceUri,
String name)
Writes an opening XML tag that has no attributes.
|
void |
writeTag(Writer w,
String namespaceUri,
String name,
AttributeList attributes,
boolean close)
Writes an opening XML tag along with a list of attribute/value pairs.
|
void |
writeTag(Writer w,
String namespace,
String name,
String attributeName,
String attributeValue,
boolean close)
Writes an opening XML tag with an attribute/value pair.
|
void |
writeTextNormalized(Writer writer,
String s,
boolean transformNewLine)
Normalizes the given string and writes the result directly to the stream.
|
void |
writeXmlDeclaration(Writer writer,
String encoding)
Writes the XML declaration that usually appears at the top of every XML file.
|
public static final int OPEN_TAG_INCREASE
public static final int CLOSE_TAG_DECREASE
public static final int INDENT_ONLY
public static final boolean CLOSE
public static final boolean OPEN
public XmlWriterSupport()
public XmlWriterSupport(TagDescription safeTags, String indentString)
safeTags
- the tags that are safe for line breaks.indentString
- the indent string.public XmlWriterSupport(TagDescription safeTags, String indentString, String lineseparator)
safeTags
- the tags that are safe for line breaks.indentString
- the indent string.lineseparator
- the lineseparator that should be used for writing XML files.public boolean isHtmlCompatiblityMode()
public void setHtmlCompatiblityMode(boolean htmlCompatiblityMode)
htmlCompatiblityMode
- true, if the HTML compatiblity mode is enabled, false otherwise.public boolean isAlwaysAddNamespace()
public void setAlwaysAddNamespace(boolean alwaysAddNamespace)
alwaysAddNamespace
- set to true, if all attributes should be qualified, false otherwise.public int getAdditionalIndent()
public void setAdditionalIndent(int additionalIndent)
additionalIndent
- the indent level.public String getLineSeparator()
public void writeXmlDeclaration(Writer writer, String encoding) throws IOException
encoding
- the encoding that should be declared (this has to match the encoding of the writer, or funny things
may happen when parsing the xml file later).IOException
- if there is a problem writing to the character stream.public void setEncoding(String encoding)
public void writeTag(Writer w, String namespaceUri, String name) throws IOException
w
- the writer.namespaceUri
- the namespace URI for the element.name
- the tag name.IOException
- if there is an I/O problem.public void writeCloseTag(Writer w) throws IOException
w
- the writer.IOException
- if there is an I/O problem.public void writeNewLine(Writer writer) throws IOException
writer
- the writer.IOException
- if there is a problem writing to the character stream.public boolean isLineEmpty()
public void setLineEmpty(boolean lineEmpty)
lineEmpty
- defines, whether the current line should be treated as empty line.public void writeTag(Writer w, String namespace, String name, String attributeName, String attributeValue, boolean close) throws IOException
w
- the writer.namespace
- the namespace URI for the elementname
- the tag name.attributeName
- the attribute name.attributeValue
- the attribute value.close
- controls whether the tag is closed.IOException
- if there is an I/O problem.public void addImpliedNamespace(String uri, String prefix)
uri
- the uri of the namespace.prefix
- the defined prefix.public void copyNamespaces(XmlWriterSupport writerSupport)
writerSupport
- the Xml-writer from where to copy the declared namespaces.public boolean isNamespaceDefined(String uri)
uri
- the uri of the namespace.public boolean isNamespacePrefixDefined(String prefix)
prefix
- the namespace prefix.public Properties getNamespaces()
public void writeTag(Writer w, String namespaceUri, String name, AttributeList attributes, boolean close) throws IOException
w
- the writer.namespaceUri
- the namespace uri for the element (can be null).name
- the tag name.attributes
- the attributes.close
- controls whether the tag is closed.IOException
- if there is an I/O problem.public String normalizeLocal(String s, boolean transformNewLine)
s
- the string that should be XML-Encoded.transformNewLine
- a flag controling whether to transform newlines into character-entities.public void writeTextNormalized(Writer writer, String s, boolean transformNewLine) throws IOException
writer
- the writer that should receive the normalized content.s
- the string that should be XML-Encoded.transformNewLine
- a flag controling whether to transform newlines into character-entities.IOException
- if writing to the stream failed.public static String normalize(String s, boolean transformNewLine)
s
- the string.transformNewLine
- true, if a newline in the string should be converted into a character entity.public void indent(Writer writer) throws IOException
writer
- the writer which should receive the indentention.IOException
- if writing the stream failed.public void indentForClose(Writer writer) throws IOException
writer
- the writer which should receive the indentention.IOException
- if writing the stream failed.public TagDescription getTagDescription()
public void writeComment(Writer writer, String comment) throws IOException
writer
- the writer.comment
- the comment textIOException
- if there is a problem writing to the character stream.public boolean isAssumeDefaultNamespace()
public void setAssumeDefaultNamespace(boolean assumeDefaultNamespace)
assumeDefaultNamespace
- true, if attributes in the element's namespace should be written without a prefix,
false to write all attributes with a prefix.public int getCurrentIndentLevel()
public void setWriteFinalLinebreak(boolean writeFinalLinebreak)
writeFinalLinebreak
- true, if an linebreak should be added at the end of the file, false otherwise.public boolean isWriteFinalLinebreak()