cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ba...@locus.apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/processor/sql DefaultQueryCreator.java QueryCreator.java ConnectionCreator.java ConnectionDefs.java SQLProcessor.java Utils.java
Date Fri, 03 Dec 1999 08:42:29 GMT
balld       99/12/03 00:42:29

  Modified:    src/org/apache/cocoon/processor/sql ConnectionCreator.java
                        ConnectionDefs.java SQLProcessor.java Utils.java
  Added:       src/org/apache/cocoon/processor/sql DefaultQueryCreator.java
                        QueryCreator.java
  Log:
  Moved SQLQueryCreator class to QueryCreator interface and DefaultQueryCreator
  class, added session variable expansion code based on Sidney Chong's submission
  
  Revision  Changes    Path
  1.5       +0 -0      xml-cocoon/src/org/apache/cocoon/processor/sql/ConnectionCreator.java
  
  Index: ConnectionCreator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/sql/ConnectionCreator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ConnectionCreator.java	1999/12/02 09:07:45	1.4
  +++ ConnectionCreator.java	1999/12/03 08:42:28	1.5
  @@ -56,7 +56,7 @@
    * Utility methods for this processor.
    *
    * @author <a href="mailto:balld@webslingerZ.com">Donald Ball</a>
  - * @version $Revision: 1.4 $ $Date: 1999/12/02 09:07:45 $
  + * @version $Revision: 1.5 $ $Date: 1999/12/03 08:42:28 $
    */
   
   public class ConnectionCreator {
  
  
  
  1.5       +0 -0      xml-cocoon/src/org/apache/cocoon/processor/sql/ConnectionDefs.java
  
  Index: ConnectionDefs.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/sql/ConnectionDefs.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ConnectionDefs.java	1999/12/02 09:07:46	1.4
  +++ ConnectionDefs.java	1999/12/03 08:42:28	1.5
  @@ -57,7 +57,7 @@
    * Default connection values.
    *
    * @author <a href="mailto:balld@webslingerZ.com">Donald Ball</a>
  - * @version $Revision: 1.4 $ $Date: 1999/12/02 09:07:46 $
  + * @version $Revision: 1.5 $ $Date: 1999/12/03 08:42:28 $
    */
   
   public class ConnectionDefs {
  
  
  
  1.5       +5 -5      xml-cocoon/src/org/apache/cocoon/processor/sql/SQLProcessor.java
  
  Index: SQLProcessor.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/sql/SQLProcessor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SQLProcessor.java	1999/12/02 09:07:46	1.4
  +++ SQLProcessor.java	1999/12/03 08:42:28	1.5
  @@ -62,7 +62,7 @@
    * A processor that performs SQL database queries.
    *
    * @author <a href="mailto:balld@webslingerZ.com">Donald Ball</a>
  - * @version $Revision: 1.4 $ $Date: 1999/12/02 09:07:46 $
  + * @version $Revision: 1.5 $ $Date: 1999/12/03 08:42:28 $
    */
   
   public class SQLProcessor extends AbstractActor implements Processor, Status {
  @@ -81,7 +81,7 @@
       /**
        * The default query creator, does {@...} substitution
        */
  -    protected static SQLQueryCreator default_query_creator = new SQLQueryCreator();
  +    protected static QueryCreator default_query_creator = new DefaultQueryCreator();
   
       /**
        * Omit null columns
  @@ -178,12 +178,12 @@
   			timestamp_format = new SimpleDateFormat(timestamp_format_string);
           try {
               if (query == null || query.equals("")) {
  -                SQLQueryCreator query_creator;
  +                QueryCreator query_creator;
                   if (query_creator_name != null) {
                       if (query_creators.containsKey(query_creator_name)) {
  -                        query_creator = (SQLQueryCreator)query_creators.get(query_creator_name);
  +                        query_creator = (QueryCreator)query_creators.get(query_creator_name);
                       } else {
  -                        query_creator = (SQLQueryCreator)Class.forName(query_creator_name).newInstance();
  +                        query_creator = (QueryCreator)Class.forName(query_creator_name).newInstance();
                           query_creators.put(query_creator_name,query_creator);
                       }
                   } else {
  @@ -301,7 +301,7 @@
               }
               st.close(); conn.commit();
               query_element.getParentNode().replaceChild(results_node,query_element);
  -        } catch (SQLException e) {
  +        } catch (Exception e) {
               Element error_element = Utils.createErrorElement(document,namespace,query_props,e);
               query_element.getParentNode().replaceChild(error_element,query_element);
               conn.rollback();
  
  
  
  1.5       +0 -0      xml-cocoon/src/org/apache/cocoon/processor/sql/Utils.java
  
  Index: Utils.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/sql/Utils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Utils.java	1999/12/02 09:07:46	1.4
  +++ Utils.java	1999/12/03 08:42:29	1.5
  @@ -59,7 +59,7 @@
    * Utility methods for this processor.
    *
    * @author <a href="mailto:balld@webslingerZ.com">Donald Ball</a>
  - * @version $Revision: 1.4 $ $Date: 1999/12/02 09:07:46 $
  + * @version $Revision: 1.5 $ $Date: 1999/12/03 08:42:29 $
    */
   
   public class Utils {
  
  
  
  1.1                  xml-cocoon/src/org/apache/cocoon/processor/sql/DefaultQueryCreator.java
  
  Index: DefaultQueryCreator.java
  ===================================================================
  /*
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
   
      Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
   
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
   
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
   
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
   
   4. The names "Cocoon" and  "Apache Software Foundation"  must not be used to
      endorse  or promote  products derived  from this  software without  prior
      written permission. For written permission, please contact
      apache@apache.org.
   
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
   
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache 
   Software Foundation, please see <http://www.apache.org/>.
   */
  
  package org.apache.cocoon.processor.sql;
  
  import java.sql.*;
  import java.text.*;
  import java.util.*;
  import javax.servlet.http.*;
  import org.w3c.dom.*;
  
  /**
   * A class that can create a SQL query. It's given a query to start with,
   * plus a query_props table that contains parameters from the XML file, and the
   * parameters table from cocoon that notably may contain a HttpServletRequest
   * object keyed from "request".
   *
   * @author <a href="mailto:balld@webslingerZ.com">Donald Ball</a>
   * @author <a href="mailto:sidney@krdl.org.sg">Sidney Chong</a>
   * @version $Revision: 1.1 $ $Date: 1999/12/03 08:42:28 $
   */
  
  public class DefaultQueryCreator implements QueryCreator {
  
      public static final int SESSION = 1;
      public static final int REQUEST = 2;
  
      public String getQuery(Connection conn, String query, Element query_element, Properties
query_props, Dictionary parameters) throws Exception {
          HttpServletRequest req = (HttpServletRequest)parameters.get("request");
          query = substitute(query,req,
              query_props.getProperty("session-variable-left-delimiter"),
              query_props.getProperty("session-variable-right-delimiter"),
              SESSION);
          query = substitute(query,req,
              query_props.getProperty("variable-left-delimiter"),
              query_props.getProperty("variable-right-delimiter"),
              REQUEST);
          return query;
      }
  
      protected static String substitute(String query, HttpServletRequest req, String ldelim,
String rdelim, int type) {
          int llength = ldelim.length();
          int rlength = rdelim.length();
          int offset = 0;
          while (true) {
              int lindex = query.indexOf(ldelim,offset);
              if (lindex < 0) break;
              int rindex = query.indexOf(rdelim,offset+llength);
              if (rindex < 0 || rindex < lindex) break;
              String name = query.substring(lindex+llength,rindex);
              String value = getValue(req, name, type);
              if (value == null) break;
              query = query.substring(0,lindex)+value+query.substring(rindex+rlength);
              offset = lindex+value.length();
          }
          return query;
      }
  
      protected static String getValue(HttpServletRequest req, String name, int type) {
          String val = null;
          switch ( type ) {
              case SESSION :
                  val = (String) (req.getSession(true).getValue(name));
                  break;
              case REQUEST :
                  val = req.getParameter(name);
                  break;
              default :
                  val = "";
          }
          return val;
      }
  
  }
  
  
  
  1.1                  xml-cocoon/src/org/apache/cocoon/processor/sql/QueryCreator.java
  
  Index: QueryCreator.java
  ===================================================================
  /*
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
   
      Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
   
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
   
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
   
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
   
   4. The names "Cocoon" and  "Apache Software Foundation"  must not be used to
      endorse  or promote  products derived  from this  software without  prior
      written permission. For written permission, please contact
      apache@apache.org.
   
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
   
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache 
   Software Foundation, please see <http://www.apache.org/>.
   */
  
  package org.apache.cocoon.processor.sql;
  
  import java.sql.*;
  import java.text.*;
  import java.util.*;
  import javax.servlet.http.*;
  import org.w3c.dom.*;
  
  /**
   * An interface that describes a class that can create a SQL query.
   *
   * @author <a href="mailto:balld@webslingerZ.com">Donald Ball</a>
   * @version $Revision: 1.1 $ $Date: 1999/12/03 08:42:28 $
   */
  
  public interface QueryCreator {
  
      public String getQuery(Connection conn, String query, Element query_element, Properties
query_props, Dictionary parameters) throws Exception;
  
  }
  
  
  

Mime
View raw message