openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hthom...@apache.org
Subject svn commit: r1227364 - /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
Date Wed, 04 Jan 2012 22:29:38 GMT
Author: hthomann
Date: Wed Jan  4 22:29:38 2012
New Revision: 1227364

URL: http://svn.apache.org/viewvc?rev=1227364&view=rev
Log:
OPENJPA-2102: Added code to compare decoded URLs in AbstractCFMetaDataFactory.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java?rev=1227364&r1=1227363&r2=1227364&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
Wed Jan  4 22:29:38 2012
@@ -787,7 +787,8 @@ public abstract class AbstractCFMetaData
                         if (log.isTraceEnabled())
                             log.trace(_loc.get("resource-url", urlString));
                         if (peMap != null) {
-                            if (puUrlString != null && urlString.indexOf(puUrlString)
!= -1) 
+                        	//OPENJPA-2102: decode the URL to remove such things a spaces ('
') encoded as '%20'
+                            if (puUrlString != null && decode(urlString).indexOf(decode(puUrlString))
!= -1) 
                                 urls.add(url);
                             if (mappingFileNames != null && mappingFileNames.size()
!= 0) {
                                 for (String mappingFileName : mappingFileNames) {
@@ -865,6 +866,66 @@ public abstract class AbstractCFMetaData
             names.addAll(newNames);
         }
     }
+    
+    /**
+     * Decodes a URL-encoded path string.  For example, an encoded
+     * space (%20) is decoded into a normal space (' ') character.
+     * Added via OPENJPA-2102.
+     * @param String encoded - the encoded URL string
+     * @return String decoded - the decoded string.
+     */
+    public static String decode(String s) {
+       if (s == null) {
+          return null;
+       }
+
+       int i = s.indexOf('%');
+       if (i == -1) {
+          return s;
+       }
+
+       StringBuilder builder = new StringBuilder();
+       int begin = 0;
+
+       do {
+          builder.append(s, begin, i);
+          begin = i + 3;
+
+          char ch = (char) Integer.parseInt(s.substring(i + 1, begin), 16);
+
+          if ((ch & 0x80) != 0) {
+             // Decode "modified UTF-8".
+
+             if (s.charAt(begin++) != '%') {
+                throw new IllegalArgumentException();
+             }
+
+             char ch2 = (char) Integer.parseInt(s.substring(begin, begin + 2), 16);
+             begin += 2;
+
+             if ((ch & 0xe0) == 0xc0) {
+                ch = (char) (((ch & 0x1f) << 6) | (ch2 & 0x3f));
+             } else if ((ch & 0xf0) == 0xe0) {
+                if (s.charAt(begin++) != '%') {
+                   throw new IllegalArgumentException();
+                }
+
+                char ch3 = (char) Integer.parseInt(s.substring(begin, begin + 2), 16);
+                begin += 2;
+
+                ch = (char) (((ch & 0x0f) << 12) | ((ch2 & 0x3f) << 6)
| (ch3 & 0x3f));
+             } else {
+                throw new IllegalArgumentException();
+             }
+          }
+
+          builder.append(ch);
+       } while ((i = s.indexOf('%', begin)) != -1);
+
+       builder.append(s, begin, s.length());
+
+       return builder.toString();
+    }
 
     /**
      * Implement this method to map metadata resources to the persistent



Mime
View raw message