com.oroad.stxx.transform.document
Class SAXDocumentBuilder

java.lang.Object
  extended bycom.oroad.stxx.transform.document.SAXDocumentBuilder

public class SAXDocumentBuilder
extends java.lang.Object

Builds a document by firing SAX events. Uses a SAXSerializer to serialize the information into SAX events.

Author:
Don Brown

Nested Class Summary
protected  class SAXDocumentBuilder.RootNodeFilter
          Swallows the closing of the root node and stores its name.
 
Field Summary
protected static java.lang.String ALWAYS_USE_ROOT_KEY
          Whether to always used the chained root node as the document root
protected  boolean alwaysUseChainedRoot
          Whether to always use the chained root node as the document root
protected static java.lang.String CHAINED_ROOT_NODE
          The name of the chained root node
protected  java.lang.String chainedRootNode
          The name of the chained root node
protected  boolean isStrutsPlugin
          Whether stxx is being used as a Struts plugin
protected static org.apache.commons.logging.Log log
          The logging instance
protected  org.apache.struts.util.MessageResources messages
          The message resources
protected  BuilderRules rules
          The builder rules
protected  SAXSerializer serializer
          The serializer to use
protected static java.lang.String SERIALIZER_CLASS_KEY
          The class implementing SAXSerializer
 
Constructor Summary
SAXDocumentBuilder()
           
 
Method Summary
protected  void attachActionErrors(javax.servlet.http.HttpServletRequest request, org.apache.struts.action.ActionErrors aes, java.util.Locale locale, org.apache.struts.util.MessageResources appRes, XMLConsumer handler)
          Process the ActionErrors collection to create an XML node list of all errors.
protected  void attachActionMessages(javax.servlet.http.HttpServletRequest request, org.apache.struts.action.ActionMessages aes, java.util.Locale locale, org.apache.struts.util.MessageResources appRes, XMLConsumer handler)
          Process the ActionMessages collection to create an XML node list of all messages.
protected  void attachRequest(javax.servlet.http.HttpServletRequest request, boolean includeParameters, boolean includeAttributes, XMLConsumer handler)
          Process the HttpServletRequest object to create an XML node list of all parameters and attributes.
protected  void attachResources(javax.servlet.http.HttpServletRequest req, java.util.Locale locale, PropertyMessageResources application, XMLConsumer handler)
          Get's the proper application resources file for a particular locale.
 void buildDocument(javax.servlet.http.HttpServletRequest request, XMLConsumer handler)
          Builds the document
protected  java.lang.String convertDocument(java.lang.Object xml, XMLConsumer handler, javax.xml.transform.Transformer trans, boolean isRoot)
          Converts a single xml document into SAX events.
 void init(StxxProperties props, BuilderRules rules)
          Initializes from StxxProperties
protected  java.lang.String startDocumentFromActions(javax.servlet.http.HttpServletRequest request, XMLConsumer handler)
          Sends action-created XML documents to the XMLConsumer and returns the name of the root node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERIALIZER_CLASS_KEY

protected static final java.lang.String SERIALIZER_CLASS_KEY
The class implementing SAXSerializer

See Also:
Constant Field Values

ALWAYS_USE_ROOT_KEY

protected static final java.lang.String ALWAYS_USE_ROOT_KEY
Whether to always used the chained root node as the document root

See Also:
Constant Field Values

CHAINED_ROOT_NODE

protected static final java.lang.String CHAINED_ROOT_NODE
The name of the chained root node

See Also:
Constant Field Values

chainedRootNode

protected java.lang.String chainedRootNode
The name of the chained root node


alwaysUseChainedRoot

protected boolean alwaysUseChainedRoot
Whether to always use the chained root node as the document root


serializer

protected SAXSerializer serializer
The serializer to use


messages

protected org.apache.struts.util.MessageResources messages
The message resources


rules

protected BuilderRules rules
The builder rules


isStrutsPlugin

protected boolean isStrutsPlugin
Whether stxx is being used as a Struts plugin


log

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

Constructor Detail

SAXDocumentBuilder

public SAXDocumentBuilder()
Method Detail

init

public void init(StxxProperties props,
                 BuilderRules rules)
Initializes from StxxProperties

Parameters:
props - The stxx properties
rules - The builder rules

buildDocument

public void buildDocument(javax.servlet.http.HttpServletRequest request,
                          XMLConsumer handler)
Builds the document

Parameters:
request - The HTTP request
handler - The SAX event consumer

startDocumentFromActions

protected java.lang.String startDocumentFromActions(javax.servlet.http.HttpServletRequest request,
                                                    XMLConsumer handler)
                                             throws org.xml.sax.SAXException
Sends action-created XML documents to the XMLConsumer and returns the name of the root node.

Parameters:
request - The http request
handler - The XMLConsumer
Returns:
The name of the root node
Throws:
org.xml.sax.SAXException - If something goes wrong

convertDocument

protected java.lang.String convertDocument(java.lang.Object xml,
                                           XMLConsumer handler,
                                           javax.xml.transform.Transformer trans,
                                           boolean isRoot)
Converts a single xml document into SAX events. Currently this method supports JDOM documents and w3c DOM documents.

Parameters:
xml - The XML object
handler - The XMLConsumer
trans - The transformer
isRoot - Whether the document's root element is the new document's root element
Returns:
The name of the root node

attachActionErrors

protected void attachActionErrors(javax.servlet.http.HttpServletRequest request,
                                  org.apache.struts.action.ActionErrors aes,
                                  java.util.Locale locale,
                                  org.apache.struts.util.MessageResources appRes,
                                  XMLConsumer handler)
                           throws org.xml.sax.SAXException
Process the ActionErrors collection to create an XML node list of all errors.

Parameters:
aes - The ActionErrors collection
request - The http request
handler - The XMLConsumer
Throws:
org.xml.sax.SAXException - If something goes wrong

attachActionMessages

protected void attachActionMessages(javax.servlet.http.HttpServletRequest request,
                                    org.apache.struts.action.ActionMessages aes,
                                    java.util.Locale locale,
                                    org.apache.struts.util.MessageResources appRes,
                                    XMLConsumer handler)
                             throws org.xml.sax.SAXException
Process the ActionMessages collection to create an XML node list of all messages.

Parameters:
aes - The ActionMessages collection
request - The http request
handler - The XMLConsumer
Throws:
org.xml.sax.SAXException - If something goes wrong

attachRequest

protected void attachRequest(javax.servlet.http.HttpServletRequest request,
                             boolean includeParameters,
                             boolean includeAttributes,
                             XMLConsumer handler)
                      throws org.xml.sax.SAXException
Process the HttpServletRequest object to create an XML node list of all parameters and attributes.

Parameters:
request - The request object so that I can get all the parameters and attributes
includeParameters - Whether to include parameter information
includeAttributes - Whether to include attribute information
handler - Where to send the SAX events
Throws:
org.xml.sax.SAXException - If something goes wrong

attachResources

protected void attachResources(javax.servlet.http.HttpServletRequest req,
                               java.util.Locale locale,
                               PropertyMessageResources application,
                               XMLConsumer handler)
                        throws org.xml.sax.SAXException
Get's the proper application resources file for a particular locale. This will iterate through all the keys and return it

Parameters:
locale - The locale
application - The application resources
req - The http request
handler - Where to send the SAX events
Throws:
org.xml.sax.SAXException - If something goes wrong