In StrutsCX the XSLT transformation process is organized through the StrutsCXServlet and its helper classes StrutsCXDocumentBuilder and StrutsCXTransformer. The StrutsCXServlet merely controls this process and does nothing more than:
1. create an XML document with the help of the StrutsCXDocumentBuilder and
2. forwards this document to the StrutsCXTransformer for transformation purposes.
The StrutsCXDocumentBuilder gets the necessary information it needs to generate the XML-Output-Document through the HttpServletRequest, the HttpSession as well as the ServletContext. They should then get handed over to its one and only public method createDocument(). Its the job of the Struts Action to check the presence of the wanted information in the HttpServletRequest, the HttpSession and the ServletContext. The virtual XML-Output-Document created by the StrutsCXDocumentBuilder contains the following information:
The data of the integration tier - this could be the database data, the one out of Enterprise JavaBeans or data directly out of flat XML files.
The StrutsCX-Resource-Properties, which under StrutsCX replace the Java Resource Bundles.
An (optional) ActionForm Bean with the state of the client.
An (optional) ActionErrors object with the Struts error messages.
The data of the HttpServletRequest.
The data of the HttpSession.
JDOM is used to create the XML-Output-Document.
In StrutsCX the values of each dataset needs to be presented as a JavaBean! One or more JavaBeans need to be added to an ArrayList object and passed to the StrutsCXDocumentBuilder via the HttpServletRequest. The StrutsCXDocumentBuilder uses its helper class StrutsCXBeanToElement- to automatically create one XML Element for each JavaBean and add it to the XML-Output-Document. This helper class is based loosely on its archetype Model 2X, a project quite similar to StrutsCX developed by Julien Mercay and Gilbert Bouzeid and described in the JavaWorld article 'Boost Struts with XSLT and XML - An introduction to Model 2X'. This class analyzes the content of each JavaBean with the help of the Java Reflection API and the Java BeanInfo interface. It generates the XML Element out of the name and value of the JavaBean setter and getter methods.
The handling of the ActionForm object with its setters and getters is managed by the same principle as the serialization of the ActionErrors object with the error messages. We'll discuss the StrutsCX error handling later in another chapter. ActionForm and ActionErrors objects get transfered to the StrutsCXDocumentBuilder via the HttpServletRequest.
The StrutsCX-Resources-Properties are XML files - one for each language - which contains all internationalized text Strings we need in our presentation besides the data of the integration tier. We will discuss the StrutsCX-Resources-Properties in another chapter later on. StrutsCX-Resources-Properties is not transfered via the HttpServletRequest but via the ServletContext. This is because of better performance and is done just once at the start of the Servlet container, right after the first call of one of the Action classes. Check out details in the API of the StrutsCXBaseActionHelperclass.
The XML serialization of the other values of the HttpServletRequest and the HttpSession is relatively easy: For every Request and Session attribute a XML Element is added to the XML-Output-Document.
The actual XSL transformation is done by the StrutsCXTransformer. This class encapsulates the whole transformation process by using JAXP, the Java API for XML Parsing. Of course we do need a proper XSL Stylesheet, too. It should likewise be selected by the Action class and added to the HttpServletRequest. The StrutsCXTransformer offers the comfort to read and parse this XSL Stylesheet just in case it got changed after the last call. Therefore it uses its helper class StrutsCXURIResolver which automatically converts relative URIs into absolute URIs.
The StrutsCXTransformer sends the XML data directly to the HttpServletResponse if the following parameter was added to the HttpServletRequest:
debugxml=true
This is very convenient for the development of the XSL Stylesheets and looks great in the Internet Explorer where you can open and close whole XML Element sets: