jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@locus.apache.org
Subject cvs commit: jakarta-taglibs/bsf/src/org/apache/taglibs/bsf expression.java scriptlet.java
Date Tue, 23 May 2000 23:16:47 GMT
craigmcc    00/05/23 16:16:47

  Modified:    .        LICENSE build.xml
  Added:       bsf      build.bat build.sh build.xml
               bsf/conf taglib.tld
               bsf/doc/conf web.xml
               bsf/doc/web index.html
               bsf/examples/conf web.xml
               bsf/examples/web temps.jsp
               bsf/src/org/apache/taglibs/bsf expression.java
                        scriptlet.java
  Log:
  Add a custom tag library that enables IBM's Bean Scripting Framework
  (BSF) that supports the use of multiple scripting languages in JSP pages,
  instead of just Java.
  Submitted by:	Doug Davis <dug@us.ibm.com>
  
  Revision  Changes    Path
  1.2       +2 -5      jakarta-taglibs/LICENSE
  
  Index: LICENSE
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/LICENSE,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LICENSE	2000/04/01 22:59:48	1.1
  +++ LICENSE	2000/05/23 23:16:44	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-taglibs/LICENSE,v 1.1 2000/04/01 22:59:48 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/04/01 22:59:48 $
  + * $Header: /home/cvs/jakarta-taglibs/LICENSE,v 1.2 2000/05/23 23:16:44 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/05/23 23:16:44 $
    *
    * ====================================================================
    * 
  @@ -58,8 +58,5 @@
    * <http://www.apache.org/>.
    *
    */ 
  -
  -
  -
   
   
  
  
  
  1.4       +6 -2      jakarta-taglibs/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/build.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- build.xml	2000/05/13 20:29:46	1.3
  +++ build.xml	2000/05/23 23:16:44	1.4
  @@ -1,5 +1,5 @@
   <!-- ANT Build Script for the JAKARTA-TAGLIBS Project -->
  -<!-- $Id: build.xml,v 1.3 2000/05/13 20:29:46 nacho Exp $ -->
  +<!-- $Id: build.xml,v 1.4 2000/05/23 23:16:44 craigmcc Exp $ -->
   <project name="jakarta-taglibs" default="dist" basedir=".">
   
   
  @@ -73,6 +73,10 @@
   
     -->
   
  +  <target name="bsf">
  +    <ant dir="./bsf" target="dist"/>
  +  </target>
  +
     <target name="jspspec">
       <ant dir="./jspspec" target="dist"/>
     </target>
  @@ -88,6 +92,6 @@
   
     <!-- *********************** Overall Build Command ********************** -->
   
  -  <target name="dist" depends="prepare,static,jspspec,sql,xsl"/>
  +  <target name="dist" depends="prepare,static,bsf,jspspec,sql,xsl"/>
   
   </project>
  
  
  
  1.1                  jakarta-taglibs/bsf/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/bsf/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/bsf/build.xml
  
  Index: build.xml
  ===================================================================
  <!-- ANT Build Script for the "bsf" Custom Tag Library -->
  <!-- $Id: build.xml,v 1.1 2000/05/23 23:16:44 craigmcc Exp $ -->
  <project name="bsf" 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="bsf"/>
      <property name="ant.home"       value="../../jakarta-ant"/>
      <property name="servlet.jar"    value="../../jakarta-servletapi/lib/servlet.jar"/>
  
  
      <!-- ****************** 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"/>
      <property name="lib.src"        value="lib"/>
  
  
      <!-- ********************* 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="${lib.src}" dest="${build.examples}/WEB-INF/lib"/> 
      <copydir src="${library.src}" dest="${build.examples}/WEB-INF/classes"/>
      <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/bsf/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-jsptaglib_1_1.dtd">
  
  <!-- a tab library descriptor -->
  
  <taglib>
    <!-- after this the default space is
          "http://java.sun.com/j2ee/dtds/jsptaglibrary_1_2.dtd"
     -->
  
    <tlibversion>2.0</tlibversion>
    <jspversion>1.1</jspversion>
    <shortname>BSF JSP Support</shortname>
    <uri>http://jakarta.apache.org/taglibs/bsf-2.0</uri>
    <info> Just testing </info>
  
    <tag>
      <name>scriptlet</name>
      <tagclass>bsf.scriptlet</tagclass>
      <bodycontent>JSP</bodycontent>
      <info>Run script</info>
      <attribute>
        <name>language</name>
        <required>true</required>
      </attribute>
    </tag>
  
    <tag>
      <name>expression</name>
      <tagclass>bsf.expression</tagclass>
      <bodycontent>JSP</bodycontent>
      <info>Run expression</info>
      <attribute>
        <name>language</name>
        <required>true</required>
      </attribute>
    </tag>
  
  </taglib>
  
  
  
  1.1                  jakarta-taglibs/bsf/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>
      <taglib>
          <taglib-uri>
  	   BSFTAGS
          </taglib-uri>
          <taglib-location>
             /WEB-INF/tld/xmltags.tld
          </taglib-location>
      </taglib>
  </web-app>
  
  
  
  1.1                  jakarta-taglibs/bsf/doc/web/index.html
  
  Index: index.html
  ===================================================================
  <html>
  
  <head>
  <meta http-equiv="Content-Type"
  content="text/html; charset=iso-8859-1">
  <meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
  <title>Documentation for the BSF Tag Library</title>
  </head>
  
  <body bgcolor="#FFFFFF">
  
  <h1 align="center">Documentation for the BSF Tag Library</h1>
  
  <h2>1. INTRODUCTION</h2>
  
  <p>The BSF (Bean Scripting Framework) Tag Library enables JSP
  writers to write the code portion of their JSP in languages other
  than Java.</p>
  
  <p>For a much more detailed description of BSF itself see <a
  href="http://alphaworks.ibm.com/tech/bsf">http://alphaworks.ibm.com/tech/bsf</a>,
  but here are a few key excerpts:</p>
  
  <p>The <strong>Bean Scripting Framework (BSF)</strong> is an
  architecture for incorporating scripting into Java applications
  and applets. Scripting languages such as Netscape Rhino (Javascript),
  VBScript, Perl, Tcl, Python, NetRexx and Rexx are commonly used
  to augment an application's function or to script together a set
  of application components to form an application.</p>
  
  <p>BSF supports both directions of scripting: in one case where
  the Java-side is in charge and runs/evaluates scripts at will,
  and in the other case the script runs and controls Java beans.
  Notice that while we use the word &quot;bean&quot;, it is used
  loosely - BSF works with any Java object and not just a true bean.</p>
  
  <p>BSF defines a set of JSP objects available as beans that are
  available for the scriptlet to use:</p>
  
  <blockquote>
      <blockquote>
          <blockquote>
              <p><font size="2" face="Courier">request<br>
              response<br>
              pageContext<br>
              application<br>
              out<br>
              config<br>
              page<br>
              exception<br>
              session</font></p>
          </blockquote>
      </blockquote>
  </blockquote>
  
  <p><font size="3">The BSF taglib also allows JSP writers to use
  multiple scripting languages within the same JSP document.</font></p>
  
  <h2>2. PREREQUISITE SOFTWARE</h2>
  
  <ul>
      <li>A servlet container that supports the JavaServer Pages
          Specification, version 1.1. </li>
      <li>Bean Scripting Framework : <a
          href="http://alphaworks.ibm.com/tech/bsf">http://alphaworks.ibm.com/tech/bsf</a></li>
      <li>BSF Engines and associated language run-times desired.</li>
  </ul>
  
  <h2>3. CONFIGURATION INFORMATION</h2>
  
  <p>Follow these steps to configure your web application with this
  tag library: </p>
  
  <ul>
      <li>Copy the tag library descriptor file (<font size="2"
          face="Courier New">bsf</font><font size="3"><code>/</code></font><code>bsf.tld</code>)
          to the <code>/WEB-INF</code> subdirectory of your web
          application. </li>
      <li>Copy the tag library JAR file (<font size="2"
          face="Courier New">bsf</font><font size="3"><code>/bsf</code></font><code>.jar</code>)
          to the <code>/WEB-INF/lib</code> subdirectory of your web
          application. </li>
      <li>Add a <code>&lt;taglib&gt;</code> element to your web
          application deployment descriptor in <code>/WEB-INF/web.xml</code>
          like this: <pre>
      &lt;taglib&gt;
          &lt;taglib-uri&gt;http://jakarta.apache.org/taglibs/bsf-2.0&lt;/taglib-uri&gt;
  	&lt;taglib-location&gt;/WEB-INF/bsf.tld&lt;/taglib-location&gt;
      &lt;/taglib&gt;
  </pre>
      </li>
  </ul>
  
  <p>To use the tags from this library in your JSP pages, add the
  following directive at the top of each page: </p>
  
  <pre>
      &lt;%@ taglib uri=&quot;http://jakarta.apache.org/taglibs/bsf-2.0&quot;
