com.oroad.stxx.transform.document
Class DefaultSAXSerializer

java.lang.Object
  extended bycom.oroad.stxx.transform.document.DefaultSAXSerializer
All Implemented Interfaces:
SAXSerializer

public class DefaultSAXSerializer
extends java.lang.Object
implements SAXSerializer

Serializes objects by firing SAX events

Author:
Don Brown, Silvester van der Bijl

Field Summary
protected  boolean isStrutsPlugin
          Stores whether Struts 1.1+ is present
protected static org.apache.commons.logging.Log log
          The logging instance
protected static java.lang.String USE_CSV_PARAM_FORMAT_KEY
          Whether to serialize request parameters as comma-separated values
protected  boolean useCSVParamFormat
          Whether to serialize request parameters as comma-separated values
 
Constructor Summary
DefaultSAXSerializer()
           
 
Method Summary
protected  org.xml.sax.Attributes getAttributes(java.lang.String name, java.lang.String value)
          Gets an Attributes object that has the given attribute
 void init(StxxProperties props)
          Initializes the serializer
protected  void outputJDOM(org.jdom.Document d, XMLConsumer handler)
          Serializes a JDOM document
protected  void outputJDOM(org.jdom.Element e, XMLConsumer handler)
          Serializes a JDOM element
protected  void outputNode(org.w3c.dom.Node n, XMLConsumer handler)
          Serializes a w3c DOM node
protected  void sendElement(java.lang.String eName, java.lang.String eText, java.lang.String aName, java.lang.String aValue, XMLConsumer handler)
          Sends an element that has the given attribute and text
protected  void sendElement(java.lang.String eName, java.lang.String eText, XMLConsumer handler)
          Sends an element that has the given text
 void serializeActionError(javax.servlet.http.HttpServletRequest request, java.lang.String name, org.apache.struts.action.ActionError error, java.util.Locale locale, org.apache.struts.util.MessageResources res, XMLConsumer handler)
          Serializes the action error as an element.
 void serializeActionForm(javax.servlet.http.HttpServletRequest request, java.lang.String name, org.apache.struts.action.ActionForm form, XMLConsumer handler)
          Serializes the action form as an element.
 void serializeActionMessage(javax.servlet.http.HttpServletRequest request, java.lang.String name, org.apache.struts.action.ActionMessage message, java.util.Locale locale, org.apache.struts.util.MessageResources res, XMLConsumer handler)
          Serializes the action message as an element.
protected  void serializeIt(java.lang.Object bean, java.lang.String name, XMLConsumer handler, java.util.Vector stack)
          Recursive function to serialize objects to XML.
 void serializeRequestAttribute(javax.servlet.http.HttpServletRequest request, java.lang.String name, XMLConsumer handler)
          Serializes the named request attribute as an element.
 void serializeRequestParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name, XMLConsumer handler)
          Serializes the named request parameter as an element.
 void serializeResource(javax.servlet.http.HttpServletRequest request, java.util.Map resources, java.lang.String key, XMLConsumer handler)
          Serializes the resource as an element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USE_CSV_PARAM_FORMAT_KEY

protected static final java.lang.String USE_CSV_PARAM_FORMAT_KEY
Whether to serialize request parameters as comma-separated values

See Also:
Constant Field Values

log

protected static final org.apache.commons.logging.Log log
The logging instance


useCSVParamFormat

protected boolean useCSVParamFormat
Whether to serialize request parameters as comma-separated values


isStrutsPlugin

protected boolean isStrutsPlugin
Stores whether Struts 1.1+ is present

Constructor Detail

DefaultSAXSerializer

public DefaultSAXSerializer()
Method Detail

init

public void init(StxxProperties props)
Initializes the serializer

Specified by:
init in interface SAXSerializer
Parameters:
props - The stxx properties

serializeRequestParameter

public void serializeRequestParameter(javax.servlet.http.HttpServletRequest request,
                                      java.lang.String name,
                                      XMLConsumer handler)
                               throws org.xml.sax.SAXException
Serializes the named request parameter as an element.

Specified by:
serializeRequestParameter in interface SAXSerializer
Parameters:
request - The http request
name - The name of the request parameter
handler - The SAX event consumer
Throws:
org.xml.sax.SAXException - If something goes wrong

serializeRequestAttribute

public void serializeRequestAttribute(javax.servlet.http.HttpServletRequest request,
                                      java.lang.String name,
                                      XMLConsumer handler)
                               throws org.xml.sax.SAXException
Serializes the named request attribute as an element.

Specified by:
serializeRequestAttribute in interface SAXSerializer
Parameters:
request - The http request
name - The name of the request attribute
handler - The SAX event consumer
Throws:
org.xml.sax.SAXException - If something goes wrong

