felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject svn commit: r926330 - /felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
Date Mon, 22 Mar 2010 20:58:36 GMT
Author: pauls
Date: Mon Mar 22 20:58:35 2010
New Revision: 926330

URL: http://svn.apache.org/viewvc?rev=926330&view=rev
Log:
Use harmony code to decode location URLs (FELIX-2195).

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java?rev=926330&r1=926329&r2=926330&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
Mon Mar 22 20:58:35 2010
@@ -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 @@ public class BundleArchive
      * </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 @@ public class BundleArchive
                 }
 
                 // 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 @@ public class BundleArchive
         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



Mime
View raw message