prefix=&quot;x&quot; %&gt;
  </pre>
  
  <p>where &quot;x&quot; is the tag name prefix you wish to use for
  tags from this library. You can change this value to any prefix
  you like. </p>
  
  <h2>4. TAG DOCUMENTATION</h2>
  
  <p>The BSF tag library includes several tags, with the following
  characteristics: </p>
  
  <h3>4.1 The &quot;scriptlet&quot; tag</h3>
  
  <p>This tag is the BSF taglib equivalent of the &quot;&lt;%&quot;
  JSP tag. There is one required attribute, &quot;language&quot;,
  which defines the language used in that section of the JSP. For
  example:</p>
  
  <blockquote>
      <blockquote>
          <p align="left" dir="ltr"><font size="2" face="Courier">&lt;bsf:scriptlet
          language=&quot;tcl&quot;&gt;<br>
          $out println &quot;Hello world&quot;<br>
          &lt;/bsf:scriptlet&gt;</font></p>
      </blockquote>
  </blockquote>
  
  <h3>4.2 The &quot;expression&quot; tag</h3>
  
  <p>This tag is the BSF taglib equivalent of the &quot;&lt;%=&quot;
  JSP tag. This is one required attribute, &quot;language&quot;,
  which defines the language used in that section of the JSP. For
  example:</p>
  
  <blockquote>
      <blockquote>
          <p><font size="2" face="Courier">&lt;bsf:expression
          language=&quot;perlscript&quot;&gt;<br>
          CreateBean(&quot;java.util.Date&quot;)<br>
          &lt;/bsf:expression&gt;</font></p>
      </blockquote>
  </blockquote>
  
  <h3>5. USAGE EXAMPLES</h3>
  
  <p>See the example JSP (<code>bsf-examples\temps.jsp</code>) for
  an example of the usage of the tags from this custom tag library.
  </p>
  </body>
  </html>
  
  
  
  1.1                  jakarta-taglibs/bsf/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
    "bsf" custom tag library, from the JAKARTA-TAGLIBS project.
    </description>
  
    <taglib>
      <taglib-uri>http://jakarta.apache.org/taglibs/bsf-2.0</taglib-uri>
      <taglib-location>/WEB-INF/bsf.tld</taglib-location>
    </taglib>
  
  </web-app>
  
  
  
  1.1                  jakarta-taglibs/bsf/examples/web/temps.jsp
  
  Index: temps.jsp
  ===================================================================
  <html>
  <%@ taglib uri="http://jakarta.apache.org/taglibs/bsf-2.0" prefix="bsf" %>
  <head>
     <title>Temperature Table</title>
  </head>
  <body>
  <h1>Temperature Table</h1>
  <p>American tourists visiting Canada can use this handy temperature
  table which converts from Fahrenheit to Celsius:
  <br><br>
  
  In TCL
  <table BORDER COLS=2 WIDTH="20%" >
  <tr BGCOLOR="#FFFF00">
  <th>Fahrenheit</th>
  <th>Celsius</th>
  </tr>
  <bsf:scriptlet language="tcl">
    package require java
  
    for {set i 60} {$i<=100} {incr i 10} {
      $out println "<tr ALIGN=RIGHT BGCOLOR=\"#CCCCCC\">"
      $out println "<td>$i</td>"
      $out println [concat "<td>" [format %4.2f [expr ($i - 32.0)*5/9]] "</td>"]
      $out println "</tr>"
    }
  </bsf:scriptlet>
  </table>
  <bsf:expression language="tcl">
      package require java ; java::new java.util.Date
  </bsf:expression>
  
  
  <hr>In Javascript
  <table BORDER COLS=2 WIDTH="20%" >
  <tr BGCOLOR="#FFFF00">
  <th>Fahrenheit</th>
  <th>Celsius</th>
  </tr>
  <bsf:scriptlet language="javascript">
    for (i=60; i<=100; i+=10) {
      out.println ("<tr ALIGN=RIGHT BGCOLOR=\"#CCCCCC\">")
      out.println ("<td>" +  i + "</td>")
      out.println ("<td>" + Math.round((i - 32)*5/9) + "</td>")
      out.println ("</tr>")
    }
  </bsf:scriptlet>
  </table>
  <bsf:expression language="javascript"> new java.util.Date() </bsf:expression>
  
  <hr>In Perl
  <table BORDER COLS=2 WIDTH="20%" >
  <tr BGCOLOR="#FFFF00">
  <th>Fahrenheit</th>
  <th>Celsius</th>
  </tr>
  <bsf:scriptlet language="perlscript">
    for ($i=60; $i<=100; $i+=10) {
      $out->println ("<tr ALIGN=RIGHT BGCOLOR=\"#CCCCCC\">");
      $out->println ("<td>$i</td>");
      $out->println ("<td>" . int(($i - 32)*5/9) . "</td>");
      $out->println ("</tr>");
    }
  </bsf:scriptlet>
  </table>
  <bsf:expression language="perlscript"> CreateBean("java.util.Date") </bsf:expression>
  
  <hr>In JACL
  <table BORDER COLS=2 WIDTH="20%" >
  <tr BGCOLOR="#FFFF00">
  <th>Fahrenheit</th>
  <th>Celsius</th>
  </tr>
  <bsf:scriptlet language="jacl">
  package require java
  
  for {set i 60} {$i<=100} {incr i 10} {
    $out println "<tr ALIGN=RIGHT BGCOLOR=\"#CCCCCC\">"
    $out println "<td>$i</td>"
    $out println [concat "<td>" [format %4.2f [expr ($i - 32.0)*5/9]] "</td>"]
    $out println "</tr>"
  }
  </bsf:scriptlet>
  </table>
  
  
  <hr>In JPython
  <table BORDER COLS=2 WIDTH="20%" >
  <tr BGCOLOR="#FFFF00">
  <th>Fahrenheit</th>
  <th>Celsius</th>
  </tr>
  <bsf:scriptlet language="jpython">
  from java.util import Date;
  
  for i in range(60,100,10):
    out.println ("<tr ALIGN=RIGHT BGCOLOR=\"#CCCCCC\">");
    out.println ("<td>%d</td>" % i);
    out.println ("<td>%4.2f</td>" % ((i - 32.0)*5/9));
    out.println ("</tr>");
  </bsf:scriptlet>
  </table>
  
  <hr>In LotusScript
  <table BORDER COLS=2 WIDTH="20%" >
  <tr BGCOLOR="#FFFF00">
  <th>Fahrenheit</th>
  <th>Celsius</th>
  </tr>
  <bsf:scriptlet language="lotusscript">
  for i = 60 to 100 step 10
      out.println "<tr ALIGN=RIGHT BGCOLOR=""#CCCCCC"">"
      out.println "<td>" &  i & "</td>"
      out.println "<td>" & format((i - 32)*5/9," 0.00") & "</td>"
      out.println "</tr>"
      next
  </bsf:scriptlet>
  </table>
  
  <bsf:expression language="lotusscript"> CreateBean("java.util.Date") </bsf:expression>
  
  </body>
  </html>
  
  
  
  1.1                  jakarta-taglibs/bsf/src/org/apache/taglibs/bsf/expression.java
  
  Index: expression.java
  ===================================================================
  package org.apache.taglibs.bsf ;
  
  import javax.servlet.jsp.* ;
  import javax.servlet.jsp.tagext.* ;
  import java.io.IOException ;
  
  import com.ibm.bsf.* ;
  
  public class expression implements BodyTag
  {
      protected Tag          parent ;
      protected BodyContent  bodyOut ;
      protected PageContext  pageContext ;
      protected String       language ;
  
      public void setLanguage(String value)           { language = value ; };
      public void setParent(Tag parent)               { this.parent = parent ; };
      public Tag  getParent()                         { return( this.parent ); };
      public void doInitBody()  throws JspException   { };
      public int  doAfterBody() throws JspException   { return 0; };
      public void release()                           { };
      public void setBodyContent(BodyContent bodyOut) { this.bodyOut = bodyOut;};
      public int  doStartTag() throws JspException    { return(EVAL_BODY_TAG);};
  
      public void setPageContext(PageContext pageContext) { 
          this.pageContext = pageContext ;
      };
  
      private void register( BSFManager mgr, String name, Object bean ) 
                       throws Exception {
  	if ( bean == null ) return ;
          try {
  	    mgr.declareBean( name, bean, bean.getClass() );
  	}
  	catch( Exception e ) {
  	    throw e ;
  	}
      };
  
      public int doEndTag() throws JspException {
          try {
              JspWriter out = pageContext.getOut();
  	    if ( bodyOut == null ) return( EVAL_PAGE );
  
              BSFManager mgr  = new BSFManager ();
              BSFEngine  BSFengine = mgr.loadScriptingEngine (language);
  
              try {
  	        register( mgr, "request"    , pageContext.getRequest() );
  		register( mgr, "response"   , pageContext.getResponse() );
  		register( mgr, "pageContext", pageContext );
  		register( mgr, "application", pageContext.getServletContext() );
  		register( mgr, "out"        , out );
  		register( mgr, "config"     , pageContext.getServletConfig() );
  		register( mgr, "page"       , pageContext.getPage() );
  		register( mgr, "exception"  , pageContext.getException() );
  		register( mgr, "session"    , pageContext.getSession() );
  	    } catch( Exception e ) {
  	        out.println( e.toString() );
  	        e.printStackTrace();
  	    }
  
  	    Object result ;
  	    result = BSFengine.eval ("<unknown>", 0, 0, bodyOut.getString() );
  	    if ( result != null )
  	        out.println( result.toString() );
  	} catch( Exception e ) {
  	    System.out.println( e.toString() );
  	    e.printStackTrace();
  	    // throw new JspException( e.toString() );
  	}
          return( EVAL_PAGE );
      };
  }
  
  
  
  1.1                  jakarta-taglibs/bsf/src/org/apache/taglibs/bsf/scriptlet.java
  
  Index: scriptlet.java
  ===================================================================
  package org.apache.taglibs.bsf ;
  
  import javax.servlet.jsp.* ;
  import javax.servlet.jsp.tagext.* ;
  import java.io.IOException ;
  
  import com.ibm.bsf.* ;
  
  public class scriptlet implements BodyTag
  {
      protected Tag          parent ;
      protected BodyContent  bodyOut ;
      protected PageContext  pageContext ;
      protected String       language ;
  
      public void setLanguage(String value)           { language = value ; };
      public void setParent(Tag parent)               { this.parent = parent ; };
      public Tag  getParent()                         { return( this.parent ); };
      public void doInitBody()  throws JspException   { };
      public int  doAfterBody() throws JspException   { return 0; };
      public void setBodyContent(BodyContent bodyOut) { this.bodyOut = bodyOut;};
      public int  doStartTag() throws JspException    { return(EVAL_BODY_TAG);};
      public void release()                           { };
  
      public void setPageContext(PageContext pageContext) { 
          this.pageContext = pageContext ;
      };
  
      private void register( BSFManager mgr, String name, Object bean ) 
                       throws Exception {
  	if ( bean == null ) return ;
          try {
              mgr.declareBean( name, bean, bean.getClass() );
  	}
  	catch( Exception e ) {
  	    throw e ;
  	}
      };
  
      public int doEndTag() throws JspException {
          try {
              JspWriter out = pageContext.getOut();
  	    if ( bodyOut == null ) return( EVAL_PAGE );
  
              BSFManager mgr  = new BSFManager();
              BSFEngine  engine = mgr.loadScriptingEngine(language);
  
              try {
  	        register( mgr, "request"    , pageContext.getRequest() );
  		register( mgr, "response"   , pageContext.getResponse() );
  		register( mgr, "pageContext", pageContext );
  		register( mgr, "application", pageContext.getServletContext() );
  		register( mgr, "out"        , out );
  		register( mgr, "config"     , pageContext.getServletConfig() );
  		register( mgr, "page"       , pageContext.getPage() );
  		register( mgr, "exception"  , pageContext.getException() );
  		register( mgr, "session"    , pageContext.getSession() );
  	    } catch( Exception e ) {
  	        out.println( e.toString() );
  	        e.printStackTrace();
  	    }
  
  	    engine.exec ("<JSP>", 1, 1, bodyOut.getString() );
  
  	} catch( Exception e ) {
  	    System.out.println( e.toString() );
  	    e.printStackTrace();
  	    // throw new JspException( e.toString() );
  	}
          return( EVAL_PAGE );
      };
  
  }
  
  
  

Mime
View raw message