Configuring with Struts 1.0
web.xml
Stxx works with Struts 1.0.x by sub-classing the ActionServlet class to insert the stxx processing instructions where they are needed. To facilitate this, changes to the web.xml file are required.
Since the ActionServlet class has been overridden by stxx, so the web.xml needs to point to the new implementation.
<servlet-name>action</servlet-name> <servlet-class> com.oroad.stxx.action.ActionServlet </servlet-class>
The factory attribute needs to point to the stxx application resources factory class. This is because stxx changes the way that application resources are used.
<init-param> <param-name>factory</param-name> <param-value> com.oroad.stxx.util.PropertyMessageResourcesFactory </param-value> </init-param>
The forward attribute needs to point to the stxx implementation of the ActionForward class that supports transformations.
<init-param> <param-name>forward</param-name> <param-value> com.oroad.stxx.action.ActionForward </param-value> </init-param>
Once this has been configured, a parameter will need to be set which points to the stxx properties file where further configuration parameters can be set. This file is expected to be loaded from the classpath, so it must reside in /WEB-INF/classes to be found.
<init-param> <param-name>stxxInit</param-name> <param-value>/stxx.properties</param-value> </init-param>
Name | Value | Status |
---|---|---|
action | com.oroad.stxx.action.ActionServlet | Required |
factory | com.oroad.stxx.util.PropertyMessageResourcesFactory | Required |
forward | com.oroad.stxx.action.ActionForward | Required |
stxxInit | /stxx.properties | Required |
struts-config.xml
The next change you need to make is to the struts-config.xml file. The changes here are to add a new tag called <transform> that nests underneath the <forward> tag. This tag allows you to add as many transformation possibilities as you need, but only one will be run for a particular forward.
The changes will look like this:
<action path="/contactListExample" type="com.oroad.stxx.example.ContactListExampleAction" scope="request"> <forward name="success"> <transform name="default" path="/contactListExample.xsl"/> <transform name="Mozilla" path="/contactListExample_Mozilla.xsl"/> <transform name="MSIE" path="/contactListExample_MSIE.xsl"/> </forward> </action>
The name attribute of the transform tag is the most important. It allows for stxx to choose the transformation to perform on the XML for a given criteria. By default, stxx will choose the transformation based on the type of browser the client is using.
In this case, the value of the name attribute maps to the list of defined user-agents in the stxx.properties file. A value of default is the value to be used if no match to the user-agents can be found.
For example, you could put the name "Mozilla" in the stxx.properties user-agent property and assign various Mozilla user-agents strings as the value, then stxx will try to match the user agent of the client to whatever is in the Mozilla property. For more information, please check out the section Configuring stxx.properties.
The path defines the location that stxx can find the XSL file to transform the XML into HTML. The path is referenced from the root of the web application, for example "/foo.xsl" will match to the URL http://www.foo.com/webapp/foo.xsl.
The "type" attribute is the key that tells stxx which transformation process to use. By default, it is set to 'html.' This tells stxx that the XML you create should be transformed with the 'html' transformer, which is usually configured to combined the XML with the XSL template you specify and output HTML as it is in this example. Stxx supports transformation types that use XSL-FO (for PDF's, SVG's, RTF's, etc), Cocoon, Velocity, XMLForm, and of course XSL transformations for any text-based output type.
Attribute | Value | Status |
---|---|---|
name | The name of the selector | Required |
path | The path to the XSL file | Required |
render | client | server (default) | Optional |
debug | true | false (default) | Optional |
type | Which transformer to use, html is the default | Optional |
The same transform tag also works within the global-forwards tag.
by Don Brown