JSP Version

In this version, the resources listed under the Tools tab of http://www.thexmltoolkit.org are stored in a mySQL database, rather than in an XML file. The JSP script establishes the connection with the database, checks the connection, performs the query, and returns the results to be combined with a static XML file, transformed by the XSL, and formatted with CSS to display the Web page.

The resulting Web page looks exactly like the Tools page on this Web site; the only difference being that the names, descriptions, and URLs of the listed resources come from a database.


<%-- 
*******************************************************************************************
* COPYRIGHT NOTICE:
* Copyright 2006 Center for Technology in Government.
* The Center grants permission to use and modify this software code free of charge provided  
* this copyright notice is included. By using this code you agree to indemnify the Center from 
* any liability that might arise from its use. Selling the code is expressly forbidden.
* ******************************************************************************************
--%>

<%-- Must specify the jsp tag library -- xtags and make sure it has been installed correctly   --%>
<%@ taglib uri="http://jakarta.apache.org/taglibs/xtags-1.0" prefix="xtags" %>

 <%@ page import="java.io.*" %>
 <%@ page import="java.sql.*" %>
 
 <%--***********************************************************************
   Initial information for database connection and xml translating
******************************************************************************--%>
<%
String connectionURL = "jdbc:mysql://path_to_database";
String username = "username";
String password = "password";
String tableName = "tablename";
String xmlSource = "path/file.xml";
String xslSource  = "path.file.xsl";
String sqlQuery = "SELECT * FROM  " + tableName;
%>


 <%--***********************************************************************
       Conncect to database and send out the SQL query
******************************************************************************--%>
<%
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
try
{
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    connection = DriverManager.getConnection(connectionURL, username, password);
    statement = connection.createStatement();
    rs = statement.executeQuery(sqlQuery);
}
catch (Exception E) 
{
	out.println("Unable to load driver. " + E);
}
%>

 <%-- *********************************************
 * Open XML file, only has title info, no data
 * Get data from database 
 * Convert database data to XML format, 
 * Append new data to XML file, processed only in memory 
 * Generated xml data format must conform to existing XSL sheet
 * Use existing XSL file, nothing needs to be changed
 * New xml data only exist in memory 
**************************************************  --%>
 
<xtags:parse id="xmlData" uri="<%= xmlSource %>" >
</xtags:parse>
<xtags:context select="//book/chapter">
<xtags:add>
<%
     while (rs.next()) 
     {
%>
    <sect1>
	    <title>
	        <ulink url="<%= rs.getString("url") %>" >
	           <%= rs.getString("title") %>
	        </ulink>
	    </title>
	   <para>
	       <%= rs.getString("description") +"(" %>
	       <ulink url="<%= rs.getString("url") %>" >
	          <%= rs.getString("url") %>
	       </ulink>
	        )
	    </para>
</sect1>
<%
     }
     rs.close();
%>
</xtags:add>
</xtags:context>

<%--*****************************************
 * Translate xml data into html 
 * Send back to clent browser
 * Use existing XSL file 
 * Processed in Memory 
***************************************** --%>

 <xtags:style  document="<%= xmlData %>" xsl="<%= xslSource %>">
         <xtags:param name="name" value="<%= tableName %>"/>
         <xtags:param name="extension" value=".jsp"/>
 </xtags:style>

You must have the xtags library installed and configured properly for this script to work. Valid values would need to be inserted for your database connection. Otherwise, this script works much like the scripts in the Environment section of this Web site.