net.refractions.udig.catalog
Class URLUtils

java.lang.Object
  extended by net.refractions.udig.catalog.URLUtils

public class URLUtils
extends java.lang.Object

Utilities for dealing with the catalog's use of URLs as identifiers

Since:
1.1.0
Author:
Jesse

Constructor Summary
URLUtils()
           
 
Method Summary
static java.net.URL constructURL(java.io.File reference, java.lang.String url)
          Creates a URL from the string.
static java.net.URL toRelativePath(java.io.File reference, java.net.URL destination)
          Converts the URL to a URL indicating the relative path from the reference file to the location indicated by the destination URL.
static boolean urlEquals(java.net.URL url1, java.net.URL url2, boolean stripRef)
          Primarily for testing the comparison of URLS.
static java.io.File urlToFile(java.net.URL url)
          Takes a URL and converts it to a File.
static java.lang.String urlToString(java.net.URL url1, boolean ignoreRef)
          Provides a standard way of converting to string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

URLUtils

public URLUtils()
Method Detail

urlEquals

public static boolean urlEquals(java.net.URL url1,
                                java.net.URL url2,
                                boolean stripRef)
Primarily for testing the comparison of URLS. it is not a simple thing because different platforms can sometimes create ones with a dangling / or with / vs \ some times file:/// or file:/.

Parameters:
url1 - first url to compare
url2 - second url
stripRef - if the reference should be ignored. For example searching for the IService of a IGeoResource. The Service ID would not have a reference but the IGeoResource would so ignore the reference in this case.
Returns:
true if they refer to the same resource.

urlToString

public static java.lang.String urlToString(java.net.URL url1,
                                           boolean ignoreRef)
Provides a standard way of converting to string.

Parameters:
url1 - url to convert to string
ignoreRef - wether to ignore te reference in the string.
Returns:
the url in string form. Always uses / and file:/. (rather than file:///).

toRelativePath

public static java.net.URL toRelativePath(java.io.File reference,
                                          java.net.URL destination)
Converts the URL to a URL indicating the relative path from the reference file to the location indicated by the destination URL. If it is not possible to to make a relative path then the destination URL will be returned unchanged.

Examples:

Parameters:
reference - the "from" file. The file that the relative path will start at. MUST BE A FILE
destination - the URL to transform to a relative path
Returns:
the relative path from reference to destination

constructURL

public static java.net.URL constructURL(java.io.File reference,
                                        java.lang.String url)
                                 throws java.net.MalformedURLException
Creates a URL from the string. If the String is a relative URL (and is a file) the returned URL will be resolved to the Absolute path with respect to the reference parameter.

Parameters:
reference - the base of any relative path. MUST BE A FILE
url - the url in string form.
Returns:
the URL created from the string
Throws:
java.net.MalformedURLException

urlToFile

public static java.io.File urlToFile(java.net.URL url)
Takes a URL and converts it to a File. The attempts to deal with Windows UNC format specific problems, specifically files located on network shares and different drives. If the URL.getAuthority() returns null or is empty, then only the url's path property is used to construct the file. Otherwise, the authority is prefixed before the path. It is assumed that url.getProtocol returns "file". Authority is the drive or network share the file is located on. Such as "C:", "E:", "\\fooServer"

Parameters:
url -
Returns: