Package org.apache.ws.commons.serialize
Class XMLWriterImpl
java.lang.Object
org.apache.ws.commons.serialize.XMLWriterImpl
- All Implemented Interfaces:
XMLWriter
,ContentHandler
- Direct Known Subclasses:
CharSetXMLWriter
,OrderedAttributeXMLWriter
,PassThroughXMLWriter
Default implementation of
XMLWriter
. Works with Java 1.2 and
later.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
canEncode
(char c) Returns whether the XMLWriter can encode the characterc
without an escape sequence like &#ddd;.void
characters
(char[] ch, int start, int length) Inserts a string of characters into the document.void
This method finishs the handlers action.void
endElement
(String namespaceURI, String localName, String qName) Terminates an element.void
endPrefixMapping
(String prefix) Terminates use of a namespace prefix.Returns the locatorReturns the writers encoding.Returns the string being used to indent an XML element by one level.Returns the line terminator.Returns the JaxbXMLSerializers Writer.void
ignorableWhitespace
(char[] ch, int start, int length) Calls the character method with the same arguments.private void
indentMe()
boolean
Returns, whether an XML declaration is being generated.boolean
Returns, whether the methodContentHandler.endDocument()
should do a flush on the target stream.boolean
Returns, whether theXMLWriter
is indenting (pretty printing).void
processingInstruction
(String target, String data) Inserts a processing instruction.void
setDeclarating
(boolean pDeclarating) Sets, whether an XML declaration is being generated.void
setDocumentLocator
(Locator pLocator) Sets the locator.void
setEncoding
(String pEncoding) Sets the writers encoding.void
setFlushing
(boolean pFlushing) Sets, whether the methodContentHandler.endDocument()
should do a flush on the target stream.void
setIndenting
(boolean pIndenting) Returns, whether theXMLWriter
is indenting (pretty printing).void
setIndentString
(String pIndentString) Sets the string being used to indent an XML element by one level.void
setLineFeed
(String pLineFeed) Sets the line terminator.void
Sets the JaxbXMLSerializers Writer.void
skippedEntity
(String ent) Not actually implemented, because I don't know how to skip entities.void
Starts a document.void
startElement
(String namespaceURI, String localName, String qName, Attributes attr) Starts a new element.void
startPrefixMapping
(String prefix, String namespaceURI) Starts use of a namespace prefix.private void
private void
writeCData
(String v) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xml.sax.ContentHandler
declaration
-
Field Details
-
STATE_OUTSIDE
private static final int STATE_OUTSIDE- See Also:
-
STATE_IN_START_ELEMENT
private static final int STATE_IN_START_ELEMENT- See Also:
-
STATE_IN_ELEMENT
private static final int STATE_IN_ELEMENT- See Also:
-
encoding
-
indentString
-
lineFeed
-
w
-
l
-
delayedPrefixes
-
curIndent
int curIndent -
state
private int state -
declarating
private boolean declarating -
indenting
private boolean indenting -
flushing
private boolean flushing
-
-
Constructor Details
-
XMLWriterImpl
public XMLWriterImpl()
-
-
Method Details
-
setEncoding
Description copied from interface:XMLWriter
Sets the writers encoding.- Specified by:
setEncoding
in interfaceXMLWriter
- Parameters:
pEncoding
- Writers encoding, by default null, in which case UTF-8 is being used.
-
getEncoding
Description copied from interface:XMLWriter
Returns the writers encoding.- Specified by:
getEncoding
in interfaceXMLWriter
- Returns:
- Writers encoding, by default null, in which case UTF-8 is being used.
-
setDeclarating
public void setDeclarating(boolean pDeclarating) Description copied from interface:XMLWriter
Sets, whether an XML declaration is being generated.- Specified by:
setDeclarating
in interfaceXMLWriter
- Parameters:
pDeclarating
- Whether an XML declaration is generated. Defaults to false.
-
isDeclarating
public boolean isDeclarating()Description copied from interface:XMLWriter
Returns, whether an XML declaration is being generated.- Specified by:
isDeclarating
in interfaceXMLWriter
- Returns:
- Whether an XML declaration is generated. Defaults to false.
-
setIndenting
public void setIndenting(boolean pIndenting) Description copied from interface:XMLWriter
Returns, whether theXMLWriter
is indenting (pretty printing). If you want indenting, you should consider to invoke the methodsXMLWriter.setIndentString(java.lang.String)
andXMLWriter.setLineFeed(java.lang.String)
as well.- Specified by:
setIndenting
in interfaceXMLWriter
- Parameters:
pIndenting
- Whether indentation is enabled. Defaults to false.
-
isIndenting
public boolean isIndenting()Description copied from interface:XMLWriter
Returns, whether theXMLWriter
is indenting (pretty printing). If you want indenting, you should consider to invoke the methodsXMLWriter.setIndentString(java.lang.String)
andXMLWriter.setLineFeed(java.lang.String)
as well.- Specified by:
isIndenting
in interfaceXMLWriter
- Returns:
- Whether indentation is enabled. Defaults to false.
-
setIndentString
Description copied from interface:XMLWriter
Sets the string being used to indent an XML element by one level. Ignored, if indentation is disabled.- Specified by:
setIndentString
in interfaceXMLWriter
- Parameters:
pIndentString
- The indentation string, by default " " (two blanks).
-
getIndentString
Description copied from interface:XMLWriter
Returns the string being used to indent an XML element by one level. Ignored, if indentation is disabled.- Specified by:
getIndentString
in interfaceXMLWriter
- Returns:
- The indentation string, by default " " (two blanks).
-
setLineFeed
Description copied from interface:XMLWriter
Sets the line terminator. Ignored, if indentation is disabled.- Specified by:
setLineFeed
in interfaceXMLWriter
- 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.
-
getLineFeed
Description copied from interface:XMLWriter
Returns the line terminator. Ignored, if indentation is disabled.- Specified by:
getLineFeed
in interfaceXMLWriter
- 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.
-
setFlushing
public void setFlushing(boolean pFlushing) Description copied from interface:XMLWriter
Sets, whether the methodContentHandler.endDocument()
should do a flush on the target stream.- Specified by:
setFlushing
in interfaceXMLWriter
- Parameters:
pFlushing
- True, if a flush should be done. Defaults to false.
-
isFlushing
public boolean isFlushing()Description copied from interface:XMLWriter
Returns, whether the methodContentHandler.endDocument()
should do a flush on the target stream.- Specified by:
isFlushing
in interfaceXMLWriter
- Returns:
- True, if a flush should be done. Defaults to false.
-
setWriter
Sets the JaxbXMLSerializers Writer.
-
getWriter
Returns the JaxbXMLSerializers Writer.
-
setDocumentLocator
Sets the locator.- Specified by:
setDocumentLocator
in interfaceContentHandler
- Parameters:
pLocator
- A locator for use in case of errors- See Also:
-
getDocumentLocator
Returns the locator- Returns:
- A locator previously set with setDocumentLocator or null.
- See Also:
-
startPrefixMapping
Starts use of a namespace prefix.
- Specified by:
startPrefixMapping
in interfaceContentHandler
- Parameters:
prefix
- The prefixnamespaceURI
- The namespace URI- Throws:
SAXException
- Not actually thrown, just for compliance to the interface specification.
-
endPrefixMapping
Terminates use of a namespace prefix.
- Specified by:
endPrefixMapping
in interfaceContentHandler
- Parameters:
prefix
- The prefix being abandoned.- Throws:
SAXException
- Not actually thrown, just for compliance to the interface specification.
-
startDocument
Starts a document.
- Specified by:
startDocument
in interfaceContentHandler
- Throws:
SAXException
- Not actually thrown, just for compliance to the interface specification.
-
endDocument
This method finishs the handlers action. After calling endDocument you may start a new action by calling startDocument again.
- Specified by:
endDocument
in interfaceContentHandler
- Throws:
SAXException
- Not actually thrown, just for compliance to the interface specification.
-
ignorableWhitespace
Calls the character method with the same arguments.- Specified by:
ignorableWhitespace
in interfaceContentHandler
- Parameters:
ch
- A string of whitespace characters being inserted into the document.start
- The index of the first character.length
- The number of characters.- Throws:
SAXException
- Thrown in case of an IOException.
-
stopTerminator
- Throws:
IOException
-
characters
Inserts a string of characters into the document.- Specified by:
characters
in interfaceContentHandler
- Parameters:
ch
- The characters being inserted. A substring, to be precise.start
- Index of the first characterlength
- Number of characters being inserted- Throws:
SAXException
- Thrown in case of an IOException
-
canEncode
public boolean canEncode(char c) Description copied from interface:XMLWriter
Returns whether the XMLWriter can encode the character
c
without an escape sequence like &#ddd;. -
endElement
Terminates an element.
- Specified by:
endElement
in interfaceContentHandler
- Parameters:
namespaceURI
- The namespace URI, if any, or nulllocalName
- The local name, without prefix, or nullqName
- The qualified name, including a prefix, or null- Throws:
SAXException
- Thrown in case of an IOException.
-
indentMe
- Throws:
IOException
-
writeCData
- Throws:
IOException
-
startElement
public void startElement(String namespaceURI, String localName, String qName, Attributes attr) throws SAXException Starts a new element.- Specified by:
startElement
in interfaceContentHandler
- Parameters:
namespaceURI
- The namespace URI, if any, or nulllocalName
- The local name, without prefix, or nullqName
- The qualified name, including a prefix, or nullattr
- The element attributes- Throws:
SAXException
- Thrown in case of an IOException.
-
skippedEntity
Not actually implemented, because I don't know how to skip entities.- Specified by:
skippedEntity
in interfaceContentHandler
- Parameters:
ent
- The entity being skipped.- Throws:
SAXException
- Not actually thrown, just for compliance to the interface specification.
-
processingInstruction
Inserts a processing instruction.- Specified by:
processingInstruction
in interfaceContentHandler
- Parameters:
target
- The PI targetdata
- The PI data- Throws:
SAXException
- Thrown in case of an IOException
-