lapisx.net
Class URLUtil

java.lang.Object
  extended bylapisx.net.URLUtil

public abstract class URLUtil
extends Object


Constructor Summary
URLUtil()
           
 
Method Summary
static URL FileToURL(File file)
          Convert a local filename to a URL.
static String getBasename(URL url)
          Get the basename part of a URL, which is the filename without extension: e.g., "index".
static URL getDirectoryURL(URL url)
          Get the URL of a page's directory.
static String getExtension(URL url)
          Get the extension part of a URL, e.g. ".html".
static String getFilename(URL url)
          Get the filename part of a URL, like "index.html".
static URL getPageURL(URL url)
          Get the URL of a page, omitting any anchor reference (like #ref).
static URL getParentURL(URL url)
          Get the URL of a page's parent directory.
static String getQuery(URL url)
          Get the query part of the link, like "?
static URL getServiceURL(URL url)
          Get the URL of a Web service, omitting any query or anchor reference.
static File HrefToFile(String href)
          Convert a string (representing either a filename or a local file: URL) to a File.
static File HrefToFile(String href, File curdir)
           
static URL HrefToURL(String href)
          Convert a string (representing either a filename or a URL) to a URL.
static URL HrefToURL(String href, File curdir)
          Convert a string (representing either a filename or a local URL) to a URL.
static Reader open(String href)
          Open a file or URL.
static Reader open(URL url)
          Open a URL.
static String relativeTo(String here, String there)
          Compute relative HREF for filename when the current location is filename
static String relativeTo(URL here, String there)
          Compute relative HREF for URL there when the current location is URL here.
static String relativeTo(URL here, URL there)
          Computes relative HREF for URL there when the current location is URL here.
static File URLToFile(URL url)
          Convert a file: URL to a filename appropriate to the current system platform.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

URLUtil

public URLUtil()
Method Detail

FileToURL

public static URL FileToURL(File file)
Convert a local filename to a URL. For example, if the filename is "C:\FOO\BAR\BAZ", the resulting URL is "file:/C:/FOO/BAR/BAZ".

Parameters:
file - File to convert
Returns:
URL corresponding to file

URLToFile

public static File URLToFile(URL url)
                      throws MalformedURLException
Convert a file: URL to a filename appropriate to the current system platform. For example, on MS Windows, if the URL is "file:/FOO/BAR/BAZ", the resulting filename is "\FOO\BAR\BAZ".

Parameters:
url - URL to convert
Returns:
File corresponding to url
Throws:
MalformedURLException - if url is not a file: URL.

HrefToFile

public static File HrefToFile(String href)
                       throws MalformedURLException
Convert a string (representing either a filename or a local file: URL) to a File. Tries to behave reasonably on common platforms (especially Win32 and Unix).

Examples:


HrefToFile

public static File HrefToFile(String href,
                              File curdir)
                       throws MalformedURLException
Throws:
MalformedURLException

HrefToURL

public static URL HrefToURL(String href)
Convert a string (representing either a filename or a URL) to a URL.

Examples:


HrefToURL

public static URL HrefToURL(String href,
                            File curdir)
Convert a string (representing either a filename or a local URL) to a URL.

Examples:


getPageURL

public static URL getPageURL(URL url)
Get the URL of a page, omitting any anchor reference (like #ref).

Parameters:
url - URL to parse
Returns:
url sans anchor reference

getServiceURL

public static URL getServiceURL(URL url)
Get the URL of a Web service, omitting any query or anchor reference.

Returns:
the URL sans query and anchor reference

getDirectoryURL

public static URL getDirectoryURL(URL url)
Get the URL of a page's directory.

Parameters:
url - URL to parse
Returns:
url sans filename, query and anchor reference

getParentURL

public static URL getParentURL(URL url)
Get the URL of a page's parent directory.

Parameters:
url - URL to parse
Returns:
url sans filename, query and anchor reference

getFilename

public static String getFilename(URL url)
Get the filename part of a URL, like "index.html". Never contains '/'; may be the empty string.

Parameters:
url - URL to parse
Returns:
the filename portion of url

getQuery

public static String getQuery(URL url)
Get the query part of the link, like "?query". Either starts with a '?', or is the empty string.

Parameters:
url - URL to parse
Returns:
the query portion

getBasename

public static String getBasename(URL url)
Get the basename part of a URL, which is the filename without extension: e.g., "index". Never contains '/' or '.'; may be the empty string.

Parameters:
url - URL to parse
Returns:
the basename portion of url

getExtension

public static String getExtension(URL url)
Get the extension part of a URL, e.g. ".html". Either starts with a period or is the empty string.

Parameters:
url - URL to parse
Returns:
the basename portion of url

relativeTo

public static String relativeTo(URL here,
                                URL there)
Computes relative HREF for URL there when the current location is URL here.


relativeTo

public static String relativeTo(URL here,
                                String there)
Compute relative HREF for URL there when the current location is URL here.


relativeTo

public static String relativeTo(String here,
                                String there)
Compute relative HREF for filename when the current location is filename

open

public static Reader open(String href)
                   throws IOException
Open a file or URL.

Parameters:
href - filename or URL to open
Returns:
stream of data from open file or Web page
Throws:
IOException

open

public static Reader open(URL url)
                   throws IOException
Open a URL.

Parameters:
url - URL to open
Returns:
stream of data from url
Throws:
IOException