tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cvs commit: jakarta-tomcat-catalina/webapps/docs changelog.xml
Date Tue, 20 Sep 2005 10:56:50 GMT
remm        2005/09/20 03:56:50

  Modified:    jasper2/src/share/org/apache/jasper/tagplugins/jstl
                        tagPlugins.xml
               webapps/docs changelog.xml
  Added:       jasper2/src/share/org/apache/jasper/tagplugins/jstl
                        Util.java
               jasper2/src/share/org/apache/jasper/tagplugins/jstl/core
                        Otherwise.java Import.java Remove.java
                        ForTokens.java When.java Redirect.java Catch.java
                        Choose.java If.java Out.java Url.java Param.java
                        Set.java ForEach.java
  Removed:     jasper2/src/share/org/apache/jasper/tagplugins/jstl
                        When.java Otherwise.java Choose.java ForEach.java
                        If.java
  Log:
  - JSTL tag plugins for the core tag library.
  - Submitted by Jing Li as part of SoC.
  
  Revision  Changes    Path
  1.4       +29 -5     jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/tagPlugins.xml
  
  Index: tagPlugins.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/tagPlugins.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- tagPlugins.xml	15 Feb 2003 01:41:46 -0000	1.3
  +++ tagPlugins.xml	20 Sep 2005 10:56:46 -0000	1.4
  @@ -1,22 +1,46 @@
   <tag-plugins>
     <tag-plugin>
       <tag-class>org.apache.taglibs.standard.tag.rt.core.IfTag</tag-class>
  -    <plugin-class>org.apache.jasper.tagplugins.jstl.If</plugin-class>
  +    <plugin-class>org.apache.jasper.tagplugins.jstl.core.If</plugin-class>
     </tag-plugin>
     <tag-plugin>
       <tag-class>org.apache.taglibs.standard.tag.common.core.ChooseTag</tag-class>
  -    <plugin-class>org.apache.jasper.tagplugins.jstl.Choose</plugin-class>
  +    <plugin-class>org.apache.jasper.tagplugins.jstl.core.Choose</plugin-class>
     </tag-plugin>
     <tag-plugin>
       <tag-class>org.apache.taglibs.standard.tag.rt.core.WhenTag</tag-class>
  -    <plugin-class>org.apache.jasper.tagplugins.jstl.When</plugin-class>
  +    <plugin-class>org.apache.jasper.tagplugins.jstl.core.When</plugin-class>
     </tag-plugin>
     <tag-plugin>
       <tag-class>org.apache.taglibs.standard.tag.common.core.OtherwiseTag</tag-class>
  -    <plugin-class>org.apache.jasper.tagplugins.jstl.Otherwise</plugin-class>
  +    <plugin-class>org.apache.jasper.tagplugins.jstl.core.Otherwise</plugin-class>
     </tag-plugin>
     <tag-plugin>
       <tag-class>org.apache.taglibs.standard.tag.rt.core.ForEachTag</tag-class>
  -    <plugin-class>org.apache.jasper.tagplugins.jstl.ForEach</plugin-class>
  +    <plugin-class>org.apache.jasper.tagplugins.jstl.core.ForEach</plugin-class>
  +  </tag-plugin>
  +  <tag-plugin>
  +  	<tag-class>org.apache.taglibs.standard.tag.rt.core.OutTag</tag-class>
  +  	<plugin-class>org.apache.jasper.tagplugins.jstl.core.Out</plugin-class>
  +  </tag-plugin>
  +  <tag-plugin>
  +    <tag-class>org.apache.taglibs.standard.tag.rt.core.SetTag</tag-class>
  +    <plugin-class>org.apache.jasper.tagplugins.jstl.core.Set</plugin-class>
  +  </tag-plugin>
  +  <tag-plugin>
  +    <tag-class>org.apache.taglibs.standard.tag.common.core.RemoveTag</tag-class>
  +    <plugin-class>org.apache.jasper.tagplugins.jstl.core.Remove</plugin-class>
  +  </tag-plugin>
  +  <tag-plugin>
  +    <tag-class>org.apache.taglibs.standard.tag.common.core.CatchTag</tag-class>
  +    <plugin-class>org.apache.jasper.tagplugins.jstl.core.Catch</plugin-class>
  +  </tag-plugin>
  +  <tag-plugin>
  +    <tag-class>org.apache.taglibs.standard.tag.rt.core.ForTokensTag</tag-class>
  +    <plugin-class>org.apache.jasper.tagplugins.jstl.core.ForTokens</plugin-class>
  +  </tag-plugin>
  +  <tag-plugin>
  +    <tag-class>org.apache.taglibs.standard.tag.rt.core.ImportTag</tag-class>
  +    <plugin-class>org.apache.jasper.tagplugins.jstl.core.Import</plugin-class>
     </tag-plugin>
   </tag-plugins>
  
  
  
  1.1                  jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/Util.java
  
  Index: Util.java
  ===================================================================
  /*
   * Copyright 1999,2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  package org.apache.jasper.tagplugins.jstl;
  
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.io.StringWriter;
  import java.io.UnsupportedEncodingException;
  import java.util.Locale;
  
  import javax.servlet.ServletOutputStream;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpServletResponseWrapper;
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.JspTagException;
  import javax.servlet.jsp.PageContext;
  
  /**
   * Util contains some often used consts, static methods and embedded class
   * to support the JSTL tag plugin.
   */
  
  public class Util {
      
      public static final String VALID_SCHEME_CHAR = 
          "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+.-";
      
      public static final String DEFAULT_ENCODING = 
          "ISO-8859-1";
      
      public static final int HIGHEST_SPECIAL = '>';
      
      public static char[][] specialCharactersRepresentation = new char[HIGHEST_SPECIAL + 1][];
      
      static {
          specialCharactersRepresentation['&'] = "&amp;".toCharArray();
          specialCharactersRepresentation['<'] = "&lt;".toCharArray();
          specialCharactersRepresentation['>'] = "&gt;".toCharArray();
          specialCharactersRepresentation['"'] = "&#034;".toCharArray();
          specialCharactersRepresentation['\''] = "&#039;".toCharArray();
      }
      
      /**
       * Converts the given string description of a scope to the corresponding
       * PageContext constant.
       *
       * The validity of the given scope has already been checked by the
       * appropriate TLV.
       *
       * @param scope String description of scope
       *
       * @return PageContext constant corresponding to given scope description
       * 
       * taken from org.apache.taglibs.standard.tag.common.core.Util  
       */
      public static int getScope(String scope){
          int ret = PageContext.PAGE_SCOPE;
          
          if("request".equalsIgnoreCase(scope)){
              ret = PageContext.REQUEST_SCOPE;
          }else if("session".equalsIgnoreCase(scope)){
              ret = PageContext.SESSION_SCOPE;
          }else if("application".equalsIgnoreCase(scope)){
              ret = PageContext.APPLICATION_SCOPE;
          }
          
          return ret;
      }
      
      /**
       * Returns <tt>true</tt> if our current URL is absolute,
       * <tt>false</tt> otherwise.
       * taken from org.apache.taglibs.standard.tag.common.core.ImportSupport
       */
      public static boolean isAbsoluteUrl(String url){
          if(url == null){
              return false;
          }
          
          int colonPos = url.indexOf(":");
          if(colonPos == -1){
              return false;
          }
          
          for(int i=0;i<colonPos;i++){
              if(VALID_SCHEME_CHAR.indexOf(url.charAt(i)) == -1){
                  return false;
              }
          }
          
          return true;
      }
      
      /**
       * Get the value associated with a content-type attribute.
       * Syntax defined in RFC 2045, section 5.1.
       * taken from org.apache.taglibs.standard.tag.common.core.Util
       */
      public static String getContentTypeAttribute(String input, String name) {
          int begin;
          int end;
          int index = input.toUpperCase().indexOf(name.toUpperCase());
          if (index == -1) return null;
          index = index + name.length(); // positioned after the attribute name
          index = input.indexOf('=', index); // positioned at the '='
          if (index == -1) return null;
          index += 1; // positioned after the '='
          input = input.substring(index).trim();
          
          if (input.charAt(0) == '"') {
              // attribute value is a quoted string
              begin = 1;
              end = input.indexOf('"', begin);
              if (end == -1) return null;
          } else {
              begin = 0;
              end = input.indexOf(';');
              if (end == -1) end = input.indexOf(' ');
              if (end == -1) end = input.length();
          }
          return input.substring(begin, end).trim();
      }
      
      /**
       * Strips a servlet session ID from <tt>url</tt>.  The session ID
       * is encoded as a URL "path parameter" beginning with "jsessionid=".
       * We thus remove anything we find between ";jsessionid=" (inclusive)
       * and either EOS or a subsequent ';' (exclusive).
       * 
       * taken from org.apache.taglibs.standard.tag.common.core.ImportSupport
       */
      public static String stripSession(String url) {
          StringBuffer u = new StringBuffer(url);
          int sessionStart;
          while ((sessionStart = u.toString().indexOf(";jsessionid=")) != -1) {
              int sessionEnd = u.toString().indexOf(";", sessionStart + 1);
              if (sessionEnd == -1)
                  sessionEnd = u.toString().indexOf("?", sessionStart + 1);
              if (sessionEnd == -1) 				// still
                  sessionEnd = u.length();
              u.delete(sessionStart, sessionEnd);
          }
          return u.toString();
      }
      
      
      /**
       * Performs the following substring replacements
       * (to facilitate output to XML/HTML pages):
       *
       *    & -> &amp;
       *    < -> &lt;
       *    > -> &gt;
       *    " -> &#034;
       *    ' -> &#039;
       *
       * See also OutSupport.writeEscapedXml().
       * 
       * taken from org.apache.taglibs.standard.tag.common.core.Util
       */
      public static String escapeXml(String buffer) {
          int start = 0;
          int length = buffer.length();
          char[] arrayBuffer = buffer.toCharArray();
          StringBuffer escapedBuffer = null;
          
          for (int i = 0; i < length; i++) {
              char c = arrayBuffer[i];
              if (c <= HIGHEST_SPECIAL) {
                  char[] escaped = specialCharactersRepresentation[c];
                  if (escaped != null) {
                      // create StringBuffer to hold escaped xml string
                      if (start == 0) {
                          escapedBuffer = new StringBuffer(length + 5);
                      }
                      // add unescaped portion
                      if (start < i) {
                          escapedBuffer.append(arrayBuffer,start,i-start);
                      }
                      start = i + 1;
                      // add escaped xml
                      escapedBuffer.append(escaped);
                  }
              }
          }
          // no xml escaping was necessary
          if (start == 0) {
              return buffer;
          }
          // add rest of unescaped portion
          if (start < length) {
              escapedBuffer.append(arrayBuffer,start,length-start);
          }
          return escapedBuffer.toString();
      }
      
      /** Utility methods
       * taken from org.apache.taglibs.standard.tag.common.core.UrlSupport
       */
      public static String resolveUrl(
              String url, String context, PageContext pageContext)
      throws JspException {
          // don't touch absolute URLs
          if (isAbsoluteUrl(url))
              return url;
          
          // normalize relative URLs against a context root
          HttpServletRequest request =
              (HttpServletRequest) pageContext.getRequest();
          if (context == null) {
              if (url.startsWith("/"))
                  return (request.getContextPath() + url);
              else
                  return url;
          } else {
              if (!context.startsWith("/") || !url.startsWith("/")) {
                  throw new JspTagException(
                  "In URL tags, when the \"context\" attribute is specified, values of both \"context\" and \"url\" must start with \"/\".");
              }
              if (context.equals("/")) {
                  // Don't produce string starting with '//', many
                  // browsers interpret this as host name, not as
                  // path on same host.
                  return url;
              } else {
                  return (context + url);
              }
          }
      }
      
      /** Wraps responses to allow us to retrieve results as Strings. 
       * mainly taken from org.apache.taglibs.standard.tag.common.core.importSupport 
       */
      public static class ImportResponseWrapper extends HttpServletResponseWrapper{
          
          private StringWriter sw = new StringWriter();
          private ByteArrayOutputStream bos = new ByteArrayOutputStream();
          private ServletOutputStream sos = new ServletOutputStream() {
              public void write(int b) throws IOException {
                  bos.write(b);
              }
          };
          private boolean isWriterUsed;
          private boolean isStreamUsed;
          private int status = 200;
          private String charEncoding;
          
          public ImportResponseWrapper(HttpServletResponse arg0) {
              super(arg0);
              // TODO Auto-generated constructor stub
          }
          
          public PrintWriter getWriter() {
              if (isStreamUsed)
                  throw new IllegalStateException("Unexpected internal error during &lt;import&gt: " +
                  "Target servlet called getWriter(), then getOutputStream()");
              isWriterUsed = true;
              return new PrintWriter(sw);
          }
          
          public ServletOutputStream getOutputStream() {
              if (isWriterUsed)
                  throw new IllegalStateException("Unexpected internal error during &lt;import&gt: " +
                  "Target servlet called getOutputStream(), then getWriter()");
              isStreamUsed = true;
              return sos;
          }
          
          /** Has no effect. */
          public void setContentType(String x) {
              // ignore
          }
          
          /** Has no effect. */
          public void setLocale(Locale x) {
              // ignore
          }
          
          public void setStatus(int status) {
              this.status = status;
          }
          
          public int getStatus() {
              return status;
          }
          
          public String getCharEncoding(){
              return this.charEncoding;
          }
          
          public void setCharEncoding(String ce){
              this.charEncoding = ce;
          }
          
          public String getString() throws UnsupportedEncodingException {
              if (isWriterUsed)
                  return sw.toString();
              else if (isStreamUsed) {
                  if (this.charEncoding != null && !this.charEncoding.equals(""))
                      return bos.toString(charEncoding);
                  else
                      return bos.toString("ISO-8859-1");
              } else
                  return "";		// target didn't write anything
          }
      }
      
  }
  
  
  
  1.1                  jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/core/Otherwise.java
  
  Index: Otherwise.java
  ===================================================================
  /*
   * Copyright 1999,2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  package org.apache.jasper.tagplugins.jstl.core;
  
  import org.apache.jasper.compiler.tagplugin.*;
  
  public final class Otherwise implements TagPlugin {
      
      public void doTag(TagPluginContext ctxt) {
          
          // See When.java for the reason whey "}" is need at the beginng and
          // not at the end.
          ctxt.generateJavaSource("} else {");
          ctxt.generateBody();
      }
  }
  
  
  
  1.1                  jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/core/Import.java
  
  Index: Import.java
  ===================================================================
  /*
   * Copyright 1999,2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  package org.apache.jasper.tagplugins.jstl.core;
  
  import org.apache.jasper.compiler.tagplugin.TagPlugin;
  import org.apache.jasper.compiler.tagplugin.TagPluginContext;
  import org.apache.jasper.tagplugins.jstl.Util;
  
  public class Import implements TagPlugin {
      
      public void doTag(TagPluginContext ctxt) {
          boolean hasContext, hasVar, hasScope, hasVarReader, hasCharEncoding;
          
          //flags
          hasContext  = ctxt.isAttributeSpecified("context");
          hasVar = ctxt.isAttributeSpecified("var");
          hasScope = ctxt.isAttributeSpecified("scope");
          hasVarReader = ctxt.isAttributeSpecified("varReader");
          hasCharEncoding = ctxt.isAttributeSpecified("charEncoding");
          
          //variables' names
          String urlName = ctxt.getTemporaryVariableName();           
          String contextName = ctxt.getTemporaryVariableName();       
          String iauName = ctxt.getTemporaryVariableName();           // is absolute url
          String urlObjName = ctxt.getTemporaryVariableName();        //URL object
          String ucName = ctxt.getTemporaryVariableName();            //URLConnection
          String inputStreamName = ctxt.getTemporaryVariableName();   
          String tempReaderName = ctxt.getTemporaryVariableName();
          String tempReaderName2 = ctxt.getTemporaryVariableName();
          String charSetName = ctxt.getTemporaryVariableName();
          String charEncodingName = ctxt.getTemporaryVariableName();
          String contentTypeName = ctxt.getTemporaryVariableName();
          String varReaderName = ctxt.getTemporaryVariableName();
          String servletContextName = ctxt.getTemporaryVariableName();
          String servletPathName = ctxt.getTemporaryVariableName();
          String requestDispatcherName = ctxt.getTemporaryVariableName();
          String irwName = ctxt.getTemporaryVariableName();           //ImportResponseWrapper name
          String brName = ctxt.getTemporaryVariableName();            //BufferedReader name
          String sbName = ctxt.getTemporaryVariableName();            //StringBuffer name
          String tempStringName = ctxt.getTemporaryVariableName();
          
          //is absolute url
          ctxt.generateJavaSource("boolean " + iauName + ";");
          
          //get the url value
          ctxt.generateJavaSource("String " + urlName + " = ");
          ctxt.generateAttribute("url");
          ctxt.generateJavaSource(";");
          
          //validate the url
          ctxt.generateJavaSource("if(" + urlName + " == null || " + urlName + ".equals(\"\")){");
          ctxt.generateJavaSource("    throw new JspTagException(\"The \\\"url\\\" attribute " +
          "illegally evaluated to \\\"null\\\" or \\\"\\\" in &lt;import&gt;\");");
          ctxt.generateJavaSource("}");
          
          //initialize the is_absolute_url
          ctxt.generateJavaSource(iauName + " = " +
                  "org.apache.jasper.tagplugins.jstl.Util.isAbsoluteUrl(" + urlName + ");");
          
          //validate the context
          if(hasContext){
              
              ctxt.generateJavaSource("String " + contextName + " = ");
              ctxt.generateAttribute("context");
              ctxt.generateJavaSource(";");
              
              ctxt.generateJavaSource("if((!" + contextName + ".startsWith(\"/\")) " +
                      "|| (!" + urlName + ".startsWith(\"/\"))){");
              ctxt.generateJavaSource("    throw new JspTagException" +
                      "(\"In URL tags, when the \\\"context\\\" attribute is specified, " +
              "values of both \\\"context\\\" and \\\"url\\\" must start with \\\"/\\\".\");");
              ctxt.generateJavaSource("}");
              
          }
          
          //define charset
          ctxt.generateJavaSource("String " + charSetName + " = null;");
          
          //if the charEncoding attribute is specified
          if(hasCharEncoding){
              
              //initialize the charEncoding
              ctxt.generateJavaSource("String " + charEncodingName + " = ");
              ctxt.generateAttribute("charEncoding");
              ctxt.generateJavaSource(";");
              
              //assign appropriate value tp the charset
              ctxt.generateJavaSource("if(null != " + charEncodingName + " " +
                      "&& !" + charEncodingName + ".equals(\"\")){");
              ctxt.generateJavaSource("    " + charSetName + " = " 
                      + charEncodingName + ";");
              ctxt.generateJavaSource("}");
          }
          
          //reshape the url string
          ctxt.generateJavaSource("if(!"+iauName+"){");
          ctxt.generateJavaSource("    if(!" + urlName + ".startsWith(\"/\")){");
          ctxt.generateJavaSource("        String " + servletPathName + " = " +
          "((HttpServletRequest)pageContext.getRequest()).getServletPath();");
          ctxt.generateJavaSource("        " + urlName + " = " 
                  + servletPathName + ".substring(0," + servletPathName + ".lastIndexOf('/')) + '/' + " + urlName + ";");
          ctxt.generateJavaSource("    }");
          ctxt.generateJavaSource("}");
          
          //if the varReader attribute specified
          if(hasVarReader){
              
              //get the String value of varReader
              ctxt.generateJavaSource("String " + varReaderName + " = ");
              ctxt.generateAttribute("varReader");
              ctxt.generateJavaSource(";");
              
              //if the url is absolute url
              ctxt.generateJavaSource("if(" + iauName + "){");
              
              //get the content of the target
              ctxt.generateJavaSource("    java.net.URL " + urlObjName + " = new java.net.URL(" + urlName + ");");
              ctxt.generateJavaSource("    java.net.URLConnection " + ucName + " = " 
                      + urlObjName + ".openConnection();");
              ctxt.generateJavaSource("    java.io.InputStream " + inputStreamName + " = " 
                      + ucName + ".getInputStream();");
              
              ctxt.generateJavaSource("    if(" + charSetName + " == null){");
              ctxt.generateJavaSource("        String " + contentTypeName + " = " 
                      + ucName + ".getContentType();");
              ctxt.generateJavaSource("        if(null != " + contentTypeName + "){");
              ctxt.generateJavaSource("            " + charSetName + " = " +
                      "org.apache.jasper.tagplugins.jstl.Util.getContentTypeAttribute(" + contentTypeName + ", \"charset\");");
              ctxt.generateJavaSource("            if(" + charSetName + " == null) " 
                      + charSetName + " = org.apache.jasper.tagplugins.jstl.Util.DEFAULT_ENCODING;");
              ctxt.generateJavaSource("        }else{");
              ctxt.generateJavaSource("            " + charSetName + " = org.apache.jasper.tagplugins.jstl.Util.DEFAULT_ENCODING;");
              ctxt.generateJavaSource("        }");
              ctxt.generateJavaSource("    }");
              
              if(!hasCharEncoding){
                  ctxt.generateJavaSource("    String " + contentTypeName + " = " + ucName + ".getContentType();");
              }
              
              //define the Reader
              ctxt.generateJavaSource("    java.io.Reader " + tempReaderName + " = null;");
              
              //initialize the Reader object
              ctxt.generateJavaSource("    try{");
              ctxt.generateJavaSource("        " + tempReaderName + " = new java.io.InputStreamReader(" + inputStreamName + ", " + charSetName + ");");
              ctxt.generateJavaSource("    }catch(Exception ex){");
              ctxt.generateJavaSource("        " + tempReaderName + " = new java.io.InputStreamReader(" + inputStreamName + ", org.apache.jasper.tagplugins.jstl.Util.DEFAULT_ENCODING);");
              ctxt.generateJavaSource("    }");
              
              //validate the response
              ctxt.generateJavaSource("    if(" + ucName + " instanceof java.net.HttpURLConnection){");
              ctxt.generateJavaSource("        int status = ((java.net.HttpURLConnection) " + ucName + ").getResponseCode();");
              ctxt.generateJavaSource("        if(status < 200 || status > 299){");
              ctxt.generateJavaSource("            throw new JspTagException(status + \" \" + " + urlName + ");");
              ctxt.generateJavaSource("        }");
              ctxt.generateJavaSource("    }");
              
              //set attribute in the page context scope
              ctxt.generateJavaSource("    pageContext.setAttribute(" + varReaderName + ", " + tempReaderName + ");");
              
              //if the url is relative
              ctxt.generateJavaSource("}else{");
              
              //if the url is relative, http request is needed
              ctxt.generateJavaSource("    if (!(pageContext.getRequest() instanceof HttpServletRequest  " +
              "&& pageContext.getResponse() instanceof HttpServletResponse)){");
              ctxt.generateJavaSource("        throw new JspTagException(\"Relative &lt;import&gt; from non-HTTP request not allowed\");");
              ctxt.generateJavaSource("    }");
              
              //get the servlet context of the context defined in the context attribute
              ctxt.generateJavaSource("    ServletContext " + servletContextName + " = null;");
              if(hasContext){
                  ctxt.generateJavaSource("    if(null != " + contextName + "){");
                  ctxt.generateJavaSource("        " + servletContextName + " = pageContext.getServletContext().getContext(" + contextName + ");" );
                  ctxt.generateJavaSource("    }else{");
                  ctxt.generateJavaSource("        " + servletContextName + " = pageContext.getServletContext();");
                  ctxt.generateJavaSource("    }");
              }else{
                  ctxt.generateJavaSource("    " + servletContextName + " = pageContext.getServletContext();");
              }
              
              //
              ctxt.generateJavaSource("    if(" + servletContextName + " == null){");
              if(hasContext){
                  ctxt.generateJavaSource("        throw new JspTagException(\"Unable to get RequestDispatcher for Context: \\\" \"+" + contextName + "+\" \\\" and URL: \\\" \" +" + urlName + "+ \" \\\". Verify values and/or enable cross context access.\");");
              }else{
                  ctxt.generateJavaSource("        throw new JspTagException(\"Unable to get RequestDispatcher for  URL: \\\" \" +" + urlName + "+ \" \\\". Verify values and/or enable cross context access.\");");
              }
              ctxt.generateJavaSource("    }");
              
              //get the request dispatcher
              ctxt.generateJavaSource("    RequestDispatcher " + requestDispatcherName + " = " + servletContextName + ".getRequestDispatcher(org.apache.jasper.tagplugins.jstl.Util.stripSession("+urlName+"));");
              ctxt.generateJavaSource("    if(" + requestDispatcherName + " == null) throw new JspTagException(org.apache.jasper.tagplugins.jstl.Util.stripSession("+urlName+"));");
              
              //initialize a ImportResponseWrapper to include the resource
              ctxt.generateJavaSource("    org.apache.jasper.tagplugins.jstl.Util.ImportResponseWrapper " + irwName + " = new org.apache.jasper.tagplugins.jstl.Util.ImportResponseWrapper((HttpServletResponse) pageContext.getResponse());");
              ctxt.generateJavaSource("    if(" + charSetName + " == null){");
              ctxt.generateJavaSource("        " + charSetName + " = org.apache.jasper.tagplugins.jstl.Util.DEFAULT_ENCODING;");
              ctxt.generateJavaSource("    }");
              ctxt.generateJavaSource("    " + irwName + ".setCharEncoding(" + charSetName + ");");
              ctxt.generateJavaSource("    try{");
              ctxt.generateJavaSource("        " + requestDispatcherName + ".include(pageContext.getRequest(), " + irwName + ");");
              ctxt.generateJavaSource("    }catch(java.io.IOException ex){");
              ctxt.generateJavaSource("        throw new JspException(ex);");
              ctxt.generateJavaSource("    }catch(RuntimeException ex){");
              ctxt.generateJavaSource("        throw new JspException(ex);");
              ctxt.generateJavaSource("    }catch(ServletException ex){");
              ctxt.generateJavaSource("        Throwable rc = ex.getRootCause();");
              ctxt.generateJavaSource("        if (rc == null)");
              ctxt.generateJavaSource("            throw new JspException(ex);");
              ctxt.generateJavaSource("        else");
              ctxt.generateJavaSource("            throw new JspException(rc);");
              ctxt.generateJavaSource("    }");
              
              //validate the response status
              ctxt.generateJavaSource("    if(" + irwName + ".getStatus() < 200 || " + irwName + ".getStatus() > 299){");
              ctxt.generateJavaSource("        throw new JspTagException(" + irwName + ".getStatus()+\" \" + org.apache.jasper.tagplugins.jstl.Util.stripSession(" + urlName + "));");
              ctxt.generateJavaSource("    }");
              
              //push in the page context
              ctxt.generateJavaSource("    java.io.Reader " + tempReaderName + " = new java.io.StringReader(" + irwName + ".getString());");
              ctxt.generateJavaSource("    pageContext.setAttribute(" + varReaderName + ", " + tempReaderName + ");");
              
              ctxt.generateJavaSource("}");
              
              //execute the body action
              ctxt.generateBody();
              
              //close the reader
              ctxt.generateJavaSource("java.io.Reader " + tempReaderName2 + " = (java.io.Reader)pageContext.getAttribute(" + varReaderName + ");");
              ctxt.generateJavaSource("if(" + tempReaderName2 + " != null) " + tempReaderName2 + ".close();");
              ctxt.generateJavaSource("pageContext.removeAttribute(" + varReaderName + ",1);");
          }
          
          //if the varReader is not specified 
          else{
              
              ctxt.generateJavaSource("pageContext.setAttribute(\"url_without_param\"," + urlName + ");");
              ctxt.generateBody();
              ctxt.generateJavaSource(urlName + " = (String)pageContext.getAttribute(\"url_without_param\");");
              ctxt.generateJavaSource("pageContext.removeAttribute(\"url_without_param\");");
              String strScope = "page";
              if(hasScope){
                  strScope = ctxt.getConstantAttribute("scope");
              }
              int iScope = Util.getScope(strScope);
              
              ctxt.generateJavaSource("String " + tempStringName + " = null;");
              
              ctxt.generateJavaSource("if(" + iauName + "){");
              
              //get the content of the target
              ctxt.generateJavaSource("    java.net.URL " + urlObjName + " = new java.net.URL(" + urlName + ");");
              ctxt.generateJavaSource("    java.net.URLConnection " + ucName + " = " + urlObjName + ".openConnection();");
              ctxt.generateJavaSource("    java.io.InputStream " + inputStreamName + " = " + ucName + ".getInputStream();");
              ctxt.generateJavaSource("    java.io.Reader " + tempReaderName + " = null;");
              
              ctxt.generateJavaSource("    if(" + charSetName + " == null){");
              ctxt.generateJavaSource("        String " + contentTypeName + " = " 
                      + ucName + ".getContentType();");
              ctxt.generateJavaSource("        if(null != " + contentTypeName + "){");
              ctxt.generateJavaSource("            " + charSetName + " = " +
                      "org.apache.jasper.tagplugins.jstl.Util.getContentTypeAttribute(" + contentTypeName + ", \"charset\");");
              ctxt.generateJavaSource("            if(" + charSetName + " == null) " 
                      + charSetName + " = org.apache.jasper.tagplugins.jstl.Util.DEFAULT_ENCODING;");
              ctxt.generateJavaSource("        }else{");
              ctxt.generateJavaSource("            " + charSetName + " = org.apache.jasper.tagplugins.jstl.Util.DEFAULT_ENCODING;");
              ctxt.generateJavaSource("        }");
              ctxt.generateJavaSource("    }");
              
              ctxt.generateJavaSource("    try{");
              ctxt.generateJavaSource("        " + tempReaderName + " = new java.io.InputStreamReader(" + inputStreamName + "," + charSetName + ");");
              ctxt.generateJavaSource("    }catch(Exception ex){");
              //ctxt.generateJavaSource("        throw new JspTagException(ex.toString());");
              ctxt.generateJavaSource("        " + tempReaderName + " = new java.io.InputStreamReader(" + inputStreamName + ",org.apache.jasper.tagplugins.jstl.Util.DEFAULT_ENCODING);");
              ctxt.generateJavaSource("    }");
              
              //validate the response
              ctxt.generateJavaSource("    if(" + ucName + " instanceof java.net.HttpURLConnection){");
              ctxt.generateJavaSource("        int status = ((java.net.HttpURLConnection) " + ucName + ").getResponseCode();");
              ctxt.generateJavaSource("        if(status < 200 || status > 299){");
              ctxt.generateJavaSource("            throw new JspTagException(status + \" \" + " + urlName + ");");
              ctxt.generateJavaSource("        }");
              ctxt.generateJavaSource("    }");
              
              ctxt.generateJavaSource("    java.io.BufferedReader " + brName + " =  new java.io.BufferedReader(" + tempReaderName + ");");
              ctxt.generateJavaSource("    StringBuffer " + sbName + " = new StringBuffer();");
              String index = ctxt.getTemporaryVariableName();
              ctxt.generateJavaSource("    int " + index + ";");
              ctxt.generateJavaSource("    while(("+index+" = "+brName+".read()) != -1) "+sbName+".append((char)"+index+");");
              ctxt.generateJavaSource("    " + tempStringName + " = " +sbName + ".toString();");
              
              ctxt.generateJavaSource("}else{");
              
              //if the url is relative, http request is needed.
              ctxt.generateJavaSource("    if (!(pageContext.getRequest() instanceof HttpServletRequest  " +
              "&& pageContext.getResponse() instanceof HttpServletResponse)){");
              ctxt.generateJavaSource("        throw new JspTagException(\"Relative &lt;import&gt; from non-HTTP request not allowed\");");
              ctxt.generateJavaSource("    }");
              
              //get the servlet context of the context defined in the context attribute
              ctxt.generateJavaSource("    ServletContext " + servletContextName + " = null;");
              if(hasContext){
                  ctxt.generateJavaSource("    if(null != " + contextName + "){");
                  ctxt.generateJavaSource("        " + servletContextName + " = pageContext.getServletContext().getContext(" + contextName + ");" );
                  ctxt.generateJavaSource("    }else{");
                  ctxt.generateJavaSource("        " + servletContextName + " = pageContext.getServletContext();");
                  ctxt.generateJavaSource("    }");
              }else{
                  ctxt.generateJavaSource("    " + servletContextName + " = pageContext.getServletContext();");
              }
              
              //
              ctxt.generateJavaSource("    if(" + servletContextName + " == null){");
              if(hasContext){
                  ctxt.generateJavaSource("        throw new JspTagException(\"Unable to get RequestDispatcher for Context: \\\" \" +" + contextName + "+ \" \\\" and URL: \\\" \" +" + urlName + "+ \" \\\". Verify values and/or enable cross context access.\");");
              }else{
                  ctxt.generateJavaSource("        throw new JspTagException(\"Unable to get RequestDispatcher for URL: \\\" \" +" + urlName + "+ \" \\\". Verify values and/or enable cross context access.\");");
              }
              ctxt.generateJavaSource("    }");
              
              //get the request dispatcher
              ctxt.generateJavaSource("    RequestDispatcher " + requestDispatcherName + " = " + servletContextName + ".getRequestDispatcher(org.apache.jasper.tagplugins.jstl.Util.stripSession("+urlName+"));");
              ctxt.generateJavaSource("    if(" + requestDispatcherName + " == null) throw new JspTagException(org.apache.jasper.tagplugins.jstl.Util.stripSession("+urlName+"));");
              
              //initialize a ImportResponseWrapper to include the resource
              ctxt.generateJavaSource("    org.apache.jasper.tagplugins.jstl.Util.ImportResponseWrapper " + irwName + " = new org.apache.jasper.tagplugins.jstl.Util.ImportResponseWrapper((HttpServletResponse) pageContext.getResponse());");
              ctxt.generateJavaSource("    if(" + charSetName + " == null){");
              ctxt.generateJavaSource("        " + charSetName + " = org.apache.jasper.tagplugins.jstl.Util.DEFAULT_ENCODING;");
              ctxt.generateJavaSource("    }");
              ctxt.generateJavaSource("    " + irwName + ".setCharEncoding(" + charSetName + ");");
              ctxt.generateJavaSource("    try{");
              ctxt.generateJavaSource("        " + requestDispatcherName + ".include(pageContext.getRequest(), " + irwName + ");");
              ctxt.generateJavaSource("    }catch(java.io.IOException ex){");
              ctxt.generateJavaSource("        throw new JspException(ex);");
              ctxt.generateJavaSource("    }catch(RuntimeException ex){");
              ctxt.generateJavaSource("        throw new JspException(ex);");
              ctxt.generateJavaSource("    }catch(ServletException ex){");
              ctxt.generateJavaSource("        Throwable rc = ex.getRootCause();");
              ctxt.generateJavaSource("        if (rc == null)");
              ctxt.generateJavaSource("            throw new JspException(ex);");
              ctxt.generateJavaSource("        else");
              ctxt.generateJavaSource("            throw new JspException(rc);");
              ctxt.generateJavaSource("    }");
              
              //validate the response status
              ctxt.generateJavaSource("    if(" + irwName + ".getStatus() < 200 || " + irwName + ".getStatus() > 299){");
              ctxt.generateJavaSource("        throw new JspTagException(" + irwName + ".getStatus()+\" \" + org.apache.jasper.tagplugins.jstl.Util.stripSession(" + urlName + "));");
              ctxt.generateJavaSource("    }");
              
              ctxt.generateJavaSource("    " + tempStringName + " = " + irwName + ".getString();");
              
              ctxt.generateJavaSource("}");
              
              if(hasVar){
                  String strVar = ctxt.getConstantAttribute("var");
                  ctxt.generateJavaSource("pageContext.setAttribute(\""+strVar+"\"," + tempStringName + "," + iScope + ");");
              }else{
                  ctxt.generateJavaSource("pageContext.getOut().print(" + tempStringName + ");");
              }
          }
      }
      
      
      
  }
  
  
  
  1.1                  jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/core/Remove.java
  
  Index: Remove.java
  ===================================================================
  /*
   * Copyright 1999,2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  package org.apache.jasper.tagplugins.jstl.core;
  
  import org.apache.jasper.compiler.tagplugin.TagPlugin;
  import org.apache.jasper.compiler.tagplugin.TagPluginContext;
  import org.apache.jasper.tagplugins.jstl.Util;
  
  public class Remove implements TagPlugin {
      
      public void doTag(TagPluginContext ctxt) {
          
          //scope flag
          boolean hasScope = ctxt.isAttributeSpecified("scope");
          
          //the value of the "var"
          String strVar = ctxt.getConstantAttribute("var");
          
          //remove attribute from certain scope.
          //default scope is "page".
          if(hasScope){
              int iScope = Util.getScope(ctxt.getConstantAttribute("scope"));
              ctxt.generateJavaSource("pageContext.removeAttribute(\"" + strVar + "\"," + iScope + ");");
          }else{
              ctxt.generateJavaSource("pageContext.removeAttribute(\"" + strVar + "\");");
          }
      }
      
  }
  
  
  
  1.1                  jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/core/ForTokens.java
  
  Index: ForTokens.java
  ===================================================================
  /*
   * Copyright 1999,2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  package org.apache.jasper.tagplugins.jstl.core;
  
  import org.apache.jasper.compiler.tagplugin.TagPlugin;
  import org.apache.jasper.compiler.tagplugin.TagPluginContext;
  
  public class ForTokens implements TagPlugin {
      
      public void doTag(TagPluginContext ctxt) {
          boolean hasVar, hasVarStatus, hasBegin, hasEnd, hasStep;
          
          //init the flags
          hasVar = ctxt.isAttributeSpecified("var");
          hasVarStatus = ctxt.isAttributeSpecified("varStatus");
          hasBegin = ctxt.isAttributeSpecified("begin");
          hasEnd = ctxt.isAttributeSpecified("end");
          hasStep = ctxt.isAttributeSpecified("step");
          
          if(hasVarStatus){
              ctxt.dontUseTagPlugin();
              return;
          }
          
          //define all the temp variables' names
          String itemsName = ctxt.getTemporaryVariableName();
          String delimsName = ctxt.getTemporaryVariableName();
          String stName = ctxt.getTemporaryVariableName();
          String beginName = ctxt.getTemporaryVariableName();
          String endName  = ctxt.getTemporaryVariableName();
          String stepName = ctxt.getTemporaryVariableName();
          String index = ctxt.getTemporaryVariableName();
          String temp  = ctxt.getTemporaryVariableName();
          String tokensCountName = ctxt.getTemporaryVariableName();
          
          //get the value of the "items" attribute 
          ctxt.generateJavaSource("String " + itemsName + " = (String)");
          ctxt.generateAttribute("items");
          ctxt.generateJavaSource(";");
          
          //get the value of the "delim" attribute
          ctxt.generateJavaSource("String " + delimsName + " = (String)");
          ctxt.generateAttribute("delims");
          ctxt.generateJavaSource(";");
          
          //new a StringTokenizer Object according to the "items" and the "delim"
          ctxt.generateJavaSource("java.util.StringTokenizer " + stName + " = " +
                  "new java.util.StringTokenizer(" + itemsName + ", " + delimsName + ");");
          
          //if "begin" specified, move the token to the "begin" place
          //and record the begin index. default begin place is 0.
          ctxt.generateJavaSource("int " + tokensCountName + " = " + stName + ".countTokens();");
          if(hasBegin){
              ctxt.generateJavaSource("int " + beginName + " = "  );
              ctxt.generateAttribute("begin");
              ctxt.generateJavaSource(";");
              ctxt.generateJavaSource("for(int " + index + " = 0; " + index + " < " + beginName + " && " + stName + ".hasMoreTokens(); " + index + "++, " + stName + ".nextToken()){}");
          }else{
              ctxt.generateJavaSource("int " + beginName + " = 0;");
          }
          
          //when "end" is specified, if the "end" is more than the last index,
          //record the end place as the last index, otherwise, record it as "end";
          //default end place is the last index 
          if(hasEnd){
              ctxt.generateJavaSource("int " + endName + " = 0;"  );
              ctxt.generateJavaSource("if((" + tokensCountName + " - 1) < ");
              ctxt.generateAttribute("end");
              ctxt.generateJavaSource("){");
              ctxt.generateJavaSource("    " + endName + " = " + tokensCountName + " - 1;");
              ctxt.generateJavaSource("}else{");
              ctxt.generateJavaSource("    " + endName + " = ");
              ctxt.generateAttribute("end");
              ctxt.generateJavaSource(";}");
          }else{
              ctxt.generateJavaSource("int " + endName + " = " + tokensCountName + " - 1;");
          }
          
          //get the step value from "step" if specified.
          //default step value is 1.
          if(hasStep){
              ctxt.generateJavaSource("int " + stepName + " = "  );
              ctxt.generateAttribute("step");
              ctxt.generateJavaSource(";");
          }else{
              ctxt.generateJavaSource("int " + stepName + " = 1;");
          }
          
          //the loop
          ctxt.generateJavaSource("for(int " + index + " = " + beginName + "; " + index + " <= " + endName + "; " + index + "++){");
          ctxt.generateJavaSource("    String " + temp + " = " + stName + ".nextToken();");
          ctxt.generateJavaSource("    if(((" + index + " - " + beginName + ") % " + stepName + ") == 0){");
          //if var specified, put the current token into the attribute "var" defines.
          if(hasVar){
              String strVar = ctxt.getConstantAttribute("var");
              ctxt.generateJavaSource("        pageContext.setAttribute(\"" + strVar + "\", " + temp + ");");
          }
          ctxt.generateBody();
          ctxt.generateJavaSource("    }");
          ctxt.generateJavaSource("}");
      }
      
  }
  
  
  
  1.1                  jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/core/When.java
  
  Index: When.java
  ===================================================================
  /*
   * Copyright 1999,2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  package org.apache.jasper.tagplugins.jstl.core;
  
  import org.apache.jasper.compiler.tagplugin.*;
  
  public final class When implements TagPlugin {
      
      public void doTag(TagPluginContext ctxt) {
          // Get the parent context to determine if this is the first <c:when>
          TagPluginContext parentContext = ctxt.getParentContext();
          if (parentContext == null) {
              ctxt.dontUseTagPlugin();
              return;
          }
          
          if ("true".equals(parentContext.getPluginAttribute("hasBeenHere"))) {
              ctxt.generateJavaSource("} else if(");
              // See comment below for the reason we generate the extra "}" here.
          }
          else {
              ctxt.generateJavaSource("if(");
              parentContext.setPluginAttribute("hasBeenHere", "true");
          }
          ctxt.generateAttribute("test");
          ctxt.generateJavaSource("){");
          ctxt.generateBody();
          
          // We don't generate the closing "}" for the "if" here because there
          // may be whitespaces in between <c:when>'s.  Instead we delay
          // generating it until the next <c:when> or <c:otherwise> or
          // <c:choose>
      }
  }
  
  
  
  1.1                  jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/core/Redirect.java
  
  Index: Redirect.java
  ===================================================================
  /*
   * Copyright 1999,2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  package org.apache.jasper.tagplugins.jstl.core;
  
  import org.apache.jasper.compiler.tagplugin.TagPlugin;
  import org.apache.jasper.compiler.tagplugin.TagPluginContext;
  
  public class Redirect implements TagPlugin {
      
      public void doTag(TagPluginContext ctxt) {
          
          //flag for the existence of the "context"
          boolean hasContext = ctxt.isAttributeSpecified("context");
          
          //names of the temp variables
          String urlName = ctxt.getTemporaryVariableName();
          String contextName = ctxt.getTemporaryVariableName();
          String baseUrlName = ctxt.getTemporaryVariableName();
          String resultName = ctxt.getTemporaryVariableName();
          String responseName = ctxt.getTemporaryVariableName();
          
          //get context
          ctxt.generateJavaSource("String " + contextName + " = null;");
          if(hasContext){
              ctxt.generateJavaSource(contextName + " = ");
              ctxt.generateAttribute("context");
              ctxt.generateJavaSource(";");
          }
          
          //get the url
          ctxt.generateJavaSource("String " + urlName + " = ");
          ctxt.generateAttribute("url");
          ctxt.generateJavaSource(";");
          
          //get the raw url according to "url" and "context"
          ctxt.generateJavaSource("String " + baseUrlName + " = " +
                  "org.apache.jasper.tagplugins.jstl.Util.resolveUrl(" + urlName + ", " + contextName + ", pageContext);");
          ctxt.generateJavaSource("pageContext.setAttribute" +
                  "(\"url_without_param\", " + baseUrlName + ");");
          
          //add params
          ctxt.generateBody();
          
          ctxt.generateJavaSource("String " + resultName + " = " +
          "(String)pageContext.getAttribute(\"url_without_param\");");
          ctxt.generateJavaSource("pageContext.removeAttribute" +
          "(\"url_without_param\");");
          
          //get the response object
          ctxt.generateJavaSource("HttpServletResponse " + responseName + " = " +
          "((HttpServletResponse) pageContext.getResponse());");
          
          //if the url is relative, encode it
          ctxt.generateJavaSource("if(!org.apache.jasper.tagplugins.jstl.Util.isAbsoluteUrl(" + resultName + ")){");
          ctxt.generateJavaSource("    " + resultName + " = "
                  + responseName + ".encodeRedirectURL(" + resultName + ");");
          ctxt.generateJavaSource("}");
          
          //do redirect
          ctxt.generateJavaSource("try{");
          ctxt.generateJavaSource("    " + responseName + ".sendRedirect(" + resultName + ");");
          ctxt.generateJavaSource("}catch(java.io.IOException ex){");
          ctxt.generateJavaSource("    throw new JspTagException(ex.toString(), ex);");
          ctxt.generateJavaSource("}");
      }
      
  }
  
  
  
  1.1                  jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/core/Catch.java
  
  Index: Catch.java
  ===================================================================
  /*
   * Copyright 1999,2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  package org.apache.jasper.tagplugins.jstl.core;
  
  import org.apache.jasper.compiler.tagplugin.TagPlugin;
  import org.apache.jasper.compiler.tagplugin.TagPluginContext;
  
  public class Catch implements TagPlugin {
      
      public void doTag(TagPluginContext ctxt) {
          
          //flag for the existence of the var attribute
          boolean hasVar = ctxt.isAttributeSpecified("var");
          
          //temp name for exception and caught
          String exceptionName = ctxt.getTemporaryVariableName();
          String caughtName = ctxt.getTemporaryVariableName();
          
          //main part to generate code
          ctxt.generateJavaSource("boolean " + caughtName + " = false;");
          ctxt.generateJavaSource("try{");
          ctxt.generateBody();
          ctxt.generateJavaSource("}");
          
          //do catch
          ctxt.generateJavaSource("catch(Throwable " + exceptionName + "){");
          
          //if the var specified, the exception object should 
          //be set to the attribute "var" defines in page scope 
          if(hasVar){
              String strVar = ctxt.getConstantAttribute("var");
              ctxt.generateJavaSource("    pageContext.setAttribute(\"" + strVar + "\", " 
                      + exceptionName + ", PageContext.PAGE_SCOPE);");
          }
          
          //whenever there's exception caught, 
          //the flag caught should be set true;
          ctxt.generateJavaSource("    " + caughtName + " = true;");
          ctxt.generateJavaSource("}");
          
          //do finally
          ctxt.generateJavaSource("finally{");
          
          //if var specified, the attribute it defines 
          //in page scope should be removed
          if(hasVar){
              String strVar = ctxt.getConstantAttribute("var");
              ctxt.generateJavaSource("    if(!" + caughtName + "){");
              ctxt.generateJavaSource("        pageContext.removeAttribute(\"" + strVar + "\", PageContext.PAGE_SCOPE);");
              ctxt.generateJavaSource("    }");
          }
          
          ctxt.generateJavaSource("}");
      }
      
  }
  
  
  
  1.1                  jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/core/Choose.java
  
  Index: Choose.java
  ===================================================================
  /*
   * Copyright 1999,2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  package org.apache.jasper.tagplugins.jstl.core;
  
  import org.apache.jasper.compiler.tagplugin.*;
  
  public final class Choose implements TagPlugin {
      
      public void doTag(TagPluginContext ctxt) {
          
          // Not much to do here, much of the work will be done in the
          // containing tags, <c:when> and <c:otherwise>.
          
          ctxt.generateBody();
          // See comments in When.java for the reason "}" is generated here.
          ctxt.generateJavaSource("}");
      }
  }
  
  
  
  1.1                  jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/core/If.java
  
  Index: If.java
  ===================================================================
  /*
   * Copyright 1999,2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  package org.apache.jasper.tagplugins.jstl.core;
  
  import org.apache.jasper.compiler.tagplugin.*;
  
  public final class If implements TagPlugin {
      
      public void doTag(TagPluginContext ctxt) {
          String condV = ctxt.getTemporaryVariableName();
          ctxt.generateJavaSource("boolean " + condV + "=");
          ctxt.generateAttribute("test");
          ctxt.generateJavaSource(";");
          if (ctxt.isAttributeSpecified("var")) {
              String scope = "PageContext.PAGE_SCOPE";
              if (ctxt.isAttributeSpecified("scope")) {
                  String scopeStr = ctxt.getConstantAttribute("scope");
                  if ("request".equals(scopeStr)) {
                      scope = "PageContext.REQUEST_SCOPE";
                  } else if ("session".equals(scopeStr)) {
                      scope = "PageContext.SESSION_SCOPE";
                  } else if ("application".equals(scopeStr)) {
                      scope = "PageContext.APPLICATION_SCOPE";
                  }
              }
              ctxt.generateJavaSource("_jspx_page_context.setAttribute(");
              ctxt.generateAttribute("var");
              ctxt.generateJavaSource(", new Boolean(" + condV + ")," + scope + ");");
          }
          ctxt.generateJavaSource("if (" + condV + "){");
          ctxt.generateBody();
          ctxt.generateJavaSource("}");
      }
  }
  
  
  
  1.1                  jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/core/Out.java
  
  Index: Out.java
  ===================================================================
  /*
   * Copyright 1999,2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  package org.apache.jasper.tagplugins.jstl.core;
  
  import org.apache.jasper.compiler.tagplugin.TagPlugin;
  import org.apache.jasper.compiler.tagplugin.TagPluginContext;
  
  
  public final class Out implements TagPlugin {
      
      public void doTag(TagPluginContext ctxt) {
          
          //these two data member are to indicate 
          //whether the corresponding attribute is specified
          boolean hasDefault=false, hasEscapeXml=false;
          hasDefault = ctxt.isAttributeSpecified("default");
          hasEscapeXml = ctxt.isAttributeSpecified("escapeXml");
          
          //strValName, strEscapeXmlName & strDefName are two variables' name 
          //standing for value, escapeXml and default attribute
          String strValName = ctxt.getTemporaryVariableName();
          String strDefName = ctxt.getTemporaryVariableName();
          String strEscapeXmlName = ctxt.getTemporaryVariableName();
          
          //according to the tag file, the value attribute is mandatory.
          ctxt.generateJavaSource("String " + strValName + " = null;");
          ctxt.generateJavaSource("if(");
          ctxt.generateAttribute("value");
          ctxt.generateJavaSource("!=null){");
          ctxt.generateJavaSource("    " + strValName + " = (");
          ctxt.generateAttribute("value");
          ctxt.generateJavaSource(").toString();");
          ctxt.generateJavaSource("}");
          
          //initiate the strDefName with null.
          //if the default has been specified, then assign the value to it;
          ctxt.generateJavaSource("String " + strDefName + " = null;\n");
          if(hasDefault){
              ctxt.generateJavaSource("if(");
              ctxt.generateAttribute("default");
              ctxt.generateJavaSource(" != null){");
              ctxt.generateJavaSource(strDefName + " = (");
              ctxt.generateAttribute("default");
              ctxt.generateJavaSource(").toString();");
              ctxt.generateJavaSource("}");
          }
          
          //initiate the strEscapeXmlName with true;
          //if the escapeXml is specified, assign the value to it;
          ctxt.generateJavaSource("boolean " + strEscapeXmlName + " = true;");
          if(hasEscapeXml){
              ctxt.generateJavaSource(strEscapeXmlName + " = Boolean.parseBoolean((");
              ctxt.generateAttribute("default");
              ctxt.generateJavaSource(").toString());");
          }
          
          //main part. 
          ctxt.generateJavaSource("if(null != " + strValName +"){");
          ctxt.generateJavaSource("    if(" + strEscapeXmlName + "){");
          ctxt.generateJavaSource("        " + strValName + " = org.apache.jasper.tagplugins.jstl.Util.escapeXml(" + strValName + ");");
          ctxt.generateJavaSource("    }");
          ctxt.generateJavaSource("    out.write(" + strValName + ");");
          ctxt.generateJavaSource("}else{");
          ctxt.generateJavaSource("    if(null != " + strDefName + "){");
          ctxt.generateJavaSource("        if(" + strEscapeXmlName + "){");
          ctxt.generateJavaSource("            " + strDefName + " = org.apache.jasper.tagplugins.jstl.Util.escapeXml(" + strDefName + ");");
          ctxt.generateJavaSource("        }");
          ctxt.generateJavaSource("        out.write(" + strDefName + ");");
          ctxt.generateJavaSource("    }else{");
          ctxt.generateBody();
          ctxt.generateJavaSource("    }");
          ctxt.generateJavaSource("}");   
      }
  }
  
  
  
  1.1                  jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/core/Url.java
  
  Index: Url.java
  ===================================================================
  /*
   * Copyright 1999,2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  package org.apache.jasper.tagplugins.jstl.core;
  
  import org.apache.jasper.compiler.tagplugin.TagPlugin;
  import org.apache.jasper.compiler.tagplugin.TagPluginContext;
  import org.apache.jasper.tagplugins.jstl.Util;
  
  public class Url implements TagPlugin {
      
      public void doTag(TagPluginContext ctxt) {
          
          //flags
          boolean hasVar, hasContext, hasScope;
          
          //init flags
          hasVar = ctxt.isAttributeSpecified("var");
          hasContext = ctxt.isAttributeSpecified("context");
          hasScope = ctxt.isAttributeSpecified("scope");
          
          //define name of the temp variables
          String valueName = ctxt.getTemporaryVariableName();
          String contextName = ctxt.getTemporaryVariableName();
          String baseUrlName = ctxt.getTemporaryVariableName();
          String resultName = ctxt.getTemporaryVariableName();
          String responseName = ctxt.getTemporaryVariableName();
          
          //get the scope
          String strScope = "page";
          if(hasScope){
              strScope = ctxt.getConstantAttribute("scope");
          }
          int iScope = Util.getScope(strScope);
          
          //get the value
          ctxt.generateJavaSource("String " + valueName + " = ");
          ctxt.generateAttribute("value");
          ctxt.generateJavaSource(";");
          
          //get the context
          ctxt.generateJavaSource("String " + contextName + " = null;");
          if(hasContext){
              ctxt.generateJavaSource(contextName + " = ");
              ctxt.generateAttribute("context");
              ctxt.generateJavaSource(";");
          }
          
          //get the raw url
          ctxt.generateJavaSource("String " + baseUrlName + " = " +
                  "org.apache.jasper.tagplugins.jstl.Util.resolveUrl(" + valueName + ", " + contextName + ", pageContext);");
          ctxt.generateJavaSource("pageContext.setAttribute" +
                  "(\"url_without_param\", " + baseUrlName + ");");
          
          //add params
          ctxt.generateBody();
          
          ctxt.generateJavaSource("String " + resultName + " = " +
          "(String)pageContext.getAttribute(\"url_without_param\");");
          ctxt.generateJavaSource("pageContext.removeAttribute(\"url_without_param\");");
          
          //if the url is relative, encode it
          ctxt.generateJavaSource("if(!org.apache.jasper.tagplugins.jstl.Util.isAbsoluteUrl(" + resultName + ")){");
          ctxt.generateJavaSource("    HttpServletResponse " + responseName + " = " +
          "((HttpServletResponse) pageContext.getResponse());");
          ctxt.generateJavaSource("    " + resultName + " = "
                  + responseName + ".encodeURL(" + resultName + ");");
          ctxt.generateJavaSource("}");
          
          //if "var" is specified, the url string store in the attribute var defines
          if(hasVar){
              String strVar = ctxt.getConstantAttribute("var");
              ctxt.generateJavaSource("pageContext.setAttribute" +
                      "(\"" + strVar + "\", " + resultName + ", " + iScope + ");");
              
              //if var is not specified, just print out the url string
          }else{
              ctxt.generateJavaSource("try{");
              ctxt.generateJavaSource("    pageContext.getOut().print(" + resultName + ");");
              ctxt.generateJavaSource("}catch(java.io.IOException ex){");
              ctxt.generateJavaSource("    throw new JspTagException(ex.toString(), ex);");
              ctxt.generateJavaSource("}");
          }
      }
      
  }
  
  
  
  1.1                  jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/core/Param.java
  
  Index: Param.java
  ===================================================================
  /*
   * Copyright 1999,2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  package org.apache.jasper.tagplugins.jstl.core;
  
  import org.apache.jasper.compiler.tagplugin.TagPlugin;
  import org.apache.jasper.compiler.tagplugin.TagPluginContext;
  
  public class Param implements TagPlugin {
      
      public void doTag(TagPluginContext ctxt) {
          
          //don't support the body content
          
          //define names of all the temp variables
          String nameName = ctxt.getTemporaryVariableName();
          String valueName = ctxt.getTemporaryVariableName();
          String urlName = ctxt.getTemporaryVariableName();
          String encName = ctxt.getTemporaryVariableName();
          String index = ctxt.getTemporaryVariableName();
          
          //if the param tag has no parents, throw a exception
          TagPluginContext parent = ctxt.getParentContext();
          if(parent == null){
              ctxt.generateJavaSource(" throw new JspTagExcption" +
              "(\"&lt;param&gt; outside &lt;import&gt; or &lt;urlEncode&gt;\");");
              return;
          }
          
          //get the url string before adding this param
          ctxt.generateJavaSource("String " + urlName + " = " +
          "(String)pageContext.getAttribute(\"url_without_param\");");
          
          //get the value of "name"
          ctxt.generateJavaSource("String " + nameName + " = ");
          ctxt.generateAttribute("name");
          ctxt.generateJavaSource(";");
          
          //if the "name" is null then do nothing.
          //else add such string "name=value" to the url.
          //and the url should be encoded
          ctxt.generateJavaSource("if(" + nameName + " != null && !" + nameName + ".equals(\"\")){");
          ctxt.generateJavaSource("    String " + valueName + " = ");
          ctxt.generateAttribute("value");
          ctxt.generateJavaSource(";");
          ctxt.generateJavaSource("    if(" + valueName + " == null) " + valueName + " = \"\";");
          ctxt.generateJavaSource("    String " + encName + " = pageContext.getResponse().getCharacterEncoding();");
          ctxt.generateJavaSource("    " + nameName + " = java.net.URLEncoder.encode(" + nameName + ", " + encName + ");");
          ctxt.generateJavaSource("    " + valueName + " = java.net.URLEncoder.encode(" + valueName + ", " + encName + ");");
          ctxt.generateJavaSource("    int " + index + ";");
          ctxt.generateJavaSource("    " + index + " = " + urlName + ".indexOf(\'?\');");
          //if the current param is the first one, add a "?" ahead of it
          //else add a "&" ahead of it
          ctxt.generateJavaSource("    if(" + index + " == -1){");
          ctxt.generateJavaSource("        " + urlName + " = " + urlName + " + \"?\" + " + nameName + " + \"=\" + " + valueName + ";");
          ctxt.generateJavaSource("    }else{");
          ctxt.generateJavaSource("        " + urlName + " = " + urlName + " + \"&\" + " + nameName + " + \"=\" + " + valueName + ";");
          ctxt.generateJavaSource("    }");
          ctxt.generateJavaSource("    pageContext.setAttribute(\"url_without_param\"," + urlName + ");");
          ctxt.generateJavaSource("}");	
      }
  }
  
  
  
  1.1                  jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/core/Set.java
  
  Index: Set.java
  ===================================================================
  /*
   * Copyright 1999,2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  package org.apache.jasper.tagplugins.jstl.core;
  
  import org.apache.jasper.compiler.tagplugin.TagPlugin;
  import org.apache.jasper.compiler.tagplugin.TagPluginContext;
  import org.apache.jasper.tagplugins.jstl.Util;
  
  public class Set implements TagPlugin {
      
      public void doTag(TagPluginContext ctxt) {
          
          //the flags to indicate whether the attributes have been specified
          boolean hasValue = false, hasVar = false, hasScope = false, 
          hasTarget = false;
          
          //the scope name
          String strScope;
          //the id of the scope
          int iScope;
          
          //initialize the flags
          hasValue = ctxt.isAttributeSpecified("value");
          hasVar = ctxt.isAttributeSpecified("var");
          hasScope = ctxt.isAttributeSpecified("scope");
          hasTarget = ctxt.isAttributeSpecified("target");
          
          //the temp variables name
          String resultName = ctxt.getTemporaryVariableName();
          String targetName = ctxt.getTemporaryVariableName();
          String propertyName = ctxt.getTemporaryVariableName();
          
          //initialize the "result" which will be assigned to the var or target.property
          ctxt.generateJavaSource("Object " + resultName + " = null;");
          if(hasValue){
              ctxt.generateJavaSource(resultName + " = ");
              ctxt.generateAttribute("value");
              ctxt.generateJavaSource(";");
          }else{
              ctxt.dontUseTagPlugin();
              return;
          }
          
          //initialize the strScope
          if(hasScope){
              strScope = ctxt.getConstantAttribute("scope");
          }else{
              strScope = "page";
          }
          
          //get the iScope according to the strScope
          iScope = Util.getScope(strScope);
          
          //if the attribute var has been specified then assign the result to the var;
          if(hasVar){
              String strVar = ctxt.getConstantAttribute("var");
              ctxt.generateJavaSource("if(null != " + resultName + "){");
              ctxt.generateJavaSource("    pageContext.setAttribute(\"" + strVar + "\"," + resultName + "," + iScope + ");");
              ctxt.generateJavaSource("} else {");
              if(hasScope){
                  ctxt.generateJavaSource("    pageContext.removeAttribute(\"" + strVar + "\"," + iScope + ");");
              }else{
                  ctxt.generateJavaSource("    pageContext.removeAttribute(\"" + strVar + "\");");
              }
              ctxt.generateJavaSource("}");
              
              //else assign the result to the target.property
          }else if(hasTarget){
              
              //generate the temp variable name
              String pdName = ctxt.getTemporaryVariableName();
              String successFlagName = ctxt.getTemporaryVariableName();
              String index = ctxt.getTemporaryVariableName();
              String methodName = ctxt.getTemporaryVariableName();
              
              //initialize the property
              ctxt.generateJavaSource("String " + propertyName + " = null;");
              ctxt.generateJavaSource("if(");
              ctxt.generateAttribute("property");
              ctxt.generateJavaSource(" != null){");
              ctxt.generateJavaSource("    " + propertyName + " = (");
              ctxt.generateAttribute("property");
              ctxt.generateJavaSource(").toString();");
              ctxt.generateJavaSource("}");
              
              //initialize the target
              ctxt.generateJavaSource("Object " + targetName + " = ");
              ctxt.generateAttribute("target");
              ctxt.generateJavaSource(";");
              
              //the target is ok
              ctxt.generateJavaSource("if(" + targetName + " != null){");
              
              //if the target is a map, then put the result into the map with the key property
              ctxt.generateJavaSource("    if(" + targetName + " instanceof java.util.Map){");
              ctxt.generateJavaSource("        if(null != " + resultName + "){");
              ctxt.generateJavaSource("            ((java.util.Map) " + targetName + ").put(" + propertyName + "," + resultName + ");");
              ctxt.generateJavaSource("        }else{");
              ctxt.generateJavaSource("            ((java.util.Map) " + targetName + ").remove(" + propertyName + ");");
              ctxt.generateJavaSource("        }");
              
              //else assign the result to the target.property
              ctxt.generateJavaSource("    }else{");
              ctxt.generateJavaSource("        try{");
              
              //get all the property of the target
              ctxt.generateJavaSource("            java.beans.PropertyDescriptor " + pdName + "[] = java.beans.Introspector.getBeanInfo(" + targetName + ".getClass()).getPropertyDescriptors();");
              
              //the success flag is to imply whether the assign is successful
              ctxt.generateJavaSource("            boolean " + successFlagName + " = false;");
              
              //find the right property
              ctxt.generateJavaSource("            for(int " + index + "=0;" + index + "<" + pdName + ".length;" + index + "++){");
              ctxt.generateJavaSource("                if(" + pdName + "[" + index + "].getName().equals(" + propertyName + ")){");
              
              //get the "set" method;
              ctxt.generateJavaSource("                    java.lang.reflect.Method " + methodName + " = " + pdName + "[" + index + "].getWriteMethod();");
              ctxt.generateJavaSource("                    if(null == " + methodName + "){");
              ctxt.generateJavaSource("                        throw new JspException(\"No setter method in &lt;set&gt; for property \"+" + propertyName + ");");
              ctxt.generateJavaSource("                    }");
              
              //invoke the method through the reflection
              ctxt.generateJavaSource("                    if(" + resultName + " != null){");
              ctxt.generateJavaSource("                        " + methodName + ".invoke(" + targetName + ", new Object[]{(" + methodName + ".getParameterTypes()[0]).cast(" + resultName + ")});");
              ctxt.generateJavaSource("                    }else{");
              ctxt.generateJavaSource("                        " + methodName + ".invoke(" + targetName + ", new Object[]{null});");
              ctxt.generateJavaSource("                    }");
              ctxt.generateJavaSource("                    " + successFlagName + " = true;");
              ctxt.generateJavaSource("                }");
              ctxt.generateJavaSource("            }");
              ctxt.generateJavaSource("            if(!" + successFlagName + "){");
              ctxt.generateJavaSource("                throw new JspException(\"Invalid property in &lt;set&gt;:\"+" + propertyName + ");");
              ctxt.generateJavaSource("            }");
              ctxt.generateJavaSource("        }");
              
              //catch the el exception and throw it as a JspException
              ctxt.generateJavaSource("        catch (IllegalAccessException ex) {");
              ctxt.generateJavaSource("            throw new JspException(ex);");
              ctxt.generateJavaSource("        } catch (java.beans.IntrospectionException ex) {");
              ctxt.generateJavaSource("            throw new JspException(ex);");
              ctxt.generateJavaSource("        } catch (java.lang.reflect.InvocationTargetException ex) {");
              ctxt.generateJavaSource("            throw new JspException(ex);");
              ctxt.generateJavaSource("        }");
              ctxt.generateJavaSource("    }");
              ctxt.generateJavaSource("}else{");
              ctxt.generateJavaSource("    throw new JspException();");
              ctxt.generateJavaSource("}");
          }
      }
      
  }
  
  
  
  1.1                  jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/core/ForEach.java
  
  Index: ForEach.java
  ===================================================================
  /*
   * Copyright 1999,2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  package org.apache.jasper.tagplugins.jstl.core;
  
  import org.apache.jasper.compiler.tagplugin.*;
  
  public final class ForEach implements TagPlugin {
      
      private boolean hasVar, hasBegin, hasEnd, hasStep;
      
      public void doTag(TagPluginContext ctxt) {
          
          String index = null;
          
          boolean hasVarStatus = ctxt.isAttributeSpecified("varStatus");
          if (hasVarStatus) {
              ctxt.dontUseTagPlugin();
              return;
          }
          
          hasVar = ctxt.isAttributeSpecified("var");
          hasBegin = ctxt.isAttributeSpecified("begin");
          hasEnd = ctxt.isAttributeSpecified("end");
          hasStep = ctxt.isAttributeSpecified("step");
          
          boolean hasItems = ctxt.isAttributeSpecified("items");
          if (hasItems) {
              doCollection(ctxt);
              return;
          }
          
          // We must have a begin and end attributes
          index = ctxt.getTemporaryVariableName();
          ctxt.generateJavaSource("for (int " + index + " = ");
          ctxt.generateAttribute("begin");
          ctxt.generateJavaSource("; " + index + " <= ");
          ctxt.generateAttribute("end");
          if (hasStep) {
              ctxt.generateJavaSource("; " + index + "+=");
              ctxt.generateAttribute("step");
              ctxt.generateJavaSource(") {");
          }
          else {
              ctxt.generateJavaSource("; " + index + "++) {");
          }
          
          // If var is specified and the body contains an EL, then sycn
          // the var attribute
          if (hasVar /* && ctxt.hasEL() */) {
              ctxt.generateJavaSource("_jspx_page_context.setAttribute(");
              ctxt.generateAttribute("var");
              ctxt.generateJavaSource(", String.valueOf(" + index + "));");
          }
          ctxt.generateBody();
          ctxt.generateJavaSource("}");
      }
      
      /**
       * Generate codes for Collections
       * The pseudo code is:
       */
      private void doCollection(TagPluginContext ctxt) {
          
          ctxt.generateImport("java.util.*");
          generateIterators(ctxt);
          
          String itemsV = ctxt.getTemporaryVariableName();
          ctxt.generateJavaSource("Object " + itemsV + "= ");
          ctxt.generateAttribute("items");
          ctxt.generateJavaSource(";");
          
          String indexV=null, beginV=null, endV=null, stepV=null;
          if (hasBegin) {
              beginV = ctxt.getTemporaryVariableName();
              ctxt.generateJavaSource("int " + beginV + " = ");
              ctxt.generateAttribute("begin");
              ctxt.generateJavaSource(";");
          }
          if (hasEnd) {
              indexV = ctxt.getTemporaryVariableName();
              ctxt.generateJavaSource("int " + indexV + " = 0;");
              endV = ctxt.getTemporaryVariableName();
              ctxt.generateJavaSource("int " + endV + " = ");
              ctxt.generateAttribute("end");
              ctxt.generateJavaSource(";");
          }
          if (hasStep) {
              stepV = ctxt.getTemporaryVariableName();
              ctxt.generateJavaSource("int " + stepV + " = ");
              ctxt.generateAttribute("step");
              ctxt.generateJavaSource(";");
          }
          
          String iterV = ctxt.getTemporaryVariableName();
          ctxt.generateJavaSource("Iterator " + iterV + " = null;");
          // Object[]
          ctxt.generateJavaSource("if (" + itemsV + " instanceof Object[])");
          ctxt.generateJavaSource(iterV + "=toIterator((Object[])" + itemsV + ");");
          // boolean[]
          ctxt.generateJavaSource("else if (" + itemsV + " instanceof boolean[])");
          ctxt.generateJavaSource(iterV + "=toIterator((boolean[])" + itemsV + ");");
          // byte[]
          ctxt.generateJavaSource("else if (" + itemsV + " instanceof byte[])");
          ctxt.generateJavaSource(iterV + "=toIterator((byte[])" + itemsV + ");");
          // char[]
          ctxt.generateJavaSource("else if (" + itemsV + " instanceof char[])");
          ctxt.generateJavaSource(iterV + "=toIterator((char[])" + itemsV + ");");
          // short[]
          ctxt.generateJavaSource("else if (" + itemsV + " instanceof short[])");
          ctxt.generateJavaSource(iterV + "=toIterator((short[])" + itemsV + ");");
          // int[]
          ctxt.generateJavaSource("else if (" + itemsV + " instanceof int[])");
          ctxt.generateJavaSource(iterV + "=toIterator((int[])" + itemsV + ");");
          // long[]
          ctxt.generateJavaSource("else if (" + itemsV + " instanceof long[])");
          ctxt.generateJavaSource(iterV + "=toIterator((long[])" + itemsV + ");");
          // float[]
          ctxt.generateJavaSource("else if (" + itemsV + " instanceof float[])");
          ctxt.generateJavaSource(iterV + "=toIterator((float[])" + itemsV + ");");
          // double[]
          ctxt.generateJavaSource("else if (" + itemsV + " instanceof double[])");
          ctxt.generateJavaSource(iterV + "=toIterator((double[])" + itemsV + ");");
          
          // Collection
          ctxt.generateJavaSource("else if (" + itemsV + " instanceof Collection)");
          ctxt.generateJavaSource(iterV + "=((Collection)" + itemsV + ").iterator();");
          
          // Iterator
          ctxt.generateJavaSource("else if (" + itemsV + " instanceof Iterator)");
          ctxt.generateJavaSource(iterV + "=(Iterator)" + itemsV + ";");
          
          // Enumeration
          ctxt.generateJavaSource("else if (" + itemsV + " instanceof Enumeration)");
          ctxt.generateJavaSource(iterV + "=toIterator((Enumeration)" + itemsV + ");");
          
          // Map
          ctxt.generateJavaSource("else if (" + itemsV + " instanceof Map)");
          ctxt.generateJavaSource(iterV + "=((Map)" + itemsV + ").entrySet().iterator();");
          
          if (hasBegin) {
              String tV = ctxt.getTemporaryVariableName();
              ctxt.generateJavaSource("for (int " + tV + "=" + beginV + ";" +
                      tV + ">0 && " + iterV + ".hasNext(); " +
                      tV + "--)");
              ctxt.generateJavaSource(iterV + ".next();");
          }
          
          ctxt.generateJavaSource("while (" + iterV + ".hasNext()){");
          if (hasVar) {
              ctxt.generateJavaSource("_jspx_page_context.setAttribute(");
              ctxt.generateAttribute("var");
              ctxt.generateJavaSource(", " + iterV + ".next());");
          }
          
          ctxt.generateBody();
          
          if (hasStep) {
              String tV = ctxt.getTemporaryVariableName();
              ctxt.generateJavaSource("for (int " + tV + "=" + stepV + "-1;" +
                      tV + ">0 && " + iterV + ".hasNext(); " +
                      tV + "--)");
              ctxt.generateJavaSource(iterV + ".next();");
          }
          if (hasEnd) {
              if (hasStep) {
                  ctxt.generateJavaSource(indexV + "+=" + stepV + ";");
              }
              else {
                  ctxt.generateJavaSource(indexV + "++;");
              }
              if (hasBegin) {
                  ctxt.generateJavaSource("if(" + beginV + "+" + indexV +
                          ">"+ endV + ")");
              }
              else {
                  ctxt.generateJavaSource("if(" + indexV + ">" + endV + ")");
              }
              ctxt.generateJavaSource("break;");
          }
          ctxt.generateJavaSource("}");	// while
      }
      
      /**
       * Generate iterators for data types supported in items
       */
      private void generateIterators(TagPluginContext ctxt) {
          
          // Object[]
          ctxt.generateDeclaration("ObjectArrayIterator", 
                  "private Iterator toIterator(final Object[] a){\n" +
                  "  return (new Iterator() {\n" +
                  "    int index=0;\n" +
                  "    public boolean hasNext() {\n" +
                  "      return index < a.length;}\n" +
                  "    public Object next() {\n" +
                  "      return a[index++];}\n" +
                  "    public void remove() {}\n" +
                  "  });\n" +
                  "}"
          );
          
          // boolean[]
          ctxt.generateDeclaration("booleanArrayIterator", 
                  "private Iterator toIterator(final boolean[] a){\n" +
                  "  return (new Iterator() {\n" +
                  "    int index=0;\n" +
                  "    public boolean hasNext() {\n" +
                  "      return index < a.length;}\n" +
                  "    public Object next() {\n" +
                  "      return new Boolean(a[index++]);}\n" +
                  "    public void remove() {}\n" +
                  "  });\n" +
                  "}"
          );
          
          // byte[]
          ctxt.generateDeclaration("byteArrayIterator", 
                  "private Iterator toIterator(final byte[] a){\n" +
                  "  return (new Iterator() {\n" +
                  "    int index=0;\n" +
                  "    public boolean hasNext() {\n" +
                  "      return index < a.length;}\n" +
                  "    public Object next() {\n" +
                  "      return new Byte(a[index++]);}\n" +
                  "    public void remove() {}\n" +
                  "  });\n" +
                  "}"
          );
          
          // char[]
          ctxt.generateDeclaration("charArrayIterator", 
                  "private Iterator toIterator(final char[] a){\n" +
                  "  return (new Iterator() {\n" +
                  "    int index=0;\n" +
                  "    public boolean hasNext() {\n" +
                  "      return index < a.length;}\n" +
                  "    public Object next() {\n" +
                  "      return new Character(a[index++]);}\n" +
                  "    public void remove() {}\n" +
                  "  });\n" +
                  "}"
          );
          
          // short[]
          ctxt.generateDeclaration("shortArrayIterator", 
                  "private Iterator toIterator(final short[] a){\n" +
                  "  return (new Iterator() {\n" +
                  "    int index=0;\n" +
                  "    public boolean hasNext() {\n" +
                  "      return index < a.length;}\n" +
                  "    public Object next() {\n" +
                  "      return new Short(a[index++]);}\n" +
                  "    public void remove() {}\n" +
                  "  });\n" +
                  "}"
          );
          
          // int[]
          ctxt.generateDeclaration("intArrayIterator", 
                  "private Iterator toIterator(final int[] a){\n" +
                  "  return (new Iterator() {\n" +
                  "    int index=0;\n" +
                  "    public boolean hasNext() {\n" +
                  "      return index < a.length;}\n" +
                  "    public Object next() {\n" +
                  "      return new Integer(a[index++]);}\n" +
                  "    public void remove() {}\n" +
                  "  });\n" +
                  "}"
          );
          
          // long[]
          ctxt.generateDeclaration("longArrayIterator", 
                  "private Iterator toIterator(final long[] a){\n" +
                  "  return (new Iterator() {\n" +
                  "    int index=0;\n" +
                  "    public boolean hasNext() {\n" +
                  "      return index < a.length;}\n" +
                  "    public Object next() {\n" +
                  "      return new Long(a[index++]);}\n" +
                  "    public void remove() {}\n" +
                  "  });\n" +
                  "}"
          );
          
          // float[]
          ctxt.generateDeclaration("floatArrayIterator",
                  "private Iterator toIterator(final float[] a){\n" +
                  "  return (new Iterator() {\n" +
                  "    int index=0;\n" +
                  "    public boolean hasNext() {\n" +
                  "      return index < a.length;}\n" +
                  "    public Object next() {\n" +
                  "      return new Float(a[index++]);}\n" +
                  "    public void remove() {}\n" +
                  "  });\n" +
                  "}"
          );
          
          // double[]
          ctxt.generateDeclaration("doubleArrayIterator",
                  "private Iterator toIterator(final double[] a){\n" +
                  "  return (new Iterator() {\n" +
                  "    int index=0;\n" +
                  "    public boolean hasNext() {\n" +
                  "      return index < a.length;}\n" +
                  "    public Object next() {\n" +
                  "      return new Double(a[index++]);}\n" +
                  "    public void remove() {}\n" +
                  "  });\n" +
                  "}"
          );
          
          // Enumeration
          ctxt.generateDeclaration("enumIterator",
                  "private Iterator toIterator(final Enumeration e){\n" +
                  "  return (new Iterator() {\n" +
                  "    public boolean hasNext() {\n" +
                  "      return e.hasMoreElements();}\n" +
                  "    public Object next() {\n" +
                  "      return e.nextElement();}\n" +
                  "    public void remove() {}\n" +
                  "  });\n" +
                  "}"
          );
          
      }
  }
  
  
  
  1.375     +4 -0      jakarta-tomcat-catalina/webapps/docs/changelog.xml
  
  Index: changelog.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/webapps/docs/changelog.xml,v
  retrieving revision 1.374
  retrieving revision 1.375
  diff -u -r1.374 -r1.375
  --- changelog.xml	19 Sep 2005 11:35:50 -0000	1.374
  +++ changelog.xml	20 Sep 2005 10:56:48 -0000	1.375
  @@ -90,6 +90,10 @@
           JSP compilation speed improvement using tag library information caching, 
           submitted by Xingbo Gao (remm)
         </update>
  +      <add>
  +        Initial contribution of JSTL tag plugins supporting the core tag library of
  +        JSTL, submitted by Jing Li (remm)
  +      </add>
       </changelog>
     </subsection>
     
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message