IT.CappuccinoNet.com
home | service | references | publications | strutscx | books | links | about

StrutsCX Intro

Overview

Installation

Publications

History

FAQ

Samples

Resources

Licencing

Mailinglist

Downloads

SourceForge Logo

Gmane


StrutsCX - Installation StrutsCX

Download the strutscx-xx-src.zip. This package contains all the necessary files to work with StrutsCX.

StrutsCX itself is basically the strutscx-xx.jar and some configuration files. Here are the steps you should follow (described for StrutsCX v0.9.5 or later):

  1. Put JAR files to /WEB-INF/lib*
  2. Configure the web.xml*
  3. Configure PlugIn in struts-config.xml*
  4. Create Struts Actions
  5. Declare and configure Actions in struts-config.xml
  6. Define StrutsCX Resources properties
  7. Declare the Resources properties in the strutscx-config.xml*
  8. Create XSL Stylesheets
  9. Declare the XSL Stylesheets in the strutscx-definitions of the strutscx-config.xml
  10. Configure additional parameters in the strutscx-config.xml*
  11. Configure the strutscx-log4j-config.xml*
* Usually you do this just once  

1. Put JAR files to /WEB-INF/lib

StrutsCX relies on these JARs, so make sure they are part of your application:

Avalon*    avalon-framework-cvs-20020806.jar
Batik*    batik.jar
Castor XML**    castor-0.9.5-xml.jar
dom4j    dom4j-full-1.4.jar
FOP*    fop-0.20.5.rc3a.jar
Jakarta Commons    commons-jxpath-1.1.jar
commons-digester-1.5.jar
commons-beanutils-1.6.1.jar
commons-collections-2.1.jar
commons-logging-1.0.3.jar
commons-validator-1.0.2.jar
Jakarta ORO    jakarta-oro-2.0.7.jar
JDOM    jdom-b9.jar
Log4j    log4j-1.2.8.jar
Struts    struts-1.1.jar
StrutsCX    strutscx-0.9.5.jar
Xerces***    xercesImpl.jar

needed for basic StrutsCX
* just needed for additional use of Apache FOP
** just needed for additional use of Castor XML (which is optional)
*** just needed for the Castor XML Generator (which is optional)

Status: StrutsCX v.0.9.5

Up 

 

2. Configure the web.xml

Declare the StrutsCXServlet:
<!-- StrutsCXServlet -->
<servlet>
  <servlet-name>StrutsCXServlet</servlet-name>
  <servlet-class>com.cappuccinonet.
  strutscx.xslt.StrutsCXServlet</servlet-class>
  <init-param>
    <param-name>debug</param-name>
    <param-value>false</param-value>
  </init-param>
  <load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>StrutsCXServlet</servlet-name>
  <url-pattern>/StrutsCXServlet</url-pattern>
</servlet-mapping>

Up 

 

3. Configure PlugIn in struts-config.xml

Add the StrutsCXLog4jInitPlugIn and the StrutsCXPlugIn (in this order) to your struts-config.xml:
<plug-in className="com.cappuccinonet.
  strutscx.util.StrutsCXLog4jInitPlugIn">
  <set-property property="config" 
  value="/WEB-INF/strutscx-log4j-config.xml" />
</plug-in>
<plug-in className="
  com.cappuccinonet.strutscx.util.StrutsCXPlugIn">
  <set-property property="config" 
  value="/WEB-INF/strutscx-config.xml" />
</plug-in>
Make sure the location of the xml files in the properties is set correct.

Up 

 

4. Create Struts Actions

Inside the Struts Action you do have to do at least the following:

  1. get pointer to the XSL stylesheet and add it to the request:
    // pointer to the strutscx-definitions
    String xslFile = "simple.intro";
    // set it to the HttpServletRequest
    request.setAttribute(
      StrutsCXConstants.XSL_KEY, xslFile);
    The pointer should correspond to a strutscx-definition in the strutscx-config.xml.

  2. (optional) create the data (XML document or ArrayList with JavaBeans) and add it to the reqeust:
    // doc = any XML Document (JDOM, dom4j, DOM)
    request.setAttribute("myXML", doc);
    or
    ArrayList list = new ArrayList();
    list.add(form); // add any JavaBean
    request.setAttribute("myList", list);
  3. set the encoding:
    request.setAttribute(
    StrutsCXConstants.ENCODING_KEY, 
    "ISO-8859-1");


  4. forward to view component, i.e.:
    return (mapping.findForward("success"))

