raccoon.core.utils
Class StdResolver

java.lang.Object
  extended by raccoon.core.utils.StdResolver
All Implemented Interfaces:
IResolver

public final class StdResolver
extends java.lang.Object
implements IResolver

Convenience methods for searching within the current classpath and working directory for a resource of any kind.

This class regroups the various utility methods that where dispersed within the Raccoon project, as such all classes should now use the methods within this class to load a resource file (property, xml, ...)

The search sequence is the following:

  1. Search for the resource in the current package (either this class's package or a given class package).
  2. Search for the resource in the search path to load classes (for more information refer to ClassLoader.getSystemResource(String)
  3. Search for the resource in the current working directory.
The methods available within this class will throw a ResourceNotFoundException upon error. The following errors are possible:

In general the methods will try very hard to locate the file and as such the following expressions are valid:

Since:
Raccoon v0.5, refactored Raccoon v0.8, v0.9
Version:
$Id: StdResolver.java,v 1.1 2004/08/08 20:19:20 crouvrais Exp $
Author:
Cedric ROUVRAIS

Constructor Summary
StdResolver()
           
 
Method Summary
 java.io.InputStream getResourceAsStream(java.lang.Class pRequesterClass, java.lang.String pDesiredRessource)
          Locates the specified resource and provides an InputStream to it.
 java.io.InputStream getResourceAsStream(java.lang.String pDesiredRessource)
          Locates the specified resource and provides an InputStream to it.
static java.lang.String replaceDotWithSlash(java.lang.String pDesiredRessource)
          Replaces all the dots with '/' in order to constitute a valid file URI.
 java.net.URL resolve(java.lang.Class pRequesterClass, java.lang.String pDesiredRessource)
          Locates the specified resource and provides the exact location to it.
 java.net.URL resolve(java.lang.String pDesiredRessource)
          Locates the specified resource and provides the exact location to it.
static java.net.URL staticResolve(java.lang.Class pRequesterClass, java.lang.String pDesiredRessource)
          Locates the specified resource and provides the exact location to it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StdResolver

public StdResolver()
Method Detail

resolve

public final java.net.URL resolve(java.lang.String pDesiredRessource)
                           throws ResourceNotFoundException
Locates the specified resource and provides the exact location to it.

Specified by:
resolve in interface IResolver
Parameters:
pDesiredRessource - the resource that is to be located explicitly.
Returns:
the URL to the desired resource.
Throws:
ResourceNotFoundException - if the specified resource couldn't be found.

resolve

public final java.net.URL resolve(java.lang.Class pRequesterClass,
                                  java.lang.String pDesiredRessource)
                           throws ResourceNotFoundException
Locates the specified resource and provides the exact location to it.

Specified by:
resolve in interface IResolver
Parameters:
pRequesterClass - the requesting class that is to be used as starting point for a relative search.
pDesiredRessource - the resource that is to be located explicitly, this can be a relative location from the given requester class.
Returns:
the URL to the desired resource.
Throws:
ResourceNotFoundException - if the specified resource couldn't be found.

staticResolve

public static java.net.URL staticResolve(java.lang.Class pRequesterClass,
                                         java.lang.String pDesiredRessource)
                                  throws ResourceNotFoundException
Locates the specified resource and provides the exact location to it.

Parameters:
pRequesterClass - the requesting class that is to be used as starting point for a relative search.
pDesiredRessource - the resource that is to be located explicitly, this can be a relative location from the given requester class.
Returns:
the URL to the desired resource.
Throws:
ResourceNotFoundException - if the specified resource couldn't be found.

getResourceAsStream

public final java.io.InputStream getResourceAsStream(java.lang.String pDesiredRessource)
                                              throws ResourceNotFoundException
Locates the specified resource and provides an InputStream to it.

Specified by:
getResourceAsStream in interface IResolver
Parameters:
pDesiredRessource - the resource that is to be located explicitly.
Returns:
the URL to the desired resource.
Throws:
ResourceNotFoundException - if the specified resource couldn't be found.

getResourceAsStream

public final java.io.InputStream getResourceAsStream(java.lang.Class pRequesterClass,
                                                     java.lang.String pDesiredRessource)
                                              throws ResourceNotFoundException
Locates the specified resource and provides an InputStream to it.

Specified by:
getResourceAsStream in interface IResolver
Parameters:
pRequesterClass - the requesting class that is to be used as starting point for a relative search.
pDesiredRessource - the resource that is to be located explicitly, this can be a relative location from the given requester class.
Returns:
the URL to the desired resource.
Throws:
ResourceNotFoundException - if the specified resource couldn't be found.

replaceDotWithSlash

public static java.lang.String replaceDotWithSlash(java.lang.String pDesiredRessource)
Replaces all the dots with '/' in order to constitute a valid file URI.

Parameters:
pDesiredRessource - the resource with the dots
Returns:
the normalised file name.


Copyright null null. All Rights Reserved.