Use harmony code to decode location URLs (FELIX-2195).

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@926330 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java b/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
index e9fac70..72da012 100644
--- a/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
+++ b/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
@@ -19,7 +19,6 @@
 package org.apache.felix.framework.cache;
 
 import java.io.*;
-import java.net.URLDecoder;
 
 import java.util.Map;
 import org.apache.felix.framework.Logger;
@@ -156,7 +155,7 @@
      * </p>
      * @param logger the logger to be used by the archive.
      * @param archiveRootDir the archive root directory for storing state.
-     * @param id the bundle identifier associated with the archive.
+     * @param configMap configMap for BundleArchive
      * @throws Exception if any error occurs.
     **/
     public BundleArchive(Logger logger, Map configMap, File archiveRootDir)
@@ -985,7 +984,7 @@
                 }
 
                 // Decode any URL escaped sequences.
-                location = URLDecoder.decode(location, "UTF-8");
+                location = decode(location);
 
                 // Make sure the referenced file exists.
                 File file = new File(location.substring(FILE_PROTOCOL.length()));
@@ -1040,6 +1039,43 @@
         return result;
     }
 
+    //method from Harmony java.net.URIEncoderDecoder (luni subproject) used by URI to decode uri components.
+    static final String encoding = "UTF8"; //$NON-NLS-1$
+    private static String decode(String s) throws UnsupportedEncodingException 
+    {
+        StringBuffer result = new StringBuffer();
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        for (int i = 0; i < s.length();) 
+        {
+            char c = s.charAt(i);
+            if (c == '%') 
+            {
+                out.reset();
+                do 
+                {
+                    if (i + 2 >= s.length()) 
+                    {
+                        throw new IllegalArgumentException("Incomplete % sequence at: " + i);
+                    }
+                    int d1 = Character.digit(s.charAt(i + 1), 16);
+                    int d2 = Character.digit(s.charAt(i + 2), 16);
+                    if (d1 == -1 || d2 == -1) 
+                    {
+                        throw new IllegalArgumentException("Invalid % sequence (" + s.substring(i, i + 3) + ") at: " + String.valueOf(i));
+                    }
+                    out.write((byte) ((d1 << 4) + d2));
+                    i += 3;
+                } while (i < s.length() && s.charAt(i) == '%');
+                result.append(out.toString(encoding));
+                continue;
+            }
+            result.append(c);
+            i++;
+        }
+        return result.toString();
+    }
+
+
     /**
      * This utility method is used to retrieve the current refresh
      * counter value for the bundle. This value is used when generating