org.eclipse.webdav.client
Class URLTool

java.lang.Object
  extended by org.eclipse.webdav.client.URLTool

public class URLTool
extends Object

A utility for manipulating URLs.

Note: This class/interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.


Constructor Summary
URLTool()
           
 
Method Summary
static URL appendTrailingSlash(String url)
          Returns the given URL with a trailing slash appended to it.
static URL appendTrailingSlash(URL url)
          Returns the given URL with a trailing slash appended to it.
static URL getChild(String parent, String member)
          Returns the child URL formed by joining the given member with the given parent URL.
static URL getChild(URL parent, String member)
          Returns the child URL formed by joining the given member with the given parent URL.
static Vector getElements(String url)
          Returns all elements in the given URLs path.
static Vector getElements(URL url)
          Returns all elements in the given URLs path.
static String getLastElement(String url)
          Returns the last element in the given URLs path, or null if the URL is the root.
static String getLastElement(URL url)
          Returns the last element in the given URLs path, or null if the URL is the root.
static URL getParent(String url)
          Returns the parent URL of the given URL, or null if the given URL is the root.
static URL getParent(URL url)
          Returns the parent URL of the given URL, or null if the given URL is the root.
static URL getRoot(String urlString)
          Returns the root URL of the given URL.
static URL getRoot(URL url)
          Returns the root URL of the given URL.
static URL removeTrailingSlash(String url)
          Returns the given URL with its trailing slash removed.
static URL removeTrailingSlash(URL url)
          Returns the given URL with its trailing slash removed.
static boolean urlsOverlap(String url1, String url2)
          Returns a boolean indicating whether the given URLs overlap.
static boolean urlsOverlap(URL url1, URL url2)
          Returns a boolean indicating whether the given URLs overlap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

URLTool

public URLTool()
Method Detail

appendTrailingSlash

public static URL appendTrailingSlash(String url)
                               throws MalformedURLException
Returns the given URL with a trailing slash appended to it. If the URL already has a trailing slash the URL is returned unchanged.
Example
Given URL Returned URL
"http://hostname/folder" "http://hostname/folder/"
"http://hostname/folder/ "http://hostname/folder/"

Parameters:
url - a URL
Returns:
the given URL with a trailing slash
Throws:
MalformedURLException - if the given URL is malformed

appendTrailingSlash

public static URL appendTrailingSlash(URL url)
Returns the given URL with a trailing slash appended to it. If the URL already has a trailing slash the URL is returned unchanged.
Example
Given URL Returned URL
"http://hostname/folder" "http://hostname/folder/"
"http://hostname/folder/ "http://hostname/folder/"

Parameters:
url - a URL
Returns:
the given URL with a trailing slash

getChild

public static URL getChild(String parent,
                           String member)
                    throws MalformedURLException
Returns the child URL formed by joining the given member with the given parent URL.

Returns:
a child URL of the given parent
Throws:
MalformedURLException - if the given parent is malformed

getChild

public static URL getChild(URL parent,
                           String member)
Returns the child URL formed by joining the given member with the given parent URL.

Returns:
a child URL of the given parent

getElements

public static Vector getElements(String url)
                          throws MalformedURLException
Returns all elements in the given URLs path.
Example
Given URL Element
"http://hostname/" []
"http://hostname/folder/ [folder]
"http://hostname/folder/file [folder, file]

Parameters:
url - a URL
Returns:
all elements in the given URLs path
Throws:
MalformedURLException - if the given URL is malformed

getElements

public static Vector getElements(URL url)
Returns all elements in the given URLs path.
Example
Given URL Element
"http://hostname/" []
"http://hostname/folder/ [folder]
"http://hostname/folder/file [folder, file]

Parameters:
url - a URL
Returns:
all elements in the given URLs path

getLastElement

public static String getLastElement(String url)
                             throws MalformedURLException
Returns the last element in the given URLs path, or null if the URL is the root.
Example
Given URL Last Element
"http://hostname/" null
"http://hostname/folder/ folder
"http://hostname/folder/file file

