Webiyo

This page was generated using Webiyo. See its source code and unit tests.

org/webiyo/web/Location.java

package org.webiyo.web;

import java.io.File;

public class Location {

    private final String baseName;
    private final String path;

    public Location(String baseName, String path) {
        if (path.startsWith("/")) {
            throw new IllegalArgumentException("path must not begin with a slash: " + path);
        }
        this.baseName = baseName;
        this.path = path;
    }

    public Location(Location base, Location path) {
        this(base.baseName, base.path + path.path);
    }

    public Link toRelativeLink(Location newBase) {
        if (!baseName.equals(newBase.baseName)) {
            throw new IllegalArgumentException("can't make (" + this + ") relative to (" + newBase + ") because they have no common base");
        }
        return new Link(path).makeRelativeTo(new Link(newBase.path));
    }

    public File toFile(File base) {
        return new File(base, path);
    }

    public String toString() {
        return "$" + baseName + "/" + path;
    }
}
SourceForge