bloritsch    01/01/16 12:28:05

  Modified:    src/org/apache/cocoon/components/language/markup/xsp/java
                        Tag: xml-cocoon2 esql.xsl
  Log:
  Brought Esql to the version prior to this one.  Donald Ball will reimplement 
the
  stuff for his changes.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.24  +33 -58    
xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/java/Attic/esql.xsl
  
  Index: esql.xsl
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/java/Attic/esql.xsl,v
  retrieving revision 1.1.2.23
  retrieving revision 1.1.2.24
  diff -u -r1.1.2.23 -r1.1.2.24
  --- esql.xsl  2001/01/16 03:33:58     1.1.2.23
  +++ esql.xsl  2001/01/16 20:28:05     1.1.2.24
  @@ -1,5 +1,5 @@
   <?xml version="1.0"?>
  -<!-- $Id: esql.xsl,v 1.1.2.23 2001/01/16 03:33:58 balld Exp $-->
  +<!-- $Id: esql.xsl,v 1.1.2.24 2001/01/16 20:28:05 bloritsch Exp $-->
   <!--
   
    ============================================================================
  @@ -53,9 +53,9 @@
   
   <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  +  xmlns:xsp="http://apache.org/xsp";
     xmlns:esql="http://apache.org/cocoon/SQL/v2";
     xmlns:xspdoc="http://apache.org/cocoon/XSPDoc/v1";
  -  xmlns:xsp="http://apache.org/xsp";
   >
   <!--
   -->
  @@ -174,18 +174,26 @@
         <xsp:include>java.text.DecimalFormat</xsp:include>
         <xsp:include>java.io.StringWriter</xsp:include>
         <xsp:include>java.io.PrintWriter</xsp:include>
  -      
<xsp:include>org.apache.turbine.services.db.PoolBrokerService</xsp:include>
  -      <xsp:include>org.apache.turbine.util.db.pool.DBConnection</xsp:include>
  -      <xsl:if test="$environment = 'cocoon2'">
  -        
<xsp:include>org.apache.cocoon.components.language.markup.xsp.XSPUtil</xsp:include>
  -      </xsl:if>
  +      
