public class CachingResourceStreamLocator extends Object implements IResourceStreamLocator
This locator mitigates this problem by caching (indefinitely) references to
UrlResourceStream
and FileResourceStream
objects as they are found, and
NullResourceStreamReference
for all which are missing so they are not looked up again and
again.
Constructor and Description |
---|
CachingResourceStreamLocator(IResourceStreamLocator resourceStreamLocator)
Construct.
|
Modifier and Type | Method and Description |
---|---|
void |
clearCache()
Clears the resource cache.
|
IResourceStream |
locate(Class<?> clazz,
String path)
Locate a resource, given a path and class.
|
IResourceStream |
locate(Class<?> scope,
String path,
String style,
String variation,
Locale locale,
String extension,
boolean strict)
Locate a resource by combining the given path, style, variation, locale and extension
parameters.
|
IResourceNameIterator |
newResourceNameIterator(String path,
Locale locale,
String style,
String variation,
String extension,
boolean strict)
Markup resources and Properties files both need to iterate over different combinations of
locale, style, etc..
|
public CachingResourceStreamLocator(IResourceStreamLocator resourceStreamLocator)
resourceStreamLocator
- the delegatepublic IResourceStream locate(Class<?> clazz, String path)
IResourceStreamLocator.locate(Class, String, String, String, java.util.Locale, String, boolean)
where the
latter just takes care of trying out the different combinations for the provided style and
locale and uses this method to actually load the resource stream.
Checks for IResourceStreamReference
in the cache and returns null
if the
result is NullResourceStreamReference.INSTANCE
, or FileResourceStream
/
UrlResourceStream
if there is an entry in the cache. Otherwise asks the delegate to
find one and puts it in the cache.locate
in interface IResourceStreamLocator
clazz
- The class loader for delegating the loading of the resourcepath
- The path of the resourcepublic IResourceStream locate(Class<?> scope, String path, String style, String variation, Locale locale, String extension, boolean strict)
IResourceStreamLocator
locate
in interface IResourceStreamLocator
scope
- The class loader for delegating the loading of the resourcepath
- The path of the resourcestyle
- Any resource style, such as a skin style (see Session
)variation
- The component's variation (of the style)locale
- The locale of the resource to loadextension
- A comma separate list of extensionsstrict
- whether the specified attributes must match exactlypublic IResourceNameIterator newResourceNameIterator(String path, Locale locale, String style, String variation, String extension, boolean strict)
IResourceStreamLocator
newResourceNameIterator
in interface IResourceStreamLocator
path
- The path of the resourcelocale
- The locale of the resource to loadstyle
- Any resource style, such as a skin style (see Session
)variation
- The component's variation (of the style)extension
- A comma separate list of extensionsstrict
- whether the specified attributes must match exactlypublic void clearCache()
Copyright © 2006–2016 Apache Software Foundation. All rights reserved.