org.apache.wicket.util.resource.locator.caching
Class CachingResourceStreamLocator

java.lang.Object
  extended by org.apache.wicket.util.resource.locator.caching.CachingResourceStreamLocator
All Implemented Interfaces:
IResourceStreamLocator

public class CachingResourceStreamLocator
extends java.lang.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 and FileResourceStream objects as they are found, and NullResourceStreamReference for all which are missing so they are not looked up again and again.


Constructor Summary
CachingResourceStreamLocator(IResourceStreamLocator resourceStreamLocator)
          Construct.
 
Method Summary
 IResourceStream locate(java.lang.Class<?> clazz, java.lang.String path)
          Locate a resource, given a path and class.
 IResourceStream locate(java.lang.Class<?> scope, java.lang.String path, java.lang.String style, java.lang.String variation, java.util.Locale locale, java.lang.String extension, boolean strict)
          Locate a resource by combining the given path, style, variation, locale and extension parameters.
 ResourceNameIterator newResourceNameIterator(java.lang.String path, java.util.Locale locale, java.lang.String style, java.lang.String variation, java.lang.String extension, boolean strict)
          Markup resources and Properties files both need to iterate over different combinations of locale, style, etc..
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingResourceStreamLocator

public CachingResourceStreamLocator(IResourceStreamLocator resourceStreamLocator)
Construct.

Parameters:
resourceStreamLocator - the delegate
Method Detail

locate

public IResourceStream locate(java.lang.Class<?> clazz,
                              java.lang.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 of #locate(Class, String, String, Locale, String) 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.

Specified by:
locate in interface IResourceStreamLocator
Parameters:
clazz - The class loader for delegating the loading of the resource
path - The path of the resource
Returns:
The resource or null

locate

public IResourceStream locate(java.lang.Class<?> scope,
                              java.lang.String path,
                              java.lang.String style,
                              java.lang.String variation,
                              java.util.Locale locale,
                              java.lang.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 interface IResourceStreamLocator
Parameters:
scope - The class loader for delegating the loading of the resource
path - The path of the resource
style - 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 load
extension - A comma separate list of extensions
strict - whether the specified attributes must match exactly
Returns:
The resource or null

newResourceNameIterator

public ResourceNameIterator newResourceNameIterator(java.lang.String path,
                                                    java.util.Locale locale,
                                                    java.lang.String style,
                                                    java.lang.String variation,
                                                    java.lang.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 interface IResourceStreamLocator
Parameters:
path - The path of the resource
locale - The locale of the resource to load
style - Any resource style, such as a skin style (see Session)
variation - The component's variation (of the style)
extension - A comma separate list of extensions
strict - whether the specified attributes must match exactly
Returns:
resource name iterator


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.