XX Installation and Setup (V1.1)

David Moskowitz, President, Infoblazer LLC.

January 2006

© David Moskowitz, 2006. All Rights Reserved.

XX Foundation

Create the project directories

This tutorial assumes you will be creating a new directory structure from scratch. If you already have an existing project or directory structure, just place the appropruiate files in the existing location.

  1. Create the root web folder

This folder will be referred to as [webroot]. This is the folder where your application’s HTML or JSP files will typically reside

  1. Create [webroot]/WEB-INF folder

This is a standard J2EE folder. For this example, we’ve create c:projectstutorial.

  1. Create [webroot]/WEB-INF/lib folder
  1. Create [webroot]/WEB-INF/xml folder.

This folder will be referred to as [xmlroot]. This folder contains the XX configuration files and XSL transformation files.

Extract Framework Libraries

Extract the contents of xxframework.jar file into the [webroot]/WEB-INF/lib. While it is recommended that the entire XX library archive be included on the application classpath, it is possible to eliminate many of the Hibernate libraries if XX automation is not used. For a compelte desriptioj of the entire library archive, see

Create application web.xml file

For this step, we will create the Hello World XML servlet from the tutorial.

Create the following web.xml file in the applications WEB-INF directory, or add the appropriate lines to your existing web.xml file.

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE web-app PUBLIC “-//Sun Microsystems, Inlistc.//DTD Web Application 2.2//EN” “http://java.sun.com/j2ee/dtds/web-app_2_2.dtd”&gt;

<web-app>

<servlet>

<servlet-name>HelloWorldXML</servlet-name>

<servlet-class>org.xxframework.Base</servlet-class>

<init-param>

<param-name>configFile</param-name>

<param-value>HelloWorldXML.xml</param-value>

</init-param>

</servlet>

<servlet-mapping>

<servlet-name>HelloWorldXML</servlet-name>

<url-pattern>/HelloWorldXML</url-pattern>

</servlet-mapping>

<env-entry>

<env-entry-name>xmlpath</env-entry-name>

<env-entry-value>C:projectstutorialWEB-INFxml</env-entry-value>

<env-entry-type>java.lang.String</env-entry-type>

</env-entry>

</web-app>


This web.xml file defines a single servlet, HelloWorldXML. We use the XX Framework base servlet, org.xxframework.Base, as the servlet class. We specify an XX config file, HelloWorldXML.xml. We set the URL mapping for the servlet to /HelloWorldXML. Finally, we need to specify the exact location of the applications [xmlroot] directory. In the case, we set the location to C:projectstutorialWebRootWEB-INFxml, thought this should be changed to match your particular application.

Create XX Config file

Add the following file to the [xmlroot] directory with the name HelloWorldXML.xml.

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE xx_config SYSTEM “http://www.xxframework.org/dtd/xx_config.dtd”&gt;

<xx_config>

<classes>

<class id=”1 use=”xsl scope=”page applyxsl=”true“>

<classname>org.xxframework.tutorial.HelloWorld</classname>

<method>SayHelloXML</method>

<xsl_file>HelloWorld.xsl</xsl_file>

</class>

</classes>

<jsp>simple.jsp</jsp>

</xx_config>

This configuration will only be briefly described. For more information, please see the hello world tutorial for additional description of this servlet configuration.

This configuration specified three additional files. The first is the XX implementation class. The second is the XSL transformation file that takes the XML results of the implementation class and transforms it into HTML. The third component is the JSP page used to display the results of the operation.

These three files are contains in the XXTutorial.jar file. Extract the XML and XSL file to the [xmlroot] directory, and the jsp file to the [webroot] directory. The source code and class file for the HelloWorld class should be extracted to the WEB-INFclassesorgxxframeworktutorial directory.

The final step to configure the tutorial in the Java servers configuration file. This will vary depending on the Java server used. In our case, we will be using Tomcat 4.1, so the following line will be added to the tomcat server.xml file, in the Server/Service/Engine/Host context.

<Context path=”/tutorial docBase=”C:projectstutorial debug=”0 reloadable=”true“/>

We should now be able to start the web server and execute the following URL:

http://localhost:8080/tutorial/HelloWorldXML

You should get the following page displayed

XX Automation

