rails.util
Class ResourceLoader

java.lang.Object
  extended by rails.util.ResourceLoader

public final class ResourceLoader
extends java.lang.Object

Class ResourceLoader is an utility class to load a resource from a filename and a list of directory.

Version:
$Id: ResourceLoader.java,v 1.5 2009/01/15 20:53:28 evos Exp $
Author:
Romain Dolbeau, David Ripton

Field Summary
static java.awt.Font defaultFont
           
static java.lang.String defaultFontName
           
static int defaultFontSize
           
static int defaultFontStyle
           
static java.lang.String keyContentType
           
protected static org.apache.log4j.Logger log
           
 
Constructor Summary
ResourceLoader()
           
 
Method Summary
static byte[] getBytesFromFile(java.lang.String filename, java.util.List<java.lang.String> directories, boolean cachedOnly, boolean ignoreFail)
          Return the content of the specified file as an array of byte.
static javax.swing.text.Document getDocument(java.lang.String filename, java.util.List<java.lang.String> directories)
          Return the first Document from file of name filename in the list of directories.
static java.io.InputStream getInputStream(java.lang.String filename, java.util.List<java.lang.String> directories)
          Return the first InputStream from file of name filename in the list of directories.
static java.io.InputStream getInputStream(java.lang.String filename, java.util.List<java.lang.String> directories, boolean remote, boolean cachedOnly, boolean ignoreFail)
          Return the first InputStream from file of name filename in the list of directories.
static java.io.InputStream getInputStreamIgnoreFail(java.lang.String filename, java.util.List<java.lang.String> directories)
          Return the first InputStream from file of name filename in the list of directories, tell the getInputStream not to complain if not found.
static java.lang.Object getNewObject(java.lang.String className, java.util.List<java.lang.String> directories)
          Create an instance of the class whose name is in parameter.
static java.lang.Object getNewObject(java.lang.String className, java.util.List<java.lang.String> directories, java.lang.Object[] parameter)
          Create an instance of the class whose name is in parameter, using parameters.
static java.io.OutputStream getOutputStream(java.lang.String filename, java.util.List<java.lang.String> directories)
          Return the first OutputStream from file of name filename in the list of directories.
static java.lang.String getPathSeparator()
          Give the String to mark directories.
static void purgeFileCache()
          empty the cache so that all files have to be reloaded
static void putIntoFileCache(java.lang.String mapKey, byte[] data)
          Force adding the given data as belonging to the given key in the file cache.
static void putIntoFileCache(java.lang.String filename, java.util.List<java.lang.String> directories, byte[] data)
          Force adding the given data as belonging to the given filename in the file cache.
static void setDataServer(java.lang.String server, int port)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

keyContentType

public static final java.lang.String keyContentType
See Also:
Constant Field Values

defaultFontName

public static final java.lang.String defaultFontName
See Also:
Constant Field Values

defaultFontStyle

public static final int defaultFontStyle
See Also:
Constant Field Values

defaultFontSize

public static final int defaultFontSize
See Also:
Constant Field Values

defaultFont

public static final java.awt.Font defaultFont

log

protected static org.apache.log4j.Logger log
Constructor Detail

ResourceLoader

public ResourceLoader()
Method Detail

setDataServer

public static void setDataServer(java.lang.String server,
                                 int port)

getPathSeparator

public static java.lang.String getPathSeparator()
Give the String to mark directories.

Returns:
The String to mark directories.

purgeFileCache

public static void purgeFileCache()
empty the cache so that all files have to be reloaded


getInputStreamIgnoreFail

public static java.io.InputStream getInputStreamIgnoreFail(java.lang.String filename,
                                                           java.util.List<java.lang.String> directories)
Return the first InputStream from file of name filename in the list of directories, tell the getInputStream not to complain if not found.

Parameters:
filename - Name of the file to load.
directories - List of directories to search (in order).
Returns:
The InputStream, or null if it was not found.

getInputStream

public static java.io.InputStream getInputStream(java.lang.String filename,
                                                 java.util.List<java.lang.String> directories)
Return the first InputStream from file of name filename in the list of directories.

Parameters:
filename - Name of the file to load.
directories - List of directories to search (in order).
Returns:
The InputStream, or null if it was not found.

getInputStream

public static java.io.InputStream getInputStream(java.lang.String filename,
                                                 java.util.List<java.lang.String> directories,
                                                 boolean remote,
                                                 boolean cachedOnly,
                                                 boolean ignoreFail)
Return the first InputStream from file of name filename in the list of directories.

Parameters:
filename - Name of the file to load.
directories - List of directories to search (in order).
remote - Ask the server for the stream.
cachedOnly - Only look in the cache file, do not try to load the file from permanent storage.
ignoreFail - (=don't complain) if file not found
Returns:
The InputStream, or null if it was not found.

getBytesFromFile

public static byte[] getBytesFromFile(java.lang.String filename,
                                      java.util.List<java.lang.String> directories,
                                      boolean cachedOnly,
                                      boolean ignoreFail)
Return the content of the specified file as an array of byte.

Parameters:
filename - Name of the file to load.
directories - List of directories to search (in order).
cachedOnly - Only look in the cache file, do not try to load the file from permanent storage.
Returns:
An array of byte representing the content of the file, or null if it fails.

getOutputStream

public static java.io.OutputStream getOutputStream(java.lang.String filename,
                                                   java.util.List<java.lang.String> directories)
Return the first OutputStream from file of name filename in the list of directories.

Parameters:
filename - Name of the file to load.
directories - List of directories to search (in order).
Returns:
The OutputStream, or null if it was not found.

getDocument

public static javax.swing.text.Document getDocument(java.lang.String filename,
                                                    java.util.List<java.lang.String> directories)
Return the first Document from file of name filename in the list of directories. It also add a property of key keyContentType and of type String describing the content type of the Document. This can currently load HTML and pure text.

Parameters:
filename - Name of the file to load.
directories - List of directories to search (in order).
Returns:
The Document, or null if it was not found.

getNewObject

public static java.lang.Object getNewObject(java.lang.String className,
                                            java.util.List<java.lang.String> directories)
Create an instance of the class whose name is in parameter.

Parameters:
className - The name of the class to use.
directories - List of directories to search (in order).
Returns:
A new object, instance from the given class.

getNewObject

public static java.lang.Object getNewObject(java.lang.String className,
                                            java.util.List<java.lang.String> directories,
                                            java.lang.Object[] parameter)
Create an instance of the class whose name is in parameter, using parameters. If no parameters are given, the default constructor is used.

Parameters:
className - The name of the class to use, must not be null.
directories - List of directories to search (in order), must not be null.
parameter - Array of parameters to pass to the constructor, can be null.
Returns:
A new object, instance from the given class or null if instantiation failed.

putIntoFileCache

public static void putIntoFileCache(java.lang.String filename,
                                    java.util.List<java.lang.String> directories,
                                    byte[] data)
Force adding the given data as belonging to the given filename in the file cache.

Parameters:
filename - Name of the Image file to add.
directories - List of directories to search (in order).
data - File content to add.

putIntoFileCache

public static void putIntoFileCache(java.lang.String mapKey,
                                    byte[] data)
Force adding the given data as belonging to the given key in the file cache.

Parameters:
mapKey - Key to use in the cache.
data - File content to add.
See Also:
getMapKey(String, List), getMapKey(String[], List)