/** * Returns the trimmed url. Trimmed means that the url is free from leading or trailing whitespace characters, and * that a directory url like <code>/news/</code> is closed by a slash (<code>/</code>). * * @param url * the url to trim * @return the trimmed url */ public static String trim(String url) { if (url == null) throw new IllegalArgumentException("Argument url is null"); url = url.trim(); url = checkSeparator(url); if (url.endsWith("/") || (url.length() == 1)) return url; int index = url.lastIndexOf("/"); index = url.indexOf(".", index); if (index == -1) url += "/"; return url; }
/** * Concatenates the two urls with respect to leading and trailing slashes. The path will always end with a trailing * slash. * * @return the concatenated url of the two arguments */ public static String concat(String prefix, String suffix, boolean close) { if (prefix == null) throw new IllegalArgumentException("Argument prefix is null"); if (suffix == null) throw new IllegalArgumentException("Argument suffix is null"); prefix = checkSeparator(prefix); suffix = checkSeparator(suffix); prefix = removeDoubleSeparator(prefix); suffix = removeDoubleSeparator(suffix); if (!prefix.endsWith("/") && !suffix.startsWith("/")) prefix += "/"; if (prefix.endsWith("/") && suffix.startsWith("/")) suffix = suffix.substring(1); prefix += suffix; // Close? if (close && !prefix.endsWith("/")) { prefix += "/"; } return prefix; }