jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pier...@apache.org
Subject cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/core ParamSupport.java
Date Wed, 26 Feb 2003 22:47:07 GMT
pierred     2003/02/26 14:47:07

  Modified:    standard/src/org/apache/taglibs/standard/tag/common/core
                        ParamSupport.java
  Log:
  Fix for bug 16912.
  We take advantage of URLEncoder.encode(String,String) if running on J2SE 1.4.
  
  Revision  Changes    Path
  1.8       +47 -3     jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/core/ParamSupport.java
  
  Index: ParamSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/core/ParamSupport.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ParamSupport.java	8 Apr 2002 20:46:40 -0000	1.7
  +++ ParamSupport.java	26 Feb 2003 22:47:07 -0000	1.8
  @@ -55,6 +55,7 @@
   
   package org.apache.taglibs.standard.tag.common.core;
   
  +import java.lang.reflect.*;
   import java.util.*;
   import javax.servlet.jsp.*;
   import javax.servlet.jsp.tagext.*;
  @@ -72,6 +73,12 @@
   public abstract class ParamSupport extends BodyTagSupport {
   
       //*********************************************************************
  +    // Private constants
  +
  +    private static final Class[] URL_ENCODER_PARAM_TYPES =
  +	new Class[] { String.class, String.class };
  +
  +    //*********************************************************************
       // Protected state
   
       protected String name;                       // 'name' attribute
  @@ -85,8 +92,26 @@
       protected boolean encode = true;
   
       //*********************************************************************
  +    // Private state
  +
  +    private static Method encodeMethod1_4 = null;
  +
  +    //*********************************************************************
       // Constructor and initialization
   
  +    // URLEncoder.encode(String) has been deprecated in J2SE 1.4. 
  +    // Take advantage of the new method URLEncoder.encode(String, enc)
  +    // if J2SE 1.4 is used.
  +    static {
  +	try {
  +	    Class urlEncoderClass = Class.forName("java.net.URLEncoder");
  +	    encodeMethod1_4 = 
  +                urlEncoderClass.getMethod(
  +                    "encode",
  +		    new Class[] {String.class, String.class});
  +        } catch (Exception ex) {} // encodeMethod1_4 will be null if exception
  +    }
  +
       public ParamSupport() {
   	super();
   	init();
  @@ -121,10 +146,29 @@
   		value = bodyContent.getString().trim();
   	}
   	if (encode) {
  -	    parent.addParameter(
  -		URLEncoder.encode(name), URLEncoder.encode(value));
  -	} else
  +            if (encodeMethod1_4 != null) {
  +	        Object[] methodArgsName = new Object[2];
  +	        methodArgsName[0] = name;
  +	        methodArgsName[1] = pageContext.getResponse().getCharacterEncoding();
  +	        Object[] methodArgsValue = new Object[2];
  +	        methodArgsValue[0] = value;
  +	        methodArgsValue[1] = pageContext.getResponse().getCharacterEncoding();
  +	        
  +                try {
  +                    parent.addParameter(
  +                    (String)encodeMethod1_4.invoke(null, methodArgsName),
  +                    (String)encodeMethod1_4.invoke(null, methodArgsValue));  
  +                } catch (Exception ex) {
  +                    throw new JspException("System error invoking URLEncoder.encode() by
reflection.", ex);
  +                }
  +            } else {
  +                // must use J2SE 1.3 version
  +	        parent.addParameter(
  +		    URLEncoder.encode(name), URLEncoder.encode(value));
  +            }
  +	} else {
   	    parent.addParameter(name, value);
  +        }
   	return EVAL_PAGE;
       }
   
  
  
  

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


Mime
View raw message