org.exist.storage.serializers
Class Serializer

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

public abstract class Serializer
extends java.lang.Object
implements org.xml.sax.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
protected static QName ATTR_COUNT_QNAME
           
protected static QName ATTR_HITS_QNAME
           
protected static QName ATTR_START_QNAME
           
protected static QName ATTR_TYPE_QNAME
           
protected  DBBroker broker
           
protected  boolean createContainerElements
           
protected  java.util.Properties defaultProperties
           
protected static QName ELEM_RESULT_QNAME
           
protected static QName ELEM_VALUE_QNAME
           
protected  java.lang.String encoding
           
static java.lang.String ENCODING
           
static java.lang.String EXIST_NS
           
protected  javax.xml.transform.sax.SAXTransformerFactory factory
           
static java.lang.String GENERATE_DOC_EVENTS
           
protected  org.xml.sax.ext.LexicalHandler lexicalHandler
           
protected static Logger LOG
           
protected  java.util.Properties outputProperties
           
protected  Receiver receiver
           
static int TAG_ATTRIBUTE_MATCHES
           
static int TAG_BOTH
           
static int TAG_ELEMENT_MATCHES
           
static int TAG_NONE
           
protected  javax.xml.transform.Templates templates
           
protected  User user
           
protected  XIncludeFilter xinclude
           
protected  SAXSerializer xmlout
           
protected  javax.xml.transform.sax.TransformerHandler xslHandler
           
 
Constructor Summary
Serializer(DBBroker broker, Configuration config)
           
 
Method Summary
protected  void applyXSLHandler(java.io.Writer writer)
          If an XSL stylesheet is present, plug it into the chain.
protected  void checkStylesheetParams()
           
 org.xml.sax.ContentHandler getContentHandler()
          Required by interface XMLReader.
 org.xml.sax.DTDHandler getDTDHandler()
          Inherited from XMLReader.
 org.xml.sax.EntityResolver getEntityResolver()
          Return my internal EntityResolver
 org.xml.sax.ErrorHandler getErrorHandler()
           
 boolean getFeature(java.lang.String name)
           
protected  int getHighlightingMode()
           
 java.lang.Object getProperty(java.lang.String name)
           
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
           
 User getUser()
          Get the current User.
 boolean isStylesheetApplied()
           
 void parse(org.xml.sax.InputSource input)
           
 void parse(java.lang.String systemId)
           
protected  void releasePrettyPrinter()
           
 void reset()
          Reset the class to its initial state.
 java.lang.String serialize(DocumentImpl doc)
           
 void serialize(DocumentImpl doc, java.io.Writer writer)
          Serialize a document to the supplied writer.
 java.lang.String serialize(NodeProxy p)
          Serialize a single NodeProxy.
 java.lang.String serialize(NodeValue n)
           
protected abstract  void serializeToReceiver(DocumentImpl doc, boolean generateDocEvent)
           
protected  void serializeToReceiver(NodeImpl n, boolean generateDocEvents)
           
protected abstract  void serializeToReceiver(NodeProxy p, boolean generateDocEvent)
           
protected  void serializeToReceiver(NodeValue v, boolean generateDocEvents)
           
 void setContentHandler(org.xml.sax.ContentHandler handler)
           
protected  void setDocument(DocumentImpl doc)
           
 void setDTDHandler(org.xml.sax.DTDHandler handler)
          Inherited from XMLReader.
 void setEntityResolver(org.xml.sax.EntityResolver resolver)
          Sets the entityResolver attribute of the Serializer object
 void setErrorHandler(org.xml.sax.ErrorHandler handler)
          Sets the errorHandler attribute of the Serializer object
 void setFeature(java.lang.String name, boolean value)
          Sets the feature attribute of the Serializer object
