Java URL Normalize normalizeToURL(String surl)

Here you can find the source of normalizeToURL(String surl)

Description

normalize To URL

License

Open Source License

Declaration

public static URL normalizeToURL(String surl)
            throws MalformedURLException 

Method Source Code

//package com.java2s;
/**/*from  w  w  w .  j ava 2s. c  o  m*/
 * Copyright (c) 2006-2010, Cloudsmith Inc.
 * The code, documentation and other materials contained herein have been
 * licensed under the Eclipse Public License - v 1.0 by the copyright holder
 * listed above, as the Initial Contributor under such license. The text of
 * such license is available at www.eclipse.org.
 */

import java.io.File;
import java.net.MalformedURLException;

import java.net.URL;

public class Main {
    public static URL normalizeToURL(String surl)
            throws MalformedURLException {
        if (surl == null)
            return null;

        try {
            return new URL(surl);
        } catch (MalformedURLException e) {
            // Do a space check.
            //
            if (surl.indexOf(' ') > 0) {
                try {
                    return new URL(surl.replaceAll("\\s", "%20")); //$NON-NLS-1$ //$NON-NLS-2$
                } catch (MalformedURLException me1) {
                }
            }

            try {
                return new File(surl).toURI().toURL();
            } catch (MalformedURLException me2) {
                // Throw the original exception
                //
                throw e;
            }
        }
    }
}

Related

  1. normalizeBaseUrl(String networkUrl)
  2. normalizeCapabilitiesUrl(String url)
  3. normalizePrefix(String url)
  4. normalizeShortUrl(String url)
  5. normalizeToLUrl(String toLUrl)
  6. NormalizeURL(final String taintedURL)
  7. normalizeUrl(final String url)
  8. normalizeUrl(String baseUrl, List urlList)
  9. normalizeUrl(String baseUrl, String url)