Java URL Sanitize sanitizeURL(String url)

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

Description

sanitize URL

License

Apache License

Parameter

Parameter Description
url a parameter

Declaration

public static String sanitizeURL(String url) throws Exception 

Method Source Code

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

public class Main {
    /**//from w ww.  jav a  2s  . c  o  m
     * 
     * @param url
     * @return
     */
    public static String sanitizeURL(String url) throws Exception {
        try {
            if (url.substring(0, 7).toLowerCase().equals("http://")) {
                url = url.substring(7);
            } else if (url.substring(0, 8).toLowerCase().equals("https://")) {
                url = url.substring(8);
            } else if (url.charAt(url.length() - 1) == '/') {
                url = url.substring(0, url.length() - 1);
            }
        } catch (Exception ex) {
            throw new Exception(ex.getMessage(), ex);
        }

        return url;
    }
}

Related

  1. sanitizeCollabNetUrl(String url)
  2. sanitizeDefaultPort(String url)
  3. sanitizeForNextUrl(String url)
  4. sanitizeUri(String uri)
  5. sanitizeUri(String uri)
  6. sanitizeURL(String url)
  7. sanitizeUrl(String url)
  8. sanitizeUrl(String url)
  9. sanitizeUrlWithoutProtocol(String url, String protocol)