In this tutorial, we will setup the guestbook display page from the xx framework online sample guestbook application. We’ll limit ourselves to the display message portion and ignore the add, view, and filter message capabilities, for simplicity sake.

First set up the database. For this example, we will use MySQL 4.1 The database backup for this example is available in the Tutorial.sql archive. Restoring this backup will create a tutorial schema with a single table , Message. The table has the following structure

CREATE TABLE `messages` (

`id` int(10) unsigned NOT NULL default ‘0’,

`dateAdded` datetime NOT NULL default ‘0000-00-00 00:00:00’,

`Title` varchar(250) default NULL,

`Message` text NOT NULL,

`AddedByID` int(10) unsigned default NULL,

`Author` varchar(100) NOT NULL default ”,

`dateModified` datetime default NULL,

`addedBy` varchar(100) default NULL,

`lastModifiedBy` varchar(100) default NULL,

PRIMARY KEY (`id`)

)

Create the Java Entity class

Next create the file Message.java in the appropriate project location, in this case in WEB-INF/classes/org/xxframework/tutorial/entity directory. The sample class is contained in the Tutorial archive ad is reproduced here.

package org.xxframework.tutorial.entity;

import java.io.Serializable;

import org.xxframework.basetypes.*;

public class Message extends BaseRecord implements Serializable {

String author;

private String title;

private String message;

private static final long serialVersionUID = 1L;

public Message() {

}

public Message(Integer id) {

this.setId(id);

}

public String getAuthor() {

return author;

}

public void setAuthor(String author) {

this.author = author;

}

public String getMessage() {

return message;

}

public String getShortmessage() {

if (message.length() > 100)

return message.substring(0, 100);

else

return message;

}

public void setMessage(String message) {

this.message = message;

}

public String getTitle() {

return title;

}

public void setTitle(String title) {

this.title = title;

}

}

Note that to be part of the XX framework, the entity class must extend org.xxframework.basetypes.BaseRecord. Also, to be controlled by Hibernate, the entity class must implement Serializable. The rest of the class contains attributes with their corresponding getters and setters. The attributes correspond directly to the database fields in the message table.

Create Hibernate Mapping

Next we create the Hibernate mapping file to map from the database to the Java class. Please the file Message.hbm.xml in the entity directory. The mapping file is reproduced below

<?xml version=”1.0″?>

<!DOCTYPE hibernate-mapping PUBLIC “-//Hibernate/Hibernate Mapping DTD 2.0//EN”

http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd”&gt;

<hibernate-mapping package=”org.xxframework.tutorial.entity“>

<class name=”Message table=”messages“>

<id name=”id column=”id type=”integer“>

<generator class=”increment“/>

</id>

<property name=”title column=”Title type=”java.lang.String“/>

<property name=”message column=”Message type=”java.lang.String“/>

<property name=”author column=”Author type=”java.lang.String“/>

<property name=”dateadded column=”dateAdded type=”timestamp“/>

<property name=”datemodified column=”dateModified type=”timestamp“/>

<property name=”modifiedbyname column=”lastModifiedBy type=”java.lang.String“/>

<property name=”addedbyname column=”addedBy type=”java.lang.String“/>

</class>

</hibernate-mapping>

Create Hibernate Configuration file.

The Hibernate configuration file is needed to point the application to the correct database and load the various application mappings.

Please this file in the entity directory as well.

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE hibernate-configuration PUBLIC “-//Hibernate/Hibernate Configuration DTD 2.0//EN”

http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd”&gt;

<hibernate-configuration>

<session-factory>

<!– properties –>

<property name=”connection.url“>jdbc:mysql://localhost:3306/tutorial</property>

<property name=”connection.username“>guestbook_user</property>

<property name=”connection.password“>pasword</property>

<property name=”connection.driver_class“>com.mysql.jdbc.Driver</property>

<property name=”dialect“>net.sf.hibernate.dialect.MySQLDialect</property>

<property name=”show_sql“>true</property>

<!– mapping files –>

<mapping resource=”org/xxframework/tutorial/entity/Message.hbm.xml“/>

</session-factory>

</hibernate-configuration>

Add Hibernate path to Web.xml

Now we need to add the Hibernate configuration file location to the web.xml file.

<env-entry>

<env-entry-name>hibernate_config_file</env-entry-name>

<env-entry-value>/org/xxframework/tutorial/entity/hibernate.cfg.xml</env-entry-value>

