public class XMLWriterImpl extends java.lang.Object implements XMLWriter
XMLWriter. Works with Java 1.2 and
later.| Modifier and Type | Field and Description |
|---|---|
(package private) int |
curIndent |
private boolean |
declarating |
private java.util.Map |
delayedPrefixes |
private java.lang.String |
encoding |
private boolean |
flushing |
private boolean |
indenting |
private java.lang.String |
indentString |
private org.xml.sax.Locator |
l |
private java.lang.String |
lineFeed |
private int |
state |
private static int |
STATE_IN_ELEMENT |
private static int |
STATE_IN_START_ELEMENT |
private static int |
STATE_OUTSIDE |
private java.io.Writer |
w |
| Constructor and Description |
|---|
XMLWriterImpl() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canEncode(char c)
Returns whether the XMLWriter can encode the character
c without an escape sequence like &#ddd;. |
void |
characters(char[] ch,
int start,
int length)
Inserts a string of characters into the document.
|
void |
endDocument()
This method finishs the handlers action.
|
void |
endElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName)
Terminates an element.
|
void |
endPrefixMapping(java.lang.String prefix)
Terminates use of a namespace prefix.
|
org.xml.sax.Locator |
getDocumentLocator()
Returns the locator
|
java.lang.String |
getEncoding()
Returns the writers encoding.
|
java.lang.String |
getIndentString()
Returns the string being used to indent an XML element
by one level.
|
java.lang.String |
getLineFeed()
Returns the line terminator.
|
java.io.Writer |
getWriter()
Returns the JaxbXMLSerializers Writer.
|
void |
ignorableWhitespace(char[] ch,
int start,
int length)
Calls the character method with the same arguments.
|
private void |
indentMe() |
boolean |
isDeclarating()
Returns, whether an XML declaration is being generated.
|
boolean |
isFlushing()
Returns, whether the method
ContentHandler.endDocument()
should do a flush on the target stream. |
boolean |
isIndenting()
Returns, whether the
XMLWriter is indenting
(pretty printing). |
void |
processingInstruction(java.lang.String target,
java.lang.String data)
Inserts a processing instruction.
|
void |
setDeclarating(boolean pDeclarating)
Sets, whether an XML declaration is being generated.
|
void |
setDocumentLocator(org.xml.sax.Locator pLocator)
Sets the locator.
|
void |
setEncoding(java.lang.String pEncoding)
Sets the writers encoding.
|
void |
setFlushing(boolean pFlushing)
Sets, whether the method
ContentHandler.endDocument()
should do a flush on the target stream. |
void |
setIndenting(boolean pIndenting)
Returns, whether the
XMLWriter is indenting
(pretty printing). |
void |
setIndentString(java.lang.String pIndentString)
Sets the string being used to indent an XML element
by one level.
|
void |
setLineFeed(java.lang.String pLineFeed)
Sets the line terminator.
|
void |
setWriter(java.io.Writer pWriter)
Sets the JaxbXMLSerializers Writer.
|
void |
skippedEntity(java.lang.String ent)
Not actually implemented, because I don't know how to skip entities.
|
void |
startDocument()
Starts a document.
|
void |
startElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes attr)
Starts a new element.
|
void |
startPrefixMapping(java.lang.String prefix,
java.lang.String namespaceURI)
Starts use of a namespace prefix.
|
private void |
stopTerminator() |
private void |
writeCData(java.lang.String v) |
private static final int STATE_OUTSIDE
private static final int STATE_IN_START_ELEMENT
private static final int STATE_IN_ELEMENT
private java.lang.String encoding
private java.lang.String indentString
private java.lang.String lineFeed
private java.io.Writer w
private org.xml.sax.Locator l
private java.util.Map delayedPrefixes
int curIndent
private int state
private boolean declarating
private boolean indenting
private boolean flushing
public void setEncoding(java.lang.String pEncoding)
XMLWritersetEncoding in interface XMLWriterpEncoding - Writers encoding, by default null, in
which case UTF-8 is being used.public java.lang.String getEncoding()
XMLWritergetEncoding in interface XMLWriterpublic void setDeclarating(boolean pDeclarating)
XMLWritersetDeclarating in interface XMLWriterpDeclarating - Whether an XML declaration is generated. Defaults
to false.public boolean isDeclarating()
XMLWriterisDeclarating in interface XMLWriterpublic void setIndenting(boolean pIndenting)
XMLWriterXMLWriter is indenting
(pretty printing). If you want indenting,
you should consider to invoke the methods
XMLWriter.setIndentString(java.lang.String) and
XMLWriter.setLineFeed(java.lang.String) as well.setIndenting in interface XMLWriterpIndenting - Whether indentation is enabled. Defaults to false.public boolean isIndenting()
XMLWriterXMLWriter is indenting
(pretty printing). If you want indenting,
you should consider to invoke the methods
XMLWriter.setIndentString(java.lang.String) and
XMLWriter.setLineFeed(java.lang.String) as well.isIndenting in interface XMLWriterpublic void setIndentString(java.lang.String pIndentString)
XMLWritersetIndentString in interface XMLWriterpIndentString - The indentation string, by default " " (two blanks).public java.lang.String getIndentString()
XMLWritergetIndentString in interface XMLWriterpublic void setLineFeed(java.lang.String pLineFeed)
XMLWritersetLineFeed in interface XMLWriterpLineFeed - 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.public java.lang.String getLineFeed()
XMLWritergetLineFeed in interface XMLWriterpublic void setFlushing(boolean pFlushing)
XMLWriterContentHandler.endDocument()
should do a flush on the target stream.setFlushing in interface XMLWriterpFlushing - True, if a flush should be done. Defaults to
false.public boolean isFlushing()
XMLWriterContentHandler.endDocument()
should do a flush on the target stream.isFlushing in interface XMLWriterpublic void setWriter(java.io.Writer pWriter)
Sets the JaxbXMLSerializers Writer.
public java.io.Writer getWriter()
Returns the JaxbXMLSerializers Writer.
public void setDocumentLocator(org.xml.sax.Locator pLocator)
setDocumentLocator in interface org.xml.sax.ContentHandlerpLocator - A locator for use in case of errorsgetDocumentLocator()public org.xml.sax.Locator getDocumentLocator()
setDocumentLocator(org.xml.sax.Locator)public void startPrefixMapping(java.lang.String prefix,
java.lang.String namespaceURI)
throws org.xml.sax.SAXException
Starts use of a namespace prefix.
startPrefixMapping in interface org.xml.sax.ContentHandlernamespaceURI - The namespace URIprefix - The prefixorg.xml.sax.SAXException - Not actually thrown, just for compliance to the interface specification.public void endPrefixMapping(java.lang.String prefix)
throws org.xml.sax.SAXException
Terminates use of a namespace prefix.
endPrefixMapping in interface org.xml.sax.ContentHandlerprefix - The prefix being abandoned.org.xml.sax.SAXException - Not actually thrown, just for compliance to the interface specification.public void startDocument()
throws org.xml.sax.SAXException
Starts a document.
startDocument in interface org.xml.sax.ContentHandlerorg.xml.sax.SAXException - Not actually thrown, just for compliance to the interface specification.public void endDocument()
throws org.xml.sax.SAXException
This method finishs the handlers action. After calling endDocument you may start a new action by calling startDocument again.
endDocument in interface org.xml.sax.ContentHandlerorg.xml.sax.SAXException - Not actually thrown, just for compliance to the
interface specification.public void ignorableWhitespace(char[] ch,
int start,
int length)
throws org.xml.sax.SAXException
ignorableWhitespace in interface org.xml.sax.ContentHandlerch - A string of whitespace characters being inserted into the document.start - The index of the first character.length - The number of characters.org.xml.sax.SAXException - Thrown in case of an IOException.private void stopTerminator()
throws java.io.IOException
java.io.IOExceptionpublic void characters(char[] ch,
int start,
int length)
throws org.xml.sax.SAXException
characters in interface org.xml.sax.ContentHandlerch - The characters being inserted. A substring, to be precise.start - Index of the first characterlength - Number of characters being insertedorg.xml.sax.SAXException - Thrown in case of an IOExceptionpublic boolean canEncode(char c)
XMLWriterReturns whether the XMLWriter can encode the character
c without an escape sequence like &#ddd;.
public void endElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName)
throws org.xml.sax.SAXException
Terminates an element.
endElement in interface org.xml.sax.ContentHandlernamespaceURI - The namespace URI, if any, or nulllocalName - The local name, without prefix, or nullqName - The qualified name, including a prefix, or nullorg.xml.sax.SAXException - Thrown in case of an IOException.private void indentMe()
throws java.io.IOException
java.io.IOExceptionprivate void writeCData(java.lang.String v)
throws java.io.IOException
java.io.IOExceptionpublic void startElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes attr)
throws org.xml.sax.SAXException
startElement in interface org.xml.sax.ContentHandlernamespaceURI - The namespace URI, if any, or nulllocalName - The local name, without prefix, or nullqName - The qualified name, including a prefix, or nullattr - The element attributesorg.xml.sax.SAXException - Thrown in case of an IOException.public void skippedEntity(java.lang.String ent)
throws org.xml.sax.SAXException
skippedEntity in interface org.xml.sax.ContentHandlerent - The entity being skipped.org.xml.sax.SAXException - Not actually thrown, just for compliance to the interface specification.public void processingInstruction(java.lang.String target,
java.lang.String data)
throws org.xml.sax.SAXException
processingInstruction in interface org.xml.sax.ContentHandlertarget - The PI targetdata - The PI dataorg.xml.sax.SAXException - Thrown in case of an IOException