Java URL Normalize normalizeUrl(String url)

Here you can find the source of normalizeUrl(String url)

Description

normalize Url

License

Apache License

Declaration

private static String normalizeUrl(String url) throws URISyntaxException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.URI;
import java.net.URISyntaxException;

public class Main {
    private static String normalizeUrl(String url) throws URISyntaxException {
        URI uri = new URI(url);
        String scheme = uri.getScheme().toLowerCase();
        String authority = uri.getAuthority().toLowerCase();
        boolean dropPort = ((scheme.equals("http")) && (uri.getPort() == 80))
                || ((scheme.equals("https")) && (uri.getPort() == 443));

        if (dropPort) {
            int index = authority.lastIndexOf(":");
            if (index >= 0) {
                authority = authority.substring(0, index);
            }/*  w w w  . j a va  2s.c o  m*/
        }
        String path = uri.getRawPath();
        if ((path == null) || (path.length() <= 0)) {
            path = "/";
        }

        return scheme + "://" + authority + path;
    }
}

Related

  1. normalizeUrl(String url)
  2. NormalizeURL(String URL)
  3. normalizeUrl(String url)
  4. normalizeUrl(String url)
  5. normalizeUrl(String url)
  6. normalizeUrl(String url)
  7. normalizeURL(URL codebase)
  8. normalizeUrl(URL url)
  9. normalizeUrl(URL url)