froehlich 02/04/19 11:15:08
Modified: src/java/org/apache/cocoon/components/language/markup/xsp/java
Tag: cocoon_2_0_3_branch esql.xsl
Log:
redo of previous patch....sry christian h.
Revision Changes Path
No revision
No revision
1.13.2.2 +76 -215
xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/esql.xsl
Index: esql.xsl
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/esql.xsl,v
retrieving revision 1.13.2.1
retrieving revision 1.13.2.2
diff -u -r1.13.2.1 -r1.13.2.2
--- esql.xsl 19 Apr 2002 17:07:59 -0000 1.13.2.1
+++ esql.xsl 19 Apr 2002 18:15:08 -0000 1.13.2.2
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
-<!-- $Id: esql.xsl,v 1.13.2.1 2002/04/19 17:07:59 froehlich Exp $-->
+<!-- $Id: esql.xsl,v 1.13.2.2 2002/04/19 18:15:08 froehlich Exp $-->
<!--
============================================================================
@@ -56,7 +56,7 @@
* ESQL Logicsheet
*
* @author ?
- * @version CVS $Revision: 1.13.2.1 $ $Date: 2002/04/19 17:07:59 $
+ * @version CVS $Revision: 1.13.2.2 $ $Date: 2002/04/19 18:15:08 $
-->
<xsl:stylesheet version="1.0"
@@ -71,39 +71,11 @@
<xsl:param name="filename"/>
<xsl:param name="language"/>
-<xsl:variable name="cocoon1-environment">Cocoon 1</xsl:variable>
-<xsl:variable name="cocoon2-environment">Cocoon 2</xsl:variable>
-
-<xsl:variable
name="cocoon1-xsp-namespace-uri">http://www.apache.org/1999/XSP/Core</xsl:variable>
-<xsl:variable name="cocoon2-xsp-namespace-uri">http://apache.org/xsp</xsl:variable>
+<xsl:variable name="environment">Cocoon 2</xsl:variable>
+<xsl:variable name="xsp-namespace-uri">http://apache.org/xsp</xsl:variable>
<xsl:variable name="prefix">esql</xsl:variable>
-<xsl:variable name="environment">
- <xsl:choose>
- <xsl:when test="starts-with($XSP-ENVIRONMENT,$cocoon1-environment)">
- <xsl:text>Cocoon1</xsl:text>
- </xsl:when>
- <xsl:when test="starts-with($XSP-ENVIRONMENT,$cocoon2-environment)">
- <xsl:text>Cocoon2</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>Cocoon2</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:variable>
-
-<xsl:variable name="xsp-namespace-uri">
- <xsl:choose>
- <xsl:when test="$environment = 'Cocoon1'">
- <xsl:value-of select="$cocoon1-xsp-namespace-uri"/>
- </xsl:when>
- <xsl:when test="$environment = 'Cocoon2'">
- <xsl:value-of select="$cocoon2-xsp-namespace-uri"/>
- </xsl:when>
- </xsl:choose>
-</xsl:variable>
-
<xsl:template name="get-nested-content">
<xsl:param name="content"/>
<xsl:choose>
@@ -120,57 +92,33 @@
<xsl:template name="get-nested-string">
<xsl:param name="content"/>
<xsl:choose>
- <xsl:when test="$environment = 'Cocoon1'">
- <xsl:choose>
- <xsl:when test="$content/*">
- ""
- <xsl:for-each select="$content/node()">
+ <!-- if $content has sub-elements, concatenate them -->
+ <xsl:when test="$content/*">
+ ""
+ <xsl:for-each select="$content/node()">
+ <xsl:choose>
+ <xsl:when test="name(.)">
+ <!-- element -->
<xsl:choose>
- <xsl:when test="name(.)">
- + <xsl:apply-templates select="."/>
- </xsl:when>
- <xsl:otherwise>
+ <xsl:when test="namespace-uri(.)='http://apache.org/xsp' and
local-name(.)='text'">
+ <!-- xsp:text element -->
+ "<xsl:value-of select="translate(.,'	 ',' ')"/>"
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- </xsl:when>
- <xsl:otherwise>
- "<xsl:value-of select="normalize-space($content)"/>"
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:when test="$environment = 'Cocoon2'">
- <xsl:choose>
- <!-- if $content has sub-elements, concatenate them -->
- <xsl:when test="$content/*">
- ""
- <xsl:for-each select="$content/node()">
- <xsl:choose>
- <xsl:when test="name(.)">
- <!-- element -->
- <xsl:choose>
- <xsl:when test="namespace-uri(.)='http://apache.org/xsp' and
local-name(.)='text'">
- <!-- xsp:text element -->
- + "<xsl:value-of select="translate(.,'	 ',' ')"/>"
- </xsl:when>
- <xsl:otherwise>
- <!-- other elements -->
- + <xsl:apply-templates select="."/>
- </xsl:otherwise>
- </xsl:choose>
</xsl:when>
<xsl:otherwise>
- <!-- text node -->
- + "<xsl:value-of select="translate(.,'	 ',' ')"/>"
+ <!-- other elements -->
+ + <xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
- </xsl:for-each>
- </xsl:when>
- <!-- else return the text value of $content -->
- <xsl:otherwise>"<xsl:value-of
select="normalize-space($content)"/>"</xsl:otherwise>
- </xsl:choose>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- text node -->
+ + "<xsl:value-of select="translate(.,'	 ',' ')"/>"
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
</xsl:when>
+ <!-- else return the text value of $content -->
+ <xsl:otherwise>"<xsl:value-of
select="normalize-space($content)"/>"</xsl:otherwise>
</xsl:choose>
</xsl:template>
@@ -236,45 +184,22 @@
<xsp:include>java.util.List</xsp:include>
<xsp:include>java.util.Iterator</xsp:include>
<xsp:include>java.util.ListIterator</xsp:include>
+ <xsp:include>java.math.BigDecimal</xsp:include>
<xsp:include>java.sql.Struct</xsp:include>
<xsp:include>java.sql.Types</xsp:include>
- <xsl:choose>
- <xsl:when test="$environment = 'Cocoon1'">
-
<xsp:include>org.apache.cocoon.processor.xsp.library.sql.EsqlHelper</xsp:include>
-
<xsp:include>org.apache.cocoon.processor.xsp.library.sql.EsqlQuery</xsp:include>
-
<xsp:include>org.apache.cocoon.processor.xsp.library.sql.EsqlConnection</xsp:include>
- </xsl:when>
- <xsl:when test="$environment = 'Cocoon2'">
-
<xsp:include>org.apache.cocoon.components.language.markup.xsp.EsqlHelper</xsp:include>
-
<xsp:include>org.apache.cocoon.components.language.markup.xsp.EsqlQuery</xsp:include>
-
<xsp:include>org.apache.cocoon.components.language.markup.xsp.EsqlConnection</xsp:include>
-
<xsp:include>org.apache.cocoon.components.language.markup.xsp.EsqlConnectionCocoon2</xsp:include>
-
<xsp:include>org.apache.cocoon.components.language.markup.xsp.XSPUtil</xsp:include>
- </xsl:when>
- </xsl:choose>
+
<xsp:include>org.apache.cocoon.components.language.markup.xsp.EsqlHelper</xsp:include>
+
<xsp:include>org.apache.cocoon.components.language.markup.xsp.EsqlQuery</xsp:include>
+
<xsp:include>org.apache.cocoon.components.language.markup.xsp.EsqlConnection</xsp:include>
+
<xsp:include>org.apache.cocoon.components.language.markup.xsp.EsqlConnectionCocoon2</xsp:include>
+
<xsp:include>org.apache.cocoon.components.language.markup.xsp.XSPUtil</xsp:include>
<xsl:if test=".//esql:connection/esql:pool">
- <xsl:choose>
- <xsl:when test="$environment = 'Cocoon1'">
-
<xsp:include>org.apache.turbine.services.db.PoolBrokerService</xsp:include>
- <xsp:include>org.apache.turbine.util.db.pool.DBConnection</xsp:include>
- </xsl:when>
- <xsl:when test="$environment = 'Cocoon2'">
-
<xsp:include>org.apache.avalon.excalibur.datasource.DataSourceComponent</xsp:include>
- </xsl:when>
- </xsl:choose>
+
<xsp:include>org.apache.avalon.excalibur.datasource.DataSourceComponent</xsp:include>
</xsl:if>
</xsp:structure>
<xsp:logic>
- <xsl:if test="$environment = 'Cocoon2'">
- <xsl:call-template name="variables"><xsl:with-param name="modifier"
select="'private'"/></xsl:call-template>
- </xsl:if>
+ <xsl:call-template name="variables"><xsl:with-param name="modifier"
select="'private'"/></xsl:call-template>
<xsl:if test=".//esql:connection/esql:pool">
- <xsl:choose>
- <xsl:when test="$environment = 'Cocoon1'">
- static PoolBrokerService _esql_pool = PoolBrokerService.getInstance();
- </xsl:when>
- <xsl:when test="$environment = 'Cocoon2'">
private static ComponentSelector _esql_selector = null;
public void compose(ComponentManager manager) throws
org.apache.avalon.framework.component.ComponentException {
@@ -287,14 +212,8 @@
}
}
}
- </xsl:when>
- </xsl:choose>
</xsl:if>
- <xsl:choose>
- <xsl:when test="$environment = 'Cocoon1'">
- </xsl:when>
- <xsl:when test="$environment = 'Cocoon2'">
protected void _esql_printObject ( Object obj, AttributesImpl xspAttr)
throws SAXException
{
if ( obj instanceof List) {
@@ -324,8 +243,6 @@
<xsp:content><xsp:expr>obj</xsp:expr></xsp:content>;
}
}
- </xsl:when>
- </xsl:choose>
</xsp:logic>
<xsl:apply-templates/>
</xsp:page>
@@ -335,7 +252,7 @@
<xsl:param name="modifier" select="''"/>
<xsp:logic>
<xsl:value-of select="$modifier"/> Stack _esql_connections = new Stack();
- <xsl:value-of select="$modifier"/> EsqlConnection<xsl:value-of
select="$environment"/> _esql_connection = null;
+ <xsl:value-of select="$modifier"/> EsqlConnectionCocoon2 _esql_connection =
null;
<xsl:value-of select="$modifier"/> Stack _esql_queries = new Stack();
<xsl:value-of select="$modifier"/> EsqlQuery _esql_query = null;
<xsl:value-of select="$modifier"/> SQLException _esql_exception = null;
@@ -346,11 +263,6 @@
<xsl:template match="xsp:page/*[not(self::xsp:*)]">
<xsl:copy>
<xsl:apply-templates select="@*"/>
- <xsp:logic>
- <xsl:if test="$environment = 'Cocoon1'">
- <xsl:call-template name="variables"/>
- </xsl:if>
- </xsp:logic>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
@@ -367,21 +279,10 @@
if (_esql_connection != null) {
_esql_connections.push(_esql_connection);
}
- _esql_connection = new EsqlConnection<xsl:value-of select="$environment"/>();
+ _esql_connection = new EsqlConnectionCocoon2();
try {
<xsl:choose>
- <xsl:when test="esql:pool and $environment = 'Cocoon1'">
- try {
- _esql_connection.db_connection =
_esql_pool.getConnection(String.valueOf(<xsl:copy-of select="$pool"/>));
- _esql_connection.connection =
_esql_connection.db_connection.getConnection();
- } catch (Exception _esql_exception_<xsl:value-of
select="generate-id(.)"/>) {
- throw new RuntimeException("Error opening pooled connection:
"+String.valueOf(<xsl:copy-of select="$pool"/>)+": "+_esql_exception_<xsl:value-of
select="generate-id(.)"/>.getMessage());
- }
- if (_esql_connection.connection == null) {
- throw new RuntimeException("Could not open pooled connection:
"+String.valueOf(<xsl:copy-of select="$pool"/>));
- }
- </xsl:when>
- <xsl:when test="esql:pool and $environment = 'Cocoon2'">
+ <xsl:when test="esql:pool">
try {
_esql_connection.datasource = (DataSourceComponent)
_esql_selector.select(String.valueOf(<xsl:copy-of select="$pool"/>));
_esql_connection.connection =
_esql_connection.datasource.getConnection();
@@ -437,18 +338,11 @@
if(!_esql_connection.getAutoCommit()) {
_esql_connection.commit();
}
- <xsl:choose>
- <xsl:when test="esql:pool and $environment = 'Cocoon1'">
- _esql_pool.releaseConnection(_esql_connection.db_connection);
- </xsl:when>
- <xsl:otherwise>
- _esql_connection.close();
- </xsl:otherwise>
- </xsl:choose>
+ _esql_connection.close();
if (_esql_connections.empty()) {
_esql_connection = null;
} else {
- _esql_connection = (EsqlConnection<xsl:value-of
select="$environment"/>)_esql_connections.pop();
+ _esql_connection = (EsqlConnectionCocoon2)_esql_connections.pop();
}
} catch (Exception _esql_exception_<xsl:value-of select="generate-id(.)"/>) {}
}
@@ -569,14 +463,7 @@
}
</xsl:otherwise>
</xsl:choose>
- <xsl:choose>
- <xsl:when test="$environment = 'Cocoon1'">
- System.err.println("QUERY: " + _esql_query.getQueryString());
- </xsl:when>
- <xsl:otherwise>
- getLogger().debug("esql query: " + _esql_query.getQueryString());
- </xsl:otherwise>
- </xsl:choose>
+ getLogger().debug("esql query: " + _esql_query.getQueryString());
<xsl:if test="esql:call">
// call results
<xsp:content>
@@ -671,6 +558,7 @@
<xsp:expr>_esql_query.getStatement().getUpdateCount()</xsp:expr>
</xsl:template>
+
<xsl:template match="esql:results//esql:row-results">
<xsl:variable name="group" select=".//esql:group"/>
<xsp:logic>
@@ -680,7 +568,7 @@
do {
<xsp:content>
- <xsl:apply-templates/>
+ <xsl:apply-templates/>
</xsp:content>
<xsl:if test="count($group) < 1">
<xsl:call-template name="nextRow"/>
@@ -697,6 +585,8 @@
</xsp:logic>
</xsl:template>
+
+
<xsl:template name="nextRow">
//checking out early?
if (_esql_query.getMaxRows() != -1 && _esql_query.getCurrentRow() -
_esql_query.getSkipRows() == _esql_query.getMaxRows()) {
@@ -706,18 +596,25 @@
}
</xsl:template>
+
+
<xsl:template match="esql:results//esql:previous-results"/>
+
<xsl:template match="esql:results//esql:previous-results" mode="more">
<xsp:content>
<xsl:apply-templates/>
</xsp:content>
</xsl:template>
+
+
<xsl:template match="esql:group" mode="vars">
_esql_query.setGroupingVar("<xsl:value-of select="@group-on"/>Changed", new
Boolean(true));
</xsl:template>
+
+
<xspdoc:desc>Allows header and footer elements around groups of consecutive records
with identical values in column named by @group-on. Facilitates a single query with
joins to be used in lieu of some nested queries.</xspdoc:desc>
<xsl:template match="esql:group|esql:group//esql:group[.//esql:member]"
priority="3">
<xsp:logic>
@@ -728,11 +625,12 @@
<xsl:with-param name="group-on" select="@group-on"/>
</xsl:apply-templates>
</xsp:content>
- _esql_query.nextRow(); //readvance (see previousRow() in esql:member)
}
</xsp:logic>
</xsl:template>
+
+
<xsl:template match="esql:group//node()[.//esql:member]">
<xsl:param name="group-on"/>
<xsl:copy>
@@ -742,6 +640,8 @@
</xsl:copy>
</xsl:template>
+
+
<xspdoc:desc>Used in conjunction with and nested inside esql:group. Formatting for
individual records goes within esql:member. Header and footer stuff goes in between
group and member.</xspdoc:desc>
<xsl:template match="esql:member|esql:group//esql:member[.//esql:member]">
<xsl:param name="group-on"/>
@@ -765,12 +665,11 @@
}
if (((Boolean)_esql_query.getGroupingVar("<xsl:value-of
select="$group-on"/>Changed")).booleanValue()) {
//footer contents
- _esql_query.previousRow(); //if we want the footer to be able to
- // access common columns of the group as the header can, we
- // must back up into the last record.
</xsp:logic>
</xsl:template>
+
+
<xsl:template match="esql:results//esql:more-results"/>
<xsl:template match="esql:results//esql:more-results" mode="more">
@@ -782,34 +681,6 @@
<xspdoc:desc>results in a set of elements whose names are the names of the columns.
the elements each have one text child, whose value is the value of the column
interpreted as a string. No special formatting is allowed here. If you want to mess
around with the names of the elements or the value of the text field, use the
type-specific get methods and write out the result fragment yourself.</xspdoc:desc>
<xsl:template match="esql:row-results//esql:get-columns">
<xsl:variable name="tagcase"><xsl:value-of select="@tag-case"/></xsl:variable>
- <xsl:choose>
- <xsl:when test="$environment = 'Cocoon1'">
- <xsp:logic>
- for (int _esql_i=1; _esql_i <=
_esql_query.getResultSetMetaData().getColumnCount(); _esql_i++) {
- Node _esql_node = document.createElement(
- <xsl:choose>
- <xsl:when test="$tagcase='lower'">
-
_esql_query.getResultSetMetaData().getColumnName(_esql_i).toLowerCase()
- </xsl:when>
- <xsl:when test="$tagcase='upper'">
-
_esql_query.getResultSetMetaData().getColumnName(_esql_i).toUpperCase()
- </xsl:when>
- <xsl:otherwise>
- _esql_query.getResultSetMetaData().getColumnName(_esql_i)
- </xsl:otherwise>
- </xsl:choose>
- );
- _esql_node.appendChild(document.createTextNode(
- <xsl:call-template name="get-string-encoded">
- <xsl:with-param name="column-spec">_esql_i</xsl:with-param>
- <xsl:with-param
name="resultset">_esql_query.getResultSet()</xsl:with-param>
- </xsl:call-template>
- ));
- xspCurrentNode.appendChild(_esql_node);
- }
- </xsp:logic>
- </xsl:when>
- <xsl:when test="$environment = 'Cocoon2'">
<xsp:logic>
for (int _esql_i = 1; _esql_i <=
_esql_query.getResultSetMetaData().getColumnCount(); _esql_i++) {
String _esql_tagname =
_esql_query.getResultSetMetaData().getColumnName(_esql_i);
@@ -842,8 +713,13 @@
break;
case java.sql.Types.OTHER: // This is what Informix uses for Sets,
Bags, Lists
-
this._esql_printObject(_esql_query.getResultSet().getObject(_esql_i), xspAttr);
- break;
+ // postgres is broken as it doesn't allow getObject()
+ // to retrieve any type (i.e. bit and bit varying)
+ // so don't handle complex types different for postgres
+ if (!_esql_connection.getUrl().startsWith("jdbc:postgresql:")) {
+
this._esql_printObject(_esql_query.getResultSet().getObject(_esql_i), xspAttr);
+ break;
+ }
default:
// standard type
@@ -860,13 +736,6 @@
}
this.characters("\n");
</xsp:logic>
- </xsl:when>
- <xsl:otherwise>
- <xsp:logic>
- throw new RuntimeException("esql:get-columns is not supported in this
environment: "+<xsl:value-of select="$environment"/>);
- </xsp:logic>
- </xsl:otherwise>
- </xsl:choose>
</xsl:template>
<xspdoc:desc>returns the value of the given column as a string</xspdoc:desc>
@@ -944,6 +813,19 @@
</xsl:choose>
</xsl:template>
+<xspdoc:desc>returns the value of the given column as a BigDecimal. if a format
attribute exists, its value is taken to be a decimal format string as defined in
java.text.DecimalFormat, and the result is formatted accordingly.</xspdoc:desc>
+<xsl:template
match="esql:row-results//esql:get-bigdecimal|esql:call-results//esql:get-bigdecimal">
+ <xsl:choose>
+ <xsl:when test="@format">
+ <xsp:expr>new DecimalFormat("<xsl:value-of
select="@format"/>").format(<xsl:call-template
name="get-resultset"/>.getBigDecimal(<xsl:call-template
name="get-column"/>))</xsp:expr>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsp:expr><xsl:call-template
name="get-resultset"/>.getBigDecimal(<xsl:call-template name="get-column"/>)</xsp:expr>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+
<xspdoc:desc>returns the current result set</xspdoc:desc>
<xsl:template match="esql:results//esql:get-resultset">
<xsp:expr><xsl:call-template name="get-resultset"/></xsp:expr>
@@ -1005,20 +887,6 @@
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
- <xsl:choose>
- <xsl:when test="$environment = 'Cocoon1'">
- <xsl:choose>
- <xsl:when test="../esql:row-results">
- <xsp:logic>
- xspCurrentNode.appendChild(this.xspParser.parse(new InputSource(new
StringReader(<xsl:copy-of select="$content"/>))).getDocumentElement();
- </xsp:logic>
- </xsl:when>
- <xsl:otherwise>
- <xsp:expr>this.xspParser.parse(new InputSource(new
StringReader(<xsl:copy-of select="$content"/>))).getDocumentElement()</xsp:expr>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:when test="$environment = 'Cocoon2'">
<xsp:logic>
{
org.apache.cocoon.components.parser.Parser newParser = null;
@@ -1041,13 +909,6 @@
}
}
</xsp:logic>
- </xsl:when>
- <xsl:otherwise>
- <xsp:logic>
- throw new RuntimeException("esql:get-xml is not supported in this
environment: "+<xsl:value-of select="$environment"/>);
- </xsp:logic>
- </xsl:otherwise>
- </xsl:choose>
</xsl:template>
<xspdoc:desc>returns the number of columns in the resultset.</xspdoc:desc>
@@ -1247,4 +1108,4 @@
</xsl:copy>
</xsl:template>
-</xsl:stylesheet>
+</xsl:stylesheet>
\ No newline at end of file
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]