Here you can find the source of resolveURL(URL contextURL, String url)
public static URL resolveURL(URL contextURL, String url)
//package com.java2s; /**/*from www. j ava 2 s. 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 resolveURL(URL contextURL, String url) { if (url == null) return null; try { if (contextURL == null) return normalizeToURL(url); return new URL(contextURL, url); } catch (MalformedURLException e) { return null; } } 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; } } } }