Up 

 

5. Declare and configure Actions in struts-config.xml

Define an Action-Mapping for each of your Struts Actions, i.e.:
<action path="/info" 
  type="com.....SimpleAction">
  <forward name="success" 
    path="/StrutsCXServlet"/>
</action>
Note that we do forward to the StrutsCXServlet - not to a JSP!

Up 

 

6. Define StrutsCX Resources properties

StrutsCX does not use the Java Resource Bundle technology with its ApplicationResources.properties. Instead you may define pure XML files for this purpose. StrutsCX automatically serializes these XML files into the XML-Output-Document so you may access the values in your XSL stylesheets.
Here an example on how such a file may look like.

<resourcesproperties lang="de">
  <strings>
    <home>home</home>
    <info>info</info>
    <error>error</error>
  </strings>
</resourcesproperties>
You are free in declare elements as far as it follows the XML specification. If you like you can define these files in charsets different to ISO-8859-1. The name and location of these files you'll define in the strutscx-config.xml. See the next step.

Up 

 

7. Declare the Resourece properties in the strutscx-config.xml

If your application has different languages you should set the <lang> Element. It defines the languages this application will provide. StrutsCX uses StringTokenizer to read this information, so please pay attention to the space:

<lang>en de </lang>
Make sure to provide the appropriate resourec-properties files for each language.

Inside <resources-properties> element you declare pointers to the resources properties files described above, usually you define one for each <lang> element:

<resources-properties>
  <on>ON</on>
  <!-- provide a file for each <lang> -->
  <en>/WEB-INF/xml/variables_en.xml</en>
  <de>/WEB-INF/xml/variables_de.xml</de>
</resources-properties>
Note: If you do not need resources properties in your application you can switch this feature off by setting the value OFF (default ON) to the <on> element.

Up 

 

8. Create XSL Stylesheets

Since StrutsCX auto-creates an XML tree (we call it XML-Output-Document) from you data, the HttpServletRequest, the HttpSession, the Struts ActionForm and the Struts ActionErrors object you should now provide an XSL Stylesheet to transform it. Note: You may view the XML-Output-Document by pointing with your Browser to your action's path and add debugxml=true request parameter:
http://localhost:8080/strutscx-simple/
                             info.do?debugxml=true

Up 

 

9. Declare the XSL Stylesheets in the strutscx-definitions of the strutscx-config.xml

Up 

The most important parameters to set in the strutscx-config.xml are the <strutscx-definitions>. Here you declare pointers to XSL stylesheets. Inside the Actions you call these pointers rather than the stylesheet directly:

<strutscx-definitions>
  <!-- a unique name -->
  <definition name="simple.intro">
    <!-- location of a XSL stylesheet-->
    <put>/WEB-INF/xsl/simple.xsl</put>
  </definition>
</strutscx-definitions>

 

10. Configure additional parameters in the strutscx-config.xml

There are some more parameters which are rather specific and intended for advanced StrutsCX users:

The <documentbuilder> and <transformer> elements should stay untached. You just need them if you provide your own StrutsCXDocumentBuilder or StrutsCXTransformer:

<documentbuilder>
  <!-- the documentbuilder we do use; 
       replace it with your own version -->
  <class id="standard">
  com.cappuccinonet.strutscx.xslt.
    StrutsCXStandardDocumentBuilder
  </class>
  <!-- DocumentBuilder to keep 
  XML-Output-Document 
  backward compatible up to StrutsCX v0.9.3 -->
  <!--<class id="standard">
  com.cappuccinonet.strutscx.xslt.
    StrutsCXClassicDocumentBuilder
  </class>-->