serializeActionError

public void serializeActionError(javax.servlet.http.HttpServletRequest request,
                                 java.lang.String name,
                                 org.apache.struts.action.ActionError error,
                                 java.util.Locale locale,
                                 org.apache.struts.util.MessageResources res,
                                 XMLConsumer handler)
                          throws org.xml.sax.SAXException
Serializes the action error as an element.

Specified by:
serializeActionError in interface SAXSerializer
Parameters:
request - The http request
name - The property name
error - The action error
locale - The current locale
res - The current resource bundle
handler - The SAX event consumer
Throws:
org.xml.sax.SAXException - If something goes wrong

serializeActionMessage

public void serializeActionMessage(javax.servlet.http.HttpServletRequest request,
                                   java.lang.String name,
                                   org.apache.struts.action.ActionMessage message,
                                   java.util.Locale locale,
                                   org.apache.struts.util.MessageResources res,
                                   XMLConsumer handler)
                            throws org.xml.sax.SAXException
Serializes the action message as an element.

Specified by:
serializeActionMessage in interface SAXSerializer
Parameters:
request - The http request
name - The property name
message - The action message
locale - The current locale
res - The current resource bundle
handler - The SAX event consumer
Throws:
org.xml.sax.SAXException - If something goes wrong

serializeActionForm

public void serializeActionForm(javax.servlet.http.HttpServletRequest request,
                                java.lang.String name,
                                org.apache.struts.action.ActionForm form,
                                XMLConsumer handler)
                         throws org.xml.sax.SAXException
Serializes the action form as an element.

Specified by:
serializeActionForm in interface SAXSerializer
Parameters:
request - The http request
form - The action form
handler - The SAX event consumer
name - The name of the form
Throws:
org.xml.sax.SAXException - If something goes wrong

serializeResource

public void serializeResource(javax.servlet.http.HttpServletRequest request,
                              java.util.Map resources,
                              java.lang.String key,
                              XMLConsumer handler)
                       throws org.xml.sax.SAXException
Serializes the resource as an element.

Specified by:
serializeResource in interface SAXSerializer
Parameters:
request - The http request
resources - The resources
key - The resource key
handler - The SAX event consumer
Throws:
org.xml.sax.SAXException - If something goes wrong

getAttributes

protected org.xml.sax.Attributes getAttributes(java.lang.String name,
                                               java.lang.String value)
                                        throws org.xml.sax.SAXException
Gets an Attributes object that has the given attribute

Parameters:
name - The attribute name
value - The attribute value
Returns:
The attributes object
Throws:
org.xml.sax.SAXException - If something goes wrong

sendElement

protected void sendElement(java.lang.String eName,
                           java.lang.String eText,
                           java.lang.String aName,
                           java.lang.String aValue,
                           XMLConsumer handler)
                    throws org.xml.sax.SAXException
Sends an element that has the given attribute and text

Parameters:
eName - The name of the element
eText - The text value
aName - The name of the attribute
aValue - The value of the attribute
handler - The SAX event consumer
Throws:
org.xml.sax.SAXException - If something goes wrong

sendElement

protected void sendElement(java.lang.String eName,
                           java.lang.String eText,
                           XMLConsumer handler)
                    throws org.xml.sax.SAXException
Sends an element that has the given text

Parameters:
eName - The name of the element
eText - The text value
handler - The SAX event consumer
Throws:
org.xml.sax.SAXException - If something goes wrong

serializeIt

protected void serializeIt(java.lang.Object bean,
                           java.lang.String name,
                           XMLConsumer handler,
                           java.util.Vector stack)
                    throws org.xml.sax.SAXException
Recursive function to serialize objects to XML. Currently it will serialize Collections, maps, org.jdom.Document, org.jdom.Element, Array org.w3c.dom.Node, and javabeans. It maintains a stack of objects serialized already in the current functioncall. This is used to avoid looping (stack overflow) of circular linked objects.

Parameters:
bean - The object you want serialized.
name - The name of the object, used for element <name/>
handler - XMLConsumer
stack - Vector of objects we're serializing since the first calling of this function (to prevent looping on circular references).
Throws:
org.xml.sax.SAXException - If something goes wrong

outputJDOM

protected void outputJDOM(org.jdom.Document d,
                          XMLConsumer handler)
Serializes a JDOM document

Parameters:
handler - The SAX event consumer

outputJDOM

protected void outputJDOM(org.jdom.Element e,
                          XMLConsumer handler)
Serializes a JDOM element

Parameters:
e - The element
handler - The SAX event consumer

outputNode

protected void outputNode(org.w3c.dom.Node n,
                          XMLConsumer handler)
Serializes a w3c DOM node

Parameters:
n - The node
handler - The SAX event consumer