Java Utililty Methods URL Normalize

List of utility methods to do URL Normalize

Description

The list of methods to do URL Normalize are organized into topic(s).

Method

StringnormalizeCapabilitiesUrl(String url)
normalize Capabilities Url
URL inUrl = new URL(url);
URL ret = new URL(inUrl.getProtocol(), inUrl.getHost(), inUrl.getPort(), inUrl.getFile());
return ret.toExternalForm();
StringnormalizePrefix(String url)
normalize Prefix
final String[] prefixes = new String[] { "http://", "https://", "ftp://", "www." };
for (String p : prefixes) {
    if (url.startsWith(p)) {
        url = url.substring(p.length());
return url;
StringnormalizeShortUrl(String url)
normalize Short Url
url = url.toLowerCase();
url = url.replaceAll("^(^(http|https)://)|www.", "");
url = url.replaceAll("//", "");
int endIndex = url.lastIndexOf("/");
if (endIndex == (url.length() - 1)) {
    url = url.substring(0, endIndex);
return url;
...
StringnormalizeToLUrl(String toLUrl)
normalize To L Url
String res = toLUrl.replace("http", "https");
res = res.replace("//treasuryoflives.org", "//www.treasuryoflives.org");
res = res.replace("//beta.treasuryoflives.org", "//www.treasuryoflives.org");
return res;
URLnormalizeToURL(String surl)
normalize To URL
if (surl == null)
    return null;
try {
    return new URL(surl);
} catch (MalformedURLException e) {
    if (surl.indexOf(' ') > 0) {
        try {
            return new URL(surl.replaceAll("\\s", "%20")); 
...
StringNormalizeURL(final String taintedURL)
Normalization code courtesy of 'Mike Houston' http://stackoverflow.com/questions/2993649/how-to-normalize-a-url-in-java
final URL url;
try {
    url = new URI(taintedURL).normalize().toURL();
} catch (URISyntaxException e) {
    throw new MalformedURLException(e.getMessage());
final String path = url.getPath().replace("/$", "");
final SortedMap<String, String> params = CreateParameterMap(url.getQuery());
...
StringnormalizeUrl(final String url)
Returns normalized url path.
try {
    return new URI(url).normalize().toASCIIString();
} catch (final URISyntaxException e) {
    return url;
ListnormalizeUrl(String baseUrl, List urlList)
normalize Url
List<String> newUrlList = new ArrayList<>();
for (String url : urlList) {
    newUrlList.add(normalizeUrl(baseUrl, url));
return newUrlList;
StringnormalizeUrl(String baseUrl, String url)
normalize Url
URL parent = new URL(baseUrl);
if (url.startsWith("?")) {
    return parent.toExternalForm().replace("?" + parent.getQuery(), "") + url;
URL spec = new URL(parent, url);
return spec.toExternalForm();
StringnormalizeURL(String solrServerUrl)
normalize URL
String serverUrl = solrServerUrl;
if (serverUrl.endsWith("/")) {
    serverUrl = serverUrl.substring(0, serverUrl.length() - 1);
return serverUrl;