org.crosswire.common.util
Class ResourceUtil

java.lang.Object
  extended by org.crosswire.common.util.ResourceUtil

public class ResourceUtil
extends Object

Better implemenetations of the getResource methods with less ambiguity and that are less dependent on the specific classloader situation.

Distribution Licence:
JSword is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
The License is available on the internet here, or by writing to: Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
The copyright to this program is held by it's authors.

Version:
$Id: ResourceUtil.java,v 1.7 2004/10/02 23:50:53 joe Exp $
Author:
Joe Walker [joe at eireneh dot com], DM Smith [ dmsmith555 at yahoo dot com ]
See Also:
Licence

Constructor Summary
private ResourceUtil()
          Prevent Instansiation
 
Method Summary
static Properties getProperties(Class clazz)
          Get and load a properties file from the writable area or if that fails from the classpath (where a default ought to be stored)
private static Properties getProperties(Class clazz, String subject)
          Get and load a properties file from the writable area or if that fails from the classpath (where a default ought to be stored)
static Properties getProperties(String subject)
          Get and load a properties file from the writable area or if that fails from the classpath (where a default ought to be stored)
static URL getResource(Class clazz, String resourceName)
          Generic resource URL fetcher.
static URL getResource(String search)
          Generic resource URL fetcher.
static InputStream getResourceAsStream(Class clazz, String search)
          Generic resource URL fetcher
static InputStream getResourceAsStream(String search)
          Generic resource URL fetcher
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceUtil

private ResourceUtil()
Prevent Instansiation

Method Detail

getResource

public static URL getResource(String search)
                       throws MissingResourceException
Generic resource URL fetcher. One way or the other we'll find it! Either as a relative or an absolute reference.

Parameters:
search - The name of the resource (without a leading /) to find
Returns:
The requested resource
Throws:
MissingResourceException - if the resource can not be found

getResource

public static URL getResource(Class clazz,
                              String resourceName)
                       throws MissingResourceException
Generic resource URL fetcher. One way or the other we'll find it! Either as a relative or an absolute reference.

Parameters:
clazz - The resource to find
Returns:
The requested resource
Throws:
MissingResourceException - if the resource can not be found

getResourceAsStream

public static InputStream getResourceAsStream(String search)
                                       throws IOException,
                                              MissingResourceException
Generic resource URL fetcher

Returns:
The requested resource
Throws:
IOException - if there is a problem reading the file
MissingResourceException - if the resource can not be found

getResourceAsStream

public static InputStream getResourceAsStream(Class clazz,
                                              String search)
                                       throws IOException,
                                              MissingResourceException
Generic resource URL fetcher

Returns:
The requested resource
Throws:
IOException - if there is a problem reading the file
MissingResourceException - if the resource can not be found

getProperties

public static Properties getProperties(String subject)
                                throws IOException,
                                       MissingResourceException
Get and load a properties file from the writable area or if that fails from the classpath (where a default ought to be stored)

Parameters:
subject - The name of the desired resource (without any extension)
Returns:
The found and loaded properties file
Throws:
IOException - if the resource can not be loaded
MissingResourceException - if the resource can not be found

getProperties

public static Properties getProperties(Class clazz)
                                throws IOException,
                                       MissingResourceException
Get and load a properties file from the writable area or if that fails from the classpath (where a default ought to be stored)

Parameters:
clazz - The name of the desired resource
Returns:
The found and loaded properties file
Throws:
IOException - if the resource can not be loaded
MissingResourceException - if the resource can not be found

getProperties

private static Properties getProperties(Class clazz,
                                        String subject)
                                 throws IOException,
                                        MissingResourceException
Get and load a properties file from the writable area or if that fails from the classpath (where a default ought to be stored)

Parameters:
clazz - The name of the desired resource
Returns:
The found and loaded properties file
Throws:
IOException - if the resource can not be loaded
MissingResourceException - if the resource can not be found

Copyright ? 2003-2004