Class ResourceManagerImpl
- java.lang.Object
-
- org.apache.velocity.runtime.resource.ResourceManagerImpl
-
- All 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 745757 2009-02-19 06:48:10Z nbubna $
-
-
Field Summary
Fields Modifier and Type Field Description protected ResourceCache
globalCache
Object implementing ResourceCache to be our resource manager's Resource cache.private boolean
isInit
Has this Manager been initialized?protected Log
log
Logging.private boolean
logWhenFound
switch to turn off log notice when a resource is found for the first time.static int
RESOURCE_CONTENT
A static content resource.private static java.lang.String
RESOURCE_LOADER_IDENTIFIER
token used to identify the loader internally.static int
RESOURCE_TEMPLATE
A template resources.protected java.util.List
resourceLoaders
The List of templateLoaders that the Runtime will use to locate the InputStream source of a template.protected RuntimeServices
rsvc
The internal RuntimeServices object.private java.util.List
sourceInitializerList
This is a list of the template input stream source initializers, basically properties for a particular template stream source.
-
Constructor Summary
Constructors Constructor Description ResourceManagerImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private void
assembleResourceLoaderInitializers()
This will produce a List of Hashtables, each hashtable contains the intialization info for a particular resource loader.protected Resource
createResource(java.lang.String resourceName, int resourceType)
Create a new Resource of the specified type.private ResourceLoader
getLoaderForResource(java.lang.String resourceName)
Returns the firstResourceLoader
in which the specified resource exists.java.lang.String
getLoaderNameForResource(java.lang.String resourceName)
Determines if a template exists, and returns name of the loader that provides it.Resource
getResource(java.lang.String resourceName, int resourceType)
Resource
getResource(java.lang.String resourceName, int resourceType, java.lang.String encoding)
Gets the named resource.void
initialize(RuntimeServices rsvc)
Initialize the ResourceManager.protected Resource
loadResource(java.lang.String resourceName, int resourceType, java.lang.String encoding)
Loads a resource from the current set of resource loaders.protected Resource
refreshResource(Resource resource, java.lang.String encoding)
Takes an existing resource, and 'refreshes' it.
-
-
-
Field Detail
-
RESOURCE_TEMPLATE
public static final int RESOURCE_TEMPLATE
A template resources.- See Also:
- Constant Field Values
-
RESOURCE_CONTENT
public static final int RESOURCE_CONTENT
A static content resource.- See Also:
- Constant Field Values
-
RESOURCE_LOADER_IDENTIFIER
private static final java.lang.String RESOURCE_LOADER_IDENTIFIER
token used to identify the loader internally.- See Also:
- Constant Field Values
-
globalCache
protected ResourceCache globalCache
Object implementing ResourceCache to be our resource manager's Resource cache.
-
resourceLoaders
protected final java.util.List resourceLoaders
The List of templateLoaders that the Runtime will use to locate the InputStream source of a template.
-
sourceInitializerList
private final java.util.List 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.<loader-id>.resource.loader.<property> = <value>
-
isInit
private boolean isInit
Has this Manager been initialized?
-
logWhenFound
private boolean logWhenFound
switch to turn off log notice when a resource is found for the first time.
-
rsvc
protected RuntimeServices rsvc
The internal RuntimeServices object.
-
log
protected Log log
Logging.
-
-
Method Detail
-
initialize
public void initialize(RuntimeServices rsvc)
Initialize the ResourceManager.- Specified by:
initialize
in interfaceResourceManager
- Parameters:
rsvc
- The Runtime Services object which is associated with this Resource Manager.
-
assembleResourceLoaderInitializers
private void assembleResourceLoaderInitializers()
This will produce a List of Hashtables, each hashtable contains the intialization info for a particular resource loader. This Hashtable will be passed in when initializing the the template loader.
-
getResource
public Resource getResource(java.lang.String resourceName, int resourceType, java.lang.String encoding) throws ResourceNotFoundException, ParseErrorException
Gets the named resource. Returned class type corresponds to specified type (i.e.Template
toRESOURCE_TEMPLATE
). This method is now unsynchronized which requires that ResourceCache implementations be thread safe (as the default is).- Specified by:
getResource
in interfaceResourceManager
- 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.
-
createResource
protected Resource createResource(java.lang.String resourceName, int resourceType)
Create a new Resource of the specified type.- Parameters:
resourceName
- The name of the resource to retrieve.resourceType
- The type of resource (RESOURCE_TEMPLATE
,RESOURCE_CONTENT
, etc.).- Returns:
- new instance of appropriate resource type
- Since:
- 1.6
-
loadResource
protected Resource loadResource(java.lang.String resourceName, int resourceType, java.lang.String encoding) throws ResourceNotFoundException, ParseErrorException
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 Resource refreshResource(Resource resource, java.lang.String encoding) throws ResourceNotFoundException, ParseErrorException
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 refreshencoding
- character encoding of the resource to refresh.- Throws:
ResourceNotFoundException
- if template not found from current source for this ResourceParseErrorException
- if template cannot be parsed due to syntax (or other) error.
-
getResource
public Resource getResource(java.lang.String resourceName, int resourceType) throws ResourceNotFoundException, ParseErrorException, java.lang.Exception
Gets the named resource. Returned class type corresponds to specified type (i.e.Template
toRESOURCE_TEMPLATE
).- 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.java.lang.Exception
- if a problem in parse
-
getLoaderNameForResource
public java.lang.String getLoaderNameForResource(java.lang.String resourceName)
Determines if 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 interfaceResourceManager
- Parameters:
resourceName
- Name of template or content resource- Returns:
- class name of loader than can provide it
-
getLoaderForResource
private ResourceLoader getLoaderForResource(java.lang.String resourceName)
Returns the firstResourceLoader
in which the specified resource exists.
-
-