cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java esql.xsl
Date Tue, 09 Apr 2002 12:50:40 GMT
haul        02/04/09 05:50:40

  Modified:    src/java/org/apache/cocoon/components/language/markup/xsp/java
                        esql.xsl
  Log:
  * removed references to Cocoon1 because esql.xsl in not in sync with C1
    since introduction of Esql* helper classes. (~200 lines = 17%)
  
  * stop esql to handle complex types for postgres on esql:get-columns
  
  Revision  Changes    Path
  1.14      +61 -210   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
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- esql.xsl	22 Feb 2002 12:14:12 -0000	1.13
  +++ esql.xsl	9 Apr 2002 12:50:40 -0000	1.14
  @@ -1,6 +1,6 @@
   <?xml version="1.0"?>
   
  -<!-- $Id: esql.xsl,v 1.13 2002/02/22 12:14:12 tcurdt Exp $-->
  +<!-- $Id: esql.xsl,v 1.14 2002/04/09 12:50:40 haul Exp $-->
   <!--
   
    ============================================================================
  @@ -56,7 +56,7 @@
    * ESQL Logicsheet
    *
    * @author ?
  - * @version CVS $Revision: 1.13 $ $Date: 2002/02/22 12:14:12 $
  + * @version CVS $Revision: 1.14 $ $Date: 2002/04/09 12:50:40 $
   -->
   
   <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(.,'&#9;&#10;&#13;','
  ')"/>"
  -              </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(.,'&#9;&#10;&#13;','
  ')"/>"
  -                  </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(.,'&#9;&#10;&#13;','
  ')"/>"
  +              <!-- 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(.,'&#9;&#10;&#13;','   ')"/>"
  +          </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>
   
  @@ -238,43 +186,19 @@
         <xsp:include>java.util.ListIterator</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 +211,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 +242,6 @@
                 <xsp:content><xsp:expr>obj</xsp:expr></xsp:content>;
              }
           }
  -        </xsl:when>
  -      </xsl:choose>
       </xsp:logic>
       <xsl:apply-templates/>
     </xsp:page>
  @@ -335,7 +251,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 +262,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 +278,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 +337,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 +462,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 +557,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 +567,7 @@
   
       do {
         <xsp:content>
  -      <xsl:apply-templates/>
  +        <xsl:apply-templates/>
         </xsp:content>
         <xsl:if test="count($group) &lt; 1">	
           <xsl:call-template name="nextRow"/>
  @@ -697,6 +584,8 @@
     </xsp:logic>
   </xsl:template>
   
  +
  +
   <xsl:template name="nextRow">
     //checking out early?
       if (_esql_query.getMaxRows() != -1 &amp;&amp; _esql_query.getCurrentRow() -
_esql_query.getSkipRows() == _esql_query.getMaxRows()) {
  @@ -706,18 +595,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>
  @@ -732,6 +628,8 @@
   </xsp:logic>
   </xsl:template>
   
  +
  +
   <xsl:template match="esql:group//node()[.//esql:member]">
     <xsl:param name="group-on"/>
     <xsl:copy>
  @@ -741,6 +639,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"/>
  @@ -767,6 +667,8 @@
     </xsp:logic>
   </xsl:template>
   
  +
  +
   <xsl:template match="esql:results//esql:more-results"/>
   
   <xsl:template match="esql:results//esql:more-results" mode="more">
  @@ -778,34 +680,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 &lt;= _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 &lt;= _esql_query.getResultSetMetaData().getColumnCount();
_esql_i++) {
             String _esql_tagname = _esql_query.getResultSetMetaData().getColumnName(_esql_i);
  @@ -838,8 +712,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
  @@ -856,13 +735,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>
  @@ -1001,20 +873,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;
  @@ -1037,13 +895,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>
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message