Class 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 and FileResourceStream objects as they are found, and NullResourceStreamReference for all which are missing so they are not looked up again and again.

    • 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 of 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.
        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​(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 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 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 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
      • clearCache

        public void clearCache()
        Clears the resource cache.
        Since:
        6.16.0