org.apache.wicket
Class SharedResources

java.lang.Object
  extended by org.apache.wicket.SharedResources

public class SharedResources
extends Object

Class which holds shared resources. Resources can be shared by name. An optional scope can be given to prevent naming conflicts and a locale and/or style can be given as well.

Unlike component hosted resources, shared resources have stable URLs, which makes them suitable for indexing by web crawlers and caching by web browsers. As they are also not synchronised on the Session, they can be loaded asynchronously, which is important with images and resources such as JavaScript and CSS.

Author:
Jonathan Locke, Johan Compagner, Gili Tzabari
See Also:
Resource

Method Summary
 void add(Class<?> scope, String name, Locale locale, String style, Resource resource)
          Adds a resource.
 void add(String name, Locale locale, Resource resource)
          Adds a resource.
 void add(String name, Resource resource)
          Adds a resource.
 Resource get(Class<?> scope, String name, Locale locale, String style, boolean exact)
           
 Resource get(String key)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 Class<?> getAliasClass(String alias)
          Gets the class for a given resource alias.
 boolean isThrowExceptionIfNotMapped()
           
 void putClassAlias(Class<?> clz, String alias)
          Sets an alias for a class so that a resource url can look like: resources/images/Image.jpg instead of resources/org.apache.wicket.resources.ResourceClass/Image.jpg
 void remove(String key)
          Removes a shared resource.
 String resourceKey(Class<?> scope, String path, Locale locale, String style)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
static String resourceKey(String path, Locale locale, String style)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 void setThrowExceptionIfNotMapped(boolean throwExceptionIfNotMapped)
          Set to true, if an exception shall be thrown if no alias has been defined for the class and thus the fully-qualified-class name is exposed in the URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

resourceKey

public static String resourceKey(String path,
                                 Locale locale,
                                 String style)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.

Inserts _[locale] and _[style] into path just before any extension that might exist.

Parameters:
path - The resource path
locale - The locale
style - The style (see Session)
Returns:
The localized path

add

public final void add(Class<?> scope,
                      String name,
                      Locale locale,
                      String style,
                      Resource resource)
Adds a resource.

Parameters:
scope - Scope of resource
name - Logical name of resource
locale - The locale of the resource
style - The resource style (see Session)
resource - Resource to store

add

public final void add(String name,
                      Locale locale,
                      Resource resource)
Adds a resource.

Parameters:
name - Logical name of resource
locale - The locale of the resource
resource - Resource to store

add

public final void add(String name,
                      Resource resource)
Adds a resource.

Parameters:
name - Logical name of resource
resource - Resource to store

get

public final Resource get(Class<?> scope,
                          String name,
                          Locale locale,
                          String style,
                          boolean exact)
Parameters:
scope - The resource's scope
name - Name of resource to get
locale - The locale of the resource
style - The resource style (see Session)
exact - If true then only return the resource that is registered for the given locale and style.
Returns:
The logical resource

get

public final Resource get(String key)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT.

Parameters:
key - Shared resource key
Returns:
The resource

putClassAlias

public final void putClassAlias(Class<?> clz,
                                String alias)
Sets an alias for a class so that a resource url can look like: resources/images/Image.jpg instead of resources/org.apache.wicket.resources.ResourceClass/Image.jpg

Parameters:
clz - The class that has to be aliased.
alias - The alias string.

getAliasClass

public final Class<?> getAliasClass(String alias)
Gets the class for a given resource alias.

Parameters:
alias -
Returns:
The class this is an alias for.
See Also:
putClassAlias(Class, String)

remove

public final void remove(String key)
Removes a shared resource.

Parameters:
key - Shared resource key

resourceKey

public String resourceKey(Class<?> scope,
                          String path,
                          Locale locale,
                          String style)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.

Parameters:
scope - The scope of the resource
path - The resource path
locale - The locale
style - The style (see Session)
Returns:
The localized path

isThrowExceptionIfNotMapped

public boolean isThrowExceptionIfNotMapped()
Returns:
If true an exception is thrown if no alias has been defined for the class and thus the fully-qualified-class-name is exposed in the URL.

setThrowExceptionIfNotMapped

public void setThrowExceptionIfNotMapped(boolean throwExceptionIfNotMapped)
Set to true, if an exception shall be thrown if no alias has been defined for the class and thus the fully-qualified-class name is exposed in the URL.

Parameters:
throwExceptionIfNotMapped -


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