You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by gi...@locus.apache.org on 2000/08/17 22:04:24 UTC
cvs commit: xml-cocoon/src/org/apache/cocoon/transformation SQLTransformer.java
giacomo 00/08/17 13:04:24
Modified: conf Tag: xml-cocoon2 sitemap.xmap
samples/documents Tag: xml-cocoon2 welcome.xml
samples/documents/sql Tag: xml-cocoon2 sql-page.xml
samples/stylesheets Tag: xml-cocoon2 sql-page2html.xsl
src/org/apache/cocoon/transformation Tag: xml-cocoon2
SQLTransformer.java
Log:
Added SQL example and thus had to fix SQLTransformer
Revision Changes Path
No revision
No revision
1.1.2.8 +12 -0 xml-cocoon/conf/Attic/sitemap.xmap
Index: sitemap.xmap
===================================================================
RCS file: /home/cvs/xml-cocoon/conf/Attic/sitemap.xmap,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -u -r1.1.2.7 -r1.1.2.8
--- sitemap.xmap 2000/08/17 16:48:33 1.1.2.7
+++ sitemap.xmap 2000/08/17 20:04:14 1.1.2.8
@@ -126,6 +126,18 @@
</map:serialize>
</map:match>
+ <map:match pattern="^sql_page$">
+ <map:generate src="documents/sql/sql-page.xml"/>
+ <map:transform type="sql">
+ <parameter name="driver" value="org.gjt.mm.mysql.Driver"/>
+ <parameter name="dburl" value="jdbc:mysql://localhost/test"/>
+ <parameter name="username" value="test"/>
+ <parameter name="password" value="test"/>
+ </map:transform>
+ <map:transform src="stylesheets/sql-page2html.xsl"/>
+ <map:serialize/>
+ </map:match>
+
<map:match pattern="^generror$">
<map:generate src="documents/error-giving-page.xml"/>
<map:transform src="stylesheets/simple-welcome2html.xsl"/>
No revision
No revision
1.1.2.3 +5 -0 xml-cocoon/samples/documents/Attic/welcome.xml
Index: welcome.xml
===================================================================
RCS file: /home/cvs/xml-cocoon/samples/documents/Attic/welcome.xml,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- welcome.xml 2000/08/16 05:08:09 1.1.2.2
+++ welcome.xml 2000/08/17 20:04:17 1.1.2.3
@@ -29,6 +29,11 @@
<sample name="Simple XSP" url="simple_dynamic_page">
Simple XSP example.
</sample>
+ <sample name="Simple SQL" url="sql_page">
+ Simple SQL example. You should make sure that you have a database and
+ table according to the conf/sitemap.xmap and the documens/sql/sql-page.sql
+ definitions.
+ </sample>
</group>
<group name="Error Page Example">
<sample name="Error Page" url="generror">
No revision
No revision
1.1.2.2 +2 -2 xml-cocoon/samples/documents/sql/Attic/sql-page.xml
Index: sql-page.xml
===================================================================
RCS file: /home/cvs/xml-cocoon/samples/documents/sql/Attic/sql-page.xml,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- sql-page.xml 2000/06/06 23:20:01 1.1.2.1
+++ sql-page.xml 2000/08/17 20:04:20 1.1.2.2
@@ -1,12 +1,12 @@
<?xml version="1.0"?>
-<page xmlns:sql="http://xml.apache.org/cocoon/SQL">
+<page xmlns:sql="http://apache.org/cocoon/SQL">
<title>Hello</title>
<content>
<para>This is my first Cocoon2 page filled with sql data!</para>
- <execute-query xmlns="http://xml.apache.org/cocoon/SQL">
+ <execute-query xmlns="http://apache.org/cocoon/SQL">
<query>
select id,name from department_table
</query>
No revision
No revision
1.1.2.3 +28 -10 xml-cocoon/samples/stylesheets/Attic/sql-page2html.xsl
Index: sql-page2html.xsl
===================================================================
RCS file: /home/cvs/xml-cocoon/samples/stylesheets/Attic/sql-page2html.xsl,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- sql-page2html.xsl 2000/06/06 23:20:05 1.1.2.2
+++ sql-page2html.xsl 2000/08/17 20:04:21 1.1.2.3
@@ -1,24 +1,42 @@
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:sql="http://xml.apache.org/cocoon/SQL">
+ xmlns:sql="http://apache.org/cocoon/SQL">
<xsl:import href="simple-page2html.xsl"/>
<xsl:template match="sql:ROWSET">
- <hr/>
- <xsl:apply-templates/>
- <hr/>
+ <xsl:choose>
+ <xsl:when test="ancestor::sql:ROWSET">
+ <tr>
+ <td>
+ <table border="1">
+ <xsl:apply-templates/>
+ </table>
+ </td>
+ </tr>
+ </xsl:when>
+ <xsl:otherwise>
+ <table border="1">
+ <xsl:apply-templates/>
+ </table>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:template>
<xsl:template match="sql:ROW">
- <dl compact="compact">
- <xsl:for-each select="./*">
- <dt><xsl:value-of select="name(.)"/></dt>
- <dd><xsl:value-of select="text()"/></dd>
- </xsl:for-each>
- </dl>
+ <tr>
+ <xsl:apply-templates/>
+ </tr>
+ </xsl:template>
+
+ <xsl:template match="sql:name">
+ <td><xsl:value-of select="."/></td>
+ </xsl:template>
+
+ <xsl:template match="sql:id">
+ <!-- ignore -->
</xsl:template>
</xsl:stylesheet>
No revision
No revision
1.1.2.5 +19 -9 xml-cocoon/src/org/apache/cocoon/transformation/Attic/SQLTransformer.java
Index: SQLTransformer.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/transformation/Attic/SQLTransformer.java,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- SQLTransformer.java 2000/08/04 21:12:13 1.1.2.4
+++ SQLTransformer.java 2000/08/17 20:04:23 1.1.2.5
@@ -37,7 +37,7 @@
* @author <a href="mailto:balld@webslingerZ.com">Donald Ball</a>
* @author <a href="mailto:giacomo.pati@pwr.ch">Giacomo Pati</a>
* (PWR Organisation & Entwicklung)
- * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/08/04 21:12:13 $ $Author: giacomo $
+ * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/08/17 20:04:23 $ $Author: giacomo $
*/
public class SQLTransformer extends AbstractTransformer {
@@ -45,7 +45,7 @@
protected boolean debug = true;
/** The SQL namespace **/
- public static final String my_uri = "http://xml.apache.org/cocoon/SQL";
+ public static final String my_uri = "http://apache.org/cocoon/SQL";
public static final String my_name = "SQLTransformer";
/** The SQL namespace element names **/
@@ -55,6 +55,7 @@
public static final String MAGIC_USERNAME = "username";
public static final String MAGIC_PASSWORD = "password";
public static final String MAGIC_QUERY = "query";
+ public static final String MAGIC_VALUE = "value";
public static final String MAGIC_ANCESTOR_VALUE = "ancestor-value";
public static final String MAGIC_ANCESTOR_VALUE_LEVEL_ATTRIBUTE = "level";
public static final String MAGIC_ANCESTOR_VALUE_NAME_ATTRIBUTE = "name";
@@ -79,7 +80,7 @@
protected String current_name;
/** The current state of the event receiving FSM **/
- protected int current_state;
+ protected int current_state = STATE_OUTSIDE;
/** The value of the value element we're currently receiving **/
protected StringBuffer current_value = new StringBuffer();
@@ -98,18 +99,21 @@
// Check the driver
String parameter = parameters.getParameter("driver",null);
if (parameter != null) {
+ if (debug) { System.err.println("DRIVER: "+parameter); }
default_properties.setProperty("driver",parameter);
}
// Check the dburl
parameter = parameters.getParameter("dburl",null);
if (parameter != null) {
+ if (debug) { System.err.println("DBURL: "+parameter); }
default_properties.setProperty("dburl",parameter);
}
// Check the username
parameter = parameters.getParameter("username",null);
if (parameter != null) {
+ if (debug) { System.err.println("USERNAME: "+parameter); }
default_properties.setProperty("username",parameter);
}
@@ -129,7 +133,7 @@
* This will be the meat of SQLTransformer, where the query is run.
*/
protected void executeQuery(int index) throws SAXException {
- this.contentHandler.startPrefixMapping("",my_uri);
+ this.contentHandler.startPrefixMapping("",my_uri);
AttributesImpl attr = new AttributesImpl();
Query query = (Query)queries.elementAt(index);
try {
@@ -151,7 +155,7 @@
throw new SAXException(e);
}
this.end(query.rowset_name);
- this.contentHandler.endPrefixMapping("");
+ this.contentHandler.endPrefixMapping("");
}
protected static void throwIllegalStateException(String message) {
@@ -200,6 +204,7 @@
case STATE_INSIDE_QUERY_ELEMENT:
if (current_value.length() > 0) {
getCurrentQuery().addQueryPart(current_value.toString());
+ if (debug) { System.err.println("QUERY IS \""+current_value.toString()+"\""); }
current_value.setLength(0);
}
current_state = STATE_INSIDE_EXECUTE_QUERY_ELEMENT;
@@ -252,8 +257,10 @@
throwIllegalStateException("Ancestor value elements must have a "+MAGIC_ANCESTOR_VALUE_NAME_ATTRIBUTE+" attribute");
}
AncestorValue av = new AncestorValue(level,name);
+ if (debug) { System.err.println("ANCESTOR VALUE "+level+" "+name); }
if (current_value.length() > 0) {
getCurrentQuery().addQueryPart(current_value.toString());
+ if (debug) { System.err.println("QUERY IS \""+current_value.toString()+"\""); }
current_value.setLength(0);
}
getCurrentQuery().addQueryPart(av);
@@ -311,24 +318,27 @@
super.endElement(uri,name,raw);
return;
}
- if (debug) { System.err.println("RECEIVED END ELEMENT "+name); }
+ if (debug) { System.err.println("RECEIVED END ELEMENT "+name+"("+uri+")"); }
if (name.equals(MAGIC_EXECUTE_QUERY)) {
endExecuteQueryElement();
} else if (name.equals(MAGIC_QUERY)) {
endQueryElement();
} else if (name.equals(MAGIC_ANCESTOR_VALUE)) {
endAncestorValueElement();
- } else {
+ } else if (name.equals(MAGIC_VALUE)) {
endValueElement();
+ } else {
+ super.endElement(uri,name,raw);
}
}
public void characters(char ary[], int start, int length)
throws SAXException {
- if (current_state != STATE_INSIDE_VALUE_ELEMENT) {
+ if (current_state != STATE_INSIDE_VALUE_ELEMENT
+ && current_state != STATE_INSIDE_QUERY_ELEMENT) {
super.characters(ary,start,length);
}
- if (debug) { System.err.println("RECEIVED CHARACTERS: "+new String(ary,start,length)); }
+ if (debug) { System.err.println("RECEIVED CHARACTERS: "+new String(ary,start,length)); }
current_value.append(ary,start,length);
}