protected  void setPrettyPrinter(java.io.Writer writer, boolean xmlDecl)
           
 void setProperties(java.util.Hashtable table)
           
 void setProperties(java.util.Properties properties)
           
 void setProperty(java.lang.String prop, java.lang.Object value)
           
 void setReceiver(Receiver receiver)
           
 void setSAXHandlers(org.xml.sax.ContentHandler contentHandler, org.xml.sax.ext.LexicalHandler lexicalHandler)
          Set the ContentHandler to be used during serialization.
 void setStylesheet(DocumentImpl doc, java.lang.String stylesheet)
          Plug an XSL stylesheet into the processing pipeline.
 void setStylesheet(java.lang.String stylesheet)
           
protected  void setStylesheetFromProperties(org.w3c.dom.Document doc)
           
 void setStylesheetParam(java.lang.String param, java.lang.String value)
          Set stylesheet parameter
 void setUser(User user)
          Set the current User.
protected  void setXSLHandler()
           
 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final Logger LOG

EXIST_NS

public static final java.lang.String EXIST_NS
See Also:
Constant Field Values

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

GENERATE_DOC_EVENTS

public static final java.lang.String GENERATE_DOC_EVENTS
See Also:
Constant Field Values

ENCODING

public static final java.lang.String ENCODING
See Also:
Constant Field Values

ATTR_HITS_QNAME

protected static final QName ATTR_HITS_QNAME

ATTR_START_QNAME

protected static final QName ATTR_START_QNAME

ATTR_COUNT_QNAME

protected static final QName ATTR_COUNT_QNAME

ELEM_RESULT_QNAME

protected static final QName ELEM_RESULT_QNAME

ATTR_TYPE_QNAME

protected static final QName ATTR_TYPE_QNAME

ELEM_VALUE_QNAME

protected static final QName ELEM_VALUE_QNAME

broker

protected DBBroker broker

encoding

protected java.lang.String encoding

factory

protected javax.xml.transform.sax.SAXTransformerFactory factory

createContainerElements

protected boolean createContainerElements

defaultProperties

protected java.util.Properties defaultProperties

outputProperties

protected java.util.Properties outputProperties

templates

protected javax.xml.transform.Templates templates

xslHandler

protected javax.xml.transform.sax.TransformerHandler xslHandler

xinclude

protected XIncludeFilter xinclude

receiver

protected Receiver receiver

xmlout

protected SAXSerializer xmlout

lexicalHandler

protected org.xml.sax.ext.LexicalHandler lexicalHandler

user

protected User user
Constructor Detail

Serializer

public Serializer(DBBroker broker,
                  Configuration config)
Method Detail

setProperties

public void setProperties(java.util.Properties properties)
                   throws org.xml.sax.SAXNotRecognizedException,
                          org.xml.sax.SAXNotSupportedException
Throws:
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException

setProperties

public void setProperties(java.util.Hashtable table)
                   throws org.xml.sax.SAXNotRecognizedException,
                          org.xml.sax.SAXNotSupportedException
Throws:
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException

setProperty

public void setProperty(java.lang.String prop,
                        java.lang.Object value)
                 throws org.xml.sax.SAXNotRecognizedException,
                        org.xml.sax.SAXNotSupportedException
Specified by:
setProperty in interface org.xml.sax.XMLReader
Throws:
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException

getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String defaultValue)

isStylesheetApplied

public boolean isStylesheetApplied()

getHighlightingMode

protected int getHighlightingMode()

applyXSLHandler

protected void applyXSLHandler(java.io.Writer writer)
If an XSL stylesheet is present, plug it into the chain.


getEntityResolver

public org.xml.sax.EntityResolver getEntityResolver()
Return my internal EntityResolver

Specified by:
getEntityResolver in interface org.xml.sax.XMLReader
Returns:
The entityResolver value

getErrorHandler

public org.xml.sax.ErrorHandler getErrorHandler()
Specified by:
getErrorHandler in interface org.xml.sax.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(java.lang.String name)
                   throws org.xml.sax.SAXNotRecognizedException,
                          org.xml.sax.SAXNotSupportedException
Specified by:
getFeature in interface org.xml.sax.XMLReader
Throws:
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException

getProperty

public java.lang.Object getProperty(java.lang.String name)
                             throws org.xml.sax.SAXNotRecognizedException,
                                    org.xml.sax.SAXNotSupportedException
