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 class Serializer
extends java.lang.Object
implements org.xml.sax.XMLReader

This is the base class for all serializers. Serializers are 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(). serialize() internally calls toSAX() and uses a Xerces XML Writer to consume the stream. If the processXInclude property is set, XInclude elements in the source document will be expanded.

Author:
Wolfgang Meier

Field Summary
protected  DBBroker broker
           
protected  org.xml.sax.ContentHandler contentHandler
           
protected  boolean createContainerElements
           
protected  org.xml.sax.DTDHandler dtdHandler
           
protected  java.lang.String encoding
           
static java.lang.String ENCODING
           
static java.lang.String EXIST_NS
           
static java.lang.String EXPAND_XINCLUDES
           
protected  javax.xml.transform.TransformerFactory factory
           
static java.lang.String GENERATE_DOC_EVENTS
           
protected  boolean generateDocEvents
           
static java.lang.String HIGHLIGHT_MATCHES
           
protected  int highlightMatches
           
protected  boolean indent
           
protected  org.xml.sax.ext.LexicalHandler lexicalHandler
           
protected static org.apache.log4j.Logger LOG
           
static java.lang.String PRETTY_PRINT
           
protected  boolean processXInclude
           
protected  boolean processXSL
           
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  javax.xml.transform.sax.TransformerHandler xslHandler
           
 
Constructor Summary
Serializer(DBBroker broker, Configuration config)
          Constructor for the Serializer object
 
Method Summary
protected  java.io.StringWriter applyXSLHandler()
          If an XSL stylesheet is present, plug it into the chain.
 org.xml.sax.ContentHandler getContentHandler()
          Return the current ContentHandler
 org.xml.sax.DTDHandler getDTDHandler()
          Return the current DTDHandler
 org.xml.sax.EntityResolver getEntityResolver()
          Return my internal EntityResolver
 org.xml.sax.ErrorHandler getErrorHandler()
          Return my ErrorHandler
 boolean getFeature(java.lang.String name)
          Gets the feature attribute of the Serializer object
 java.lang.Object getProperty(java.lang.String name)
          Gets the property attribute of the Serializer object
 User getUser()
          Get the current User.
 void parse(org.xml.sax.InputSource input)
          Description of the Method
 void parse(java.lang.String systemId)
          Description of the Method
 void reset()
          Reset the class to its initial state.
 java.lang.String serialize(org.w3c.dom.Document doc)
          Serialize a document
 java.lang.String serialize(org.w3c.dom.Node n)
          Serialize a single node
 java.lang.String serialize(NodeProxy p)
          Serialize a single NodeProxy
 java.lang.String serialize(NodeSet set, int start, int howmany)
          Serialize a set of nodes
 java.lang.String serialize(NodeSet set, int start, int howmany, long queryTime)
          Serialize a set of nodes
protected  void serializeToSAX(org.w3c.dom.Document doc, boolean generateDocEvent)
          Serialize a document to a SAX stream
protected  void serializeToSAX(org.w3c.dom.Node n, boolean generateDocEvents)
          Serialize a single Node to the SAX stream
protected  void serializeToSAX(NodeProxy p, boolean generateDocEvents)
          Serialize a single NodeProxy to the SAX stream
protected  void serializeToSAX(NodeSet set, int start, int howmany, long queryTime)
          Serialize a NodeSet to the SAX stream
 void setContentHandler(org.xml.sax.ContentHandler handler)
          Set the ContentHandler to be used during serialization.
protected  void setDocument(DocumentImpl doc)
           
 void setDTDHandler(org.xml.sax.DTDHandler handler)
          Set the DTDHandler to be used during serialization.
 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
 void setLexicalHandler(org.xml.sax.ext.LexicalHandler lexicalHandler)
          Sets the lexicalHandler attribute of the Serializer object
protected  java.io.StringWriter setPrettyPrinter(boolean xmlDecl)
          Sets the prettyPrinter attribute of the Serializer object
 void setProperties(java.util.Map properties)
           
 void setProperty(java.lang.String name, java.lang.Object value)
          Sets the property attribute of the Serializer object
 void setStylesheet(DocumentImpl doc, java.lang.String stylesheet)
          Sets the stylesheet attribute of the Serializer object
 void setStylesheet(java.lang.String stylesheet)
           
 void setUser(User user)
          Set the current User.
