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/xsl/src/org/apache/taglibs/xsl ApplyTag.java ExportTag.java ImportTag.java ImportTei.java IncludeTag.java ClearResponse.java InsertWithXSL.java Return.java
Date Mon, 03 Jul 2000 19:30:24 GMT
craigmcc    00/07/03 12:30:21

  Modified:    xsl      build.xml
               xsl/conf taglib.tld
               xsl/examples/web index.html
  Added:       xsl/examples/web/jsp Apply.jsp
               xsl/examples/web/xml employeeList.xsl employees.xml
               xsl/src/org/apache/taglibs/xsl ApplyTag.java ExportTag.java
                        ImportTag.java ImportTei.java IncludeTag.java
  Removed:     xsl/examples/web/jsp XslExample.jsp
               xsl/examples/web/xml foo.xml foo.xsl
               xsl/src/org/apache/taglibs/xsl ClearResponse.java
                        InsertWithXSL.java Return.java
  Log:
  Major improvements to the XSL tag library:
  
  * New "apply" tag replaces the "InsertWithXSL" tag and adds the
    ability to retrieve the XML data, and/or the XSL stylesheet, from
    the nested body of this bean or from a JSP bean that already exists.
  
  * New "export" bean renders the content of a JSP bean (presumably after
    manipulation) to the output writer.
  
  * New "import" bean that requests dynamically created data (presumably
    in XML format) from a context-relative URL, and stores it in a JSP bean
    for future manipulation by beans such as "apply" and "export".
  
  * New "include" bean that requests dynamically created data (presumably
    in XML format) from a context-relative URL, and renders it the the
    current writer.  This differs from <jsp:include>, which renders the
    included data directly to the servlet response.
  
  Future improvements will be the ability to perform some simple
  transformations on imported or included XML data, without requiring a
  complex XSL stylesheet.
  
  Revision  Changes    Path
  1.2       +23 -12    jakarta-taglibs/xsl/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/xsl/build.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- build.xml	2000/05/13 20:29:46	1.1
  +++ build.xml	2000/07/03 19:28:51	1.2
  @@ -1,5 +1,5 @@
   <!-- ANT Build Script for the "xsl" Custom Tag Library -->
  -<!-- $Id: build.xml,v 1.1 2000/05/13 20:29:46 nacho Exp $ -->
  +<!-- $Id: build.xml,v 1.2 2000/07/03 19:28:51 craigmcc Exp $ -->
   <project name="xsl" default="main" basedir=".">
   
       <!-- ******************** Adjustable Properties *********************** -->
  @@ -14,20 +14,24 @@
   				    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.
  +	servlet.jar		    Pathname to the "servlet.jar" file
  +	                            from the Servletapi distribution.
   
           taglib.name		    Base name of this tag library subproject.
   
  +	xalan.jar                   Pathname to the "xalan.jar" file from the
  +	                            Xalan distribution.
  +
  +	xerces.jar		    Pathname to the "xerces.jar" file from the
  +	                            Xerces or Xalan distribution.
  +
       -->
   
       <property name="taglib.name"    value="xsl"/>
  -    <property name="ant.home"    value="../../jakarta-ant"/>
  -    <property name="servlet.jar"    value="../../jakarta-tools/servlet-2.2.0.jar"/>
  -    <property name="xsl.jar"       value="lib/xerces.jar;lib/xalan.jar"/>
  +    <property name="ant.home"       value="../../jakarta-ant"/>
  +    <property name="servlet.jar"    value="../../jakarta-servletapi/lib/servlet.jar"/>
  +    <property name="xalan.jar"      value="../../xml-xalan/xalan.jar"/>
  +    <property name="xerces.jar"     value="../../xml-xalan/xerces.jar"/>
   
   
       <!-- ****************** Project Standard Properties ******************* -->
  @@ -46,6 +50,7 @@
       <property name="build.dir"      value="../../build/taglibs"/>
       <property name="dist.dir"       value="../../dist/taglibs"/>
   
  +
       <!-- *********************** Default Properties ********************** -->
   
       <!--
  @@ -123,7 +128,7 @@
       <copydir src="${doc.src}/web"       dest="${build.doc}"/>
   <!--
       <javac srcdir="${doc.src}/src"   destdir="${build.doc}/WEB-INF/classes"
  -           classpath="${servlet.jar}" debug="on"/>
  +           classpath="${servlet.jar};${xalan.jar};${xerces.jar}" debug="on"/>
   -->
     </target>
   
  @@ -137,10 +142,16 @@
                 dest="${build.examples}/WEB-INF/${taglib.name}.tld"/>
       <copyfile src="${dist.library}"
                 dest="${build.examples}/WEB-INF/lib/${taglib.name}.jar"/>
  +    <copyfile  src="${servlet.jar}"
  +              dest="${build.examples}/WEB-INF/lib/servlet.jar"/>
  +    <copyfile  src="${xerces.jar}"
  +              dest="${build.examples}/WEB-INF/lib/xerces.jar"/>
  +    <copyfile  src="${xalan.jar}"
  +              dest="${build.examples}/WEB-INF/lib/xalan.jar"/>
   <!--
       <javac srcdir="${examples.src}/src"
              destdir="${build.examples}/WEB-INF/classes"
  -           classpath="${servlet.jar}" debug="on"/>
  +           classpath="${servlet.jar};${xalan.jar};${xerces.jar}" debug="on"/>
   -->
     </target>
   
  @@ -149,7 +160,7 @@
       <copyfile src="${conf.src}/taglib.tld"
                 dest="${build.library}/META-INF/taglib.tld"/>
       <javac srcdir="${library.src}" destdir="${build.library}"
  -           classpath="${servlet.jar};${xsl.jar}" debug="on"/>
  +           classpath="${servlet.jar};${xalan.jar};${xerces.jar}" debug="on"/>
     </target>
   
     <!-- Compile the library as well as the associated applications -->
  
  
  
  1.2       +173 -24   jakarta-taglibs/xsl/conf/taglib.tld
  
  Index: taglib.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/xsl/conf/taglib.tld,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- taglib.tld	2000/05/13 20:29:46	1.1
  +++ taglib.tld	2000/07/03 19:29:05	1.2
  @@ -1,62 +1,211 @@
   <?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">
  +        "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
   
  -<!-- a tab library descriptor -->
  +<!-- The tag library descriptor -->
   
   <taglib>
  -  <!-- after this the default space is
  -	"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"
  -   -->
   
  +  <!-- Basic library information -->
     <tlibversion>1.0</tlibversion>
     <jspversion>1.1</jspversion>
     <shortname>Simple XSL Tags Library</shortname>
     <uri>http://jakarta.apache.org/taglibs/xsl-1.0</uri>
     
     <info>
  -  	A simple tab library for the xml data.
  +	A simple tag library for processing XML input sources
  +	with XML stylesheet transformations.
     </info>
   
  -  <!-- InsertWithXSL tag -->
  +
  +  <!-- Apply XSL Transformations Tag -->
     <tag>
  -    <name>InsertWithXSL</name>
  -    <tagclass>org.apache.taglibs.xsl.InsertWithXSL</tagclass>
  +    <name>apply</name>
  +    <tagclass>org.apache.taglibs.xsl.ApplyTag</tagclass>
  +    <bodycontent>JSP</bodycontent>
       <info>
  -	Apply a given stylesheet to a given XML document.
  +      Apply the specified stylesheet to the specified XML input, both of
  +      which may be acquired in a variety of manners depending upon
  +      the optional attributes that are included.  Available attributes:
  +
  +      nameXml            Name of a bean (in any scope) that defines the
  +                         source of the XML data to be transformed.  This
  +                         bean must be of one of the following Java classes:
  +                         String (containing the XML data itself)
  +			 InputSource (SAX input source containing the data)
  +			 InputStream (byte stream containing the data)
  +			 Node (DOM tree containing the data
  +			 Reader (character stream containing the data)
  +                         XSLTInputSource (from which the data is read)
  +
  +      nameXsl            Name of a bean (in any scope) that defines the
  +                         source of the XSL stylesheet to be used.  This
  +                         bean must be of one of the following Java classes:
  +			 String (containing the stylesheet itself)
  +			 InputSource (SAX input source containing the
  +                           stylesheet)
  +                         InputStream (byte stream containing the stylesheet)
  +                         Node (DOM tree containing the stylesheet)
  +                         Reader (character stream containing the stylesheet)
  +                         XSLTInputSource (from which the stylesheet is read)
  +
  +      propertyXml	 If specified, the bean identified by "nameXml"
  +                         is assumed to have a property whose getter method
  +                         is called to define the XML data source, instead
  +                         of interpreting that bean itself.
  +
  +      propertyXsl        If specified, the bean identified by "nameXsl"
  +                         is assumed to have a property whose getter method
  +                         is called to define the XSL stylesheet source, instead
  +			 of interpreting that bean itself
  +
  +      xml                If specified, the context-relative path to an
  +                         application resource containing the XML data.
  +
  +      xsl		 If specified, the context-relative path to an
  +                         application resource containing the XSL stylesheet.
  +
  +      Valid attribute combinations to select the XML data source are:
  +      * "nameXml" - The named bean defines the data source.
  +      * "nameXml" and "propertyXml" - The named property of the named bean
  +        defines the data source.
  +      * "xml" - The named resource is read (with getResourceAsStream())
  +        to provide the data source.
  +      * (none) - The body of this tag is interpreted as the XML data source.
  +
  +      Valid attribute combinations to select the XSL stylesheet source are:
  +      * "nameXsl" - The named bean defines the stylesheet source.
  +      * "nameXsl" and "propertyXsl" - The named property of the named bean
  +        defines the data source.
  +      * "xsl" - The named resource is read (with getResourceAsStream())
  +        to provide the data source.
       </info>
  +    <attribute>
  +      <name>nameXml</name>
  +      <required>false</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +      <name>nameXsl</name>
  +      <required>false</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +      <name>propertyXml</name>
  +      <required>false</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +      <name>propertyXsl</name>
  +      <required>false</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
       <attribute>
  -	<name>url</name>
  -	<required>true</required>
  -	<rtexprvalue>true</rtexprvalue>
  +      <name>xml</name>
  +      <required>false</required>
  +      <rtexprvalue>true</rtexprvalue>
       </attribute>
       <attribute>
  -	<name>xsl</name>
  -	<required>true</required>
  -	<rtexprvalue>true</rtexprvalue>
  +      <name>xsl</name>
  +      <required>false</required>
  +      <rtexprvalue>true</rtexprvalue>
       </attribute>
     </tag>
   
  -  <!-- clearResponse tag -->
  +
  +  <!-- Export Tag -->
     <tag>
  -    <name>clearResponse</name>
  -    <tagclass>org.apache.taglibs.xsl.ClearResponse</tagclass>
  +    <name>export</name>
  +    <tagclass>org.apache.taglibs.xsl.ExportTag</tagclass>
       <bodycontent>empty</bodycontent>
       <info>
  -	Clear the response stream.
  +      Export the contents of the specified JSP bean in the specified scope
  +      to our output stream, presumably after its contents have been
  +      manipulated.  Available attributes:
  +
  +      name                Name of a JSP bean whose content is to be
  +                          rendered to our output stream.
  +
  +      scope               Scope in which this bean is registered.  If not
  +                          specified, page scope is assumed.
       </info>
  +    <attribute>
  +      <name>name</name>
  +      <required>true</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +      <name>scope</name>
  +      <required>false</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
     </tag>
  +
   
  -  <!-- return tag -->
  +  <!-- Import Tag -->
     <tag>
  -    <name>return</name>
  -    <tagclass>org.apache.taglibs.xsl.Return</tagclass>
  +    <name>import</name>
  +    <tagclass>org.apache.taglibs.xsl.ImportTag</tagclass>
  +    <teiclass>org.apache.taglibs.xsl.ImportTei</teiclass>
       <bodycontent>empty</bodycontent>
       <info>
  -	Convenience to return stream.
  +      Import the contents of the specified page, and store it as a String
  +      in the specified bean and scope.  This tag is useful for assigning the
  +      content of XML data (or an XSL stylesheet) to a bean that can later be
  +      manipulated with the "apply" tag.  Available attributes:
  +
  +      id                  Name of a JSP bean to be created containing the
  +                          contents of the specified page as a String.
  +
  +      page                Context-relative URI of the page (or servlet) to
  +                          be executed, and whose output should be imported.
  +
  +      scope               Scope in which the bean specified by "id" will be
  +                          created (page, request, session, application).  If
  +                          not specified, page scope is assumed.
       </info>
  +    <attribute>
  +      <name>id</name>
  +      <required>true</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +      <name>page</name>
  +      <required>true</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +      <name>scope</name>
  +      <required>false</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +  </tag>
  +
  +
  +  <!-- Include Tag -->
  +  <tag>
  +    <name>include</name>
  +    <tagclass>org.apache.taglibs.xsl.IncludeTag</tagclass>
  +    <bodycontent>empty</bodycontent>
  +    <info>
  +      Include the contents of the specified page.  This tag is similar to
  +      &lt;jsp:include&gt;, but causes the included contents to be rendered to
  +      our JspWriter (and thus to the body content of any enclosing tag)
  +      rather than being sent directly to the output stream.  Available
  +      attributes:
  +
  +      page                Context-relative URI of the page (or servlet) to
  +                          be executed, and whose output should be included
  +                          at this point.
  +    </info>
  +    <attribute>
  +      <name>page</name>
  +      <required>true</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
     </tag>
  +
   
     <!-- This tag doesn't really belong here -->
     <tag>
  
  
  
  1.2       +89 -48    jakarta-taglibs/xsl/examples/web/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/xsl/examples/web/index.html,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- index.html	2000/05/13 20:29:47	1.1
  +++ index.html	2000/07/03 19:29:17	1.2
  @@ -1,67 +1,108 @@
  -<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
   <html>
   <head>
  -   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  -   <meta name="GENERATOR" content="Mozilla/4.61 [en] (WinNT; I) [Netscape]">
  -   <meta name="Author" content="Anil K. Vijendran">
  -   <title>JSP Examples</title>
  -<!--
  -  Copyright (c) 1999 The Apache Software Foundation.  All rights 
  -  reserved.
  --->
  +   <title>JSP+XML Custom Tag Examples</title>
   </head>
  -<body bgcolor="#FFFFFF">
  -<b><font face="Arial, Helvetica, sans-serif"><font size=+2>JSP+XML
  -Custom Tags Examples</font></font></b>
  -<p>This is a collection of JSP custom-tags.
  -<p>To navigate your way through the examples, the following icons will
  -help:
  -<br>&nbsp;
  -<table BORDER=0 CELLSPACING=5 WIDTH="85%" >
  -<tr VALIGN=TOP>
  -<td WIDTH="30"><img SRC="images/execute.gif" ></td>
  -
  -<td>Execute the example</td>
  -</tr>
  -
  -<tr VALIGN=TOP>
  -<td WIDTH="30"><img SRC="images/code.gif" height=24 width=24></td>
  +<body bgcolor="white">
   
  -<td>Look at the source code for the example</td>
  -</tr>
  +<h1>JSP+XML Custom Tag Examples</h1>
   
  -<tr VALIGN=TOP>
  -<td WIDTH="30"><img SRC="images/return.gif" height=24 width=24></td>
  +<h3>Introduction</h3>
   
  -<td>Return to this screen</td>
  -</tr>
  -</table>
  +<p>This library contains a collection of JSP custom tags that are useful
  +in manipulating XML data content using XSL stylesheets.  In order to execute
  +these tags, you must have downloaded the Xalan distribution from
  +<a href="http://xml.apache.org">http://xml.apache.org</a>, and have installed
  +the <code>xalan.jar</code> and <code>xerces.jar</code> files into your
  +application's <code>/WEB-INF/lib</code> directory.</p>
  +
  +<p>When navigating the examples, the following icons will help:</p>
  +
  +<table border="0">
   
  -<br>&nbsp;
  -<table BORDER=0 CELLSPACING=5 WIDTH="85%" >
  -<tr VALIGN=TOP>
  -<td>InsertWithXSL&nbsp;</td>
  +  <tr>
  +    <td width="30"><img src="images/execute.gif"></td>
  +    <td>Execute the example JSP page</td>
  +  </tr>
  +
  +  <tr>
  +    <td width="30"><img src="images/code.gif"></td>
  +    <td>Look at the source code of the example JSP page,
  +        or one of the custom tag implementation classes.</td>
  +  </tr>
  +
  +</table>
   
  -<td VALIGN=TOP WIDTH="30%"><a href="/xsl-examples/jsp/XslExample.jsp"><img SRC="images/execute.gif" HSPACE=4 BORDER=0  align=TOP></a><a href="/xsl-examples/jsp/XslExample.jsp">Execute</a></td>
  +<h3>The Example Page</h3>
   
  -<td WIDTH="30%"><a href="/xsl-examples/jsp/ShowSource.jsp?jspFile=/jsp/XslExample.jsp"><img SRC="images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="/xsl-examples/jsp/ShowSource.jsp?jspFile=/jsp/XslExample.jsp">JSP </a></td>
  +<table border="0">
   
  -<td WIDTH="30%"><a href="/xsl-examples/jsp/ShowSource.jsp?jspFile=/WEB-INF/classes/org/apache/taglibs/xsl/InsertWithXSL.java"><img SRC="images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="/xsl-examples/jsp/ShowSource.jsp?jspFile=/WEB-INF/classes/org/apache/taglibs/xsl/InsertWithXSL.java">TagHandler </a></td>
  -</tr>
  +  <tr>
  +    <td width="30">
  +      <a href="jsp/Apply.jsp"><img border="0" src="images/execute.gif"></a>
  +    </td>
  +    <td width="170">
  +      <a href="jsp/Apply.jsp">Apply.jsp</a>
  +    <td width="30">
  +      <a href="jsp/ShowSource.jsp?jspFile=/jsp/Apply.jsp"><img border="0" src="images/code.gif"></a>
  +    </td>
  +    <td width="170">
  +      <a href="jsp/ShowSource.jsp?jspFile=/jsp/Apply.jsp">Apply.jsp</a>
  +    </td>
  +  </tr>
   
  -<tr VALIGN=TOP>
  -<td>ClearResponse&nbsp;</td>
  +</table>
   
  -<td WIDTH="30%"><a href="/xsl-examples/jsp/ShowSource.jsp?jspFile=/WEB-INF/classes/org/apache/taglibs/xsl/ClearResponse.java"><img SRC="images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="/xsl-examples/jsp/ShowSource.jsp?jspFile=/WEB-INF/classes/org/apache/taglibs/xsl/ClearResponse.java">TagHandler </a></td>
  -</tr>
  +<h3>The Custom Tag Classes</h3>
   
  -<tr VALIGN=TOP>
  -<td>Return&nbsp;</td>
  +<table border="0">
   
  -<td WIDTH="30%"><a href="/xsl-examples/jsp/ShowSource.jsp?jspFile=/WEB-INF/classes/org/apache/taglibs/xsl/Return.java"><img SRC="images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="/xsl-examples/jsp/ShowSource.jsp?jspFile=/WEB-INF/classes/org/apache/taglibs/xsl/Return.java">TagHandler </a></td>
  -</tr>
  +  <tr>
  +    <td width="30">
  +      <a href="jsp/ShowSource.jsp?jspFile=/WEB-INF/classes/org/apache/taglibs/xsl/ApplyTag.java"><img border="0" src="images/code.gif"></a>
  +    </td>
  +    <td width="170">
  +      <a href="jsp/ShowSource.jsp?jspFile=/WEB-INF/classes/org/apache/taglibs/xsl/ApplyTag.java">ApplyTag.java</a>
  +    </td>
  +    <td width="30">
  +      <a href="jsp/ShowSource.jsp?jspFile=/WEB-INF/classes/org/apache/taglibs/xsl/ExportTag.java"><img border="0" src="images/code.gif"></a>
  +    </td>
  +    <td width="170">
  +      <a href="jsp/ShowSource.jsp?jspFile=/WEB-INF/classes/org/apache/taglibs/xsl/ExportTag.java">ExportTag.java</a>
  +    </td>
  +  </tr>
  +
  +  <tr>
  +    <td width="30">
  +      <a href="jsp/ShowSource.jsp?jspFile=/WEB-INF/classes/org/apache/taglibs/xsl/ImportTag.java"><img border="0" src="images/code.gif"></a>
  +    </td>
  +    <td width="170">
  +      <a href="jsp/ShowSource.jsp?jspFile=/WEB-INF/classes/org/apache/taglibs/xsl/ImportTag.java">ImportTag.java</a>
  +    </td>
  +    <td width="30">
  +      <a href="jsp/ShowSource.jsp?jspFile=/WEB-INF/classes/org/apache/taglibs/xsl/IncludeTag.java"><img border="0" src="images/code.gif"></a>
  +    </td>
  +    <td width="170">
  +      <a href="jsp/ShowSource.jsp?jspFile=/WEB-INF/classes/org/apache/taglibs/xsl/IncludeTag.java">IncludeTag.java</a>
  +    </td>
  +  </tr>
   
   </table>
  +
  +<h3>Historical Note</h3>
  +
  +<p>The original version of this tag library had an <code>InsertWithXSL</code>
  +tag, whose functionality has been absorbed into the new <code>apply</code>
  +tag.  If you were using the former version, simply replace any use of:</p>
  +
  +<pre>
  +    &lt;xsl:InsertWithXSL url="/xml/data.xml" xsl="/xml/style.xsl"/&gt;
  +</pre>
  +
  +<p>with the new syntax:</p>
  +
  +<pre>
  +    &lt;xsl:apply xml="/xml/data.xml" xsl="/xml/style.xsl"/&gt;
  +</pre>
   
   </body>
   </html>
  
  
  
  1.1                  jakarta-taglibs/xsl/examples/web/jsp/Apply.jsp
  
  Index: Apply.jsp
  ===================================================================
  <%@taglib uri="http://jakarta.apache.org/taglibs/xsl-1.0" prefix="xsl" %>
  
  <html>
  <head>
  <title>Employee List</title>
  </head>
  <body bgcolor="white">
  
  <p>This page creates several versions of the same table, using the same XML
  data and XSL stylesheet (so that the output should appear identically), but
  using different techniques to retrieve the XML data.  Display the source of
  this JSP page (from the examples menu) to see how these techniques are used.
  </p>
  <hr>
  
  <p>This version of the table was created by reading an external XML document
  and an external XSL stylesheet.</p>
  
  <xsl:apply xml="/xml/employees.xml" xsl="/xml/employeeList.xsl"/>
  <hr>
  
  <p>This version of the table was created by treating the nested content as
  the XML document (simulating the case where the JSP page itself would be
  rendering XML output), but using an external XSL stylesheet.</p>
  
  <xsl:apply xsl="/xml/employeeList.xsl">
  <?xml version="1.0" encoding="ISO-8859-1"?>
  <employees>
    <employee id="123">
      <first-name>John</first-name>
      <last-name>Doe</last-name>
      <telephone>800-555-1212</telephone>
    </employee>
    <employee id="456">
      <first-name>Jane</first-name>
      <last-name>Smith</last-name>
      <telephone>888-555-1212</telephone>
    </employee>
    <employee id="789">
      <first-name>George</first-name>
      <last-name>Taylor</last-name>
      <telephone>555-555-1212</telephone>
    </employee>
  </employees>
  </xsl:apply>
  <hr>
  
  <p>This version of the table was created by loading the nested content with
  an <code>&lt;xsl:include&gt;</code> action (simulating asking a different
  servlet or JSP page to render the desired XML data) and using the same
  external XSL stylesheet.</p>
  
  <xsl:apply xsl="/xml/employeeList.xsl">
    <xsl:include page="/xml/employees.xml"/>
  </xsl:apply>
  <hr>
  
  <p>This version of the table was created by importing the XML data into a
  page-scope attribute, and then applying the stylesheet to it.</p>
  
  <xsl:import id="data" page="/xml/employees.xml"/>
  <xsl:apply nameXml="data" xsl="/xml/employeeList.xsl"/>
  
  </body>
  
  
  
  1.1                  jakarta-taglibs/xsl/examples/web/xml/employeeList.xsl
  
  Index: employeeList.xsl
  ===================================================================
  <?xml version="1.0"?> 
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
    <xsl:template match="employees">
      <table border="1" width="100%">
        <tr>
          <th>ID</th>
          <th>Employee Name</th>
          <th>Phone Number</th>
        </tr>
        <xsl:for-each select="employee">
          <tr>
            <td>
              <xsl:value-of select="@id"/>
            </td>
            <td>
              <xsl:value-of select="last-name"/>, 
              <xsl:value-of select="first-name"/>
            </td>
            <td>
              <xsl:value-of select="telephone"/>
            </td>
          </tr>
        </xsl:for-each>
      </table>
    </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.1                  jakarta-taglibs/xsl/examples/web/xml/employees.xml
  
  Index: employees.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  <employees>
    <employee id="123">
      <first-name>John</first-name>
      <last-name>Doe</last-name>
      <telephone>800-555-1212</telephone>
    </employee>
    <employee id="456">
      <first-name>Jane</first-name>
      <last-name>Smith</last-name>
      <telephone>888-555-1212</telephone>
    </employee>
    <employee id="789">
      <first-name>George</first-name>
      <last-name>Taylor</last-name>
      <telephone>555-555-1212</telephone>
    </employee>
  </employees>
  
  
  
  
  1.1                  jakarta-taglibs/xsl/src/org/apache/taglibs/xsl/ApplyTag.java
  
  Index: ApplyTag.java
  ===================================================================
  /*
   * $Id: ApplyTag.java,v 1.1 2000/07/03 19:30:00 craigmcc Exp $
   * ====================================================================
   *
   * 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
   * modification, 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 acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", 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 names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.taglibs.xsl;
  
  
  import java.io.InputStream;
  import java.io.Reader;
  import java.io.StringReader;
  import java.lang.reflect.Method;
  import javax.servlet.ServletContext;
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.tagext.BodyTagSupport;
  import org.apache.xalan.xslt.XSLTInputSource;
  import org.apache.xalan.xslt.XSLTProcessor;
  import org.apache.xalan.xslt.XSLTProcessorFactory;
  import org.apache.xalan.xslt.XSLTResultTarget;
  import org.w3c.dom.Node;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  
  
  /**
   * Apply an XSL stylesheet to an XML data source, rendering the output
   * to the writer of our JSP page.  This tag uses the Xalan XSLT processor,
   * available at <code>http://xml.apache.org</code>.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/07/03 19:30:00 $
   */
  
  public class ApplyTag extends BodyTagSupport {
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * The body content of this tag, if we are using it as the data source.
       */
      private String body = null;
  
  
      /**
       * The name of the XML data bean.
       */
      private String nameXml = null;
  
      public String getNameXml() {
  	return (this.nameXml);
      }
  
      public void setNameXml(String nameXml) {
  	this.nameXml = nameXml;
      }
  
  
      /**
       * The name of the XSL stylesheet bean.
       */
      private String nameXsl = null;
  
      public String getNameXsl() {
  	return (this.nameXsl);
      }
  
      public void setNameXsl(String nameXsl) {
  	this.nameXsl = nameXsl;
      }
  
  
      /**
       * The property of the XML data bean.
       */
      private String propertyXml = null;
  
      public String getPropertyXml() {
  	return (this.propertyXml);
      }
  
      public void setPropertyXml(String propertyXml) {
  	this.propertyXml = propertyXml;
      }
  
  
      /**
       * The property of the XSL stylesheet bean.
       */
      private String propertyXsl = null;
  
      public String getPropertyXsl() {
  	return (this.propertyXsl);
      }
  
      public void setPropertyXsl(String propertyXsl) {
  	this.propertyXsl = propertyXsl;
      }
  
  
      /**
       * The XML data resource.
       */
      private String xml = null;
  
      public String getXml() {
  	return (this.xml);
      }
  
      public void setXml(String xml) {
  	this.xml = xml;
      }
  
  
      /**
       * The XSL stylesheet resource.
       */
      private String xsl = null;
  
      public String getXsl() {
  	return (this.xsl);
      }
  
      public void setXsl(String xsl) {
  	this.xsl = xsl;
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Validate the attributes that were specified for consistency.
       * Evaluate the body content of this tag if we will be using it as the
       * XML data source; otherwise skip it.
       *
       * @exception JspException if a JSP error occurs
       */
      public int doStartTag() throws JspException {
  
  	// Validate the data source attributes
  	if (nameXml != null) {
  	    if (xml != null)
  		throw new JspException
  		    ("Cannot specify both 'nameXml' and 'xml'");
  	} else if (propertyXml != null) {
  	    throw new JspException
  		("Cannot specify 'propertyXml' without 'nameXml'");
  	}
  
  	// Validate the stylesheet source attributes
  	if (nameXsl != null) {
  	    if (xsl != null)
  		throw new JspException
  		    ("Cannot specify both 'nameXsl' and 'xsl'");
  	} else if (propertyXsl != null) {
  	    throw new JspException
  		("Cannot specify 'propertyXsl' without 'nameXsl'");
  	}
  	if ((nameXsl == null) && (xsl == null)) {
  	    throw new JspException
  		("Must specify either 'nameXsl' or 'xsl'");
  	}
  
  	// Evaluate the tag body only if we need it
  	if ((nameXml == null) && (xml == null))
  	    return (EVAL_BODY_TAG);
  	else
  	    return (SKIP_BODY);
  
      }
  
  
      /**
       * Save the body content that has been processed, but do not iterate.
       *
       * @exception JspException if a JSP error has occurred
       */
      public int doAfterBody() throws JspException {
  
  	if (bodyContent == null)
  	    body = "";
  	else
  	    body = bodyContent.getString().trim();
  	return (SKIP_BODY);
  
      }
  
  
      /**
       * Finish up by performing the transformation and rendering the output.
       *
       * @exception JspException if a JSP exception occurs
       */
      public int doEndTag() throws JspException {
  
  	// Prepare an input source for the data
  	XSLTInputSource data = null;
  	if (body != null)
  	    data = new XSLTInputSource(new StringReader(body));
  	else
  	    data = getInputSource(nameXml, propertyXml, xml);
  
  	// Prepare an input source for the stylesheet
  	XSLTInputSource style =
  	    getInputSource(nameXsl, propertyXsl, xsl);
  
  	// Prepare an output source for the results
  	XSLTResultTarget result =
  	    new XSLTResultTarget(pageContext.getOut());
  
  	// Create an XSLT processor and use it to perform the transformation
  	XSLTProcessor processor = null;
  	try {
  	    processor = XSLTProcessorFactory.getProcessor();
  	    processor.process(data, style, result);
  	} catch (SAXException e) {
  	    throw new JspException(e.toString());
  	}
  	return (EVAL_PAGE);
  
      }
  
  
      /**
       * Release any allocated resources.
       */
      public void release() {
  
  	this.body = null;
  
      }
  
  
      // -------------------------------------------------------- Private Methods
  
  
      /**
       * Construct and return an XSLTInputSource based on the specified
       * parameters.
       *
       * @param name Name of a bean containing the input source (or has a
       *  property that returns the input source)
       * @param property Name of a property of the specified bean that
       *  returns the input source
       * @param resource Context-relative path to an application resource
       *  that provides the input source
       *
       * @exception JspException if a JSP error occurs
       */
      private XSLTInputSource getInputSource(String name, String property,
  					   String resource)
  	throws JspException {
  
  
  	// If the resource is specified, use that for the input source
  	if (resource != null) {
  	    ServletContext context = pageContext.getServletContext();
  	    if (context == null)
  		throw new JspException("Cannot find servlet context");
  	    InputStream stream =
  		context.getResourceAsStream(resource);
  	    if (stream == null)
  		throw new JspException("Missing resource '" + resource + "'");
  	    return new XSLTInputSource(stream);
  	}
  
  	// Locate the source object
  	Object source = null;
  	Object bean = pageContext.findAttribute(name);
  	if (bean == null)
  	    throw new JspException("Missing bean '" + name + "'");
  	if (property == null)
  	    source = bean;
  	else {
  	    try {
  		char first = Character.toUpperCase(property.charAt(0));
  		String methodName = "get" + first + property.substring(1);
  		Class paramTypes[] = new Class[0];
  		Method method =
  		    bean.getClass().getMethod(methodName, paramTypes);
  		source = method.invoke(bean, new Object[0]);
  	    } catch (Exception e) {
  		throw new JspException(e.toString());
  	    }
  	}
  
  
  	// Create an XSLTInputSource for the specified source object
  	if (source instanceof XSLTInputSource)
  	    return ((XSLTInputSource) source);
  	else if (source instanceof String)
  	    return (new XSLTInputSource(new StringReader((String) source)));
  	else if (source instanceof InputSource)
  	    return (new XSLTInputSource((InputSource) source));
  	else if (source instanceof InputStream)
  	    return (new XSLTInputSource((InputStream) source));
  	else if (source instanceof Node)
  	    return (new XSLTInputSource((Node) source));
  	else if (source instanceof Reader)
  	    return (new XSLTInputSource((Reader) source));
  	else
  	    throw new JspException("Invalid input source type '" +
  				   source.getClass().getName() + "'");
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-taglibs/xsl/src/org/apache/taglibs/xsl/ExportTag.java
  
  Index: ExportTag.java
  ===================================================================
  /*
   * $Id: ExportTag.java,v 1.1 2000/07/03 19:30:00 craigmcc Exp $
   * ====================================================================
   *
   * 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
   * modification, 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 acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", 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 names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.taglibs.xsl;
  
  
  import java.io.BufferedInputStream;
  import java.io.InputStreamReader;
  import java.net.URL;
  import java.net.URLConnection;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.JspWriter;
  import javax.servlet.jsp.PageContext;
  import javax.servlet.jsp.tagext.TagSupport;
  
  
  /**
   * Export the content of the specified JSP bean (in the specified scope)
   * to our output writer, presumably after modifications have been completed.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/07/03 19:30:00 $
   */
  
  public class ExportTag extends TagSupport {
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * The name of the scripting variable to be accessed.
       */
      private String name = null;
  
      public String getName() {
  	return (this.name);
      }
  
      public void setName(String name) {
  	this.name = name;
      }
  
  
      /**
       * The scope in which the scripting variable should be accessed.
       */
      private String scope = "page";
  
      public String getScope() {
  	return (this.scope);
      }
  
      public void setScope(String scope) {
  	this.scope = scope;
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Export the contents of the specified JSP bean in the specified scope
       * to our output writer.
       *
       * @exception JspException if a JSP error occurs
       */
      public int doStartTag() throws JspException {
  
  	// Validate the value of the "scope" attribute
  	int scopeId = 0;
  	if ("page".equalsIgnoreCase(scope))
  	    scopeId = PageContext.PAGE_SCOPE;
  	else if ("request".equalsIgnoreCase(scope))
  	    scopeId = PageContext.REQUEST_SCOPE;
  	else if ("session".equalsIgnoreCase(scope))
  	    scopeId = PageContext.SESSION_SCOPE;
  	else if ("application".equalsIgnoreCase(scope))
  	    scopeId = PageContext.APPLICATION_SCOPE;
  	else
  	    throw new JspException("Invalid scope value '" + scope + "'");
  
  	// Acquire the bean we will be rendering
  	Object bean = pageContext.getAttribute(name, scopeId);
  	if (bean == null)
  	    throw new JspException("Missing JSP bean '" + name + "'");
  	;	// FIXME - Special handling for DOM, InputSource, etc.?
  	if (!(bean instanceof String))
  	    bean = bean.toString();
  
  	// Render the contents of this bean to our writer
  	try {
  	    JspWriter out = pageContext.getOut();
  	    out.print((String) bean);
  	} catch (Exception e) {
  	    throw new JspException("Error writing output: " + e.toString());
  	}
  
  	// Skip the body of this tag (which should be empty anyway)
  	return (SKIP_BODY);
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-taglibs/xsl/src/org/apache/taglibs/xsl/ImportTag.java
  
  Index: ImportTag.java
  ===================================================================
  /*
   * $Id: ImportTag.java,v 1.1 2000/07/03 19:30:03 craigmcc Exp $
   * ====================================================================
   *
   * 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
   * modification, 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 acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", 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 names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.taglibs.xsl;
  
  
  import java.io.BufferedInputStream;
  import java.io.InputStreamReader;
  import java.net.URL;
  import java.net.URLConnection;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.PageContext;
  import javax.servlet.jsp.tagext.TagSupport;
  
  
  /**
   * Import the content of the specified page, and assign it (as a String)
   * to the specified scripting variable in the specified scope.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/07/03 19:30:03 $
   */
  
  public class ImportTag extends TagSupport {
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * The name of the scripting variable to be created.
       */
      private String id = null;
  
      public String getId() {
  	return (this.id);
      }
  
      public void setId(String id) {
  	this.id = id;
      }
  
  
      /**
       * The URI of the page or servlet to be included.
       */
      private String page = null;
  
      public String getPage() {
  	return (this.page);
      }
  
      public void setPage(String page) {
  	this.page = page;
      }
  
  
      /**
       * The scope in which the scripting variable should be created.
       */
      private String scope = "page";
  
      public String getScope() {
  	return (this.scope);
      }
  
      public void setScope(String scope) {
  	this.scope = scope;
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Import the specified page and assign it to the specified bean
       * in the specified scope.
       *
       * @exception JspException if a JSP error occurs
       */
      public int doStartTag() throws JspException {
  
  	// Validate the format of the "page" attribute
  	// FIXME - deal with relative URIs like <jsp:include> does
  	if (!page.startsWith("/"))
  	    throw new JspException("Page value must start with '/'");
  
  	// Validate the value of the "scope" attribute
  	int scopeId = 0;
  	if ("page".equalsIgnoreCase(scope))
  	    scopeId = PageContext.PAGE_SCOPE;
  	else if ("request".equalsIgnoreCase(scope))
  	    scopeId = PageContext.REQUEST_SCOPE;
  	else if ("session".equalsIgnoreCase(scope))
  	    scopeId = PageContext.SESSION_SCOPE;
  	else if ("application".equalsIgnoreCase(scope))
  	    scopeId = PageContext.APPLICATION_SCOPE;
  	else
  	    throw new JspException("Invalid scope value '" + scope + "'");
  
  	// Set up the buffer to which we will write (if id is set)
  	StringBuffer sb = new StringBuffer();
  
  	// Set up a URLConnection to read the requested page.  We cannot use
  	// PageContext.include() because it writes directly to the output
  	// stream that goes back to the client. :-(
  	HttpServletRequest request =
  	    (HttpServletRequest) pageContext.getRequest();
  	StringBuffer url = new StringBuffer();
  	url.append(request.getScheme());
  	url.append("://");
  	url.append(request.getServerName());
  	if (request.getServerPort() != 80) {
  	    url.append(':');
  	    url.append(request.getServerPort());
  	}
  	if (request.getContextPath() != null)
  	    url.append(request.getContextPath());
  	url.append(page);	// FIXME - deal with relative page references
  	URLConnection conn = null;
  	try {
  	    conn = (new URL(url.toString())).openConnection();
  	    conn.setAllowUserInteraction(false);
  	    conn.setDoInput(true);
  	    conn.setDoOutput(false);
  	    conn.connect();
  	} catch (Exception e) {
  	    throw new JspException("Error opening connection: " +
  				   e.toString());
  	}
  
  	// Copy the contents of this URL
  	try {
  	    BufferedInputStream is =
  		new BufferedInputStream(conn.getInputStream());
  	    InputStreamReader in = new InputStreamReader(is);
  	    while (true) {
  		int ch = in.read();
  		if (ch < 0)
  		    break;
  		sb.append((char) ch);
  	    }
  	} catch (Exception e) {
  	    throw new JspException("Error reading connection: " +
  				   e.toString());
  	}
  
  	// Store the accumulated buffer as a bean
  	pageContext.setAttribute(id, sb.toString(), scopeId);
  
  	// Skip the body of this tag (which should be empty anyway)
  	return (SKIP_BODY);
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-taglibs/xsl/src/org/apache/taglibs/xsl/ImportTei.java
  
  Index: ImportTei.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-taglibs/xsl/src/org/apache/taglibs/xsl/ImportTei.java,v 1.1 2000/07/03 19:30:03 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/07/03 19:30:03 $
   *
   * ====================================================================
   *
   * 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
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", 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 names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  package org.apache.taglibs.xsl;
  
  
  import javax.servlet.jsp.tagext.TagData;
  import javax.servlet.jsp.tagext.TagExtraInfo;
  import javax.servlet.jsp.tagext.VariableInfo;
  
  
  /**
   * Implementation of <code>TagExtraInfo</code> for the <b>import</b>
   * tag, identifying the scripting object(s) to be made visible.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/07/03 19:30:03 $
   */
  
  public final class ImportTei extends TagExtraInfo {
  
  
      /**
       * Return information about the scripting variables to be created.
       */
      public VariableInfo[] getVariableInfo(TagData data) {
  
  	return new VariableInfo[] {
  	  new VariableInfo(data.getAttributeString("id"),
  	                   "java.lang.String",
  	                   true,
  	                   VariableInfo.AT_END)
  	};
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-taglibs/xsl/src/org/apache/taglibs/xsl/IncludeTag.java
  
  Index: IncludeTag.java
  ===================================================================
  /*
   * $Id: IncludeTag.java,v 1.1 2000/07/03 19:30:03 craigmcc Exp $
   * ====================================================================
   *
   * 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
   * modification, 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 acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", 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 names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.taglibs.xsl;
  
  
  import java.io.BufferedInputStream;
  import java.io.InputStreamReader;
  import java.net.URL;
  import java.net.URLConnection;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.JspWriter;
  import javax.servlet.jsp.PageContext;
  import javax.servlet.jsp.tagext.TagSupport;
  
  
  /**
   * Include the contents of the specified page at this point in our output.
   * This tag is similar to <code>&lt;jsp:include&gt;</code>, but does not
   * cause the output to be sent directly to the servlet response.  Therefore,
   * it can be used to capture the content of the page as body content of
   * a surrounding tag in which we are nested.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/07/03 19:30:03 $
   */
  
  public class IncludeTag extends TagSupport {
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * The URI of the page or servlet to be included.
       */
      private String page = null;
  
      public String getPage() {
  	return (this.page);
      }
  
      public void setPage(String page) {
  	this.page = page;
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Include the specified page or servlet's output at this point.
       *
       * @exception JspException if a JSP error occurs
       */
      public int doStartTag() throws JspException {
  
  	// Validate the format of the "page" attribute
  	// FIXME - deal with relative URIs like <jsp:include> does
  	if (!page.startsWith("/"))
  	    throw new JspException("Page value must start with '/'");
  
  	// Set up the output stream to which we will write
  	JspWriter out = pageContext.getOut();
  
  	// Set up a URLConnection to read the requested page.  We cannot use
  	// PageContext.include() because it writes directly to the output
  	// stream that goes back to the client. :-(
  	HttpServletRequest request =
  	    (HttpServletRequest) pageContext.getRequest();
  	StringBuffer url = new StringBuffer();
  	url.append(request.getScheme());
  	url.append("://");
  	url.append(request.getServerName());
  	if (request.getServerPort() != 80) {
  	    url.append(':');
  	    url.append(request.getServerPort());
  	}
  	if (request.getContextPath() != null)
  	    url.append(request.getContextPath());
  	url.append(page);	// FIXME - deal with relative page references
  	URLConnection conn = null;
  	try {
  	    conn = (new URL(url.toString())).openConnection();
  	    conn.setAllowUserInteraction(false);
  	    conn.setDoInput(true);
  	    conn.setDoOutput(false);
  	    conn.connect();
  	} catch (Exception e) {
  	    throw new JspException("Error opening connection: " +
  				   e.toString());
  	}
  
  	// Copy the contents of this URL
  	try {
  	    BufferedInputStream is =
  		new BufferedInputStream(conn.getInputStream());
  	    InputStreamReader in = new InputStreamReader(is);
  	    while (true) {
  		int ch = in.read();
  		if (ch < 0)
  		    break;
  		out.write(ch);
  	    }
  	} catch (Exception e) {
  	    throw new JspException("Error reading connection: " +
  				   e.toString());
  	}
  
  	// Skip the body of this tag (which should be empty anyway)
  	return (SKIP_BODY);
  
      }
  
  
  }
  
  
  

Mime
View raw message