Parameters:
url - a URL
Returns:
the last element in the given URLs path, or null if the URL is the root
Throws:
MalformedURLException - if the given URL is malformed

getLastElement

public static String getLastElement(URL url)
Returns the last element in the given URLs path, or null if the URL is the root.
Example
Given URL Last Element
"http://hostname/" null
"http://hostname/folder/ folder
"http://hostname/folder/file file

Parameters:
url - a URL
Returns:
the last element in the given URLs path, or null if the URL is the root

getParent

public static URL getParent(String url)
                     throws MalformedURLException
Returns the parent URL of the given URL, or null if the given URL is the root.
Example
Given URL Parent URL
"http://hostname/" null
"http://hostname/folder/file "http://hostname/folder/

Parameters:
url - a URL
Returns:
the parent of the given URL
Throws:
MalformedURLException - if the given URL is malformed

getParent

public static URL getParent(URL url)
Returns the parent URL of the given URL, or null if the given URL is the root.
Example
Given URL Parent URL
"http://hostname/" null
"http://hostname/folder/file "http://hostname/folder/

Parameters:
url - a URL
Returns:
the parent of the given URL

getRoot

public static URL getRoot(String urlString)
                   throws MalformedURLException
Returns the root URL of the given URL.
Example
Given URL Root URL
"http://hostname/" "http://hostname/"
"http://hostname/folder/file "http://hostname/"

Parameters:
urlString - a URL
Returns:
the root url of the given URL
Throws:
MalformedURLException - if the given URL is malformed

getRoot

public static URL getRoot(URL url)
Returns the root URL of the given URL.
Example
Given URL Root URL
"http://hostname/" "http://hostname/"
"http://hostname/folder/file "http://hostname/"

Parameters:
url - a URL
Returns:
the root URL of the given URL

removeTrailingSlash

public static URL removeTrailingSlash(String url)
                               throws MalformedURLException
Returns the given URL with its trailing slash removed. If the URL has no trailing slash, the URL is returned unchanged.
Example
Given URL Returned URL
"http://hostname/folder" "http://hostname/folder"
"http://hostname/folder/ "http://hostname/folder"

Parameters:
url - a URL
Returns:
the given URL with its last slash removed
Throws:
MalformedURLException - if the given URL is malformed

removeTrailingSlash

public static URL removeTrailingSlash(URL url)
Returns the given URL with its trailing slash removed. If the URL has no trailing slash, the URL is returned unchanged.
Example
Given URL Returned URL
"http://hostname/folder" "http://hostname/folder"
"http://hostname/folder/ "http://hostname/folder"

Parameters:
url - a URL
Returns:
the given URL with its last slash removed

urlsOverlap

public static boolean urlsOverlap(String url1,
                                  String url2)
                           throws MalformedURLException
Returns a boolean indicating whether the given URLs overlap.
Example
First URL Second URL Do they overlap
"http://hostname/folder/" "http://hostname/folder/" true
"http://hostname/folder/" "http://hostname/folder/file" true
"http://hostname/folder/file" "http://hostname/folder/" true
"http://hostname/folder1/" "http://hostname/folder2/" false

Parameters:
url1 - firt URL
url2 - second URL
Returns:
a boolean indicating whether the given URLs overlap
Throws:
MalformedURLException

urlsOverlap

public static boolean urlsOverlap(URL url1,
                                  URL url2)
Returns a boolean indicating whether the given URLs overlap.
Example
First URL Second URL Do they overlap
"http://hostname/folder/" "http://hostname/folder/" true
"http://hostname/folder/" "http://hostname/folder/file" true
"http://hostname/folder/file" "http://hostname/folder/" true
"http://hostname/folder1/" "http://hostname/folder2/" false
"http://hostname1/folder/" "http://hostname2/folder/" false

Parameters:
url1 - firt URL
url2 - second URL
Returns:
a boolean indicating whether the given URLs overlap


Copyright © 2001-2014 JBoss by Red Hat. All Rights Reserved.