Specified by:
getProperty in interface org.xml.sax.XMLReader
Throws:
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException

parse

public void parse(org.xml.sax.InputSource input)
           throws java.io.IOException,
                  org.xml.sax.SAXException
Specified by:
parse in interface org.xml.sax.XMLReader
Throws:
java.io.IOException
org.xml.sax.SAXException

setDocument

protected void setDocument(DocumentImpl doc)

parse

public void parse(java.lang.String systemId)
           throws java.io.IOException,
                  org.xml.sax.SAXException
Specified by:
parse in interface org.xml.sax.XMLReader
Throws:
java.io.IOException
org.xml.sax.SAXException

reset

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


serialize

public java.lang.String serialize(DocumentImpl doc)
                           throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

serialize

public void serialize(DocumentImpl doc,
                      java.io.Writer writer)
               throws org.xml.sax.SAXException
Serialize a document to the supplied writer.

Throws:
org.xml.sax.SAXException

serialize

public java.lang.String serialize(NodeValue n)
                           throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

serialize

public java.lang.String serialize(NodeProxy p)
                           throws org.xml.sax.SAXException
Serialize a single NodeProxy.

Parameters:
p - Description of the Parameter
Returns:
Description of the Return Value
Throws:
org.xml.sax.SAXException - Description of the Exception

setSAXHandlers

public void setSAXHandlers(org.xml.sax.ContentHandler contentHandler,
                           org.xml.sax.ext.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(org.xml.sax.ContentHandler handler)
Specified by:
setContentHandler in interface org.xml.sax.XMLReader

getContentHandler

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

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

setEntityResolver

public void setEntityResolver(org.xml.sax.EntityResolver resolver)
Sets the entityResolver attribute of the Serializer object

Specified by:
setEntityResolver in interface org.xml.sax.XMLReader
Parameters:
resolver - The new entityResolver value

setErrorHandler

public void setErrorHandler(org.xml.sax.ErrorHandler handler)
Sets the errorHandler attribute of the Serializer object

Specified by:
setErrorHandler in interface org.xml.sax.XMLReader
Parameters:
handler - The new errorHandler value

setFeature

public void setFeature(java.lang.String name,
                       boolean value)
                throws org.xml.sax.SAXNotRecognizedException,
                       org.xml.sax.SAXNotSupportedException
Sets the feature attribute of the Serializer object

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

setPrettyPrinter

protected void setPrettyPrinter(java.io.Writer writer,
                                boolean xmlDecl)

releasePrettyPrinter

protected void releasePrettyPrinter()

setStylesheetFromProperties

protected void setStylesheetFromProperties(org.w3c.dom.Document doc)

checkStylesheetParams

protected void checkStylesheetParams()

setStylesheet

public void setStylesheet(java.lang.String stylesheet)

setStylesheet

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


setStylesheetParam

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


setXSLHandler

protected void setXSLHandler()

toSAX

public void toSAX(DocumentImpl doc)
           throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

toSAX

public void toSAX(NodeValue n)
           throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

toSAX

public void toSAX(NodeProxy p)
           throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

toSAX

public void toSAX(Sequence seq,
                  int start,
                  int count,
                  boolean wrap)
           throws org.xml.sax.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 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:
org.xml.sax.SAXException

toReceiver

public void toReceiver(NodeProxy p)
                throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

serializeToReceiver

protected abstract void serializeToReceiver(NodeProxy p,
                                            boolean generateDocEvent)
                                     throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

serializeToReceiver

protected abstract void serializeToReceiver(DocumentImpl doc,
                                            boolean generateDocEvent)
                                     throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

serializeToReceiver

protected void serializeToReceiver(NodeValue v,
                                   boolean generateDocEvents)
                            throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

serializeToReceiver

protected void serializeToReceiver(NodeImpl n,
                                   boolean generateDocEvents)
                            throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

setDTDHandler

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

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

getDTDHandler

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

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


<oXygen/> XML Editor provides support for editing and debugging XQuery expressions against the eXist XML Database.