<xsp:include>org.apache.cocoon.components.datasource.DataSourceComponent</xsp:include>
       </xsp:structure>
       <xsp:logic>
         /** environment - <xsl:value-of select="$environment"/> **/
  +      private static ComponentSelector esqlSelector = null;
  +
  +      public void compose(ComponentManager manager) {
  +          super.compose(manager);
  +
  +          if (esqlSelector == null) {
  +              try {
  +                  esqlSelector = (ComponentSelector) 
manager.lookup(Roles.DB_CONNECTION);
  +              } catch (ComponentManagerException cme) {
  +                  log.error("Could not look up the datasource component", 
cme);
  +              }
  +          }
  +      }
         /** xsp namespace uri - <xsl:value-of select="$xsp-namespace-uri"/> **/
  -      static PoolBrokerService _esql_pool = PoolBrokerService.getInstance();
         class EsqlConnection {
  -        DBConnection db_connection = null;
  +        DataSourceComponent datasource = null;
           Connection connection = null;
           String dburl = null;
           String username = null;
  @@ -215,7 +223,7 @@
       Stack _esql_connections = new Stack();
       EsqlConnection _esql_connection = null;
       Stack _esql_queries = new Stack();
  -    EsqlQuery _esql_query = null; 
  +    EsqlQuery _esql_query = null;
       SQLException _esql_exception = null;
       StringWriter _esql_exception_writer = null;
     </xsp:logic>
  @@ -238,15 +246,17 @@
       try {
         <xsl:choose>
           <xsl:when test="esql:pool">
  -          _esql_connection.db_connection = 
_esql_pool.getConnection(String.valueOf(<xsl:copy-of select="$pool"/>));
  -          _esql_connection.connection = 
_esql_connection.db_connection.getConnection();
  +          _esql_connection.datasource = (DataSourceComponent) 
esqlSelector.select(String.valueOf(<xsl:copy-of select="$pool"/>));
  +          _esql_connection.connection = 
_esql_connection.datasource.getConnection();
           </xsl:when>
           <xsl:otherwise>
  +          <xsl:if test="esql:driver">
             try {
               Class.forName(String.valueOf(<xsl:copy-of 
select="$driver"/>)).newInstance();
             } catch (Exception _esql_exception_<xsl:value-of 
select="generate-id(.)"/>) {
               throw new RuntimeException("Error loading driver: 
"+String.valueOf(<xsl:copy-of select="$driver"/>));
             }
  +          </xsl:if>
             try {
               <xsl:choose>
                 <xsl:when test="esql:username">
  @@ -277,19 +287,16 @@
           throw new RuntimeException("Error setting connection autocommit");
         }
         <xsl:apply-templates/>
  +    } catch (Exception e) {
  +        log.error("Error processing the page", e);
       } finally {
         try {
           if(!_esql_connection.connection.getAutoCommit()) {
             _esql_connection.connection.commit();
           }
  -        <xsl:choose>
  -          <xsl:when test="esql:pool">
  -            _esql_pool.releaseConnection(_esql_connection.db_connection);
  -          </xsl:when>
  -          <xsl:otherwise>
  -            _esql_connection.connection.close();
  -          </xsl:otherwise>
  -        </xsl:choose>
  +
  +        _esql_connection.connection.close();
  +
           if (_esql_connections.empty()) {
             _esql_connection = null;
           } else {
  @@ -464,18 +471,6 @@
           }
         </xsp:logic>
       </xsl:when>
  -    <xsl:when test="$environment = 'cocoon2'">
  -      <xsp:logic>
  -        for (int _esql_i = 1; _esql_i &lt;= 
_esql_query.resultset_metadata.getColumnCount(); _esql_i++) {
  -          String _esql_tagname = 
_esql_query.resultset_metadata.getColumnName(_esql_i);
  -          <xsp:element>
  -            <xsp:param 
name="name"><xsp:expr>_esql_tagname</xsp:expr></xsp:param>
  -            <xsp:expr>_esql_query.resultset.getString(_esql_i)</xsp:expr>
  -          </xsp:element>
  -        }
  -        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"/>);
  @@ -574,9 +569,9 @@
     <xsp:expr><xsl:call-template 
name="get-resultset"/>.getShort(<xsl:call-template 
name="get-column"/>)</xsp:expr>
   </xsl:template>
   
  - <xspdoc:desc>returns the value of the given column interpeted as an xml 
fragment. 
  - The fragment is parsed by the default xsp parser and the document element 
is returned. 
  - If a root attribute exists, its value is taken to be the name of an element 
to wrap around the contents of 
  + <xspdoc:desc>returns the value of the given column interpeted as an xml 
fragment.
  + The fragment is parsed by the default xsp parser and the document element 
is returned.
  + If a root attribute exists, its value is taken to be the name of an element 
to wrap around the contents of
    the fragment before parsing.</xspdoc:desc>
   <xsl:template match="esql:row-results//esql:get-xml">
     <xsl:variable name="content">
  @@ -593,7 +588,6 @@
         </xsl:when>
         <xsl:otherwise>
           <!-- <xsl:call-template name="add-xml-decl"> not needed -->
  -        <xsl:text>"&lt;?xml version=\"1.0\"?&gt;"+</xsl:text>
           <xsl:call-template name="get-string"/>
         </xsl:otherwise>
       </xsl:choose>
  @@ -602,24 +596,6 @@
       <xsl:when test="$environment = 'cocoon1'">
         <xsp:expr>this.xspParser.parse(new InputSource(new 
StringReader(<xsl:copy-of select="$content"/>))).getDocumentElement()</xsp:expr>
       </xsl:when>
  -    <xsl:when test="$environment = 'cocoon2'">
  -      <xsp:logic>
  -        {
  -          /*
  -          parser.setContentHandler(this.contentHandler);
  -          parser.setLexicalHandler(this.lexicalHandler);
  -          */
  -          try {
  -            XSPUtil.include(new InputSource(new StringReader(<xsl:copy-of 
select="$content"/>)),this.contentHandler,parser);
  -            /*
  -            parser.parse(new InputSource(new StringReader(<xsl:copy-of 
select="$content"/>)));
  -            */
  -          } catch (Exception _esql_exception_<xsl:value-of 
select="generate-id(.)"/>) {
  -            throw new RuntimeException("error parsing xml: 
"+_esql_exception_<xsl:value-of select="generate-id(.)"/>.getMessage()+": 
"+String.valueOf(<xsl:copy-of select="$content"/>));
  -          }
  -        }
  -      </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"/>);
  @@ -706,11 +682,10 @@
   <xsl:template name="get-string-encoded">
     <xsl:param name="column-spec"/>
     <xsl:param name="resultset"/>
  -  <xsl:variable name="encoding"><xsl:call-template 
name="get-nested-string"><xsl:with-param name="content" 
select="esql:encoding"/></xsl:call-template></xsl:variable>
     <xsl:choose>
  -    <xsl:when test="$encoding">
  -      new String (<xsl:value-of select="$resultset"/>.getBytes 
  -        (<xsl:value-of select="$column-spec"/>), <xsl:value-of 
select="$encoding"/>)
  +    <xsl:when test="@encoding">
  +      new String (<xsl:value-of select="$resultset"/>.getBytes
  +        (<xsl:value-of select="$column-spec"/>), <xsl:value-of 
select="@encoding"/>)
       </xsl:when>
       <xsl:otherwise>
         <xsl:value-of select="$resultset"/>.getString(<xsl:value-of 
select="$column-spec"/>)
  
  
  

Reply via email to