Class BaseMarkupSerializer
- java.lang.Object
-
- org.apache.jackrabbit.vault.util.xml.serialize.BaseMarkupSerializer
-
- All Implemented Interfaces:
DOMSerializer,Serializer,ContentHandler,DocumentHandler,DTDHandler,DeclHandler,LexicalHandler
- Direct Known Subclasses:
XMLSerializer
public abstract class BaseMarkupSerializer extends Object implements ContentHandler, DocumentHandler, LexicalHandler, DTDHandler, 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 ContentHandlerasContentHandler()Return aContentHandlerinterface into this serializer.DocumentHandlerasDocumentHandler()Return aDocumentHandlerinterface into this serializer.DOMSerializerasDOMSerializer()Return aDOMSerializerinterface into this serializer.voidattributeDecl(String eName, String aName, String type, String valueDefault, String value)voidcharacters(char[] chars, int start, int length)voidcomment(char[] chars, int start, int length)voidcomment(String text)voidelementDecl(String name, String model)voidendCDATA()voidendDocument()Called at the end of the document to wrap it up.voidendDTD()voidendEntity(String name)voidendNonEscaping()voidendPrefixMapping(String prefix)voidendPreserving()voidexternalEntityDecl(String name, String publicId, String systemId)voidignorableWhitespace(char[] chars, int start, int length)voidinternalEntityDecl(String name, String value)voidnotationDecl(String name, String publicId, String systemId)voidprocessingInstruction(String target, String code)voidprocessingInstructionIO(String target, String code)booleanreset()voidserialize(Document doc)Serializes the DOM document using the previously specified writer and output format.voidserialize(DocumentFragment frag)Serializes the DOM document fragmnt using the previously specified writer and output format.voidserialize(Element elem)Serializes the DOM element using the previously specified writer and output format.voidsetDocumentLocator(Locator locator)voidsetOutputByteStream(OutputStream output)The specified stream will not be closed by this class.voidsetOutputCharStream(Writer writer)The specified writer will not be closed by this class.voidsetOutputFormat(OutputFormat format)Specifies an output format for this serializer.voidskippedEntity(String name)voidstartCDATA()voidstartDocument()voidstartDTD(String name, String publicId, String systemId)voidstartEntity(String name)voidstartNonEscaping()voidstartPrefixMapping(String prefix, String uri)voidstartPreserving()voidunparsedEntityDecl(String name, String publicId, String systemId, String notationName)-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.xml.sax.ContentHandler
endElement, startElement
-
Methods inherited from interface org.xml.sax.DocumentHandler
endElement, startElement
-
-
-
-
Method Detail
-
asDocumentHandler
public DocumentHandler asDocumentHandler() throws IOException
Description copied from interface:SerializerReturn aDocumentHandlerinterface into this serializer. If the serializer does not support theDocumentHandlerinterface, it should return null.- Specified by:
asDocumentHandlerin interfaceSerializer- Throws:
IOException
-
asContentHandler
public ContentHandler asContentHandler() throws IOException
Description copied from interface:SerializerReturn aContentHandlerinterface into this serializer. If the serializer does not support theContentHandlerinterface, it should return null.- Specified by:
asContentHandlerin interfaceSerializer- Throws:
IOException
-
asDOMSerializer
public DOMSerializer asDOMSerializer() throws 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:
IOException
-
setOutputByteStream
public void setOutputByteStream(OutputStream output)
The specified stream will not be closed by this class.
- Specified by:
setOutputByteStreamin interfaceSerializer
-
setOutputCharStream
public void setOutputCharStream(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(Element elem) throws IOException
Serializes 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:
IOException- An I/O exception occured while serializing
-
serialize
public void serialize(DocumentFragment frag) throws IOException
Serializes 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:
IOException- An I/O exception occured while serializing
-
serialize
public void serialize(Document doc) throws IOException
Serializes 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:
IOException- An I/O exception occured while serializing
-
startDocument
public void startDocument() throws SAXException- Specified by:
startDocumentin interfaceContentHandler- Specified by:
startDocumentin interfaceDocumentHandler- Throws:
SAXException
-
characters
public void characters(char[] chars, int start, int length) throws SAXException- Specified by:
charactersin interfaceContentHandler- Specified by:
charactersin interfaceDocumentHandler- Throws:
SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] chars, int start, int length) throws SAXException- Specified by:
ignorableWhitespacein interfaceContentHandler- Specified by:
ignorableWhitespacein interfaceDocumentHandler- Throws:
SAXException
-
processingInstruction
public final void processingInstruction(String target, String code) throws SAXException
- Specified by:
processingInstructionin interfaceContentHandler- Specified by:
processingInstructionin interfaceDocumentHandler- Throws:
SAXException
-
processingInstructionIO
public void processingInstructionIO(String target, String code) throws IOException
- Throws:
IOException
-
comment
public void comment(char[] chars, int start, int length) throws SAXException- Specified by:
commentin interfaceLexicalHandler- Throws:
SAXException
-
comment
public void comment(String text) throws IOException
- Throws:
IOException
-
startCDATA
public void startCDATA()
- Specified by:
startCDATAin interfaceLexicalHandler
-
endCDATA
public void endCDATA()
- Specified by:
endCDATAin interfaceLexicalHandler
-
startNonEscaping
public void startNonEscaping()
-
endNonEscaping
public void endNonEscaping()
-
startPreserving
public void startPreserving()
-
endPreserving
public void endPreserving()
-
endDocument
public void endDocument() throws 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 interfaceContentHandler- Specified by:
endDocumentin interfaceDocumentHandler- Throws:
SAXException- An I/O exception occured during serializing
-
startEntity
public void startEntity(String name)
- Specified by:
startEntityin interfaceLexicalHandler
-
endEntity
public void endEntity(String name)
- Specified by:
endEntityin interfaceLexicalHandler
-
setDocumentLocator
public void setDocumentLocator(Locator locator)
- Specified by:
setDocumentLocatorin interfaceContentHandler- Specified by:
setDocumentLocatorin interfaceDocumentHandler
-
skippedEntity
public void skippedEntity(String name) throws SAXException
- Specified by:
skippedEntityin interfaceContentHandler- Throws:
SAXException
-
startPrefixMapping
public void startPrefixMapping(String prefix, String uri) throws SAXException
- Specified by:
startPrefixMappingin interfaceContentHandler- Throws:
SAXException
-
endPrefixMapping
public void endPrefixMapping(String prefix) throws SAXException
- Specified by:
endPrefixMappingin interfaceContentHandler- Throws:
SAXException
-
startDTD
public final void startDTD(String name, String publicId, String systemId) throws SAXException
- Specified by:
startDTDin interfaceLexicalHandler- Throws:
SAXException
-
endDTD
public void endDTD()
- Specified by:
endDTDin interfaceLexicalHandler
-
elementDecl
public void elementDecl(String name, String model) throws SAXException
- Specified by:
elementDeclin interfaceDeclHandler- Throws:
SAXException
-
attributeDecl
public void attributeDecl(String eName, String aName, String type, String valueDefault, String value) throws SAXException
- Specified by:
attributeDeclin interfaceDeclHandler- Throws:
SAXException
-
internalEntityDecl
public void internalEntityDecl(String name, String value) throws SAXException
- Specified by:
internalEntityDeclin interfaceDeclHandler- Throws:
SAXException
-
externalEntityDecl
public void externalEntityDecl(String name, String publicId, String systemId) throws SAXException
- Specified by:
externalEntityDeclin interfaceDeclHandler- Throws:
SAXException
-
unparsedEntityDecl
public void unparsedEntityDecl(String name, String publicId, String systemId, String notationName) throws SAXException
- Specified by:
unparsedEntityDeclin interfaceDTDHandler- Throws:
SAXException
-
notationDecl
public void notationDecl(String name, String publicId, String systemId) throws SAXException
- Specified by:
notationDeclin interfaceDTDHandler- Throws:
SAXException
-
-