com.xmlmind.fo.util
Class URLUtil

java.lang.Object
  extended by com.xmlmind.fo.util.URLUtil

public final class URLUtil
extends Object

A collection of utility functions (static methods) operating on URLs.


Method Summary
static String fileToLocation(File file)
          Converts specified filename to the string form of a "file:" URL.
static URL fileToURL(File file)
          Converts specified filename to a "file:" URL.
static String getMIMEType(String location)
          Returns the MIME type of the file found at specified location (typically an "http" URL).
static String locationOrFilename(String spec)
          Converts specified URL string form or the path of an existing file to an URL string form.
static File locationToFile(String location)
          Converts specified "file:" URL to a filename.
static String locationToFilename(String location)
          Converts specified "file:" URL to a filename.
static String normalizeMIMEType(String format)
          Returns specified MIME type after ``normalizing'' it.
static InputStream openStream(String location)
          Opens the stream corresponding to specified location.
static URL urlOrFile(String spec)
          Converts specified URL string form or the path of an existing file to an URL.
static File urlToFile(URL url)
          Converts specified "file:" URL to a filename.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

fileToURL

public static URL fileToURL(File file)
Converts specified filename to a "file:" URL.


fileToLocation

public static String fileToLocation(File file)
Converts specified filename to the string form of a "file:" URL.


urlToFile

public static File urlToFile(URL url)
Converts specified "file:" URL to a filename.

Parameters:
url - URL to be converted
Returns:
a filename corresponding to specified URL or null if url is not a "file:" URL.

locationToFile

public static File locationToFile(String location)
Converts specified "file:" URL to a filename.

Parameters:
location - string form of the URL to be converted
Returns:
a filename corresponding to specified URL or null if location is not a "file:" URL.

locationToFilename

public static String locationToFilename(String location)
Converts specified "file:" URL to a filename.

Parameters:
location - string form of the URL to be converted
Returns:
a filename corresponding to specified URL or null if location is not a "file:" URL.

urlOrFile

public static URL urlOrFile(String spec)
Converts specified URL string form or the path of an existing file to an URL.

Parameters:
spec - the string form of an URL or the path of an existing file (not a directory).
Returns:
the corresponding URL or null if spec cannot be converted to an URL

locationOrFilename

public static String locationOrFilename(String spec)
Converts specified URL string form or the path of an existing file to an URL string form.

Parameters:
spec - the string form of an URL or the path of an existing file (not a directory).
Returns:
the string form of the corresponding URL or spec (unchanged) if spec cannot be converted to an URL

getMIMEType

public static String getMIMEType(String location)
Returns the MIME type of the file found at specified location (typically an "http" URL).

Parameters:
location - an absolute URL in its string form.
Returns:
``normalized'' MIME type (e.g. "") or null if this MIME type cannot be determined.
See Also:
normalizeMIMEType(java.lang.String)

normalizeMIMEType

public static String normalizeMIMEType(String format)
Returns specified MIME type after ``normalizing'' it.

For example, returns "text/html" for "TEXT/HTML; CHARSET=UTF-8".

Other example, returns "image/jpeg" for "image/jpg".


openStream

public static InputStream openStream(String location)
                              throws IOException,
                                     MalformedURLException
Opens the stream corresponding to specified location.

This function supports "data:" locations.

Parameters:
location - the string form of an URL
Returns:
opened input stream
Throws:
MalformedURLException - if location cannot be parsed as an URL
IOException - if an I/O error occurs during the operation