Package org.apache.wicket
Class ResourceBundles
- java.lang.Object
-
- org.apache.wicket.ResourceBundles
-
public class ResourceBundles extends Object
Contains all resource bundles that are registered in the application. Resource bundles provide a way to combine multiple resources into one, reducing the number of requests needed to load a page. The code using the resources does not need to know about the registered resources, making it possible to create resource bundles for 3rd party libraries. When a single resource from a resource bundle is requested, the bundle is rendered instead. All other resources from the bundle are marked as rendered. A specific resource can only be part of one bundle.- Author:
- papegaaij
-
-
Constructor Summary
Constructors Constructor Description ResourceBundles(ResourceReferenceRegistry registry)
Construct.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends HeaderItem>
TaddBundle(T bundle)
Adds a bundle to the registry.CssReferenceHeaderItem
addCssBundle(Class<?> scope, String name, CssResourceReference... references)
Adds a css bundle that is automatically generated by concatenating the given package resources.JavaScriptReferenceHeaderItem
addJavaScriptBundle(Class<?> scope, String name, boolean defer, JavaScriptResourceReference... references)
Adds a javascript bundle that is automatically generated by concatenating the given package resources.JavaScriptReferenceHeaderItem
addJavaScriptBundle(Class<?> scope, String name, JavaScriptResourceReference... references)
Adds a javascript bundle that is automatically generated by concatenating the given package resources.HeaderItem
findBundle(HeaderItem item)
Finds a bundle that provides the given item.protected <T extends HeaderItem & IReferenceHeaderItem>
ConcatResourceBundleReference<T>newBundleResourceReference(Class<?> scope, String name, List<T> items)
Creates a ResourceReference that will point to the bundle with the items
-
-
-
Constructor Detail
-
ResourceBundles
public ResourceBundles(ResourceReferenceRegistry registry)
Construct.- Parameters:
registry
- the registry that keeps all referenced resources
-
-
Method Detail
-
addJavaScriptBundle
public JavaScriptReferenceHeaderItem addJavaScriptBundle(Class<?> scope, String name, JavaScriptResourceReference... references)
Adds a javascript bundle that is automatically generated by concatenating the given package resources. If the given resources depend on each other, you should make sure that the resources are provided in the order they need to be concatenated. If the resources depend on other resources, that are not part of the bundle, the bundle will inherit these dependencies. This method is equivalent toaddBundle(HeaderItem)
with aJavaScriptHeaderItem
for aConcatResourceBundleReference
.- Parameters:
scope
- The scope of the bundlename
- The name of the resource. This will show up as the filename in the markup.references
- The resources this bundle will consist of.- Returns:
- the newly created bundle
-
addJavaScriptBundle
public JavaScriptReferenceHeaderItem addJavaScriptBundle(Class<?> scope, String name, boolean defer, JavaScriptResourceReference... references)
Adds a javascript bundle that is automatically generated by concatenating the given package resources. If the given resources depend on each other, you should make sure that the resources are provided in the order they need to be concatenated. If the resources depend on other resources, that are not part of the bundle, the bundle will inherit these dependencies. This method is equivalent toaddBundle(HeaderItem)
with aJavaScriptHeaderItem
for aConcatResourceBundleReference
.- Parameters:
scope
- The scope of the bundledefer
- specifies that the execution of a script should be deferred (delayed) until after the page has been loaded.name
- The name of the resource. This will show up as the filename in the markup.references
- The resources this bundle will consist of.- Returns:
- the newly created bundle
-
addCssBundle
public CssReferenceHeaderItem addCssBundle(Class<?> scope, String name, CssResourceReference... references)
Adds a css bundle that is automatically generated by concatenating the given package resources. If the given resources depend on each other, you should make sure that the resources are provided in the order they need to be concatenated. If the resources depend on other resources, that are not part of the bundle, the bundle will inherit these dependencies. This method is equivalent toaddBundle(HeaderItem)
with aCssHeaderItem
for aConcatResourceBundleReference
.- Parameters:
scope
- The scope of the bundlename
- The name of the resource. This will show up as the filename in the markup.references
- The resources this bundle will consist of.- Returns:
- the newly created bundle
-
newBundleResourceReference
protected <T extends HeaderItem & IReferenceHeaderItem> ConcatResourceBundleReference<T> newBundleResourceReference(Class<?> scope, String name, List<T> items)
Creates a ResourceReference that will point to the bundle with the items- Type Parameters:
T
- The type of the header items- Parameters:
scope
- The scope of the bundlename
- The name of the resource. This will show up as the filename in the markup.items
- The HeaderItems for the resource references for the bundle- Returns:
- A ResourceReference that will point to the bundle with the items
-
addBundle
public <T extends HeaderItem> T addBundle(T bundle)
Adds a bundle to the registry.- Parameters:
bundle
- The bundle to register- Returns:
- the bundle
- Throws:
IllegalArgumentException
- if any of the provided resources of the given bundle is already provided by a different bundle.
-
findBundle
public HeaderItem findBundle(HeaderItem item)
Finds a bundle that provides the given item.- Parameters:
item
- The item that should be provided by the bundle.- Returns:
- The bundle that provides the given item or null if no bundle is found.
-
-