com.ca.commons.cbutil
Class CBResourceLoader

java.lang.Object
  |
  +--com.ca.commons.cbutil.CBResourceLoader

public class CBResourceLoader
extends java.lang.Object

This Class provides access to a group of zip files. In the case of namespace conflicts between Zip files, the first zip file registered has priority. The zip files are accessed through CBJarResource.

See Also:
com.ca.od.util.CBJarResource

Field Summary
protected static boolean debug
          Whether to print out shtuff on the way.
protected  CBJarResource[] resourceFiles
          A list of CBJarResources objects that may be searched for packaged resources.
protected  java.util.HashSet unknownResources
          a cached list of 'unknown' resources that have been (unsuccessfully) looked up before.
 
Constructor Summary
CBResourceLoader()
          Constructor - note that that the class is useless until at least one resource file has been registered with it using the addResource() method.
 
Method Summary
 void addResource(CBJarResource resource)
          Adds a new zip/jar resource file to the list of files to be examined for resources.
 java.awt.Image getImage(java.lang.String imageName, java.awt.Toolkit imageCreator)
          Search all registered zip files for a particular Image, and return an awt Image object.
 java.io.InputStream getInputStream(java.lang.String resourceName)
          Search all registered zip files for a particular file, and return an input stream to that file.
 CBJarResource getJarContainingResource(java.lang.String resourceName)
          Searches an internal hash, followed by all Jar files, for a particular resource.
 java.lang.String[] getPrefixedResources(java.lang.String prefix)
          Returns all resources with the given prefix.
 byte[] getResource(java.lang.String resourceName)
          Search all registered zip files for a particular file, and return the data within that file as a byte array.
 java.lang.String[] getWildCardResources(java.lang.String exp)
          This is a very PRIMATIVE wildcard matching routine - it allows only ONE wildcard, and that wildcard MUST be a '*' character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

unknownResources

protected java.util.HashSet unknownResources
a cached list of 'unknown' resources that have been (unsuccessfully) looked up before.


resourceFiles

protected CBJarResource[] resourceFiles
A list of CBJarResources objects that may be searched for packaged resources.


debug

protected static boolean debug
Whether to print out shtuff on the way.

Constructor Detail

CBResourceLoader

public CBResourceLoader()
Constructor - note that that the class is useless until at least one resource file has been registered with it using the addResource() method.

Method Detail

addResource

public void addResource(CBJarResource resource)
Adds a new zip/jar resource file to the list of files to be examined for resources.


getInputStream

public java.io.InputStream getInputStream(java.lang.String resourceName)
                                   throws java.util.zip.ZipException
Search all registered zip files for a particular file, and return an input stream to that file.

java.util.zip.ZipException

getImage

public java.awt.Image getImage(java.lang.String imageName,
                               java.awt.Toolkit imageCreator)
                        throws java.util.zip.ZipException
Search all registered zip files for a particular Image, and return an awt Image object.

java.util.zip.ZipException

getResource

public byte[] getResource(java.lang.String resourceName)
                   throws java.util.zip.ZipException
Search all registered zip files for a particular file, and return the data within that file as a byte array. (This might be used to initialise a String object if the file is a text file, for instance.)

java.util.zip.ZipException

getJarContainingResource

public CBJarResource getJarContainingResource(java.lang.String resourceName)
Searches an internal hash, followed by all Jar files, for a particular resource.


getPrefixedResources

public java.lang.String[] getPrefixedResources(java.lang.String prefix)
Returns all resources with the given prefix.

Parameters:
prefix - a string to match the start of resources against, e.g. 'icons/'

getWildCardResources

public java.lang.String[] getWildCardResources(java.lang.String exp)
This is a very PRIMATIVE wildcard matching routine - it allows only ONE wildcard, and that wildcard MUST be a '*' character. (So in effect this is simply a prefix + suffix match).

Parameters:
exp - a SIMPLE wildcard expression to match, e.g. 'templates/plain*.html'