Class BaseMarkupSerializer
- java.lang.Object
-
- org.apache.jackrabbit.vault.util.xml.serialize.BaseMarkupSerializer
-
- All Implemented Interfaces:
DOMSerializer,Serializer,org.xml.sax.ContentHandler,org.xml.sax.DocumentHandler,org.xml.sax.DTDHandler,org.xml.sax.ext.DeclHandler,org.xml.sax.ext.LexicalHandler
- Direct Known Subclasses:
XMLSerializer
public abstract class BaseMarkupSerializer extends java.lang.Object implements org.xml.sax.ContentHandler, org.xml.sax.DocumentHandler, org.xml.sax.ext.LexicalHandler, org.xml.sax.DTDHandler, org.xml.sax.ext.DeclHandler, DOMSerializer, Serializer
Base class for a serializer supporting both DOM and SAX pretty serializing of XML/HTML/XHTML documents. Derives classes perform the method-specific serializing, this class provides the common serializing mechanisms.The serializer must be initialized with the proper writer and output format before it can be used by calling
setOutputCharStream(java.io.Writer)orsetOutputByteStream(java.io.OutputStream)for the writer andsetOutputFormat(org.apache.jackrabbit.vault.util.xml.serialize.OutputFormat)for the output format.The serializer can be reused any number of times, but cannot be used concurrently by two threads.
If an output stream is used, the encoding is taken from the output format (defaults to UTF-8). If a writer is used, make sure the writer uses the same encoding (if applies) as specified in the output format.
The serializer supports both DOM and SAX. DOM serializing is done by calling
serialize(Document)and SAX serializing is done by firing SAX events and using the serializer as a document handler. This also applies to derived class.If an I/O exception occurs while serializing, the serializer will not throw an exception directly, but only throw it at the end of serializing (either DOM or SAX's
DocumentHandler.endDocument().For elements that are not specified as whitespace preserving, the serializer will potentially break long text lines at space boundaries, indent lines, and serialize elements on separate lines. Line terminators will be regarded as spaces, and spaces at beginning of line will be stripped.
When indenting, the serializer is capable of detecting seemingly element content, and serializing these elements indented on separate lines. An element is serialized indented when it is the first or last child of an element, or immediate following or preceding another element.
- See Also:
Serializer,LSSerializer
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.xml.sax.ContentHandlerasContentHandler()Return aContentHandlerinterface into this serializer.org.xml.sax.DocumentHandlerasDocumentHandler()Return aDocumentHandlerinterface into this serializer.DOMSerializerasDOMSerializer()Return aDOMSerializerinterface into this serializer.voidattributeDecl(java.lang.String eName, java.lang.String aName, java.lang.String type, java.lang.String valueDefault, java.lang.String value)voidcharacters(char[] chars, int start, int length)voidcomment(char[] chars, int start, int length)voidcomment(java.lang.String text)voidelementDecl(java.lang.String name, java.lang.String model)voidendCDATA()voidendDocument()Called at the end of the document to wrap it up.voidendDTD()voidendEntity(java.lang.String name)voidendNonEscaping()voidendPrefixMapping(java.lang.String prefix)voidendPreserving()voidexternalEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)voidignorableWhitespace(char[] chars, int start, int length)voidinternalEntityDecl(java.lang.String name, java.lang.String value)voidnotationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)voidprocessingInstruction(java.lang.String target, java.lang.String code)voidprocessingInstructionIO(java.lang.String target, java.lang.String code)booleanreset()voidserialize(org.w3c.dom.Document doc)Serializes the DOM document using the previously specified writer and output format.voidserialize(org.w3c.dom.DocumentFragment frag)Serializes the DOM document fragmnt using the previously specified writer and output format.voidserialize(org.w3c.dom.Element elem)Serializes the DOM element using the previously specified writer and output format.voidsetDocumentLocator(org.xml.sax.Locator locator)voidsetOutputByteStream(java.io.OutputStream output)The specified stream will not be closed by this class.voidsetOutputCharStream(java.io.Writer writer)The specified writer will not be closed by this class.voidsetOutputFormat(OutputFormat format)Specifies an output format for this serializer.voidskippedEntity(java.lang.String name)voidstartCDATA()voidstartDocument()voidstartDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)voidstartEntity(java.lang.String name)voidstartNonEscaping()voidstartPrefixMapping(java.lang.String prefix, java.lang.String uri)voidstartPreserving()voidunparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)
-
-
-
Method Detail
-
asDocumentHandler
public org.xml.sax.DocumentHandler asDocumentHandler() throws java.io.IOExceptionDescription copied from interface:SerializerReturn aDocumentHandlerinterface into this serializer. If the serializer does not support theDocumentHandlerinterface, it should return null.- Specified by:
asDocumentHandlerin interfaceSerializer- Throws:
java.io.IOException
-
asContentHandler
public org.xml.sax.ContentHandler asContentHandler() throws java.io.IOExceptionDescription copied from interface:SerializerReturn aContentHandlerinterface into this serializer. If the serializer does not support theContentHandlerinterface, it should return null.- Specified by:
asContentHandlerin interfaceSerializer- Throws:
java.io.IOException
-
asDOMSerializer
public DOMSerializer asDOMSerializer() throws java.io.IOException
Description copied from interface:SerializerReturn aDOMSerializerinterface into this serializer. If the serializer does not support theDOMSerializerinterface, it should return null.- Specified by:
asDOMSerializerin interfaceSerializer- Throws:
java.io.IOException
-
setOutputByteStream
public void setOutputByteStream(java.io.OutputStream output)
The specified stream will not be closed by this class.
- Specified by:
setOutputByteStreamin interfaceSerializer
-
setOutputCharStream
public void setOutputCharStream(java.io.Writer writer)
The specified writer will not be closed by this class.
- Specified by:
setOutputCharStreamin interfaceSerializer
-
setOutputFormat
public void setOutputFormat(OutputFormat format)
Description copied from interface:SerializerSpecifies an output format for this serializer. It the serializer has already been associated with an output format, it will switch to the new format. This method should not be called while the serializer is in the process of serializing a document.- Specified by:
setOutputFormatin interfaceSerializer- Parameters:
format- The output format to use
-
reset
public boolean reset()
-
serialize
public void serialize(org.w3c.dom.Element elem) throws java.io.IOExceptionSerializes the DOM element using the previously specified writer and output format. Throws an exception only if an I/O exception occured while serializing.- Specified by:
serializein interfaceDOMSerializer- Parameters:
elem- The element to serialize- Throws:
java.io.IOException- An I/O exception occured while serializing
-
serialize
public void serialize(org.w3c.dom.DocumentFragment frag) throws java.io.IOExceptionSerializes the DOM document fragmnt using the previously specified writer and output format. Throws an exception only if an I/O exception occured while serializing.- Specified by:
serializein interfaceDOMSerializer- Parameters:
frag- The element to serialize- Throws:
java.io.IOException- An I/O exception occured while serializing
-
serialize
public void serialize(org.w3c.dom.Document doc) throws java.io.IOExceptionSerializes the DOM document using the previously specified writer and output format. Throws an exception only if an I/O exception occured while serializing.- Specified by:
serializein interfaceDOMSerializer- Parameters:
doc- The document to serialize- Throws:
java.io.IOException- An I/O exception occured while serializing
-
startDocument
public void startDocument() throws org.xml.sax.SAXException- Specified by:
startDocumentin interfaceorg.xml.sax.ContentHandler- Specified by:
startDocumentin interfaceorg.xml.sax.DocumentHandler- Throws:
org.xml.sax.SAXException
-
characters
public void characters(char[] chars, int start, int length) throws org.xml.sax.SAXException- Specified by:
charactersin interfaceorg.xml.sax.ContentHandler- Specified by:
charactersin interfaceorg.xml.sax.DocumentHandler- Throws:
org.xml.sax.SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] chars, int start, int length) throws org.xml.sax.SAXException- Specified by:
ignorableWhitespacein interfaceorg.xml.sax.ContentHandler- Specified by:
ignorableWhitespacein interfaceorg.xml.sax.DocumentHandler- Throws:
org.xml.sax.SAXException
-
processingInstruction
public final void processingInstruction(java.lang.String target, java.lang.String code) throws org.xml.sax.SAXException- Specified by:
processingInstructionin interfaceorg.xml.sax.ContentHandler- Specified by:
processingInstructionin interfaceorg.xml.sax.DocumentHandler- Throws:
org.xml.sax.SAXException
-
processingInstructionIO
public void processingInstructionIO(java.lang.String target, java.lang.String code) throws java.io.IOException- Throws:
java.io.IOException
-
comment
public void comment(char[] chars, int start, int length) throws org.xml.sax.SAXException- Specified by:
commentin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
comment
public void comment(java.lang.String text) throws java.io.IOException- Throws:
java.io.IOException
-
startCDATA
public void startCDATA()
- Specified by:
startCDATAin interfaceorg.xml.sax.ext.LexicalHandler
-
endCDATA
public void endCDATA()
- Specified by:
endCDATAin interfaceorg.xml.sax.ext.LexicalHandler
-
startNonEscaping
public void startNonEscaping()
-
endNonEscaping
public void endNonEscaping()
-
startPreserving
public void startPreserving()
-
endPreserving
public void endPreserving()
-
endDocument
public void endDocument() throws org.xml.sax.SAXExceptionCalled at the end of the document to wrap it up. Will flush the output stream and throw an exception if any I/O error occured while serializing.- Specified by:
endDocumentin interfaceorg.xml.sax.ContentHandler- Specified by:
endDocumentin interfaceorg.xml.sax.DocumentHandler- Throws:
org.xml.sax.SAXException- An I/O exception occured during serializing
-
startEntity
public void startEntity(java.lang.String name)
- Specified by:
startEntityin interfaceorg.xml.sax.ext.LexicalHandler
-
endEntity
public void endEntity(java.lang.String name)
- Specified by:
endEntityin interfaceorg.xml.sax.ext.LexicalHandler
-
setDocumentLocator
public void setDocumentLocator(org.xml.sax.Locator locator)
- Specified by:
setDocumentLocatorin interfaceorg.xml.sax.ContentHandler- Specified by:
setDocumentLocatorin interfaceorg.xml.sax.DocumentHandler
-
skippedEntity
public void skippedEntity(java.lang.String name) throws org.xml.sax.SAXException- Specified by:
skippedEntityin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
startPrefixMapping
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws org.xml.sax.SAXException- Specified by:
startPrefixMappingin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
endPrefixMapping
public void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXException- Specified by:
endPrefixMappingin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
startDTD
public final void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException- Specified by:
startDTDin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
endDTD
public void endDTD()
- Specified by:
endDTDin interfaceorg.xml.sax.ext.LexicalHandler
-
elementDecl
public void elementDecl(java.lang.String name, java.lang.String model) throws org.xml.sax.SAXException- Specified by:
elementDeclin interfaceorg.xml.sax.ext.DeclHandler- Throws:
org.xml.sax.SAXException
-
attributeDecl
public void attributeDecl(java.lang.String eName, java.lang.String aName, java.lang.String type, java.lang.String valueDefault, java.lang.String value) throws org.xml.sax.SAXException- Specified by:
attributeDeclin interfaceorg.xml.sax.ext.DeclHandler- Throws:
org.xml.sax.SAXException
-
internalEntityDecl
public void internalEntityDecl(java.lang.String name, java.lang.String value) throws org.xml.sax.SAXException- Specified by:
internalEntityDeclin interfaceorg.xml.sax.ext.DeclHandler- Throws:
org.xml.sax.SAXException
-
externalEntityDecl
public void externalEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException- Specified by:
externalEntityDeclin interfaceorg.xml.sax.ext.DeclHandler- Throws:
org.xml.sax.SAXException
-
unparsedEntityDecl
public void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName) throws org.xml.sax.SAXException- Specified by:
unparsedEntityDeclin interfaceorg.xml.sax.DTDHandler- Throws:
org.xml.sax.SAXException
-
notationDecl
public void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException- Specified by:
notationDeclin interfaceorg.xml.sax.DTDHandler- Throws:
org.xml.sax.SAXException
-
-