org.apache.velocity.runtime.resource

Class ResourceManagerImpl

Implemented Interfaces:
ResourceManager

public class ResourceManagerImpl
extends java.lang.Object
implements ResourceManager

Class to manage the text resource for the Velocity Runtime.

Version:
$Id: ResourceManagerImpl.java,v 1.5 2002/02/05 04:55:17 dlr Exp $

Authors:
Jason van Zyl
Paulo Gaspar
Geir Magnusson Jr.

Nested Class Summary

Field Summary

static int
RESOURCE_CONTENT
A static content resource.
private static String
RESOURCE_LOADER_IDENTIFIER
token used to identify the loader internally
static int
RESOURCE_TEMPLATE
A template resources.
protected ResourceCache
globalCache
Object implementing ResourceCache to be our resource manager's Resource cache.
private boolean
logWhenFound
switch to turn off log notice when a resource is found for the first time.
private boolean
resourceLoaderInitializersActive
Each loader needs a configuration object for its initialization, this flags keeps track of whether or not the configuration objects have been created for the resource loaders.
protected ArrayList
resourceLoaders
The List of templateLoaders that the Runtime will use to locate the InputStream source of a template.
protected RuntimeServices
rsvc
private ArrayList
sourceInitializerList
This is a list of the template input stream source initializers, basically properties for a particular template stream source.
private Hashtable
sourceInitializerMap
This is a map of public name of the template stream source to it's initializer.

Fields inherited from interface org.apache.velocity.runtime.resource.ResourceManager

RESOURCE_CONTENT, RESOURCE_TEMPLATE

Method Summary

private void
assembleResourceLoaderInitializers()
This will produce a List of Hashtables, each hashtable contains the intialization info for a particular resource loader.
String
getLoaderNameForResource(String resourceName)
Determines is a template exists, and returns name of the loader that provides it.
Resource
getResource(String resourceName, int resourceType)
Deprecated. Use
Resource
getResource(String resourceName, int resourceType, String encoding)
Gets the named resource.
void
initialize(RuntimeServices rs)
Initialize the ResourceManager.
protected Resource
loadResource(String resourceName, int resourceType, String encoding)
Loads a resource from the current set of resource loaders
protected void
refreshResource(Resource resource, String encoding)
Takes an existing resource, and 'refreshes' it.

Field Details

RESOURCE_CONTENT

public static final int RESOURCE_CONTENT
A static content resource.

Field Value:
2


RESOURCE_LOADER_IDENTIFIER

private static final String RESOURCE_LOADER_IDENTIFIER
token used to identify the loader internally


RESOURCE_TEMPLATE

public static final int RESOURCE_TEMPLATE
A template resources.

Field Value:
1


globalCache

protected ResourceCache globalCache
Object implementing ResourceCache to be our resource manager's Resource cache.


logWhenFound

private boolean logWhenFound
switch to turn off log notice when a resource is found for the first time.


resourceLoaderInitializersActive

private boolean resourceLoaderInitializersActive
Each loader needs a configuration object for its initialization, this flags keeps track of whether or not the configuration objects have been created for the resource loaders.


resourceLoaders

protected ArrayList resourceLoaders
The List of templateLoaders that the Runtime will use to locate the InputStream source of a template.


rsvc

protected RuntimeServices rsvc


sourceInitializerList

private ArrayList sourceInitializerList
This is a list of the template input stream source initializers, basically properties for a particular template stream source. The order in this list reflects numbering of the properties i.e. .resource.loader. =


sourceInitializerMap

private Hashtable sourceInitializerMap
This is a map of public name of the template stream source to it's initializer. This is so that clients of velocity can set properties of a template source stream with its public name. So for example, a client could set the File.resource.path property and this would change the resource.path property for the file template stream source.

Method Details

assembleResourceLoaderInitializers

private void assembleResourceLoaderInitializers()
This will produce a List of Hashtables, each hashtable contains the intialization info for a particular resource loader. This Hastable will be passed in when initializing the the template loader.


getLoaderNameForResource

public String getLoaderNameForResource(String resourceName)
Determines is a template exists, and returns name of the loader that provides it. This is a slightly less hokey way to support the Velocity.templateExists() utility method, which was broken when per-template encoding was introduced. We can revisit this.
Specified by:
getLoaderNameForResource in interface ResourceManager

Parameters:
resourceName - Name of template or content resource

Returns:
class name of loader than can provide it


getResource

public Resource getResource(String resourceName,
                            int resourceType)
            throws ResourceNotFoundException,
                   ParseErrorException,
                   Exception

Deprecated. Use

Gets the named resource. Returned class type corresponds to specified type (i.e. Template to RESOURCE_TEMPLATE). getResource(String resourceName, int resourceType, String encoding )

Parameters:
resourceName - The name of the resource to retrieve.
resourceType - The type of resource (RESOURCE_TEMPLATE, RESOURCE_CONTENT, etc.).

Returns:
Resource with the template parsed and ready.

Throws:
ResourceNotFoundException - if template not found from any available source.
ParseErrorException - if template cannot be parsed due to syntax (or other) error.


getResource

public Resource getResource(String resourceName,
                            int resourceType,
                            String encoding)
            throws ResourceNotFoundException,
                   ParseErrorException,
                   Exception
Gets the named resource. Returned class type corresponds to specified type (i.e. Template to RESOURCE_TEMPLATE).
Specified by:
getResource in interface ResourceManager

Parameters:
resourceName - The name of the resource to retrieve.
resourceType - The type of resource (RESOURCE_TEMPLATE, RESOURCE_CONTENT, etc.).
encoding - The character encoding to use.

Returns:
Resource with the template parsed and ready.

Throws:
ResourceNotFoundException - if template not found from any available source.
ParseErrorException - if template cannot be parsed due to syntax (or other) error.


initialize

public void initialize(RuntimeServices rs)
            throws Exception
Initialize the ResourceManager. It is assumed that assembleSourceInitializers() has been called before this is run.
Specified by:
initialize in interface ResourceManager


loadResource

protected Resource loadResource(String resourceName,
                                int resourceType,
                                String encoding)
            throws ResourceNotFoundException,
                   ParseErrorException,
                   Exception
Loads a resource from the current set of resource loaders

Parameters:
resourceName - The name of the resource to retrieve.
resourceType - The type of resource (RESOURCE_TEMPLATE, RESOURCE_CONTENT, etc.).
encoding - The character encoding to use.

Returns:
Resource with the template parsed and ready.

Throws:
ResourceNotFoundException - if template not found from any available source.
ParseErrorException - if template cannot be parsed due to syntax (or other) error.


refreshResource

protected void refreshResource(Resource resource,
                               String encoding)
            throws ResourceNotFoundException,
                   ParseErrorException,
                   Exception
Takes an existing resource, and 'refreshes' it. This generally means that the source of the resource is checked for changes according to some cache/check algorithm and if the resource changed, then the resource data is reloaded and re-parsed.

Parameters:
resource - resource to refresh

Throws:
ResourceNotFoundException - if template not found from current source for this Resource
ParseErrorException - if template cannot be parsed due to syntax (or other) error.


Copyright © 2003 Apache Software Foundation. All Rights Reserved.