Java URL Normalize normalizeUrl(String url)

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

Description

normalize Url

License

Apache License

Declaration

public static String normalizeUrl(String url) 

Method Source Code

//package com.java2s;
/**/*from   w w  w  .j a v a  2s . c  om*/
 *  Copyright 2010-2011 Buhake Sindi

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

 */

public class Main {
    public static String normalizeUrl(String url) {
        int questionMarkIndex = url.indexOf('?');
        if (questionMarkIndex > -1) {
            url = url.substring(0, questionMarkIndex);
        }

        int forwardSlashIndex = url.indexOf('/', 8);
        if (forwardSlashIndex > -1) {
            int colonIndex = url.lastIndexOf(':', forwardSlashIndex);

            if (colonIndex > -1) {
                String port = url.substring(colonIndex, forwardSlashIndex);
                if ((url.startsWith("http://") && (port.equals(":80") || port
                        .equals(":8080")))
                        || (url.startsWith("https://") && port
                                .equals(":443"))) {
                    url = url.substring(0, colonIndex)
                            + url.substring(colonIndex + port.length());
                }
            }
        }

        return url.toLowerCase();
    }
}

Related

  1. normalizeUrl(final String url)
  2. normalizeUrl(String baseUrl, List urlList)
  3. normalizeUrl(String baseUrl, String url)
  4. normalizeURL(String solrServerUrl)
  5. normalizeUrl(String url)
  6. NormalizeURL(String URL)
  7. normalizeUrl(String url)
  8. normalizeUrl(String url)
  9. normalizeUrl(String url)