protected  void setXSLHandler()
          Sets the xSLHandler attribute of the Serializer object
 void toSAX(org.w3c.dom.Document doc)
          Serialize document to SAX stream
 void toSAX(org.w3c.dom.Node n)
          Description of the Method
 void toSAX(NodeProxy p)
          Description of the Method
 void toSAX(NodeSet set, int start, int howmany)
          Description of the Method
 void toSAX(NodeSet set, int start, int howmany, long queryTime)
          Description of the Method
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final org.apache.log4j.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

PRETTY_PRINT

public static final java.lang.String PRETTY_PRINT
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

EXPAND_XINCLUDES

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

HIGHLIGHT_MATCHES

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

broker

protected DBBroker broker

encoding

protected java.lang.String encoding

factory

protected javax.xml.transform.TransformerFactory factory

indent

protected boolean indent

createContainerElements

protected boolean createContainerElements

processXInclude

protected boolean processXInclude

processXSL

protected boolean processXSL

generateDocEvents

protected boolean generateDocEvents

highlightMatches

protected int highlightMatches

templates

protected javax.xml.transform.Templates templates

xslHandler

protected javax.xml.transform.sax.TransformerHandler xslHandler

xinclude

protected XIncludeFilter xinclude

contentHandler

protected org.xml.sax.ContentHandler contentHandler

dtdHandler

protected org.xml.sax.DTDHandler dtdHandler

lexicalHandler

protected org.xml.sax.ext.LexicalHandler lexicalHandler

user

protected User user
Constructor Detail

Serializer

public Serializer(DBBroker broker,
                  Configuration config)
Constructor for the Serializer object

Parameters:
broker - Description of the Parameter
Method Detail

setProperties

public void setProperties(java.util.Map properties)

applyXSLHandler

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

Returns:
StringWriter containing the generated XML

getContentHandler

public org.xml.sax.ContentHandler getContentHandler()
Return the current ContentHandler

Specified by:
getContentHandler in interface org.xml.sax.XMLReader
Returns:
The contentHandler value

getDTDHandler

public org.xml.sax.DTDHandler getDTDHandler()
Return the current DTDHandler

Specified by:
getDTDHandler in interface org.xml.sax.XMLReader
Returns:
The dTDHandler value

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()
Return my ErrorHandler

Specified by:
getErrorHandler in interface org.xml.sax.XMLReader
Returns:
The errorHandler value

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
Gets the feature attribute of the Serializer object

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

getProperty

public java.lang.Object getProperty(java.lang.String name)
                             throws org.xml.sax.SAXNotRecognizedException,
                                    org.xml.sax.SAXNotSupportedException
Gets the property attribute of the Serializer object

Specified by:
getProperty in interface org.xml.sax.XMLReader
Parameters:
name - Description of the Parameter
Returns:
The property value
Throws:
org.xml.sax.SAXNotRecognizedException - Description of the Exception
org.xml.sax.SAXNotSupportedException - Description of the Exception

parse

public void parse(org.xml.sax.InputSource input)
           throws java.io.IOException,
                  org.xml.sax.SAXException
Description of the Method

Specified by:
parse in interface org.xml.sax.XMLReader
Parameters:
input - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception
org.xml.sax.SAXException - Description of the Exception

setDocument

protected void setDocument(DocumentImpl doc)

parse

public void parse(java.lang.String systemId)
           throws java.io.IOException,
                  org.xml.sax.SAXException
Description of the Method

Specified by:
parse in interface org.xml.sax.XMLReader
Parameters:
systemId - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception
org.xml.sax.SAXException - Description of the Exception

reset

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


serialize

public java.lang.String serialize(NodeSet set,
                                  int start,
                                  int howmany)
                           throws org.xml.sax.SAXException
Serialize a set of nodes

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

serialize

public java.lang.String serialize(NodeSet set,
                                  int start,
                                  int howmany,
                                  long queryTime)
                           throws org.xml.sax.SAXException
Serialize a set of nodes

Parameters:
set - Description of the Parameter
start - Description of the Parameter
howmany - Description of the Parameter
queryTime - Description of the Parameter
Returns:
Description of the Return Value
Throws:
org.xml.sax.SAXException - Description of the Exception

serialize

public java.lang.String serialize(org.w3c.dom.Document doc)
                           throws org.xml.sax.SAXException
Serialize a document

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

serialize

public java.lang.String serialize(org.w3c.dom.Node n)
                           throws org.xml.sax.SAXException
