jurt/com/sun/star/lib/util/UrlToFileMapper.java |  111 +++++-------------------
 qadevOOo/runner/helper/PropertyHelper.java      |   25 -----
 2 files changed, 26 insertions(+), 110 deletions(-)

New commits:
commit 586eea345e8a6b390fe7c71470c5e9fe86be3ec8
Author: Noel Grandin <n...@peralex.com>
Date:   Mon Aug 4 15:31:41 2014 +0200

    java: remove pre Java 1.5 workaround in UrlToFileMapper
    
    Since we now require Java 1.5
    Note that I tried to remove more code and use URL#toURI as the comment
    suggests, but that results in errors during make check.
    
    Change-Id: If283ee60f272b18920dcf8fc1be8766c0bed6ea5

diff --git a/jurt/com/sun/star/lib/util/UrlToFileMapper.java 
b/jurt/com/sun/star/lib/util/UrlToFileMapper.java
index 8354b85..3380992 100644
--- a/jurt/com/sun/star/lib/util/UrlToFileMapper.java
+++ b/jurt/com/sun/star/lib/util/UrlToFileMapper.java
@@ -18,39 +18,22 @@
 package com.sun.star.lib.util;
 
 import java.io.File;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
-import java.net.URLDecoder;
 import java.net.URLEncoder;
 
 /**
  * Maps Java URL representations to File representations, on any Java version.
  *
+ * This used to be used to do URL to File mapping in pre-Java1.4 days, but 
since
+ * we now require Java 1.5, it is largely unnecessary.
+ *
  * @since UDK 3.2.8
  */
 public final class UrlToFileMapper {
 
-    // java.net.URLEncoder.encode(String, String) and java.net.URI are only
-    // available since Java 1.4:
-    private static Method urlEncoderEncode;
-    private static Constructor<?> uriConstructor;
-    private static Constructor<File> fileConstructor;
-    static {
-        try {
-            urlEncoderEncode = URLEncoder.class.getMethod(
-                "encode", new Class[] { String.class, String.class });
-            Class<?> uriClass = Class.forName("java.net.URI");
-            uriConstructor = uriClass.getConstructor(
-                new Class[] { String.class });
-            fileConstructor = File.class.getConstructor(
-                new Class[] { uriClass });
-        } catch (ClassNotFoundException e) {
-        } catch (NoSuchMethodException e) {
-        }
-    }
-
     /**
      * Maps Java URL representations to File representations.
      *
@@ -60,64 +43,27 @@ public final class UrlToFileMapper {
     public static File mapUrlToFile(URL url) {
         if (url == null) {
             return null;
-        } else if (fileConstructor == null) {
-            // If java.net.URI is not available, hope that the following works
-            // well:  First, check that the given URL has a certain form.
-            // Second, use the URLDecoder to decode the URL path (taking care
-            // not to change any plus signs to spaces), hoping that the used
-            // default encoding is the proper one for file URLs.  Third, create
-            // a File from the decoded path.
-            return url.getProtocol().equalsIgnoreCase("file")
-                && url.getAuthority() == null && url.getQuery() == null
-                && url.getRef() == null
-                ? new File(URLDecoder.decode(
-                               StringHelper.replace(url.getPath(), '+', 
"%2B")))
-                : null;
         } else {
-            // If java.net.URI is available, do
-            //   URI uri = new URI(encodedUrl);
-            //   try {
-            //       return new File(uri);
-            //   } catch (IllegalArgumentException e) {
-            //       return null;
-            //   }
-            // where encodedUrl is url.toString(), but since that may contain
-            // unsafe characters (e.g., space, " "), it is encoded, as 
otherwise
-            // the URI constructor might throw java.net.URISyntaxException (in
-            // Java 1.5, URL.toURI might be used instead).
-            String encodedUrl = encode(url.toString());
             try {
-                Object uri = uriConstructor.newInstance(
-                    new Object[] { encodedUrl });
+                // where encodedUrl is url.toString(), but since that may 
contain
+                // unsafe characters (e.g., space, " "), it is encoded, as 
otherwise
+                // the URI constructor might throw java.net.URISyntaxException 
(in
+                // Java 1.5, URL.toURI might be used instead).
+                String encodedUrl = encode(url.toString());
+                URI uri = new URI(encodedUrl);
                 try {
-                    return fileConstructor.newInstance(
-                        new Object[] { uri });
-                } catch (InvocationTargetException e) {
-                    if (e.getTargetException() instanceof
-                        IllegalArgumentException) {
-                        return null;
-                    } else {
-                        throw e;
-                    }
-                }
-            } catch (InstantiationException e) {
-                throw new RuntimeException("This cannot happen: " + e);
-            } catch (IllegalAccessException e) {
-                throw new RuntimeException("This cannot happen: " + e);
-            } catch (InvocationTargetException e) {
-                if (e.getTargetException() instanceof Error) {
-                    throw (Error) e.getTargetException();
-                } else if (e.getTargetException() instanceof RuntimeException) 
{
-                    throw (RuntimeException) e.getTargetException();
-                } else {
-                    throw new RuntimeException("This cannot happen: " + e);
+                    return new File(uri);
+                } catch (IllegalArgumentException e) {
+                    return null;
                 }
+            } catch (URISyntaxException ex) {
+                throw new RuntimeException(ex); // should never happend
             }
         }
     }
 
     private static String encode(String url) {
-        StringBuffer buf = new StringBuffer();
+        StringBuffer buf = new StringBuffer(url.length());
         for (int i = 0; i < url.length(); ++i) {
             char c = url.charAt(i);
             // The RFC 2732 <uric> characters: !$&'()*+,-./:;=?@[]_~ plus 
digits
@@ -130,21 +76,16 @@ public final class UrlToFileMapper {
             } else if (c == ' ') {
                 buf.append("%20");
             } else {
-                String enc;
                 try {
-                    enc = (String) urlEncoderEncode.invoke(
-                        null,
-                        new Object[] {Character.toString(c), "UTF-8" });
-                } catch (IllegalAccessException e) {
-                    throw new RuntimeException("This cannot happen: " + e);
-                } catch (InvocationTargetException e) {
-                    throw new RuntimeException("This cannot happen: " + e);
+                    String enc = URLEncoder.encode(Character.toString(c), 
"UTF-8");
+                    buf.append(enc);
+                } catch (UnsupportedEncodingException e) {
+                    throw new RuntimeException(e); // should never happen
                 }
-                buf.append(enc);
-            }
-        }
+             }
+         }
         return buf.toString();
-    }
+     }
 
-    private UrlToFileMapper() {}
+     private UrlToFileMapper() {}
 }
commit dd0bff54debd622361ece10eefa343740007139a
Author: Noel Grandin <n...@peralex.com>
Date:   Mon Aug 4 14:52:41 2014 +0200

    java: remove java 1.4 commented out code
    
    Change-Id: I97b27b893ba516c6c29a46095f4ffc6fab838f1b

diff --git a/qadevOOo/runner/helper/PropertyHelper.java 
b/qadevOOo/runner/helper/PropertyHelper.java
index 05d6a7d..c48c58b 100644
--- a/qadevOOo/runner/helper/PropertyHelper.java
+++ b/qadevOOo/runner/helper/PropertyHelper.java
@@ -41,31 +41,6 @@ public class PropertyHelper
             else
             {
                 aSaveProperties = _aPropertyList.toArray(new 
PropertyValue[_aPropertyList.size()]);
-                // old java 1.4
-//                if (_aPropertyList.size() > 0)
-//                {
-//                    aSaveProperties = new 
PropertyValue[_aPropertyList.size()];
-//                    for (int i = 0;i<_aPropertyList.size(); i++)
-//                    {
-//                        aSaveProperties[i] = (PropertyValue) 
_aPropertyList.get(i);
-//                    }
-//                }
-//                else
-//                {
-//                    aSaveProperties = new PropertyValue[0];
-//                }
-
-// show properties?
-//                 if (_aPropertyList.size() > 0)
-//                 {
-//                     // aSaveProperties = new 
PropertyValue[_aPropertyList.size()];
-//                     for (int i = 0;i<_aPropertyList.size(); i++)
-//                     {
-//                         PropertyValue aProp = (PropertyValue) 
_aPropertyList.get(i);
-//                         showProperty(aProp);
-//                     }
-//                 }
-
             }
             return aSaveProperties;
         }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to