## org.exist.storage.serializers
Class Serializer

    java.lang.Object
      org.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 <wolfgang@exist-db.org>

Field Summary
`static java.lang.String` `ENCODING`
`static java.lang.String` `EXIST_NS`
`static java.lang.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
`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)`
`java.lang.Object` `getProperty(java.lang.String name)`
`java.lang.String` `getProperty(java.lang.String key, java.lang.String defaultValue)`
`java.lang.String` `getStylesheetProperty(java.lang.String name)`
`User` `getUser()` Get the current User.
`java.lang.String` `hasXSLPi(org.w3c.dom.Document doc)` Check if the document has an xml-stylesheet processing instruction that references an XSLT stylesheet.
`boolean` `isStylesheetApplied()`
`void` `parse(org.xml.sax.InputSource input)`
`void` `parse(java.lang.String systemId)`
`void` `prepareStylesheets(DocumentImpl doc)`
`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.
`void` `serialize(DocumentImpl doc, java.io.Writer writer, boolean prepareStylesheet)`
`java.lang.String` `serialize(NodeProxy p)` Serialize a single NodeProxy.
`java.lang.String` `serialize(NodeValue n)`
`void` `setContentHandler(org.xml.sax.ContentHandler handler)`
`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
`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)`
`void` `setStylesheetParam(java.lang.String param, java.lang.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

### 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

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()

### 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`

### getStylesheetProperty

    public java.lang.String getStylesheetProperty(java.lang.String name)

### 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`

### 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 void serialize(DocumentImpl doc,
                          java.io.Writer writer,
                          boolean prepareStylesheet)
                   throws org.xml.sax.SAXException

  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

### prepareStylesheets

    public void prepareStylesheets(DocumentImpl doc)

### 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

### 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

### 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`

### 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()`

### hasXSLPi

    public java.lang.String hasXSLPi(org.w3c.dom.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.