public static Resource createFromRoot(URL url)
  {
    String urlPath = url.getPath();
    String path = "/";

    if(!urlPath.endsWith("/"))
    {
      urlPath = PathUtils.addLeadingSlash(urlPath);
      int idx = urlPath.lastIndexOf("/"); // there will always be one due to previous line...
      path = urlPath.substring(idx + 1);
      urlPath = urlPath.substring(0, idx);
    }


    URLBuilder rootURL = URLBuilder.createFromPath(urlPath);
    rootURL.setScheme(url.getProtocol());
    rootURL.setHost(url.getHost());
    rootURL.setPort(url.getPort());
    rootURL.setUserInfo(url.getUserInfo());

    return create(rootURL.toJavaURL(), "/").createRelative(path);
  }
public static Resource createFromRoot(URL url)
  {
    String urlPath = url.getPath();
    String path = "/";

    if(!urlPath.endsWith("/"))
    {
      urlPath = PathUtils.addLeadingSlash(urlPath);
      int idx = urlPath.lastIndexOf("/"); 
      path = urlPath.substring(idx + 1);
      urlPath = urlPath.substring(0, idx);
    }


    URLBuilder rootURL = URLBuilder.createFromPath(urlPath);
    rootURL.setScheme(url.getProtocol());
    rootURL.setHost(url.getHost());
    rootURL.setPort(url.getPort());
    rootURL.setUserInfo(url.getUserInfo());

    return create(rootURL.toJavaURL(), "/").createRelative(path);
  }
public static Resource createFromRoot ( URL url ) { String urlPath = url . getPath ( ) ; String path = "/" ; if ( ! urlPath . endsWith ( "/" ) ) { urlPath = PathUtils . addLeadingSlash ( urlPath ) ; int idx = urlPath . lastIndexOf ( "/" ) ; // there will always be one due to previous line... path = urlPath . substring ( idx + 1 ) ; urlPath = urlPath . substring ( 0 , idx ) ; } URLBuilder rootURL = URLBuilder . createFromPath ( urlPath ) ; rootURL . setScheme ( url . getProtocol ( ) ) ; rootURL . setHost ( url . getHost ( ) ) ; rootURL . setPort ( url . getPort ( ) ) ; rootURL . setUserInfo ( url . getUserInfo ( ) ) ; return create ( rootURL . toJavaURL ( ) , "/" ) . createRelative ( path ) ; }
Creates the resource from a url... The root will be at the path of this url (ex:
if url is http://localhost/a/b/c/foo.html then root is /a/b/c).

@param url
@return the resource
Creates the resource from a url ... The root will be at the path of this url ( ex : if url is http : // localhost / a / b / c / foo . html then root is / a / b / c ) .