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 ImportSupport.java Util.java
Date Mon, 31 Mar 2003 13:58:38 GMT
pierred     2003/03/31 05:58:38

  Modified:    standard/src/org/apache/taglibs/standard/tag/common/core
                        ImportSupport.java Util.java
  Log:
  JSTL 1.1 has been amended to properly handle bug #10024.
  Advisory character encoding now properly fetched from "charset" attribute
  of "content-type" header.
  
  Revision  Changes    Path
  1.20      +19 -9     jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/core/ImportSupport.java
  
  Index: ImportSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/core/ImportSupport.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- ImportSupport.java	14 Mar 2003 22:04:35 -0000	1.19
  +++ ImportSupport.java	31 Mar 2003 13:58:37 -0000	1.20
  @@ -340,6 +340,7 @@
   	    // for relative URLs, delegate to our peer
   	    return new StringReader(acquireString());
   	} else {
  +            // absolute URL
               String target = targetUrl();
   	    try {
   	        // handle absolute URLs ourselves, using java.net.URL
  @@ -349,15 +350,24 @@
   
   	        // okay, we've got a stream; encode it appropriately
   	        Reader r = null;
  -	        if (charEncoding != null && !charEncoding.equals(""))
  -		    r = new InputStreamReader(i, charEncoding);
  -	        else {
  -		    String responseAdvisoryEncoding = uc.getContentEncoding();
  -		    if (responseAdvisoryEncoding != null)
  -		        r = new InputStreamReader(i, responseAdvisoryEncoding);
  -		    else
  -		        r = new InputStreamReader(i, DEFAULT_ENCODING);
  -	        }
  +                String charSet; 
  +	        if (charEncoding != null && !charEncoding.equals("")) {
  +                    charSet = charEncoding;
  +                } else {
  +                    // charSet extracted according to RFC 2045, section 5.1
  +		    String contentType = uc.getContentType();
  +		    if (contentType != null) {
  +                        charSet = Util.getContentTypeAttribute(contentType, "charset");
  +                        if (charSet == null) charSet = DEFAULT_ENCODING;
  +                    } else {
  +                        charSet = DEFAULT_ENCODING;
  +                    }
  +                }
  +                try {
  +                    r = new InputStreamReader(i, charSet);
  +                } catch (Exception ex) {
  +                    r = new InputStreamReader(i, DEFAULT_ENCODING);
  +                }
   
   		// check response code for HTTP URLs before returning, per spec,
   		// before returning
  
  
  
  1.9       +25 -1     jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/core/Util.java
  
  Index: Util.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/core/Util.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Util.java	25 Mar 2003 19:43:25 -0000	1.8
  +++ Util.java	31 Mar 2003 13:58:37 -0000	1.9
  @@ -164,5 +164,29 @@
                   sb.append(c);
           }
           return sb.toString();
  -    }    
  +    }  
  +    
  +    /**
  +     * Get the value associated with a content-type attribute.
  +     * Syntax defined in RFC 2045, section 5.1.
  +     */
  +    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 += 8; // charset=
  +        if (input.charAt(index) == '"') {
  +            // attribute value is a quoted string
  +            begin = index + 1;
  +            end = input.indexOf('"', begin);
  +            if (end == -1) return null;
  +        } else {
  +            begin = index;
  +            end = input.indexOf(';', begin);
  +            if (end == -1) end = input.indexOf(' ', begin);
  +            if (end == -1) end = input.length();
  +        }
  +        return input.substring(begin, end).trim();
  +    }
   }
  
  
  

---------------------------------------------------------------------
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