antonio     2004/07/11 10:18:37

  Modified:    src/java/org/apache/cocoon/util NetUtils.java
  Log:
  Java version detection without throwing a exception
  
  Revision  Changes    Path
  1.17      +13 -10    cocoon-2.1/src/java/org/apache/cocoon/util/NetUtils.java
  
  Index: NetUtils.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/util/NetUtils.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- NetUtils.java     16 Jun 2004 20:00:07 -0000      1.16
  +++ NetUtils.java     11 Jul 2004 17:18:37 -0000      1.17
  @@ -17,6 +17,7 @@
   
   import org.apache.cocoon.environment.Request;
   import org.apache.commons.lang.StringUtils;
  +import org.apache.commons.lang.SystemUtils;
   import org.apache.excalibur.source.SourceParameters;
   
   import java.io.ByteArrayOutputStream;
  @@ -481,22 +482,24 @@
           if (uri.indexOf("@") != -1 && (uri.startsWith("ftp://";) || 
uri.startsWith("http://";))) {
               return uri.substring(0, uri.indexOf(":") + 2) + 
uri.substring(uri.indexOf("@") + 1);
           }
  -
           return uri;
       }
   
  -
       // FIXME Remove when JDK1.3 support is removed.
       private static Method urlEncode;
       private static Method urlDecode;
   
       static {
  -        try {
  -            urlEncode = URLEncoder.class.getMethod("encode", new 
Class[]{String.class, String.class});
  -            urlDecode = URLDecoder.class.getMethod("decode", new 
Class[]{String.class, String.class});
  -        } catch (NoSuchMethodException e) {
  +        if (SystemUtils.isJavaVersionAtLeast(140)) {
  +            try {
  +                 urlEncode = URLEncoder.class.getMethod("encode", new 
Class[]{String.class, String.class});
  +                 urlDecode = URLDecoder.class.getMethod("decode", new 
Class[]{String.class, String.class});
  +            } catch (NoSuchMethodException e) {
  +             // EMPTY
  +            }
  +        } else {
               urlEncode = null;
  -            urlDecode = null;
  +            urlDecode = null;    
           }
       }
   
  @@ -509,6 +512,7 @@
               try {
                   return (String)urlEncode.invoke(s, new Object[]{ s, enc } );
               } catch (IllegalAccessException e) {
  +                // EMPTY
               } catch (InvocationTargetException e) {
                   if (e.getTargetException() instanceof 
UnsupportedEncodingException) {
                       throw 
(UnsupportedEncodingException)e.getTargetException();
  @@ -517,7 +521,6 @@
                   }
               }
           }
  -
           return URLEncoder.encode(s);
       }
   
  @@ -530,6 +533,7 @@
               try {
                   return (String)urlDecode.invoke(s, new Object[]{ s, enc } );
               } catch (IllegalAccessException e) {
  +                // EMPTY
               } catch (InvocationTargetException e) {
                   if (e.getTargetException() instanceof 
UnsupportedEncodingException) {
                       throw 
(UnsupportedEncodingException)e.getTargetException();
  @@ -538,7 +542,6 @@
                   }
               }
           }
  -
           return URLDecoder.decode(s);
       }
   }
  
  
  

Reply via email to