Class ResourceManagerImpl
- java.lang.Object
- 
- org.apache.velocity.runtime.resource.ResourceManagerImpl
 
- 
- All Implemented Interfaces:
- ResourceManager
 
 public class ResourceManagerImpl extends Object implements ResourceManager Class to manage the text resource for the Velocity Runtime.- Version:
- $Id$
- Author:
- Will Glass-Husain, Jason van Zyl, Paulo Gaspar, Geir Magnusson Jr., Henning P. Schmiedehausen
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected ResourceCacheglobalCacheObject implementing ResourceCache to be our resource manager's Resource cache.protected org.slf4j.LoggerlogLogging.static intRESOURCE_CONTENTA static content resource.static intRESOURCE_TEMPLATEA template resources.protected List<ResourceLoader>resourceLoadersThe List of templateLoaders that the Runtime will use to locate the InputStream source of a template.protected RuntimeServicesrsvcThe internal RuntimeServices object.
 - 
Constructor SummaryConstructors Constructor Description ResourceManagerImpl()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ResourcecreateResource(String resourceName, int resourceType)Create a new Resource of the specified type.StringgetLoaderNameForResource(String resourceName)Determines if a template exists, and returns name of the loader that provides it.ResourcegetResource(String resourceName, int resourceType, String encoding)Gets the named resource.voidinitialize(RuntimeServices rs)Initialize the ResourceManager.protected ResourceloadResource(String resourceName, int resourceType, String encoding)Loads a resource from the current set of resource loaders.protected ResourcerefreshResource(Resource resource, String encoding)Takes an existing resource, and 'refreshes' it.
 
- 
- 
- 
Field Detail- 
RESOURCE_TEMPLATEpublic static final int RESOURCE_TEMPLATE A template resources.- See Also:
- Constant Field Values
 
 - 
RESOURCE_CONTENTpublic static final int RESOURCE_CONTENT A static content resource.- See Also:
- Constant Field Values
 
 - 
globalCacheprotected ResourceCache globalCache Object implementing ResourceCache to be our resource manager's Resource cache.
 - 
resourceLoadersprotected final List<ResourceLoader> resourceLoaders The List of templateLoaders that the Runtime will use to locate the InputStream source of a template.
 - 
rsvcprotected RuntimeServices rsvc The internal RuntimeServices object.
 - 
logprotected org.slf4j.Logger log Logging.
 
- 
 - 
Method Detail- 
initializepublic void initialize(RuntimeServices rs) Initialize the ResourceManager.- Specified by:
- initializein interface- ResourceManager
- Parameters:
- rs- The Runtime Services object which is associated with this Resource Manager.
 
 - 
getResourcepublic Resource getResource(String resourceName, int resourceType, String encoding) throws ResourceNotFoundException, ParseErrorException Gets the named resource. Returned class type corresponds to specified type (i.e.TemplatetoRESOURCE_TEMPLATE). This method is now unsynchronized which requires that ResourceCache implementations be thread safe (as the default is).- Specified by:
- getResourcein 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.
 
 - 
createResourceprotected Resource createResource(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
 
 - 
loadResourceprotected Resource loadResource(String resourceName, int resourceType, 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.
 
 - 
refreshResourceprotected Resource refreshResource(Resource resource, 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 refresh
- encoding- character encoding of the resource to refresh.
- Returns:
- resource
- Throws:
- ResourceNotFoundException- if template not found from current source for this Resource
- ParseErrorException- if template cannot be parsed due to syntax (or other) error.
 
 - 
getLoaderNameForResourcepublic String getLoaderNameForResource(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:
- getLoaderNameForResourcein interface- ResourceManager
- Parameters:
- resourceName- Name of template or content resource
- Returns:
- class name of loader than can provide it
 
 
- 
 
-