The Collective

Collective resource servers keep multiple versions of resources in a complex filesystem.
In order to navigate this system, we must treat some directories differently.

Category directories have URLs that end in a "/", but contain no "."

public class VersioningUrlResourceServer extends UrlResourceServer {

    public Category[] getSubCategories(Category category) throws IOException {
        URL[] catURLs = getCategoryURLs(getURL(category));
        List categories = new Vector();
        for (int i = 0; i < catURLs.length; i++) {
            categories.add(new UrlCategory(this, catURLs[i]));
        }
        return (Category[])categories.toArray(new Category[0]);
    }

    private URL[] getCategoryURLs(URL parentURL) throws IOException {
        Iterator i = extractHREFs(parentURL);
        List categoryURLs = new Vector();
        while (i.hasNext()) {
            URL url = (URL)i.next();
            if (isCategoryURL(url)) {
                categoryURLs.add(url);
            }
        }
        return (URL[])categoryURLs.toArray(new URL[0]);
    }

    private boolean isCategoryURL(URL url) {
        return (url.getFile().endsWith("/")
                && (getName(url).indexOf('.') == -1));
    }
Resource directories have URLs that end in a "/", and contain a "."

    public Resource[] getResources(Category category) throws IOException {
        Vector urls = new Vector();
        URL[] resDirURLs = getResourceDirURLs(getURL(category));
        for (int i = 0; i < resDirURLs.length; i++) {
            URL dirURL = resDirURLs[i];
            urls.add(createURL(dirURL, "current/" + getName(dirURL)));
        }
        Resource[] resources = new Resource[urls.size()];
        for (int j = 0; j < urls.size(); j++) {
            resources[j] = new UrlResource(this, (URL)urls.get(j));
        }
        return resources;
    }

    private URL[] getResourceDirURLs(URL parentURL) throws IOException {
        Iterator i = extractHREFs(parentURL);
        Vector resourceDirURLs = new Vector();
        while (i.hasNext()) {
            URL url = (URL)i.next();
            if (isResourceDirURL(url)) {
                resourceDirURLs.add(url);
            }
        }
        return (URL[])resourceDirURLs.toArray(new URL[0]);
    }

    private boolean isResourceDirURL(URL url) {
        return (url.getFile().endsWith("/")
                && (getName(url).indexOf('.') > -1));
    }
Resource versions are the directory URLs found within resource directories.

    private URL[] getVersionDirURLs(URL parentURL) throws IOException {
        Iterator i = extractHREFs(parentURL);
        List versionDirURLs = new Vector();
        while (i.hasNext()) {
            URL url = (URL)i.next();
            if (isVersionDirURL(url)) {
                versionDirURLs.add(url);
            }
        }
        return (URL[])versionDirURLs.toArray(new URL[0]);
    }

    private boolean isVersionDirURL(URL url) {
        return url.getFile().endsWith("/");
    }
}