Class CachingResourceStreamLocator
- java.lang.Object
-
- org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator
-
- All Implemented Interfaces:
IResourceStreamLocator
public class CachingResourceStreamLocator extends Object implements IResourceStreamLocator
Locating resources can take a significant amount of time, especially since there are often several CSS, JavaScript and image resources on any given page. To facilitate localization and styling, Wicket will usually make several attempts at locating each resource (i.e. first with an "en_US" suffix, then "en", and so on); multiply these attempts by the number of resources on the page and this starts to add up.This locator mitigates this problem by caching (indefinitely) references to
UrlResourceStream
andFileResourceStream
objects as they are found, andNullResourceStreamReference
for all which are missing so they are not looked up again and again.
-
-
Constructor Summary
Constructors Constructor Description CachingResourceStreamLocator(IResourceStreamLocator resourceStreamLocator)
Construct.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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..
-
-
-
Constructor Detail
-
CachingResourceStreamLocator
public CachingResourceStreamLocator(IResourceStreamLocator resourceStreamLocator)
Construct.- Parameters:
resourceStreamLocator
- the delegate
-
-
Method Detail
-
locate
public IResourceStream locate(Class<?> clazz, String path)
Locate a resource, given a path and class. Typically this method is either called by external clients if they are not interested in a lookup that takes the style and locale into account, or it is called by the implementation ofIResourceStreamLocator.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 forIResourceStreamReference
in the cache and returnsnull
if the result isNullResourceStreamReference.INSTANCE
, orFileResourceStream
/UrlResourceStream
if there is an entry in the cache. Otherwise asks the delegate to find one and puts it in the cache.- Specified by:
locate
in interfaceIResourceStreamLocator
- Parameters:
clazz
- The class loader for delegating the loading of the resourcepath
- The path of the resource- Returns:
- The resource or null
-
locate
public IResourceStream locate(Class<?> scope, String path, String style, String variation, Locale locale, String extension, boolean strict)
Description copied from interface:IResourceStreamLocator
Locate a resource by combining the given path, style, variation, locale and extension parameters. The exact search order depends on the implementation.- Specified by:
locate
in interfaceIResourceStreamLocator
- Parameters:
scope
- The class loader for delegating the loading of the resourcepath
- The path of the resourcestyle
- Any resource style, such as a skin style (seeSession
)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 exactly- Returns:
- The resource or null
-
newResourceNameIterator
public IResourceNameIterator newResourceNameIterator(String path, Locale locale, String style, String variation, String extension, boolean strict)
Description copied from interface:IResourceStreamLocator
Markup resources and Properties files both need to iterate over different combinations of locale, style, etc.. And though no single locate(..) method exists which is used by both, they both use ResourceNameIterators.- Specified by:
newResourceNameIterator
in interfaceIResourceStreamLocator
- Parameters:
path
- The path of the resourcelocale
- The locale of the resource to loadstyle
- Any resource style, such as a skin style (seeSession
)variation
- The component's variation (of the style)extension
- A comma separate list of extensionsstrict
- whether the specified attributes must match exactly- Returns:
- resource name iterator
-
clearCache
public void clearCache()
Clears the resource cache.- Since:
- 6.16.0
-
-