org.exist.storage.serializers
Class Serializer

java.lang.Object
  extended by org.exist.storage.serializers.Serializer
All Implemented Interfaces:
XMLReader
Direct Known Subclasses:
NativeSerializer

public abstract class Serializer
extends Object
implements XMLReader

Serializer base class, used to serialize a document or document fragment back to XML. A serializer may be obtained by calling DBBroker.getSerializer(). The class basically offers two overloaded methods: serialize() and toSAX(). serialize() returns the XML as a string, while toSAX() generates a stream of SAX events. The stream of SAX events is passed to the ContentHandler set by setContentHandler(). Internally, both types of methods pass events to a Receiver. Subclasses thus have to implement the various serializeToReceiver() methods. Output can be configured through properties. Property keys are defined in classes OutputKeys and EXistOutputKeys

Author:
Wolfgang Meier

Field Summary
static String ENCODING
           
static int EXIST_ID_ALL
           
static int EXIST_ID_ELEMENT
           
static int EXIST_ID_NONE
           
static String GENERATE_DOC_EVENTS
           
static int TAG_ATTRIBUTE_MATCHES
           
static int TAG_BOTH
           
static int TAG_ELEMENT_MATCHES
           
static int TAG_NONE
           
 
Constructor Summary
Serializer(DBBroker broker, Configuration config)
           
 
Method Summary
 ContentHandler getContentHandler()
          Required by interface XMLReader.
 DTDHandler getDTDHandler()
          Inherited from XMLReader.
 EntityResolver getEntityResolver()
          Return my internal EntityResolver
 ErrorHandler getErrorHandler()
           
 boolean getFeature(String name)
           
 Object getProperty(String name)
           
 String getProperty(String key, String defaultValue)
           
 String getStylesheetProperty(String name)
           
 User getUser()
          Get the current User.
 String hasXSLPi(Document doc)
          Check if the document has an xml-stylesheet processing instruction that references an XSLT stylesheet.
 boolean isStylesheetApplied()
           
 void parse(InputSource input)
           
 void parse(String systemId)
           
 void prepareStylesheets(DocumentImpl doc)
           
 void reset()
          Reset the class to its initial state.
 String serialize(DocumentImpl doc)
           
 void serialize(DocumentImpl doc, Writer writer)
          Serialize a document to the supplied writer.
 void serialize(DocumentImpl doc, Writer writer, boolean prepareStylesheet)
           
 String serialize(NodeProxy p)
          Serialize a single NodeProxy.
 String serialize(NodeValue n)
           
 void setContentHandler(ContentHandler handler)
           
 void setDTDHandler(DTDHandler handler)
          Inherited from XMLReader.
 void setEntityResolver(EntityResolver resolver)
          Sets the entityResolver attribute of the Serializer object
 void setErrorHandler(ErrorHandler handler)
          Sets the errorHandler attribute of the Serializer object
 void setFeature(String name, boolean value)
          Sets the feature attribute of the Serializer object
 void setProperties(Hashtable table)
           
 void setProperties(Properties properties)
           
 void setProperty(String prop, Object value)
           
 void setReceiver(Receiver receiver)
           
 void setSAXHandlers(ContentHandler contentHandler, LexicalHandler lexicalHandler)
          Set the ContentHandler to be used during serialization.
 void setStylesheet(DocumentImpl doc, String stylesheet)
          Plug an XSL stylesheet into the processing pipeline.
 void setStylesheetParam(String param, String value)
          Set stylesheet parameter
 void setUser(User user)
          Set the current User.
 void toReceiver(NodeProxy p)
           
 void toSAX(DocumentImpl doc)
           
 void toSAX(NodeProxy p)
           
 void toSAX(NodeValue n)
           
 void toSAX(Sequence seq, int start, int count, boolean wrap)
          Serialize the items in the given sequence to SAX, starting with item start.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAG_NONE

public static final int TAG_NONE
See Also:
Constant Field Values

TAG_ELEMENT_MATCHES

public static final int TAG_ELEMENT_MATCHES
See Also:
Constant Field Values

TAG_ATTRIBUTE_MATCHES

public static final int TAG_ATTRIBUTE_MATCHES
See Also:
Constant Field Values

TAG_BOTH

public static final int TAG_BOTH
See Also:
Constant Field Values

EXIST_ID_NONE

public static final int EXIST_ID_NONE
See Also:
Constant Field Values

EXIST_ID_ELEMENT

public static final int EXIST_ID_ELEMENT
See Also:
Constant Field Values

EXIST_ID_ALL

public static final int EXIST_ID_ALL
See Also:
Constant Field Values

GENERATE_DOC_EVENTS

public static final String GENERATE_DOC_EVENTS
See Also:
Constant Field Values

ENCODING

public static final String ENCODING
See Also:
Constant Field Values
Constructor Detail

Serializer

public Serializer(DBBroker broker,
                  Configuration config)
Method Detail

setProperties

public void setProperties(Properties properties)
                   throws SAXNotRecognizedException,
                          SAXNotSupportedException
Throws:
SAXNotRecognizedException
SAXNotSupportedException

setProperties

public void setProperties(Hashtable table)
                   throws SAXNotRecognizedException,
                          SAXNotSupportedException
Throws:
SAXNotRecognizedException
SAXNotSupportedException

setProperty

public void setProperty(String prop,
                        Object value)
                 throws SAXNotRecognizedException,
                        SAXNotSupportedException
Specified by:
setProperty in interface XMLReader
Throws:
SAXNotRecognizedException
SAXNotSupportedException

getProperty

public String getProperty(String key,
                          String defaultValue)

isStylesheetApplied

public boolean isStylesheetApplied()