<env-entry-type>java.lang.String</env-entry-type>

</env-entry>

Since we are modifying the environment entries, lets specify devel mode, so that XML request and response documents will be saved to disk

<env-entry>

<env-entry-name>devel</env-entry-name>

<env-entry-value>true</env-entry-value>

<env-entry-type>java.lang.String</env-entry-type>

</env-entry>

Now that we have the database, Java, and db-Java mappings. we need to define the actual servlets to handle the list message display. This is similar to what was done in the simple hello world application above.

Add Servlet

Add the following code to web.xml. This step is no different from the Hello World sample.

First create the servlet definition

<servlet>

<servlet-name>ListMessages</servlet-name>

<servlet-class>org.xxframework.Base</servlet-class>

<init-param>

<param-name>configFile</param-name>

<param-value>ListMessages.xml</param-value>

</init-param>

</servlet>

And the servlet mapping.

<servlet-mapping>

<servlet-name>ListMessages</servlet-name>

<url-pattern>/ListMessages</url-pattern>

</servlet-mapping>

Create the XX Config file

The XX config file will have additional values related to XX automation

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE xx_config SYSTEM “http://www.xxframework.org/dtd/xx_config.dtd”&gt;

<xx_config usepool=”false newthread=”false“>

<classes>

<class id=”1 scope=”page applyxsl=”true use=”xsl“>

<classname>org.xxframework.control.RecordControl</classname>

<method>list</method>

<hb_classname>org.xxframework.tutorial.entity.Message</hb_classname>

<xsl_file>ListMessages.xsl</xsl_file>

<error_pattern>&lt;xx_error</error_pattern>

<error_jsp>simple.jsp</error_jsp>

<error_xsl>reply.xsl</error_xsl>

<security secure=”false“>

</security>

</class>

</classes>

<jsp>search.jsp</jsp>

</xx_config>

Create the XSL Mapping file

<?xml version=”1.0″ encoding=”UTF-8″?>

<xsl:stylesheet version=”1.0 xmlns:xsl=”http://www.w3.org/1999/XSL/Transform xmlns:fo=”http://www.w3.org/1999/XSL/Format“>

<xsl:include href=”includes.xsl“/>

<xsl:template match=”/root“>

<xsl:apply-templates select=”list_results“/>

</xsl:template>

<xsl:template match=”list_results“>

<table align=”center width=”700px“>

<tbody>

<tr>

<td class=”tableheading colspan=”4 align=”left“>

<xsl:call-template name=”display_record_range“>

<xsl:with-param name=”count“>

<xsl:value-of select=”count(message)“/>

</xsl:with-param>

<xsl:with-param name=”start“>

<xsl:value-of select=”(../request/start)“/>

</xsl:with-param>

<xsl:with-param name=”form_name“>ListMessages</xsl:with-param>

<xsl:with-param name=”total_records“> <xsl:value-of select=”(../request/total_records)“/>

</xsl:with-param>

</xsl:call-template>

</td>

</tr>

<tr>

<th>Posted On</th>

<th>Author</th>

<th>Title</th>

</tr>

<xsl:apply-templates select=”message“/>

</tbody>

</table>

</xsl:template>

<xsl:template match=”message“>

<tr>

<td align=”left“>

<xsl:call-template name=”format-date-time“>

<xsl:with-param name=”xsd-date-time select=”dateadded“/>

<xsl:with-param name=”format select=”‘%m/%e/%Y %i:%M %P’“/>

</xsl:call-template>

</td>

<td>

<input type=”hidden name=”id“>

<xsl:attribute name=”value“><xsl:value-of select=”id“/></xsl:attribute>

</input>

<xsl:value-of select=”author“/>

</td>

<td>

<xsl:value-of select=”title“/>

</td>

</tr>

<tr>

<td></td>

<td colspan=”3“>

<xsl:value-of select=”shortmessage“/>

<xsl:if test=”string-length(shortmessage)= 100“> </xsl:if>

</td>

</tr>

</xsl:template>

</xsl:stylesheet>

Now the application is ready to run. Start up the web server and execute the following URL:

http://localhost:8080/tutorial/ListMessages

The response should appear similar to the one below.

For a further tutorial on XX framework and Automation, see the additional tutorials on the XX Framework web site.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s