org.apache.ws.commons.serialize

Interface XMLWriter

All Superinterfaces:
org.xml.sax.ContentHandler
Known Implementing Classes:
CharSetXMLWriter, OrderedAttributeXMLWriter, PassThroughXMLWriter, XMLWriterImpl

public interface XMLWriter
extends org.xml.sax.ContentHandler

A simple serializer for XML documents, which is writing to an instance of java.io.Writer.

Method Summary

boolean
canEncode(char pChar)
Returns whether the XMLWriter can encode the character c without an escape sequence like &#ddd;.
String
getEncoding()
Returns the writers encoding.
String
getIndentString()
Returns the string being used to indent an XML element by one level.
String
getLineFeed()
Returns the line terminator.
Writer
getWriter()
Returns the target Writer.
boolean
isDeclarating()
Returns, whether an XML declaration is being generated.
boolean
isFlushing()
Returns, whether the method org.xml.sax.ContentHandler.endDocument should do a flush on the target stream.
boolean
isIndenting()
Returns, whether the XMLWriter is indenting (pretty printing).
void
setDeclarating(boolean pDeclarating)
Sets, whether an XML declaration is being generated.
void
setEncoding(String pEncoding)
Sets the writers encoding.
void
setFlushing(boolean pFlushing)
Sets, whether the method org.xml.sax.ContentHandler.endDocument should do a flush on the target stream.
void
setIndentString(String pIndentString)
Sets the string being used to indent an XML element by one level.
void
setIndenting(boolean pIndenting)
Returns, whether the XMLWriter is indenting (pretty printing).
void
setLineFeed(String pLineFeed)
Sets the line terminator.
void
setWriter(Writer pWriter)
Sets the target Writer.

Method Details

canEncode

public boolean canEncode(char pChar)
Returns whether the XMLWriter can encode the character c without an escape sequence like &#ddd;.
Parameters:
pChar - The character being checked for escaping.
Returns:
Whether to encode the character.

getEncoding

public String getEncoding()
Returns the writers encoding.
Returns:
Writers encoding, by default null, in which case UTF-8 is being used.

getIndentString

public String getIndentString()
Returns the string being used to indent an XML element by one level. Ignored, if indentation is disabled.
Returns:
The indentation string, by default " " (two blanks).

getLineFeed

public String getLineFeed()
Returns the line terminator. Ignored, if indentation is disabled.
Returns:
The line terminator, by default "\n" (Line Feed). You might prefer "\r\n" (Carriage Return, Line Feed), which is the default on Windows and related operating systems.

getWriter

public Writer getWriter()
Returns the target Writer. This is typically an instance of java.io.BufferedWriter, which is connected to an instance of java.io.OutputStreamWriter with an encoding matching the XML documents encoding.
Returns:
The target writer.

isDeclarating

public boolean isDeclarating()
Returns, whether an XML declaration is being generated.
Returns:
Whether an XML declaration is generated. Defaults to false.

isFlushing

public boolean isFlushing()
Returns, whether the method org.xml.sax.ContentHandler.endDocument should do a flush on the target stream.
Returns:
True, if a flush should be done. Defaults to false.

isIndenting

public boolean isIndenting()
Returns, whether the XMLWriter is indenting (pretty printing). If you want indenting, you should consider to invoke the methods setIndentString(java.lang.String) and setLineFeed(java.lang.String) as well.
Returns:
Whether indentation is enabled. Defaults to false.

setDeclarating

public void setDeclarating(boolean pDeclarating)
Sets, whether an XML declaration is being generated.
Parameters:
pDeclarating - Whether an XML declaration is generated. Defaults to false.

setEncoding

public void setEncoding(String pEncoding)
Sets the writers encoding.
Parameters:
pEncoding - Writers encoding, by default null, in which case UTF-8 is being used.

setFlushing

public void setFlushing(boolean pFlushing)
Sets, whether the method org.xml.sax.ContentHandler.endDocument should do a flush on the target stream.
Parameters:
pFlushing - True, if a flush should be done. Defaults to false.

setIndentString

public void setIndentString(String pIndentString)
Sets the string being used to indent an XML element by one level. Ignored, if indentation is disabled.
Parameters:
pIndentString - The indentation string, by default " " (two blanks).

setIndenting

public void setIndenting(boolean pIndenting)
Returns, whether the XMLWriter is indenting (pretty printing). If you want indenting, you should consider to invoke the methods setIndentString(java.lang.String) and setLineFeed(java.lang.String) as well.
Parameters:
pIndenting - Whether indentation is enabled. Defaults to false.

setLineFeed

public void setLineFeed(String pLineFeed)
Sets the line terminator. Ignored, if indentation is disabled.
Parameters:
pLineFeed - The line terminator, by default "\n" (Line Feed). You might prefer "\r\n" (Carriage Return, Line Feed), which is the default on Windows and related operating systems.

setWriter

public void setWriter(Writer pWriter)
Sets the target Writer. This is typically an instance of java.io.BufferedWriter, which is connected to an instance of java.io.OutputStreamWriter with an encoding matching the XML documents encoding.
Parameters:
pWriter - The target writer.