getEntityResolver

public EntityResolver getEntityResolver()
Return my internal EntityResolver

Specified by:
getEntityResolver in interface XMLReader
Returns:
The entityResolver value

getErrorHandler

public ErrorHandler getErrorHandler()
Specified by:
getErrorHandler in interface XMLReader

setUser

public void setUser(User user)
Set the current User. A valid user is required to process XInclude elements.


getUser

public User getUser()
Get the current User.


getFeature

public boolean getFeature(String name)
                   throws SAXNotRecognizedException,
                          SAXNotSupportedException
Specified by:
getFeature in interface XMLReader
Throws:
SAXNotRecognizedException
SAXNotSupportedException

getProperty

public Object getProperty(String name)
                   throws SAXNotRecognizedException,
                          SAXNotSupportedException
Specified by:
getProperty in interface XMLReader
Throws:
SAXNotRecognizedException
SAXNotSupportedException

getStylesheetProperty

public String getStylesheetProperty(String name)

parse

public void parse(InputSource input)
           throws IOException,
                  SAXException
Specified by:
parse in interface XMLReader
Throws:
IOException
SAXException

parse

public void parse(String systemId)
           throws IOException,
                  SAXException
Specified by:
parse in interface XMLReader
Throws:
IOException
SAXException

reset

public void reset()
Reset the class to its initial state.


serialize

public String serialize(DocumentImpl doc)
                 throws SAXException
Throws:
SAXException

serialize

public void serialize(DocumentImpl doc,
                      Writer writer)
               throws SAXException
Serialize a document to the supplied writer.

Throws:
SAXException

serialize

public void serialize(DocumentImpl doc,
                      Writer writer,
                      boolean prepareStylesheet)
               throws SAXException
Throws:
SAXException

serialize

public String serialize(NodeValue n)
                 throws SAXException
Throws:
SAXException

serialize

public String serialize(NodeProxy p)
                 throws SAXException
Serialize a single NodeProxy.

Parameters:
p - Description of the Parameter
Returns:
Description of the Return Value
Throws:
SAXException - Description of the Exception

prepareStylesheets

public void prepareStylesheets(DocumentImpl doc)
                        throws TransformerConfigurationException
Throws:
TransformerConfigurationException

setSAXHandlers

public void setSAXHandlers(ContentHandler contentHandler,
                           LexicalHandler lexicalHandler)
Set the ContentHandler to be used during serialization.

Parameters:
contentHandler - The new contentHandler value

setReceiver

public void setReceiver(Receiver receiver)

setContentHandler

public void setContentHandler(ContentHandler handler)
Specified by:
setContentHandler in interface XMLReader

getContentHandler

public ContentHandler getContentHandler()
Required by interface XMLReader. Always returns null.

Specified by:
getContentHandler in interface XMLReader
See Also:
XMLReader.getContentHandler()

setEntityResolver

public void setEntityResolver(EntityResolver resolver)
Sets the entityResolver attribute of the Serializer object

Specified by:
setEntityResolver in interface XMLReader
Parameters:
resolver - The new entityResolver value

setErrorHandler

public void setErrorHandler(ErrorHandler handler)
Sets the errorHandler attribute of the Serializer object

Specified by:
setErrorHandler in interface XMLReader
Parameters:
handler - The new errorHandler value

setFeature

public void setFeature(String name,
                       boolean value)
                throws SAXNotRecognizedException,
                       SAXNotSupportedException
Sets the feature attribute of the Serializer object

Specified by:
setFeature in interface XMLReader
Parameters:
name - The new feature value
value - The new feature value
Throws:
SAXNotRecognizedException - Description of the Exception
SAXNotSupportedException - Description of the Exception

setStylesheet

public void setStylesheet(DocumentImpl doc,
                          String stylesheet)
                   throws TransformerConfigurationException
Plug an XSL stylesheet into the processing pipeline. All output will be passed to this stylesheet.

Throws:
TransformerConfigurationException

setStylesheetParam

public void setStylesheetParam(String param,
                               String value)
Set stylesheet parameter


toSAX

public void toSAX(DocumentImpl doc)
           throws SAXException
Throws:
SAXException

toSAX

public void toSAX(NodeValue n)
           throws SAXException
Throws:
SAXException

toSAX

public void toSAX(NodeProxy p)
           throws SAXException
Throws:
SAXException

toSAX

public void toSAX(Sequence seq,
                  int start,
                  int count,
                  boolean wrap)
           throws SAXException
Serialize the items in the given sequence to SAX, starting with item start. If parameter wrap is set to true, output a wrapper element to enclose the serialized items. The wrapper element will be in namespace Namespaces.EXIST_NS and has the following form: <exist:result hits="sequence length" start="value of start" count="value of count">

Parameters:
seq -
start -
count -
wrap -
Throws:
SAXException

toReceiver

public void toReceiver(NodeProxy p)
                throws SAXException
Throws:
SAXException

setDTDHandler

public void setDTDHandler(DTDHandler handler)
Inherited from XMLReader. Ignored.

Specified by:
setDTDHandler in interface XMLReader
See Also:
XMLReader.setDTDHandler(org.xml.sax.DTDHandler)

getDTDHandler

public DTDHandler getDTDHandler()
Inherited from XMLReader. Ignored. Returns always null.

Specified by:
getDTDHandler in interface XMLReader
See Also:
XMLReader.getDTDHandler()

hasXSLPi

public String hasXSLPi(Document doc)
Check if the document has an xml-stylesheet processing instruction that references an XSLT stylesheet. Return the link to the stylesheet.

Parameters:
doc -
Returns:
link to the stylesheet


Copyright (C) Wolfgang Meier. All rights reserved.