Serialize a single node

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

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

serializeToSAX

protected void serializeToSAX(org.w3c.dom.Document doc,
                              boolean generateDocEvent)
                       throws org.xml.sax.SAXException
Serialize a document to a SAX stream

Parameters:
doc - Description of the Parameter
generateDocEvent - Description of the Parameter
Throws:
org.xml.sax.SAXException - Description of the Exception

serializeToSAX

protected void serializeToSAX(NodeSet set,
                              int start,
                              int howmany,
                              long queryTime)
                       throws org.xml.sax.SAXException
Serialize a NodeSet to the SAX stream

Parameters:
set - Description of the Parameter
start - Description of the Parameter
howmany - Description of the Parameter
queryTime - Description of the Parameter
Throws:
org.xml.sax.SAXException - Description of the Exception

serializeToSAX

protected void serializeToSAX(org.w3c.dom.Node n,
                              boolean generateDocEvents)
                       throws org.xml.sax.SAXException
Serialize a single Node to the SAX stream

Parameters:
n - Description of the Parameter
generateDocEvents - Description of the Parameter
Throws:
org.xml.sax.SAXException - Description of the Exception

serializeToSAX

protected void serializeToSAX(NodeProxy p,
                              boolean generateDocEvents)
                       throws org.xml.sax.SAXException
Serialize a single NodeProxy to the SAX stream

Parameters:
p - Description of the Parameter
generateDocEvents - Description of the Parameter
Throws:
org.xml.sax.SAXException - Description of the Exception

setContentHandler

public void setContentHandler(org.xml.sax.ContentHandler handler)
Set the ContentHandler to be used during serialization.

Specified by:
setContentHandler in interface org.xml.sax.XMLReader

setDTDHandler

public void setDTDHandler(org.xml.sax.DTDHandler handler)
Set the DTDHandler to be used during serialization.

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

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

setLexicalHandler

public void setLexicalHandler(org.xml.sax.ext.LexicalHandler lexicalHandler)
Sets the lexicalHandler attribute of the Serializer object

Parameters:
lexicalHandler - The new lexicalHandler value

setPrettyPrinter

protected java.io.StringWriter setPrettyPrinter(boolean xmlDecl)
Sets the prettyPrinter attribute of the Serializer object

Parameters:
xmlDecl - The new prettyPrinter value
Returns:
Description of the Return Value

setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)
                 throws org.xml.sax.SAXNotRecognizedException,
                        org.xml.sax.SAXNotSupportedException
Sets the property attribute of the Serializer object

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

setStylesheet

public void setStylesheet(java.lang.String stylesheet)

setStylesheet

public void setStylesheet(DocumentImpl doc,
                          java.lang.String stylesheet)
Sets the stylesheet attribute of the Serializer object

Parameters:
stylesheet - The new stylesheet value
Throws:
org.xml.sax.SAXException - Description of the Exception
javax.xml.transform.TransformerConfigurationException - Description of the Exception

setXSLHandler

protected void setXSLHandler()
Sets the xSLHandler attribute of the Serializer object


toSAX

public void toSAX(NodeSet set,
                  int start,
                  int howmany)
           throws org.xml.sax.SAXException
Description of the Method

Parameters:
set - Description of the Parameter
start - Description of the Parameter
howmany - Description of the Parameter
Throws:
org.xml.sax.SAXException - Description of the Exception

toSAX

public void toSAX(NodeSet set,
                  int start,
                  int howmany,
                  long queryTime)
           throws org.xml.sax.SAXException
Description of the Method

Parameters:
set - Description of the Parameter
start - Description of the Parameter
howmany - Description of the Parameter
queryTime - Description of the Parameter
Throws:
org.xml.sax.SAXException - Description of the Exception

toSAX

public void toSAX(org.w3c.dom.Document doc)
           throws org.xml.sax.SAXException
Serialize document to SAX stream

Parameters:
doc - Description of the Parameter
Throws:
org.xml.sax.SAXException - Description of the Exception

toSAX

public void toSAX(org.w3c.dom.Node n)
           throws org.xml.sax.SAXException
Description of the Method

Parameters:
n - Description of the Parameter
Throws:
org.xml.sax.SAXException - Description of the Exception

toSAX

public void toSAX(NodeProxy p)
           throws org.xml.sax.SAXException
Description of the Method

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


Copyright (C) Wolfgang Meier. All rights reserved.