Methods Summary |
---|
public boolean | add(java.net.URL url)Adds the specified URL to this set if it is not already present.
return super.add(normalize(url));
|
private static java.lang.String | cleanup(java.lang.String uri)Normalize a uri containing ../ and ./ paths.
String[] dirty = tokenize(uri, "/\\", false);
int length = dirty.length;
String[] clean = new String[length];
boolean path;
boolean finished;
while (true) {
path = false;
finished = true;
for (int i = 0, j = 0; (i < length) && (dirty[i] != null); i++) {
if (".".equals(dirty[i])) {
// ignore
} else if ("..".equals(dirty[i])) {
clean[j++] = dirty[i];
if (path) {
finished = false;
}
} else {
if ((i + 1 < length) && ("..".equals(dirty[i + 1]))) {
i++;
} else {
clean[j++] = dirty[i];
path = true;
}
}
}
if (finished) {
break;
} else {
dirty = clean;
clean = new String[length];
}
}
StringBuffer b = new StringBuffer(uri.length());
for (int i = 0; (i < length) && (clean[i] != null); i++) {
b.append(clean[i]);
if ((i + 1 < length) && (clean[i + 1] != null)) {
b.append("/");
}
}
return b.toString();
|
public boolean | contains(java.net.URL url)Returns true if this set contains the specified element.
return super.contains(normalize(url));
|
public static java.net.URL | normalize(java.net.URL url)if the url points to a file then make sure we cleanup ".." "." etc.
if (url.getProtocol().equals("file")) {
try {
File f = new File(cleanup(url.getFile()));
if(f.exists())
return f.toURL();
} catch (Exception e) {}
}
return url;
|
public boolean | remove(java.net.URL url)Removes the given URL from this set if it is present.
return super.remove(normalize(url));
|
private static java.lang.String[] | tokenize(java.lang.String str, java.lang.String delim, boolean returnTokens)Constructs a string tokenizer for the specified string. All characters
in the delim argument are the delimiters for separating tokens.
If the returnTokens flag is true, then the delimiter characters are
also returned as tokens. Each delimiter is returned as a string of
length one. If the flag is false, the delimiter characters are skipped
and only serve as separators between tokens. Then tokenizes the str
and return an String[] array with tokens.
StringTokenizer tokenizer = new StringTokenizer(str, delim, returnTokens);
String[] tokens = new String[tokenizer.countTokens()];
int i = 0;
while (tokenizer.hasMoreTokens()) {
tokens[i] = tokenizer.nextToken();
i++;
}
return tokens;
|