dsto.dfc.net
Class URLSearchPath

java.lang.Object
  extended by dsto.dfc.net.URLSearchPath

public class URLSearchPath
extends Object

Defines a set of URL paths to search for resources. Analogous to a Java classpath, but allows any URL in the path. Convenience methods as as addPathEntry(java.lang.String) and resolveToFile(java.lang.String) allow this to be used solely as a file-based search path also.

Symbolic constant expansion is provided inside path entries via a property set (see setSymbols(java.util.Properties)).

Version:
$Revision$
Author:
Matthew

Constructor Summary
URLSearchPath()
           
 
Method Summary
 void addPathEntry(String file)
          Shortcut to add a file to the search path.
 void addPathEntry(URL entry)
          Add an entry to the set of URL's in the search path.
protected static boolean containsSymbol(URL url)
           
protected static boolean exists(URL url)
           
protected  URL expandSymbols(URL url)
           
 List getEntries()
          Get the search path as a list of URL's.
 Properties getSymbols()
           
 void removeEntry(URL entry)
          Remove an entry to the set of URL's in the search path.
 String resolveToFile(String path)
          Convenience method to resolve to a file from a file URL-based search path.
 URL resolveToURL(String path)
          Resolve a relative path to a URL by searching the path.
 void setSymbols(Properties aSymbols)
          Set symbol mappings for expansion of symbolic names within search path entries.
 String unresolveToPath(String file)
          Shortcut to convert a file path relative to this search path.
 String unresolveToPath(URL url)
          Convert a URL to a path relative to this search path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

URLSearchPath

public URLSearchPath()
Method Detail

getEntries

public List getEntries()
Get the search path as a list of URL's.


addPathEntry

public void addPathEntry(String file)
Shortcut to add a file to the search path.

See Also:
addPathEntry(URL)

addPathEntry

public void addPathEntry(URL entry)
Add an entry to the set of URL's in the search path. The URL may contain symbolic references (see setSymbols(java.util.Properties)).


removeEntry

public void removeEntry(URL entry)
Remove an entry to the set of URL's in the search path.


resolveToFile

public String resolveToFile(String path)
                     throws NoSuchElementException
Convenience method to resolve to a file from a file URL-based search path. Do not use this if any non "file:" URL's are in the path.

Parameters:
path - The path to resolve. If path is absolute or exists relative to the current directory, it is returned without searching paths.
Returns:
An absolute path.
Throws:
NoSuchElementException - if path could not be resolved.

resolveToURL

public URL resolveToURL(String path)
                 throws NoSuchElementException
Resolve a relative path to a URL by searching the path.

Parameters:
path - The relative path name of the resource to resolve.
Returns:
The full URL for path.
Throws:
NoSuchElementException - if the path could not be resolved to anm existing URL.

unresolveToPath

public String unresolveToPath(String file)
Shortcut to convert a file path relative to this search path.

Parameters:
file - The path to convert.
Returns:
The file relative to this search path if possible (ie if a matching search prefix was found).
See Also:
unresolveToPath(URL)

unresolveToPath

public String unresolveToPath(URL url)
Convert a URL to a path relative to this search path.

Parameters:
url - The URL to unresolve. The first matching URL in the path that is a prefix to the URL is used.
Returns:
The relative path, or null if none could be found.

getSymbols

public Properties getSymbols()

setSymbols

public void setSymbols(Properties aSymbols)
Set symbol mappings for expansion of symbolic names within search path entries. Entries in the search path may reference these symbolic names using the ${property_name} syntax within the URL. See StringUtility.expandSymbols(java.lang.String, java.util.Map) for more information on the expansion rules.


expandSymbols

protected URL expandSymbols(URL url)
                     throws MalformedURLException
Throws:
MalformedURLException

containsSymbol

protected static boolean containsSymbol(URL url)

exists

protected static boolean exists(URL url)


Copyright © 2008 Commonwealth of Australia