You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by na...@locus.apache.org on 2000/05/10 15:00:30 UTC

cvs commit: jakarta-taglibs/sql/src/org/apache/taglibs/sql ConnectionTag.java ConnectionTagExtraInfo.java DburlTag.java DriverTag.java PasswordTag.java QueryTag.java QueryTagExtraInfo.java UserIDTag.java

nacho       00/05/10 06:00:29

  Added:       sql      build.bat build.sh build.xml
               sql/conf taglib.tld
               sql/doc/conf web.xml
               sql/examples/conf web.xml
               sql/examples/web index.jsp test.jsp
               sql/src/org/apache/taglibs/sql ConnectionTag.java
                        ConnectionTagExtraInfo.java DburlTag.java
                        DriverTag.java PasswordTag.java QueryTag.java
                        QueryTagExtraInfo.java UserIDTag.java
  Log:
  Sample Sql tags library contributed
  by Boyd Waters (NRAO, Socorro)
  
  Revision  Changes    Path
  1.1                  jakarta-taglibs/sql/build.bat
  
  Index: build.bat
  ===================================================================
  @echo off
  
  if "%SERVLET_JAR%" == "" goto noservletjar
  
  set _ANTHOME=%ANT_HOME%
  if "%ANT_HOME%" == "" set ANT_HOME=..\..\jakarta-ant
  
  if "%CLASSPATH%" == "" goto noclasspath
  
  set _CLASSPATH=%CLASSPATH%
  set CLASSPATH=%CLASSPATH%;%ANT_HOME%\lib\ant.jar;%ANT_HOME%\lib\xml.jar;%JAVA_HOME\lib\tools.jar
  goto next
  
  :noclasspath
  
  set _CLASSPATH=
  set CLASSPATH=%ANT_HOME%\lib\ant.jar;%ANT_HOME%\lib\xml.jar;%JAVA_HOME%\lib\tools.jar
  goto next
  
  :next
  
  java org.apache.tools.ant.Main -Dant.home=%ANT_HOME% -Dservlet.jar=%SERVLET_JAR% %1 %2 %3 %4 %5 %6 %7 %8 %9
  
  :clean
  set CLASSPATH=%_CLASSPATH%
  set _CLASSPATH=
  set ANT_HOME=%_ANTHOME%
  set _ANTHOME=
  set ARGS=%_ARGS%
  set _ARGS=
  goto done
  
  :noservletjar
  echo You must set SERVLET_JAR to that pathname of your servlet.jar file
  
  :done
  
  
  
  
  1.1                  jakarta-taglibs/sql/build.sh
  
  Index: build.sh
  ===================================================================
  #! /bin/sh
  
  if [ "$ANT_HOME" = "" ] ; then
    ANT_HOME=../../jakarta-ant
  fi
  
  args=""
  if [ "$SERVLET_JAR" != "" ] ; then
    args="$args -Dservlet.jar=$SERVLET_JAR"
  fi
  args="$args -Dant.home=$ANT_HOME"
  
  cp=$ANT_HOME/lib/ant.jar:$ANT_HOME/lib/xml.jar:$JAVA_HOME/lib/tools.jar
  
  java -classpath $cp:$CLASSPATH org.apache.tools.ant.Main $args "$@"
  
  
  
  1.1                  jakarta-taglibs/sql/build.xml
  
  Index: build.xml
  ===================================================================
  <!-- ANT Build Script for the "sql" Custom Tag Library -->
  <!-- $Id: build.xml,v 1.1 2000/05/10 13:00:23 nacho Exp $ -->
  <project name="jspspec" default="main" basedir=".">
  
      <!-- ******************** Adjustable Properties *********************** -->
  
      <!--
  
          The following property values should be examined and customized
  	for each custom tag library subproject.
  
  	ant.home                    Home directory for the ANT build tool
  	                            This is normally defaulted from the
  				    ANT_HOME environment variable in the
  				    build script.
  
  	servlet.jar                 Pathname of the servlet API classes
  	                            you are using to compile, such as the
  				    one that comes with Tomcat.  This is
  				    normally defaulted from the SERVLET_JAR
  				    environment variable in the build script.
  
          taglib.name		    Base name of this tag library subproject.
  
      -->
  
      <property name="taglib.name"    value="sql"/>
  
      <!-- ****************** Project Standard Properties ******************* -->
  
      <!--
  
          The following property values reflect the standard directory
  	organization for the jakarta-taglibs project, and should not
  	be changed or overridden.
  
  	build.dir                   Base directory for build targets
  	dist.dir                    Base directory for distribution targets
  
      -->
  
      <property name="build.dir"      value="../../build/taglibs"/>
      <property name="dist.dir"       value="../../dist/taglibs"/>
  
      <!-- *********************** Default Properties ********************** -->
  
      <!--
  
          The following property values reflect the recommended directory
  	structure for each custom tag library subproject.  You should only
  	need to adjust or override them if you use a different organization.
  
  	conf.src                    Library configuration source directory
          doc.src                     Documentation app source directory
          examples.src                Examples app source directory
          library.src                 Library Java source directory
  
      -->
  
      <property name="conf.src"       value="conf"/>
      <property name="doc.src"        value="doc"/>
      <property name="examples.src"   value="examples"/>
      <property name="library.src"    value="src"/>
  
  
      <!-- ********************* Derived Properties ************************* -->
  
      <!--
  
          These property values are derived from the previously defined values,
  	and should not normally be overridden from the command line.
  
          build.doc                   Target directory for documentation app
          build.examples		    Target directory for examples app
          build.library               Target directory for tag library
  	dist.doc                    Destination WAR for documentation app
  	dist.examples		    Destination WAR for examples app
  	dist.library                Destination JAR for tag library
  	dist.tld                    Destination TLD file for tag library
  
      -->
  
      <property name="build.doc"      value="${build.dir}/${taglib.name}-doc"/>
      <property name="build.examples" value="${build.dir}/${taglib.name}-examples"/>
      <property name="build.library"  value="${build.dir}/${taglib.name}"/>
      <property name="dist.doc"       value="${dist.dir}/${taglib.name}/${taglib.name}-doc.war"/>
      <property name="dist.examples"  value="${dist.dir}/${taglib.name}/${taglib.name}-examples.war"/>
      <property name="dist.library"   value="${dist.dir}/${taglib.name}/${taglib.name}.jar"/>
      <property name="dist.tld"       value="${dist.dir}/${taglib.name}/${taglib.name}.tld"/>
  
  
    <!-- ********************** Destination Preparation ********************* -->
  
    <target name="prepare">
      <!-- Set up build directories -->
      <mkdir dir="${build.dir}"/>
      <mkdir dir="${build.doc}"/>
      <mkdir dir="${build.doc}/WEB-INF"/>
      <mkdir dir="${build.doc}/WEB-INF/classes"/>
      <mkdir dir="${build.doc}/WEB-INF/lib"/>
      <mkdir dir="${build.examples}"/>
      <mkdir dir="${build.examples}/WEB-INF"/>
      <mkdir dir="${build.examples}/WEB-INF/classes"/>
      <mkdir dir="${build.examples}/WEB-INF/lib"/>
      <mkdir dir="${build.library}"/>
      <mkdir dir="${build.library}/META-INF"/>
      <!-- Set up distribution directory -->
      <mkdir dir="${dist.dir}"/>
      <mkdir dir="${dist.dir}/${taglib.name}"/>
    </target>
  
  
    <!-- **************** Compile Tag Library Components ******************** -->
  
    <!-- Compile the documentation application -->
    <target name="documentation" depends="prepare">
      <copydir src="${doc.src}/conf"      dest="${build.doc}/WEB-INF"/>
      <copydir src="${doc.src}/web"       dest="${build.doc}"/>
      <javac srcdir="${doc.src}/src"   destdir="${build.doc}/WEB-INF/classes"
             classpath="${servlet.jar}" debug="on"/>
    </target>
  
    <!-- Compile the examples application -->
    <target name="examples" depends="library-dist">
      <copydir src="${examples.src}/conf" dest="${build.examples}/WEB-INF"/>
      <copydir src="${examples.src}/web"  dest="${build.examples}"/>
      <copyfile src="${dist.tld}"
                dest="${build.examples}/WEB-INF/${taglib.name}.tld"/>
      <copyfile src="${dist.library}"
                dest="${build.examples}/WEB-INF/lib/${taglib.name}.jar"/>
      <javac srcdir="${examples.src}/src"
             destdir="${build.examples}/WEB-INF/classes"
             classpath="${servlet.jar}" debug="on"/>
    </target>
  
    <!-- Compile the tag library itself -->
    <target name="library" depends="prepare">
      <copyfile src="${conf.src}/taglib.tld"
                dest="${build.library}/META-INF/taglib.tld"/>
      <javac srcdir="${library.src}" destdir="${build.library}"
             classpath="${servlet.jar}" debug="on"/>
    </target>
  
    <!-- Compile the library as well as the associated applications -->
    <target name="main" depends="library,documentation,examples"/>
  
  
    <!-- ******************* Create Distribution Files ********************** -->
  
    <!-- Create the documentation application WAR file -->
    <target name="documentation-dist" depends="documentation">
      <jar jarfile="${dist.doc}" basedir="${build.doc}"/>
    </target>
  
    <!-- Create the examples application WAR file -->
    <target name="examples-dist" depends="examples">
      <jar jarfile="${dist.examples}" basedir="${build.examples}"/>
    </target>
  
    <!-- Create the library distribution files -->
    <target name="library-dist" depends="library">
      <jar jarfile="${dist.library}" basedir="${build.library}"/>
      <copyfile src="${conf.src}/taglib.tld" dest="${dist.tld}"/>
    </target>
  
    <!-- Create the entire set of distribution files -->
    <target name="dist" depends="library-dist,examples-dist,documentation-dist"/>
  
  
  
    <!-- ************************ Utility Commands ************************** -->
  
    <!-- Delete output directories and files so we can build from scratch -->
    <target name="clean">
      <deltree dir="${build.doc}"/>
      <deltree dir="${build.examples}"/>
      <deltree dir="${build.library}"/>
      <deltree dir="${dist.dir}/${taglib.name}"/>
    </target>
  
  </project>
  
  
  
  1.1                  jakarta-taglibs/sql/conf/taglib.tld
  
  Index: taglib.tld
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1" ?>
  <!DOCTYPE taglib
    PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
    "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
  
  <taglib>
  
    <!-- The version number of this tag library -->
    <tlibversion>1.0</tlibversion>
  
    <!-- The JSP specification version required to function -->
    <jspversion>1.1</jspversion>
  
    <!-- The short name of this tag library -->
    <shortname>Simple SQL Tags Library</shortname>
  
    <!-- Public URI that uniquely identifies this version of the tag library -->
    <uri>http://jakarta.apache.org/taglibs/sql-1.0</uri>
  
    <!-- General information about this tag library -->
    <info>
      The "sql" tag library contains working implementations of the SQL tags
      used as examples within the JSP Specification, version 1.1.
    </info>
  
    <!-- ******************** Defined Custom Tags *************************** -->
  
    <tag>
      <name>connection</name>
      <tagclass>org.apache.taglibs.sql.ConnectionTag</tagclass>
      <teiclass>org.apache.taglibs.sql.ConnectionTagExtraInfo</teiclass>
      <info>
        Example tag from Section A.2.1 of the JSP Specification, version 1.1.
      </info>
      <attribute>
        <name>id</name>
        <required>true</required>
      </attribute>
      <attribute>
        <name>ref</name>
        <required>false</required>
      </attribute>
    </tag>
  
    <tag>
      <name>userid</name>
      <tagclass>org.apache.taglibs.sql.UserIDTag</tagclass>
      <info>
        Example tag from Section A.2.1 of the JSP Specification, version 1.1.
      </info>
    </tag>
  
    <tag>
      <name>password</name>
      <tagclass>org.apache.taglibs.sql.PasswordTag</tagclass>
      <info>
        Example tag from Section A.2.1 of the JSP Specification, version 1.1.
      </info>
    </tag>
  
    <tag>
      <name>dburl</name>
      <tagclass>org.apache.taglibs.sql.DburlTag</tagclass>
      <info>
        Example tag from Section A.2.1 of the JSP Specification, version 1.1.
      </info>
    </tag>
  
    <tag>
      <name>driver</name>
      <tagclass>org.apache.taglibs.sql.DriverTag</tagclass>
      <info>
        Example tag from Section A.2.1 of the JSP Specification, version 1.1.
      </info>
    </tag>
  
  
    <tag>
      <name>query</name>
      <tagclass>org.apache.taglibs.sql.QueryTag</tagclass>
      <teiclass>org.apache.taglibs.sql.QueryTagExtraInfo</teiclass>
      <info>
        Example tag from Section A.2.2 of the JSP Specification, version 1.1.
      </info>
      <attribute>
        <name>id</name>
        <required>true</required>
      </attribute>
      <attribute>
        <name>connection</name>
        <required>true</required>
      </attribute>
      <attribute>
        <name>visibility</name>
        <required>false</required>
      </attribute>
  
    </tag>
  
  
  </taglib>
  
  
  
  1.1                  jakarta-taglibs/sql/doc/conf/web.xml
  
  Index: web.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
      "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
  
  <web-app>
  
    <description>
    Documentation for the "sql" custom tag library,
    from the JAKARTA-TAGLIBS project.
    </description>
  
  </web-app>
  
  
  
  1.1                  jakarta-taglibs/sql/examples/conf/web.xml
  
  Index: web.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
      "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
  
  <web-app>
  
    <description>
    Example web application illustrating the use of tags in the
    "sql" custom tag library, from the JAKARTA-TAGLIBS project.
    </description>
  
    <taglib>
      <taglib-uri>http://jakarta.apache.org/taglibs/sql-1.0</taglib-uri>
      <taglib-location>/WEB-INF/sql.tld</taglib-location>
    </taglib>
  
  </web-app>
  
  
  
  1.1                  jakarta-taglibs/sql/examples/web/index.jsp
  
  Index: index.jsp
  ===================================================================
  <%@ taglib uri="http://jakarta.apache.org/taglibs/sql-1.0" prefix="sql" %>
  
  <html>
  <head>
  <title>Examples of SQL Tag Library Tag Usage</title>
  </head>
  <body bgcolor="white">
  <p>Example of SQL tags Library</p>
  <form name="form1" action="test.jsp" method="get" >
    <p>. </p>
    <table width="50%" border="0" cellspacing="0" cellpadding="0">
      <tr> 
        <td>Driver</td>
        <td> 
          <input type="text" name="driver" value="sun.jdbc.odbc.JdbcOdbcDriver">
        </td>
      </tr>
      <tr> 
        <td>Dburl</td>
        <td> 
          <input type="text" name="dburl" value="jdbc:odbc:TOMCAT">
        </td>
      </tr>
      <tr> 
        <td height="20">Table</td>
        <td height="20"> 
          <input type="text" name="table" value="users">
        </td>
      </tr>
      <tr>
        <td>where clause</td>
        <td>
          <input type="text" name="where" value="user_name is not null">
        </td>
      </tr>
      <tr> 
        <td>User</td>
        <td>
          <input type="text" name="user" value="user">
        </td>
      </tr>
      <tr> 
        <td>Password</td>
        <td> 
          <input type="text" name="password" value="password">
        </td>
      </tr>
    </table>
    <p>
      <input type="submit" name="Submit" value="Submit">
    </p>
    <p>. </p>
    <p>: </p>
    <p>: </p>
    </form>
  </body>
  </html>
  
  
  
  1.1                  jakarta-taglibs/sql/examples/web/test.jsp
  
  Index: test.jsp
  ===================================================================
  <%@ taglib uri="http://jakarta.apache.org/taglibs/sql-1.0" prefix="sql" %>
  
  <html>
  <head>
  <title>Examples of JSPSPEC SQL Tag Library Tag Usage</title>
  </head>
  <body bgcolor="white">
  
  <sql:connection id="conn1" >
    <sql:dburl><%= request.getParameter("dburl") %></sql:dburl>
    <sql:driver><%= request.getParameter("driver") %></sql:driver>
    <sql:userid><%= request.getParameter("userid") %></sql:userid>
    <sql:password><%= request.getParameter("password") %></sql:password>
  </sql:connection>
  
  <sql:query id="getBoxen" connection="conn1" visibility="table">
  SELECT * FROM <%= request.getParameter("table") %>
  <% if( request.getParameter("where") != null && request.getParameter("where") != "" ) { %>
  WHERE <%= request.getParameter("where") %>
  <% } %>
  </sql:query>
  
  
  </body>
  </html>
  
  
  
  1.1                  jakarta-taglibs/sql/src/org/apache/taglibs/sql/ConnectionTag.java
  
  Index: ConnectionTag.java
  ===================================================================
  //$Id: ConnectionTag.java,v 1.1 2000/05/10 13:00:27 nacho Exp $
  //# Copyright (C) 2000 Associated Universities, Inc. Washington DC, USA.
  
  //# 
  //# This program is free software; you can redistribute it and/or modify
  //# it under the terms of the GNU General Public License as published by
  //# the Free Software Foundation; either version 2 of the License, or
  //# (at your option) any later version.
  //# 
  //# This program is distributed in the hope that it will be useful, but
  //# WITHOUT ANY WARRANTY; without even the implied warranty of
  //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  //# General Public License for more details.
  //# 
  //# You should have received a copy of the GNU General Public License
  //# along with this program; if not, write to the Free Software
  //# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  //# 
  //# Correspondence concerning OMS software should be addressed as follows:
  //#     Array Support Group - VLBA Operations
  //#     National Radio Astronomy Observatory
  //#     P. O. Box 0
  //#     Socorro, NM 87801 USA
  
  // JSP SQL TagLib EXAMPLES
  // Boyd Waters, NRAO bwaters@aoc.nrao.edu
  // May 3 2000
  //
  // These Java classes are a toy implementation of the SQL tags
  // discussed in Section A.2.1 and A.2.2 of the JavaServer Pages 1.1
  // Specification.
  //
  // This document should be available at
  // http://java.sun.com/products/jsp/download.html
  //
  // THIS IS EXAMPLE CODE INTENDED FOR EDUCATIONAL PURPOSES ONLY!!!
  // DO NOT USE IN PRODUCTION SYSTEMS!    
  
  package org.apache.taglibs.sql;
  
  import java.sql.*;
  
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  import java.util.Hashtable;
  import java.io.Writer;
  import java.io.IOException;
  
  public class ConnectionTag extends BodyTagSupport {
  
    // YOU NEED TO EDIT THESE FOR YOUR PARTICULAR DATABASE INSTALLATION!!
  
    static final String DRIVER_NAME = "sun.jdbc.odbc.JdbcOdbcDriver";
    static final String DATABASE_URL= "jdbc:odbc:TOMCAT";
  
    private final void makeConnection( String user, String passwd ) throws JspException  {
        try {
  	// load the driver
  	Class.forName( driver );
  
  	conn = DriverManager.getConnection (dburl, user, password);
  
  	// you might need to set autocommit ... check your JDBC driver docs!
  	conn.setAutoCommit(false);
        }
        catch( SQLException ex ) {
  	throw new JspException("Couldn't open database: " + dburl +
  			      "\n    SQLException: " + ex.getMessage());
        }
        catch(ClassNotFoundException ex) {
  	throw new JspException("Error Loading Driver: " + driver +
  			      "\n     ClassNotFoundException: " +
  			      ex.getMessage());
        }
    }
  
    //////////////////////////////////////////////////////////////////////////////////
  
    public ConnectionTag() { super(); }
  
    public void setUserID(String value) {
      userID = value;
      System.out.println( "ConnectionTag: userID = " + userID );
    }
  
    public void setPassword(String value) {
      password = value;
      System.out.println( "ConnectionTag: password = " + password );
    }
  
    private String userID   = null;	// the name used for database login
    private String password = null;	// the password userd for db  login
  
    private Connection conn = null;
    private String dburl;
    private String driver;
  
    public Connection getConnection() throws JspException {
      if( conn == null )
        makeConnection( userID, password );
  
      return conn;
    }
  
    public String getUserID() { return userID; }
    public String getPassword(){return password;}
  
  
    /**
     * doAfterBody
     * - evaluated after each chunk of body content?
     */
    public int doAfterBody() throws JspException {
      System.out.println( "ID: " + id );
      if( id != null ) {
        // the id attribute was set, so we should register the connection with
        // the PageContext
  
        // both userID and password are required for this implementation
        // note that you might want to make password optional.
  
        if( userID != null && password != null ) {
  	      System.out.println( "is connection null in ConnectionTag? " + (getConnection() == null) );
  
  	      pageContext.setAttribute( id, conn );
  	      return SKIP_BODY;
        }
        else return EVAL_BODY_TAG;	// we still need data...
      }
      else return SKIP_BODY;
    }
  
  
  
    /**
     * release()
     * - called by container after doEndTag()
     * - (note that we don't overrride doEndTag() so it's provided by our parent)
     *
     * avoid leaking references -- perhaps these are not necessary?
     */
    public void release() {
      conn = null;	// avoid leaking a reference to the connection
                          // note that there's still a ref to it if we
                          // registered the connection with the pageContext
  
      userID = null;
      password = null;
    }
  
    public java.lang.String getDburl() {
      return dburl;
    }
  
    public void setDburl(String newDburl) {
      dburl = newDburl;
    }
  
    public String getDriver() {
      return driver;
    }
  
    public void setDriver(String newDriver) {
      driver = newDriver;
    }
  
  }
  
  
  
  1.1                  jakarta-taglibs/sql/src/org/apache/taglibs/sql/ConnectionTagExtraInfo.java
  
  Index: ConnectionTagExtraInfo.java
  ===================================================================
  //# Copyright (C) 2000 Associated Universities, Inc. Washington DC, USA.
  //# 
  //# This program is free software; you can redistribute it and/or modify
  //# it under the terms of the GNU General Public License as published by
  //# the Free Software Foundation; either version 2 of the License, or
  //# (at your option) any later version.
  //# 
  //# This program is distributed in the hope that it will be useful, but
  //# WITHOUT ANY WARRANTY; without even the implied warranty of
  //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  //# General Public License for more details.
  //# 
  //$Id: ConnectionTagExtraInfo.java,v 1.1 2000/05/10 13:00:27 nacho Exp $
  //# You should have received a copy of the GNU General Public License
  //# along with this program; if not, write to the Free Software
  //# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  //# 
  //# Correspondence concerning OMS software should be addressed as follows:
  //#     Array Support Group - VLBA Operations
  //#     National Radio Astronomy Observatory
  //#     P. O. Box 0
  //#     Socorro, NM 87801 USA
  
  // JSP SQL TagLib EXAMPLES
  // Boyd Waters, NRAO bwaters@aoc.nrao.edu
  // May 3 2000
  //
  // These Java classes are a toy implementation of the SQL tags
  // discussed in Section A.2.1 and A.2.2 of the JavaServer Pages 1.1
  // Specification.
  //
  // This document should be available at
  // http://java.sun.com/products/jsp/download.html
  //
  // THIS IS EXAMPLE CODE INTENDED FOR EDUCATIONAL PURPOSES ONLY!!!
  // DO NOT USE IN PRODUCTION SYSTEMS!    
  
  package org.apache.taglibs.sql;
  
  import javax.servlet.jsp.tagext.*;
  
  public class ConnectionTagExtraInfo extends TagExtraInfo {
      public VariableInfo[] getVariableInfo(TagData data) {
          return new VariableInfo[] 
              {
                  new VariableInfo( data.getId(),
                                   "java.sql.Connection",
                                   true,
                                   VariableInfo.AT_END)
              };
      }
  }
  
  
  
  1.1                  jakarta-taglibs/sql/src/org/apache/taglibs/sql/DburlTag.java
  
  Index: DburlTag.java
  ===================================================================
  //$Id: DburlTag.java,v 1.1 2000/05/10 13:00:27 nacho Exp $
  //# Copyright (C) 2000 Associated Universities, Inc. Washington DC, USA.
  //# 
  //# This program is free software; you can redistribute it and/or modify
  //# it under the terms of the GNU General Public License as published by
  //# the Free Software Foundation; either version 2 of the License, or
  //# (at your option) any later version.
  //# 
  //# This program is distributed in the hope that it will be useful, but
  //# WITHOUT ANY WARRANTY; without even the implied warranty of
  //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  //# General Public License for more details.
  //# 
  //# You should have received a copy of the GNU General Public License
  //# along with this program; if not, write to the Free Software
  //# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  //# 
  //# Correspondence concerning OMS software should be addressed as follows:
  //#     Array Support Group - VLBA Operations
  //#     National Radio Astronomy Observatory
  //#     P. O. Box 0
  //#     Socorro, NM 87801 USA
  
  // JSP SQL TagLib EXAMPLES
  // Boyd Waters, NRAO bwaters@aoc.nrao.edu
  // May 3 2000
  //
  // These Java classes are a toy implementation of the SQL tags
  // discussed in Section A.2.1 and A.2.2 of the JavaServer Pages 1.1
  // Specification.
  //
  // This document should be available at
  // http://java.sun.com/products/jsp/download.html
  //
  // THIS IS EXAMPLE CODE INTENDED FOR EDUCATIONAL PURPOSES ONLY!!!
  // DO NOT USE IN PRODUCTION SYSTEMS!    
  
  package org.apache.taglibs.sql;
  
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  import java.util.Hashtable;
  import java.io.Writer;
  import java.io.IOException;
  
  public class DburlTag extends BodyTagSupport {
  
    public DburlTag() { super(); }
  
    // make sure that we eval our body
    public int doStartTag() throws JspException {
      System.out.println( "URL_TAGSTART" );
      return EVAL_BODY_TAG;
    }
  
    public int doAfterBody() throws JspException {
      System.out.println( "DBURL: " + bodyContent.getString() );
  
      ConnectionTag connectionTag =
        (ConnectionTag) TagSupport.findAncestorWithClass( this, org.apache.taglibs.sql.ConnectionTag.class );
  
      connectionTag.setDburl( bodyContent.getString() );
  
      return SKIP_BODY; // we're done processing the body
    }
  
    public int doEndTag() throws JspException { return EVAL_PAGE; }
  
    // no state for this object, so no need to release?
  }
  
  
  
  1.1                  jakarta-taglibs/sql/src/org/apache/taglibs/sql/DriverTag.java
  
  Index: DriverTag.java
  ===================================================================
  //$Id: DriverTag.java,v 1.1 2000/05/10 13:00:27 nacho Exp $
  //# Copyright (C) 2000 Associated Universities, Inc. Washington DC, USA.
  //# 
  //# This program is free software; you can redistribute it and/or modify
  //# it under the terms of the GNU General Public License as published by
  //# the Free Software Foundation; either version 2 of the License, or
  //# (at your option) any later version.
  //# 
  //# This program is distributed in the hope that it will be useful, but
  //# WITHOUT ANY WARRANTY; without even the implied warranty of
  //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  //# General Public License for more details.
  //# 
  //# You should have received a copy of the GNU General Public License
  //# along with this program; if not, write to the Free Software
  //# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  //# 
  //# Correspondence concerning OMS software should be addressed as follows:
  //#     Array Support Group - VLBA Operations
  //#     National Radio Astronomy Observatory
  //#     P. O. Box 0
  //#     Socorro, NM 87801 USA
  
  // JSP SQL TagLib EXAMPLES
  // Boyd Waters, NRAO bwaters@aoc.nrao.edu
  // May 3 2000
  //
  // These Java classes are a toy implementation of the SQL tags
  // discussed in Section A.2.1 and A.2.2 of the JavaServer Pages 1.1
  // Specification.
  //
  // This document should be available at
  // http://java.sun.com/products/jsp/download.html
  //
  // THIS IS EXAMPLE CODE INTENDED FOR EDUCATIONAL PURPOSES ONLY!!!
  // DO NOT USE IN PRODUCTION SYSTEMS!
  
  package org.apache.taglibs.sql;
  
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  import java.util.Hashtable;
  import java.io.Writer;
  import java.io.IOException;
  
  public class DriverTag extends BodyTagSupport {
  
    public DriverTag() { super(); }
  
    // make sure that we eval our body
    public int doStartTag() throws JspException {
      System.out.println( "DRIVER_TAGSTART" );
      return EVAL_BODY_TAG;
    }
  
    public int doAfterBody() throws JspException {
      System.out.println( "DRIVER: " + bodyContent.getString() );
  
      ConnectionTag connectionTag =
        (ConnectionTag) TagSupport.findAncestorWithClass( this, org.apache.taglibs.sql.ConnectionTag.class );
  
      connectionTag.setDriver( bodyContent.getString() );
  
      return SKIP_BODY; // we're done processing the body
    }
  
    public int doEndTag() throws JspException { return EVAL_PAGE; }
  
    // no state for this object, so no need to release?
  }
  
  
  
  1.1                  jakarta-taglibs/sql/src/org/apache/taglibs/sql/PasswordTag.java
  
  Index: PasswordTag.java
  ===================================================================
  //$Id: PasswordTag.java,v 1.1 2000/05/10 13:00:27 nacho Exp $
  //# Copyright (C) 2000 Associated Universities, Inc. Washington DC, USA.
  //# 
  //# This program is free software; you can redistribute it and/or modify
  //# it under the terms of the GNU General Public License as published by
  //# the Free Software Foundation; either version 2 of the License, or
  //# (at your option) any later version.
  //# 
  //# This program is distributed in the hope that it will be useful, but
  //# WITHOUT ANY WARRANTY; without even the implied warranty of
  //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  //# General Public License for more details.
  //# 
  //# You should have received a copy of the GNU General Public License
  //# along with this program; if not, write to the Free Software
  //# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  //# 
  //# Correspondence concerning OMS software should be addressed as follows:
  //#     Array Support Group - VLBA Operations
  //#     National Radio Astronomy Observatory
  //#     P. O. Box 0
  //#     Socorro, NM 87801 USA
  
  // JSP SQL TagLib EXAMPLES
  // Boyd Waters, NRAO bwaters@aoc.nrao.edu
  // May 3 2000
  //
  // These Java classes are a toy implementation of the SQL tags
  // discussed in Section A.2.1 and A.2.2 of the JavaServer Pages 1.1
  // Specification.
  //
  // This document should be available at
  // http://java.sun.com/products/jsp/download.html
  //
  // THIS IS EXAMPLE CODE INTENDED FOR EDUCATIONAL PURPOSES ONLY!!!
  // DO NOT USE IN PRODUCTION SYSTEMS!    
  
  package org.apache.taglibs.sql;
  
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  import java.util.Hashtable;
  import java.io.Writer;
  import java.io.IOException;
  
  public class PasswordTag extends BodyTagSupport {
  
    public PasswordTag() { super(); }
  
    // make sure that we eval our body
    public int doStartTag() throws JspException {
      System.out.println( "PASSWORD_TAGSTART" );
      return EVAL_BODY_TAG;
    }
  
    public int doAfterBody() throws JspException {
      System.out.println( "PASSWORD: " + bodyContent.getString() );
  
      ConnectionTag connectionTag =
        (ConnectionTag) TagSupport.findAncestorWithClass( this, org.apache.taglibs.sql.ConnectionTag.class );
  
      connectionTag.setPassword( bodyContent.getString() );
  
      return SKIP_BODY; // we're done processing the body
    }
  
    public int doEndTag() throws JspException { return EVAL_PAGE; }
  
    // no state for this object, so no need to release?
  }
  
  
  
  1.1                  jakarta-taglibs/sql/src/org/apache/taglibs/sql/QueryTag.java
  
  Index: QueryTag.java
  ===================================================================
  //$Id: QueryTag.java,v 1.1 2000/05/10 13:00:27 nacho Exp $
  //# Copyright (C) 2000 Associated Universities, Inc. Washington DC, USA.
  //# 
  //# This program is free software; you can redistribute it and/or modify
  //# it under the terms of the GNU General Public License as published by
  //# the Free Software Foundation; either version 2 of the License, or
  //# (at your option) any later version.
  //# 
  //# This program is distributed in the hope that it will be useful, but
  //# WITHOUT ANY WARRANTY; without even the implied warranty of
  //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  //# General Public License for more details.
  //# 
  //# You should have received a copy of the GNU General Public License
  //# along with this program; if not, write to the Free Software
  //# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  //# 
  //# Correspondence concerning OMS software should be addressed as follows:
  //#     Array Support Group - VLBA Operations
  //#     National Radio Astronomy Observatory
  //#     P. O. Box 0
  //#     Socorro, NM 87801 USA
  
  // JSP SQL TagLib EXAMPLES
  // Boyd Waters, NRAO bwaters@aoc.nrao.edu
  // May 3 2000
  //
  // These Java classes are a toy implementation of the SQL tags
  // discussed in Section A.2.1 and A.2.2 of the JavaServer Pages 1.1
  // Specification.
  //
  // This document should be available at
  // http://java.sun.com/products/jsp/download.html
  //
  // THIS IS EXAMPLE CODE INTENDED FOR EDUCATIONAL PURPOSES ONLY!!!
  // DO NOT USE IN PRODUCTION SYSTEMS!    
  
  package org.apache.taglibs.sql;
  
  import java.sql.*;
  
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  import java.util.Hashtable;
  import java.io.Writer;
  import java.io.IOException;
  
  
  public class QueryTag extends BodyTagSupport {
  
    public QueryTag() { super(); }
  
    public void setConnection( String connectionID ) {
      connID = connectionID;
    }
  
    public void setVisibility( String visible ) {
      this.visible = visible;
    }
  
    public String getVisibility() { return visible; }
    public String getConnection() { return connID; }
  
    private String connID = null;
    private String visible= "hide"; // flags whether we show results or not
    private ResultSet   rs= null;
  
    // make sure that we eval our body
    public int doStartTag() throws JspException {
      return EVAL_BODY_TAG;
    }
  
  
    public int doAfterBody() throws JspException {
      String sql = bodyContent.getString();
  
      Connection conn = (Connection) pageContext.getAttribute( connID );
  
      try {
        System.out.println( connID );
        System.out.println( sql );
        System.out.println( conn == null );
  
        Statement stmt = conn.createStatement();
  
        System.out.println( stmt == null );
  
                    rs = stmt.executeQuery( sql );
  
        pageContext.setAttribute( id, rs );
      }
      catch( Exception e ) {
        e.printStackTrace();
  
        throw new JspException( e.getMessage() );
      }
  
      // display the results only if visible attribute is set
      if( visible.equalsIgnoreCase("table") ) {
        try {
  	// I guess we display the items as a table
  
  	bodyContent.println("<table>");
  
  	// first, get column names...
  	bodyContent.println("<tr>");
  
  	ResultSetMetaData metaData = rs.getMetaData();
  
  	int numCols = metaData.getColumnCount() + 1;
  
  	for( int col = 1; col < numCols; col++ )
  	  bodyContent.println("    <th>" + metaData.getColumnName( col ) + "</th>\n");
  	
  	bodyContent.println("</tr>\n");
  
  
  	// now display the data...
  	while( rs.next() ) {
  	  bodyContent.println("<tr>");
  
  	  for( int col = 1; col < numCols; col++ ) {
  	    bodyContent.print("    <td>");
  
  	    try{
  	      bodyContent.print(rs.getObject( col ).toString());
  	    }
  	    catch( Exception e){ /* IGNORE FAILURE */ }
  
  	    bodyContent.println("</td>");
  	  }
  
  	  bodyContent.println("</tr>");
  	}
  
  	bodyContent.println("</table>");
  
  	metaData = null;
        }
        catch( Exception e ) {
  	e.printStackTrace();
  	throw new JspException( e.getMessage() );
        }
  
      } // end if
  
      return SKIP_BODY;
    }
  
  
    // write out the body to the web page, if there's anything to write...
  
    public int doEndTag() throws JspException {
      try {
        if( bodyContent != null )
  	bodyContent.writeOut( bodyContent.getEnclosingWriter());
      }
      catch( IOException e ) {
        throw new JspException( e.getMessage() );
      }
      return EVAL_PAGE;
    }
  
    // clean-up -- this should be called by the JSP Container...
    public void release() {
      System.out.println( "queryTag - cleaning up..." );
      connID = null;
  
      if( rs != null )
        try{ rs.close(); } catch( SQLException e ){}
      
      rs = null;
    }
  }
  
  
  
  1.1                  jakarta-taglibs/sql/src/org/apache/taglibs/sql/QueryTagExtraInfo.java
  
  Index: QueryTagExtraInfo.java
  ===================================================================
  //$Id: QueryTagExtraInfo.java,v 1.1 2000/05/10 13:00:27 nacho Exp $
  //# Copyright (C) 2000 Associated Universities, Inc. Washington DC, USA.
  //# 
  //# This program is free software; you can redistribute it and/or modify
  //# it under the terms of the GNU General Public License as published by
  //# the Free Software Foundation; either version 2 of the License, or
  //# (at your option) any later version.
  //# 
  //# This program is distributed in the hope that it will be useful, but
  //# WITHOUT ANY WARRANTY; without even the implied warranty of
  //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  //# General Public License for more details.
  //# 
  //# You should have received a copy of the GNU General Public License
  //# along with this program; if not, write to the Free Software
  //# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  //# 
  //# Correspondence concerning OMS software should be addressed as follows:
  //#     Array Support Group - VLBA Operations
  //#     National Radio Astronomy Observatory
  //#     P. O. Box 0
  //#     Socorro, NM 87801 USA
  
  // JSP SQL TagLib EXAMPLES
  // Boyd Waters, NRAO bwaters@aoc.nrao.edu
  // May 3 2000
  //
  // These Java classes are a toy implementation of the SQL tags
  // discussed in Section A.2.1 and A.2.2 of the JavaServer Pages 1.1
  // Specification.
  //
  // This document should be available at
  // http://java.sun.com/products/jsp/download.html
  //
  // THIS IS EXAMPLE CODE INTENDED FOR EDUCATIONAL PURPOSES ONLY!!!
  // DO NOT USE IN PRODUCTION SYSTEMS!    
  
  package org.apache.taglibs.sql;
  
  import javax.servlet.jsp.tagext.*;
  
  public class QueryTagExtraInfo extends TagExtraInfo {
      public VariableInfo[] getVariableInfo(TagData data) {
          return new VariableInfo[] 
              {
                  new VariableInfo( data.getId(),
                                   "java.sql.ResultSet",
                                   true,
                                   VariableInfo.AT_END)
              };
      }
  }
  
  
  
  1.1                  jakarta-taglibs/sql/src/org/apache/taglibs/sql/UserIDTag.java
  
  Index: UserIDTag.java
  ===================================================================
  //$Id: UserIDTag.java,v 1.1 2000/05/10 13:00:27 nacho Exp $
  //# Copyright (C) 2000 Associated Universities, Inc. Washington DC, USA.
  //# 
  //# This program is free software; you can redistribute it and/or modify
  //# it under the terms of the GNU General Public License as published by
  //# the Free Software Foundation; either version 2 of the License, or
  //# (at your option) any later version.
  //# 
  //# This program is distributed in the hope that it will be useful, but
  //# WITHOUT ANY WARRANTY; without even the implied warranty of
  //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  //# General Public License for more details.
  //# 
  //# You should have received a copy of the GNU General Public License
  //# along with this program; if not, write to the Free Software
  //# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  //# 
  //# Correspondence concerning OMS software should be addressed as follows:
  //#     Array Support Group - VLBA Operations
  //#     National Radio Astronomy Observatory
  //#     P. O. Box 0
  //#     Socorro, NM 87801 USA
  
  // JSP SQL TagLib EXAMPLES
  // Boyd Waters, NRAO bwaters@aoc.nrao.edu
  // May 3 2000
  //
  // These Java classes are a toy implementation of the SQL tags
  // discussed in Section A.2.1 and A.2.2 of the JavaServer Pages 1.1
  // Specification.
  //
  // This document should be available at
  // http://java.sun.com/products/jsp/download.html
  //
  // THIS IS EXAMPLE CODE INTENDED FOR EDUCATIONAL PURPOSES ONLY!!!
  // DO NOT USE IN PRODUCTION SYSTEMS!    
  
  package org.apache.taglibs.sql;
  
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  import java.util.Hashtable;
  import java.io.Writer;
  import java.io.IOException;
  
  public class UserIDTag extends BodyTagSupport {
    int i = 0;
  
    public UserIDTag() { super(); }
  
    // make sure that we eval our body
    public int doStartTag() throws JspException {
      System.out.println( "USERIDTAGSTART" );
      return EVAL_BODY_TAG;
    }
  
    public int doAfterBody() throws JspException {
      System.out.println( "USERID: " + bodyContent.getString() );
  
      ConnectionTag connectionTag =
        (ConnectionTag) TagSupport.findAncestorWithClass( this, org.apache.taglibs.sql.ConnectionTag.class );
  
      connectionTag.setUserID( bodyContent.getString() );
  
      return SKIP_BODY; // we're done processing the body
    }
  
    public int doEndTag() throws JspException {
      return EVAL_PAGE;
    }
  
    // no state for this object, so no need to release?
  }