translator
Class ResourceLocator

java.lang.Object
  extended by translator.ResourceLocator

public class ResourceLocator
extends java.lang.Object

This class encapsulates the loading of (almost) arbitrary resources. Resource loading is performed by checking the following approaches:

  1. Loading using Class.getResourceAsStream()
  2. Loading using ClassLoader.getSystemResourceAsStream()
  3. Loading using the codebase as a URL, if it Applet mode
  4. Loading using a FileInputStream (not possible for Applets and WebStart applications)

Version:
0.7 10.06.2005
Author:
Guido Roessling (roessling@acm.org>

Constructor Summary
ResourceLocator()
          (empty) default constructor
 
Method Summary
static ResourceLocator getResourceLocator()
          returns the current (internal) locator, creating a new one first if needed
 java.io.InputStream getResourceStream(java.lang.String resourceName)
          Retrieve a resource by its name in String format
 java.io.InputStream getResourceStream(java.lang.String resourceName, boolean runsAsApplet, java.net.URL codeBaseName)
          Retrieve a resource by its name in String format, a boolean indicating if the current environment is an Applet, and the codebase, if so.
 java.io.InputStream getResourceStream(java.lang.String resourceName, java.lang.String extension)
          Retrieve a resource by its name and extension in String format
 java.io.InputStream getResourceStream(java.lang.String resourceName, java.lang.String extension, boolean runsAsApplet, java.net.URL codeBase)
          Retrieve a resource by its name and extension in String format, a boolean indicating if the current environment is an Applet, and the codebase, if so.
 java.io.InputStream getResourceStream(java.lang.String resourceName, java.lang.String extension, java.lang.String directoryName)
          Retrieve a resource by its name and extension plus directory in String format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceLocator

public ResourceLocator()
(empty) default constructor

Method Detail

getResourceLocator

public static ResourceLocator getResourceLocator()
returns the current (internal) locator, creating a new one first if needed

Returns:
the current ResourceLocator; if none is present, generates one first.

getResourceStream

public java.io.InputStream getResourceStream(java.lang.String resourceName)
Retrieve a resource by its name in String format

Parameters:
resourceName - the name of the resource to be loaded
Returns:
an InputStream to the resource. May be null if none of the approaches taken can locate the resource.
See Also:
getResourceStream(String, String, boolean, URL)

getResourceStream

public java.io.InputStream getResourceStream(java.lang.String resourceName,
                                             java.lang.String extension)
Retrieve a resource by its name and extension in String format

Parameters:
resourceName - the name of the resource to be loaded
extension - the filename extension, important e.g. for I18N applications where the filename encodes the locale.
Returns:
an InputStream to the resource. May be null if none of the approaches taken can locate the resource.
See Also:
getResourceStream(String, String, boolean, URL)

getResourceStream

public java.io.InputStream getResourceStream(java.lang.String resourceName,
                                             boolean runsAsApplet,
                                             java.net.URL codeBaseName)
Retrieve a resource by its name in String format, a boolean indicating if the current environment is an Applet, and the codebase, if so.

Parameters:
resourceName - the name of the resource to be loaded
runsAsApplet - indicates if this is an Application (=false) or an Applet (=true)
codeBaseName - the URL pointing towards the Applet's codebase, if this is actually an Applet (runsAsApplet == true)
Returns:
an InputStream to the resource. May be null if none of the approaches taken can locate the resource.
See Also:
getResourceStream(String, String, boolean, URL)

getResourceStream

public java.io.InputStream getResourceStream(java.lang.String resourceName,
                                             java.lang.String extension,
                                             java.lang.String directoryName)
Retrieve a resource by its name and extension plus directory in String format.

Parameters:
resourceName - the name of the resource to be loaded
extension - the filename's extension (if any - else null)
directoryName - the path for the file
Returns:
an InputStream to the resource. May be null if none of the approaches taken can locate the resource.
See Also:
getResourceStream(String, String, boolean, URL)

getResourceStream

public java.io.InputStream getResourceStream(java.lang.String resourceName,
                                             java.lang.String extension,
                                             boolean runsAsApplet,
                                             java.net.URL codeBase)
Retrieve a resource by its name and extension in String format, a boolean indicating if the current environment is an Applet, and the codebase, if so.

Parameters:
resourceName - the name of the resource to be loaded
extension - the filename's extension (if any - else null)
runsAsApplet - indicates if this is an Application (=false) or an Applet (=true)
codeBase - the URL pointing towards the Applet's codebase, if this is actually an Applet (runsAsApplet == true)
Returns:
an InputStream to the resource. May be null if none of the approaches taken can locate the resource.