Package org.apache.ws.commons.serialize
Class XMLWriterImpl
- java.lang.Object
-
- org.apache.ws.commons.serialize.XMLWriterImpl
-
- All Implemented Interfaces:
XMLWriter,org.xml.sax.ContentHandler
- Direct Known Subclasses:
CharSetXMLWriter,OrderedAttributeXMLWriter,PassThroughXMLWriter
public class XMLWriterImpl extends java.lang.Object implements XMLWriter
Default implementation ofXMLWriter. Works with Java 1.2 and later.
-
-
Constructor Summary
Constructors Constructor Description XMLWriterImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanEncode(char c)Returns whether the XMLWriter can encode the charactercwithout an escape sequence like &#ddd;.voidcharacters(char[] ch, int start, int length)Inserts a string of characters into the document.voidendDocument()This method finishs the handlers action.voidendElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)Terminates an element.voidendPrefixMapping(java.lang.String prefix)Terminates use of a namespace prefix.org.xml.sax.LocatorgetDocumentLocator()Returns the locatorjava.lang.StringgetEncoding()Returns the writers encoding.java.lang.StringgetIndentString()Returns the string being used to indent an XML element by one level.java.lang.StringgetLineFeed()Returns the line terminator.java.io.WritergetWriter()Returns the JaxbXMLSerializers Writer.voidignorableWhitespace(char[] ch, int start, int length)Calls the character method with the same arguments.booleanisDeclarating()Returns, whether an XML declaration is being generated.booleanisFlushing()Returns, whether the methodContentHandler.endDocument()should do a flush on the target stream.booleanisIndenting()Returns, whether theXMLWriteris indenting (pretty printing).voidprocessingInstruction(java.lang.String target, java.lang.String data)Inserts a processing instruction.voidsetDeclarating(boolean pDeclarating)Sets, whether an XML declaration is being generated.voidsetDocumentLocator(org.xml.sax.Locator pLocator)Sets the locator.voidsetEncoding(java.lang.String pEncoding)Sets the writers encoding.voidsetFlushing(boolean pFlushing)Sets, whether the methodContentHandler.endDocument()should do a flush on the target stream.voidsetIndenting(boolean pIndenting)Returns, whether theXMLWriteris indenting (pretty printing).voidsetIndentString(java.lang.String pIndentString)Sets the string being used to indent an XML element by one level.voidsetLineFeed(java.lang.String pLineFeed)Sets the line terminator.voidsetWriter(java.io.Writer pWriter)Sets the JaxbXMLSerializers Writer.voidskippedEntity(java.lang.String ent)Not actually implemented, because I don't know how to skip entities.voidstartDocument()Starts a document.voidstartElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attr)Starts a new element.voidstartPrefixMapping(java.lang.String prefix, java.lang.String namespaceURI)Starts use of a namespace prefix.
-
-
-
Method Detail
-
setEncoding
public void setEncoding(java.lang.String pEncoding)
Description copied from interface:XMLWriterSets the writers encoding.- Specified by:
setEncodingin interfaceXMLWriter- Parameters:
pEncoding- Writers encoding, by default null, in which case UTF-8 is being used.
-
getEncoding
public java.lang.String getEncoding()
Description copied from interface:XMLWriterReturns the writers encoding.- Specified by:
getEncodingin 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:XMLWriterSets, whether an XML declaration is being generated.- Specified by:
setDeclaratingin interfaceXMLWriter- Parameters:
pDeclarating- Whether an XML declaration is generated. Defaults to false.
-
isDeclarating
public boolean isDeclarating()
Description copied from interface:XMLWriterReturns, whether an XML declaration is being generated.- Specified by:
isDeclaratingin interfaceXMLWriter- Returns:
- Whether an XML declaration is generated. Defaults to false.
-
setIndenting
public void setIndenting(boolean pIndenting)
Description copied from interface:XMLWriterReturns, whether theXMLWriteris 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:
setIndentingin interfaceXMLWriter- Parameters:
pIndenting- Whether indentation is enabled. Defaults to false.
-
isIndenting
public boolean isIndenting()
Description copied from interface:XMLWriterReturns, whether theXMLWriteris 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:
isIndentingin interfaceXMLWriter- Returns:
- Whether indentation is enabled. Defaults to false.
-
setIndentString
public void setIndentString(java.lang.String pIndentString)
Description copied from interface:XMLWriterSets the string being used to indent an XML element by one level. Ignored, if indentation is disabled.- Specified by:
setIndentStringin interfaceXMLWriter- Parameters:
pIndentString- The indentation string, by default " " (two blanks).
-
getIndentString
public java.lang.String getIndentString()
Description copied from interface:XMLWriterReturns the string being used to indent an XML element by one level. Ignored, if indentation is disabled.- Specified by:
getIndentStringin interfaceXMLWriter- Returns:
- The indentation string, by default " " (two blanks).
-
setLineFeed
public void setLineFeed(java.lang.String pLineFeed)
Description copied from interface:XMLWriterSets the line terminator. Ignored, if indentation is disabled.- Specified by:
setLineFeedin 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
public java.lang.String getLineFeed()
Description copied from interface:XMLWriterReturns the line terminator. Ignored, if indentation is disabled.- Specified by:
getLineFeedin 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:XMLWriterSets, whether the methodContentHandler.endDocument()should do a flush on the target stream.- Specified by:
setFlushingin interfaceXMLWriter- Parameters:
pFlushing- True, if a flush should be done. Defaults to false.
-
isFlushing
public boolean isFlushing()
Description copied from interface:XMLWriterReturns, whether the methodContentHandler.endDocument()should do a flush on the target stream.- Specified by:
isFlushingin interfaceXMLWriter- Returns:
- True, if a flush should be done. Defaults to false.
-
setWriter
public void setWriter(java.io.Writer pWriter)
Sets the JaxbXMLSerializers Writer.
-
getWriter
public java.io.Writer getWriter()
Returns the JaxbXMLSerializers Writer.
-
setDocumentLocator
public void setDocumentLocator(org.xml.sax.Locator pLocator)
Sets the locator.- Specified by:
setDocumentLocatorin interfaceorg.xml.sax.ContentHandler- Parameters:
pLocator- A locator for use in case of errors- See Also:
getDocumentLocator()
-
getDocumentLocator
public org.xml.sax.Locator getDocumentLocator()
Returns the locator- Returns:
- A locator previously set with setDocumentLocator or null.
- See Also:
setDocumentLocator(org.xml.sax.Locator)
-
startPrefixMapping
public void startPrefixMapping(java.lang.String prefix, java.lang.String namespaceURI) throws org.xml.sax.SAXExceptionStarts use of a namespace prefix.
- Specified by:
startPrefixMappingin interfaceorg.xml.sax.ContentHandler- Parameters:
namespaceURI- The namespace URIprefix- The prefix- Throws:
org.xml.sax.SAXException- Not actually thrown, just for compliance to the interface specification.
-
endPrefixMapping
public void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXExceptionTerminates use of a namespace prefix.
- Specified by:
endPrefixMappingin interfaceorg.xml.sax.ContentHandler- Parameters:
prefix- The prefix being abandoned.- Throws:
org.xml.sax.SAXException- Not actually thrown, just for compliance to the interface specification.
-
startDocument
public void startDocument() throws org.xml.sax.SAXExceptionStarts a document.
- Specified by:
startDocumentin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException- Not actually thrown, just for compliance to the interface specification.
-
endDocument
public void endDocument() throws org.xml.sax.SAXExceptionThis method finishs the handlers action. After calling endDocument you may start a new action by calling startDocument again.
- Specified by:
endDocumentin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException- Not actually thrown, just for compliance to the interface specification.
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXExceptionCalls the character method with the same arguments.- Specified by:
ignorableWhitespacein interfaceorg.xml.sax.ContentHandler- 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:
org.xml.sax.SAXException- Thrown in case of an IOException.
-
characters
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXExceptionInserts a string of characters into the document.- Specified by:
charactersin interfaceorg.xml.sax.ContentHandler- Parameters:
ch- The characters being inserted. A substring, to be precise.start- Index of the first characterlength- Number of characters being inserted- Throws:
org.xml.sax.SAXException- Thrown in case of an IOException
-
canEncode
public boolean canEncode(char c)
Description copied from interface:XMLWriterReturns whether the XMLWriter can encode the character
cwithout an escape sequence like &#ddd;.
-
endElement
public void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXExceptionTerminates an element.
- Specified by:
endElementin interfaceorg.xml.sax.ContentHandler- 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:
org.xml.sax.SAXException- Thrown in case of an IOException.
-
startElement
public void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attr) throws org.xml.sax.SAXExceptionStarts a new element.- Specified by:
startElementin interfaceorg.xml.sax.ContentHandler- 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:
org.xml.sax.SAXException- Thrown in case of an IOException.
-
skippedEntity
public void skippedEntity(java.lang.String ent) throws org.xml.sax.SAXExceptionNot actually implemented, because I don't know how to skip entities.- Specified by:
skippedEntityin interfaceorg.xml.sax.ContentHandler- Parameters:
ent- The entity being skipped.- Throws:
org.xml.sax.SAXException- Not actually thrown, just for compliance to the interface specification.
-
processingInstruction
public void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXExceptionInserts a processing instruction.- Specified by:
processingInstructionin interfaceorg.xml.sax.ContentHandler- Parameters:
target- The PI targetdata- The PI data- Throws:
org.xml.sax.SAXException- Thrown in case of an IOException
-
-