public String createValidURL(String parent, String next)
            throws Exception
    {
        if (next.startsWith("http") ||
                next.startsWith("ftp")) {
            // absolute URL
            return next;
        } else if (next.length() == 0) {
            return parent;
        } else if (next.charAt(0) == '/') {
            // right after the domain
            int domainStart = parent.indexOf("://") + 3;
            if (domainStart == 2) {
                // indexof returned -1
                throw new Exception("Bug- Invalid parent url '" + parent + "'");
            }
            int domainEnd = parent.indexOf('/', domainStart);
            String homeURL = null;
            if (domainEnd == -1) {
                homeURL = parent;
            } else {
                homeURL = parent.substring(0, domainEnd);
                if (homeURL.charAt(homeURL.length() - 1) == '/') {
                    throw new Exception("Bug");
                }
            }
            return homeURL + next;
        } else {
            // relative url
            int dirEnd = parent.lastIndexOf('/');
            int protoEnd = parent.indexOf("://");
            String dirURL = null;
            if (dirEnd == -1 || protoEnd + 2 == dirEnd) {
                //throw new Exception("Bug - Invalid parent url '" + parent + "'");
                dirURL = parent + "/";
            } else {
                dirURL = parent.substring(0, dirEnd+1);
            }
            return dirURL + next;
        }
    }