OPENJPA-2102: Added code to compare decoded URLs in AbstractCFMetaDataFactory.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.0.x@1225657 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Heath Thomann 2011-12-29 21:09:35 +00:00
parent fea6083a29
commit 35a09a7f36
1 changed files with 62 additions and 1 deletions

View File

@ -780,7 +780,8 @@ public abstract class AbstractCFMetaDataFactory
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) {
@ -858,6 +859,66 @@ public abstract class AbstractCFMetaDataFactory
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