FileDocCategorySizeDatePackage
URLHashSet.javaAPI DocApache Axis 1.45024Sat Apr 22 18:57:28 BST 2006org.apache.axis.utils

URLHashSet

public class URLHashSet extends HashSet
Class URLHashSet
author
Davanum Srinivas (dims@apache.org)

Fields Summary
Constructors Summary
Methods Summary
public booleanadd(java.net.URL url)
Adds the specified URL to this set if it is not already present.

param
url url to be added to this set.
return
true if the set did not already contain the specified element.

        return super.add(normalize(url));
    
private static java.lang.Stringcleanup(java.lang.String uri)
Normalize a uri containing ../ and ./ paths.

param
uri The uri path to normalize
return
The normalized uri

        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 booleancontains(java.net.URL url)
Returns true if this set contains the specified element.

param
url url whose presence in this set is to be tested.
return
true if this set contains the specified element.

        return super.contains(normalize(url));
    
public static java.net.URLnormalize(java.net.URL url)
if the url points to a file then make sure we cleanup ".." "." etc.

param
url url to be normalized
return
normalized url

        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 booleanremove(java.net.URL url)
Removes the given URL from this set if it is present.

param
url url to be removed from this set, if present.
return
true if the set contained the specified element.

        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.

param
str a string to be parsed
param
delim the delimiters
param
returnTokens flag indicating whether to return the delimiters as tokens
return
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;