</documentbuilder>
<transformer>
  <!-- the transformer we do use; 
  replace it with your own version -->
  <class id="standard">
  com.cappuccinonet.strutscx.xslt.
    StrutsCXStandardTransformer
  </class>
  <class id="fop">
  com.cappuccinonet.strutscx.xslt.
    StrutsCXFOPTransformer
  </class>
</transformer>

Configure StrutsCX's use of Apache FOP inside the <fop> element. If you use FOP make sure to set here the location of the userconfig.xml. If you do not use FOP you can set here this feature OFF. You then don't need to provide the FOP JARs in the /WEB-INF/lib folder:

<fop>
  <!-- switch use of apache FOP ON|OFF-->
  <on>OFF</on>
  <config>/WEB-INF/userconfig.xml</config>
</fop>

Inside the <debugxml> element you can switch the use of the (optional) debugxml=true Request parameter ON or OFF. Note: For security reasons this switch should stay OFF in non-testing environments:

<debugxml>
  <!-- switch debugxml ON|OFF-->
  <on>ON</on>
</debugxml>

The <encoding> element defines encodings for various languages. You can add or change these parameters according your needs. This list is used by the StrutsCXServlet and its helpers to find out the encoding for the default Locale by using request.getLocale().getLanguage(). You may use this parameters in the Action to set the right encoding. See the strutscx-demo.war's BaseAction on how this could be done:

<encoding>
  <en>ISO-8859-1</en>
  <de>ISO-8859-1</de>
  ...
  <ko>EUC-KR</ko>
  ...
  <zh>GB2312</zh>
  <!--Big5</zh>-->
</encoding>


Note: If you like you can validate your strutscx-config.xml with help of the (optional) strutscx-config.dtd.

Up 

 

11. Configure the strutscx-log4j-config.xml

If you're new to StrutsCX just leave this file untached. Otherwise you can set here the debug level for the StrutsCX classes inside the logger element. If you like you can add logger elements for your classes, too. See the log4j documentation for details.

Up 



You are ready!

 

IMPORTANT: StrutsCX Keys

While working with StrutsCX you will deal with these parameters.

Up 






Installation of the sample applications

The installation needs minimum effort and shouldn't take more than 2 minutes. This are all the components necessary:

  1. The Java 2 Standard Edition v. 1.4 or later and the Java 2 Enterprise Edition v. 1.4.*
  2. A Servlet Container that supports the Servlet Spezifikation 2.2 or later, e.g. Tomcat 4 or Orion 1.5.x.
  3. The (optional) Korean Character Set for your operating system.
  4. The strutscx-xx.war sample applications which already contain all the necessary StrutsCX files. You can download them from SourceForge.

* JDK 1.3 users will find some help >>here.

Use the Tomcate Manager (since Tomcat 4.1.7) to install the strutscx.war

  • http://localhost:8080/manager/html
Alternatively and even more comfortable...
  • ...use this Ant script. Don't miss to set the properties at the top of the file according to your system. The catalnina-ant.jar should be present int the
    %ANT_HOME%/lib
    folder. You'll find it in the
    %TOMCAT_HOME%/server/lib
    directory.

If everything worked fine the sturtscx-xx.war package was automatically deployed into the Servlet Container. You now can access the StrutsCX sample with your browser under the following address:

http://localhost:8080/strutscx-xx

See here for some notes on the creation of the sample applicaitions.

(Optional) Korean language support to view samples

Today the installation of non-european Character Sets fortunately is no problem any more. Normally all 4th generation Browsers offer all the necessary fonts or you can easily install them: On MacOS 9.0 you can find the fonts on the Install CD. Windows uses Unicode as native Character Set since NT or 2000. If some characters are missing, they can easily be installed using the Windows Setup. Solaris 7 and newer completely supports Unicode and provides all necessary fonts. On Linux the Unicode support is somewhat infancy, but this will change in the near future.

Up 





Imprint/Impressum

IT.CappuccinoNet.com IT.CappuccinoNet.conm
© IT.CappuccinoNet.com, 2000-2008
| Last modified 03.18.2005