Package org.apache.wicket
Class SharedResources
- java.lang.Object
-
- 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.
-
-
Constructor Summary
Constructors Constructor Description SharedResources(ResourceReferenceRegistry registry)
Construct.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(Class<?> scope, String name, Locale locale, String style, String variation, IResource resource)
Adds a resource.void
add(String name, Locale locale, IResource resource)
Adds a resource.void
add(String name, IResource resource)
Adds a resource.ResourceReference
get(Class<?> scope, String name, Locale locale, String style, String variation, boolean strict)
Resolves aResourceReference
for a shared resource.ResourceReference
get(String name)
Resolves aResourceReference
for a shared resource by usingApplication
as a scope andnull
for locale, style and variation.ResourceReference
remove(ResourceReference.Key key)
Removes a resource.
-
-
-
Constructor Detail
-
SharedResources
public SharedResources(ResourceReferenceRegistry registry)
Construct.- Parameters:
registry
-
-
-
Method Detail
-
add
public final void add(Class<?> scope, String name, Locale locale, String style, String variation, IResource resource)
Adds a resource.- Parameters:
scope
- Scope of resourcename
- Logical name of resourcelocale
- The locale of the resourcestyle
- The resource style (seeSession
)variation
- The component specific variation of the styleresource
- Resource to store
-
add
public final void add(String name, Locale locale, IResource resource)
Adds a resource.- Parameters:
name
- Logical name of resourcelocale
- The locale of the resourceresource
- Resource to store
-
add
public final void add(String name, IResource resource)
Adds a resource.- Parameters:
name
- Logical name of resourceresource
- Resource to store
-
get
public final ResourceReference get(String name)
Resolves aResourceReference
for a shared resource by usingApplication
as a scope andnull
for locale, style and variation.- Parameters:
name
- Logical name of resource
-
get
public ResourceReference get(Class<?> scope, String name, Locale locale, String style, String variation, boolean strict)
Resolves aResourceReference
for a shared resource.- Parameters:
scope
- Scope of resourcename
- Logical name of resourcelocale
- The locale of the resourcestyle
- The resource style (seeSession
)variation
- The component specific variation of the stylestrict
- If true, "weaker" combination of scope, name, locale etc. are not tested- Returns:
- Either the resource reference found in the registry or, if requested, a resource reference automatically created based on the parameters provided. The automatically created resource reference will automatically be added to the registry.
-
remove
public final ResourceReference remove(ResourceReference.Key key)
Removes a resource.- Parameters:
key
- the resource reference's identifier- Returns:
- the removed
ResourceReference
.null
if there was no registration for thisResourceReference.Key
-
-