org.apache.wicket.settings.def
Class ResourceSettings

java.lang.Object
  extended by org.apache.wicket.settings.def.ResourceSettings
All Implemented Interfaces:
IPropertiesFactoryContext, IResourceSettings

public class ResourceSettings
extends Object
implements IResourceSettings

Author:
Jonathan Locke, Chris Turner, Eelco Hillenius, Juergen Donnerstag, Johan Compagner, Igor Vaynberg (ivaynberg), Martijn Dashorst, James Carman

Constructor Summary
ResourceSettings(Application application)
          Configures Wicket's default ResourceLoaders.
For an example in FooApplication let bar.Foo extend Component, this results in the following ordering: component specific bar/Foo.properties org/apache/wicket/Component.properties package specific bar/package.properties package.properties (on Foo's class loader) org/apache/wicket/package.properties org/apache/package.properties org/package.properties package.properties (on Component's class loader) application specific FooApplication.properties Application.properties validator specific Initializer specific bar.Foo.properties (Foo implementing IInitializer)
 
Method Summary
 void addResourceFactory(String name, IResourceFactory resourceFactory)
          Adds a resource factory to the list of factories to consult when generating resources automatically
 IResourceCachingStrategy getCachingStrategy()
          gets the resource caching strategy
 ICssCompressor getCssCompressor()
          Get the CSS compressor to remove comments and whitespace characters from css resources
 Duration getDefaultCacheDuration()
          Get the the default cache duration for resources.
 IFileCleaner getFileCleaner()
           
 Comparator<? super ResourceAggregator.RecordedHeaderItem> getHeaderItemComparator()
           
 IJavaScriptCompressor getJavaScriptCompressor()
          Get the javascript compressor to remove comments and whitespace characters from javascripts
 Localizer getLocalizer()
          Get the application's localizer.
 IPackageResourceGuard getPackageResourceGuard()
          Gets the package resource guard.
 String getParentFolderPlaceholder()
          Placeholder string for '..' within resource urls (which will be crippled by the browser and not work anymore).
 IPropertiesFactory getPropertiesFactory()
          Get the property factory which will be used to load property files
 IResourceFactory getResourceFactory(String name)
           
 List<IResourceFinder> getResourceFinders()
          Gets the resource finders to use when searching for resources.
 Duration getResourcePollFrequency()
           
 IResourceStreamLocator getResourceStreamLocator()
           
 IModificationWatcher getResourceWatcher(boolean start)
           
 List<IStringResourceLoader> getStringResourceLoaders()
           
 boolean getThrowExceptionOnMissingResource()
           
 boolean getUseDefaultOnMissingResource()
           
 boolean getUseMinifiedResources()
           
 boolean isEncodeJSessionId()
          A flag indicating whether static resources should have jsessionid encoded in their url.
 void setCachingStrategy(IResourceCachingStrategy strategy)
          sets the resource caching strategy
 ICssCompressor setCssCompressor(ICssCompressor compressor)
          Set the CSS compressor implemententation use e.g.
 void setDefaultCacheDuration(Duration duration)
          Set the the default cache duration for resources.
 void setEncodeJSessionId(boolean encodeJSessionId)
          Sets a flag indicating whether the jsessionid should be encoded in the url for resources implementing IStaticCacheableResource when the cookies are disabled and there is an active http session.
 void setFileCleaner(IFileCleaner fileUploadCleaner)
          Sets a cleaner that can be used to remove files asynchronously.
 void setHeaderItemComparator(Comparator<? super ResourceAggregator.RecordedHeaderItem> headerItemComparator)
          Sets the comparator used by the resource aggregator for sorting header items.
 IJavaScriptCompressor setJavaScriptCompressor(IJavaScriptCompressor compressor)
          Set the javascript compressor implemententation use e.g.
 void setLocalizer(Localizer localizer)
          Sets the localizer which will be used to find property values.
 void setPackageResourceGuard(IPackageResourceGuard packageResourceGuard)
          Sets the package resource guard.
 void setParentFolderPlaceholder(String sequence)
          Placeholder string for '..' within resource urls (which will be crippled by the browser and not work anymore).
 void setPropertiesFactory(IPropertiesFactory factory)
          Set the property factory which will be used to load property files
 void setResourceFinders(List<IResourceFinder> resourceFinders)
          Sets the finders to use when searching for resources.
 void setResourcePollFrequency(Duration resourcePollFrequency)
          Sets the resource polling frequency.
 void setResourceStreamLocator(IResourceStreamLocator resourceStreamLocator)
          Sets the resource stream locator for this application
 void setResourceWatcher(IModificationWatcher watcher)
          Sets the resource watcher
 void setThrowExceptionOnMissingResource(boolean throwExceptionOnMissingResource)
           
 void setUseDefaultOnMissingResource(boolean useDefaultOnMissingResource)
           
 void setUseMinifiedResources(boolean useMinifiedResources)
          Sets whether to use pre-minified resources when available.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceSettings

public ResourceSettings(Application application)
Configures Wicket's default ResourceLoaders.
For an example in FooApplication let bar.Foo extend Component, this results in the following ordering:
component specific
  • bar/Foo.properties
  • org/apache/wicket/Component.properties
package specific
  • bar/package.properties
  • package.properties (on Foo's class loader)
  • org/apache/wicket/package.properties
  • org/apache/package.properties
  • org/package.properties
  • package.properties (on Component's class loader)
application specific
  • FooApplication.properties
  • Application.properties
validator specific
Initializer specific
  • bar.Foo.properties (Foo implementing IInitializer)

Parameters:
application -
Method Detail

addResourceFactory

public void addResourceFactory(String name,
                               IResourceFactory resourceFactory)
Description copied from interface: IResourceSettings
Adds a resource factory to the list of factories to consult when generating resources automatically

Specified by:
addResourceFactory in interface IResourceSettings
Parameters:
name - The name to give to the factory
resourceFactory - The resource factory to add
See Also:
IResourceSettings.addResourceFactory(java.lang.String, org.apache.wicket.IResourceFactory)

getLocalizer

public Localizer getLocalizer()
Description copied from interface: IPropertiesFactoryContext
Get the application's localizer. to modify the way Wicket resolves keys to localized messages you can add custom resource loaders to the list returned by IResourceSettings.getStringResourceLoaders().

Specified by:
getLocalizer in interface IPropertiesFactoryContext
Returns:
The application wide localizer instance
See Also:
IPropertiesFactoryContext.getLocalizer()

getPackageResourceGuard

public IPackageResourceGuard getPackageResourceGuard()
Description copied from interface: IResourceSettings
Gets the package resource guard.

Specified by:
getPackageResourceGuard in interface IResourceSettings
Returns:
The package resource guard
See Also:
IResourceSettings.getPackageResourceGuard()

getPropertiesFactory

public IPropertiesFactory getPropertiesFactory()
Description copied from interface: IResourceSettings
Get the property factory which will be used to load property files

Specified by:
getPropertiesFactory in interface IResourceSettings
Returns:
PropertiesFactory
See Also:
IResourceSettings.getPropertiesFactory()

getResourceFactory

public IResourceFactory getResourceFactory(String name)
Specified by:
getResourceFactory in interface IResourceSettings
Parameters:
name - Name of the factory to get
Returns:
The IResourceFactory with the given name.
See Also:
IResourceSettings.getResourceFactory(java.lang.String)

getResourceFinders

public List<IResourceFinder> getResourceFinders()
Description copied from interface: IResourceSettings
Gets the resource finders to use when searching for resources. By default, a finder that looks in the classpath root is configured. WebApplication adds the classpath directory META-INF/resources. To configure additional search paths or filesystem paths, add to this list.

Specified by:
getResourceFinders in interface IResourceSettings
Returns:
Returns the resourceFinders.
See Also:
IResourceSettings.getResourceFinders()

getResourcePollFrequency

public Duration getResourcePollFrequency()
Specified by:
getResourcePollFrequency in interface IResourceSettings
Returns:
Returns the resourcePollFrequency.
See Also:
IResourceSettings.getResourcePollFrequency()

getResourceStreamLocator

public IResourceStreamLocator getResourceStreamLocator()
Specified by:
getResourceStreamLocator in interface IPropertiesFactoryContext
Returns:
Resource locator for this application
See Also:
IPropertiesFactoryContext.getResourceStreamLocator()

getResourceWatcher

public IModificationWatcher getResourceWatcher(boolean start)
Specified by:
getResourceWatcher in interface IPropertiesFactoryContext
Parameters:
start - boolean if the resource watcher should be started if not already started.
Returns:
Resource watcher with polling frequency determined by setting, or null if no polling frequency has been set.
See Also:
IPropertiesFactoryContext.getResourceWatcher(boolean)

setResourceWatcher

public void setResourceWatcher(IModificationWatcher watcher)
Description copied from interface: IResourceSettings
Sets the resource watcher

Specified by:
setResourceWatcher in interface IResourceSettings
See Also:
IResourceSettings.setResourceWatcher(org.apache.wicket.util.watch.IModificationWatcher)

getFileCleaner

public IFileCleaner getFileCleaner()
Specified by:
getFileCleaner in interface IResourceSettings
Returns:
the a cleaner which can be used to remove files asynchronously.

setFileCleaner

public void setFileCleaner(IFileCleaner fileUploadCleaner)
Description copied from interface: IResourceSettings
Sets a cleaner that can be used to remove files asynchronously.

Used internally to delete the temporary files created by FileUpload functionality

Specified by:
setFileCleaner in interface IResourceSettings
Parameters:
fileUploadCleaner - the actual cleaner implementation. Can be null

getStringResourceLoaders

public List<IStringResourceLoader> getStringResourceLoaders()
Specified by:
getStringResourceLoaders in interface IResourceSettings
Returns:
mutable list of all available string resource loaders
See Also:
IResourceSettings.getStringResourceLoaders()

getThrowExceptionOnMissingResource

public boolean getThrowExceptionOnMissingResource()
Specified by:
getThrowExceptionOnMissingResource in interface IResourceSettings
Returns:
boolean
See Also:
IResourceSettings.getThrowExceptionOnMissingResource()

getUseDefaultOnMissingResource

public boolean getUseDefaultOnMissingResource()
Specified by:
getUseDefaultOnMissingResource in interface IResourceSettings
Returns:
Whether to use a default value (if available) when a missing resource is requested
See Also:
IResourceSettings.getUseDefaultOnMissingResource()

setLocalizer

public void setLocalizer(Localizer localizer)
Description copied from interface: IResourceSettings
Sets the localizer which will be used to find property values.

Specified by:
setLocalizer in interface IResourceSettings
See Also:
IResourceSettings.setLocalizer(org.apache.wicket.Localizer)

setPackageResourceGuard

public void setPackageResourceGuard(IPackageResourceGuard packageResourceGuard)
Description copied from interface: IResourceSettings
Sets the package resource guard.

Specified by:
setPackageResourceGuard in interface IResourceSettings
Parameters:
packageResourceGuard - The package resource guard
See Also:
IResourceSettings.setPackageResourceGuard(org.apache.wicket.markup.html.IPackageResourceGuard)

setPropertiesFactory

public void setPropertiesFactory(IPropertiesFactory factory)
Description copied from interface: IResourceSettings
Set the property factory which will be used to load property files

Specified by:
setPropertiesFactory in interface IResourceSettings
See Also:
IResourceSettings.setPropertiesFactory(org.apache.wicket.resource.IPropertiesFactory)

setResourceFinders

public void setResourceFinders(List<IResourceFinder> resourceFinders)
Description copied from interface: IResourceSettings
Sets the finders to use when searching for resources. By default, the resources are located on the classpath. To add additional search paths, add to the list given by IResourceSettings.getResourceFinders(). Use this method if you want to completely exchange the list of resource finders.

Specified by:
setResourceFinders in interface IResourceSettings
Parameters:
resourceFinders - The resourceFinder to set
See Also:
IResourceSettings.setResourceFinders(java.util.List)

setResourcePollFrequency

public void setResourcePollFrequency(Duration resourcePollFrequency)
Description copied from interface: IResourceSettings
Sets the resource polling frequency. This is the duration of time between checks of resource modification times. If a resource, such as an HTML file, has changed, it will be reloaded. The default is one second in 'development' mode and 'never' in deployment mode.

Specified by:
setResourcePollFrequency in interface IResourceSettings
Parameters:
resourcePollFrequency - Frequency at which to poll resources or null if polling should be disabled
See Also:
IResourceSettings.setResourcePollFrequency(org.apache.wicket.util.time.Duration)

setResourceStreamLocator

public void setResourceStreamLocator(IResourceStreamLocator resourceStreamLocator)
Sets the resource stream locator for this application Consider wrapping resourceStreamLocator in CachingResourceStreamLocator. This way the locator will not be asked more than once for IResourceStreams which do not exist.

Specified by:
setResourceStreamLocator in interface IResourceSettings
Parameters:
resourceStreamLocator - new resource stream locator
See Also:
getResourceStreamLocator()

setThrowExceptionOnMissingResource

public void setThrowExceptionOnMissingResource(boolean throwExceptionOnMissingResource)
Specified by:
setThrowExceptionOnMissingResource in interface IResourceSettings
See Also:
IResourceSettings.setThrowExceptionOnMissingResource(boolean)

setUseDefaultOnMissingResource

public void setUseDefaultOnMissingResource(boolean useDefaultOnMissingResource)
Specified by:
setUseDefaultOnMissingResource in interface IResourceSettings
Parameters:
useDefaultOnMissingResource - Whether to use a default value (if available) when a missing resource is requested
See Also:
IResourceSettings.setUseDefaultOnMissingResource(boolean)

getDefaultCacheDuration

public final Duration getDefaultCacheDuration()
Description copied from interface: IResourceSettings
Get the the default cache duration for resources.

Specified by:
getDefaultCacheDuration in interface IResourceSettings
Returns:
cache duration (Duration.NONE will be returned if caching is disabled)
See Also:
IResourceSettings.getDefaultCacheDuration()

setDefaultCacheDuration

public final void setDefaultCacheDuration(Duration duration)
Description copied from interface: IResourceSettings
Set the the default cache duration for resources.

Based on RFC-2616 this should not exceed one year. If you set Duration.NONE caching will be disabled.

Specified by:
setDefaultCacheDuration in interface IResourceSettings
Parameters:
duration - default cache duration in seconds
See Also:
IResourceSettings.setDefaultCacheDuration(org.apache.wicket.util.time.Duration)

getJavaScriptCompressor

public IJavaScriptCompressor getJavaScriptCompressor()
Description copied from interface: IResourceSettings
Get the javascript compressor to remove comments and whitespace characters from javascripts

Specified by:
getJavaScriptCompressor in interface IResourceSettings
Returns:
whether the comments and whitespace characters will be stripped from resources served through JavaScriptPackageResource. Null is a valid value.

setJavaScriptCompressor

public IJavaScriptCompressor setJavaScriptCompressor(IJavaScriptCompressor compressor)
Description copied from interface: IResourceSettings
Set the javascript compressor implemententation use e.g. by JavaScriptPackageResource. A typical implementation will remove comments and whitespace. But a no-op implementation is available as well.

Specified by:
setJavaScriptCompressor in interface IResourceSettings
Parameters:
compressor - The implementation to be used
Returns:
The old value

getCssCompressor

public ICssCompressor getCssCompressor()
Description copied from interface: IResourceSettings
Get the CSS compressor to remove comments and whitespace characters from css resources

Specified by:
getCssCompressor in interface IResourceSettings
Returns:
whether the comments and whitespace characters will be stripped from resources served through CssPackageResource. Null is a valid value.

setCssCompressor

public ICssCompressor setCssCompressor(ICssCompressor compressor)
Description copied from interface: IResourceSettings
Set the CSS compressor implemententation use e.g. by CssPackageResource. A typical implementation will remove comments and whitespace. But a no-op implementation is available as well.

Specified by:
setCssCompressor in interface IResourceSettings
Parameters:
compressor - The implementation to be used
Returns:
The old value

getParentFolderPlaceholder

public String getParentFolderPlaceholder()
Description copied from interface: IResourceSettings
Placeholder string for '..' within resource urls (which will be crippled by the browser and not work anymore). Note that by default the placeholder string is ::. Resources are protected by a IPackageResourceGuard implementation such as PackageResourceGuard which you may use or extend based on your needs.

Specified by:
getParentFolderPlaceholder in interface IResourceSettings
Returns:
placeholder
See Also:
IResourceSettings.getParentFolderPlaceholder()

setParentFolderPlaceholder

public void setParentFolderPlaceholder(String sequence)
Description copied from interface: IResourceSettings
Placeholder string for '..' within resource urls (which will be crippled by the browser and not work anymore). Note that by default the placeholder string is null and thus will not allow to access parent folders. That is by purpose and for security reasons (see Wicket-1992). In case you really need it, a good value for placeholder would e.g. be "$up$". Resources additionally are protected by a IPackageResourceGuard implementation such as PackageResourceGuard which you may use or extend based on your needs.

Specified by:
setParentFolderPlaceholder in interface IResourceSettings
Parameters:
sequence - character sequence which must not be ambiguous within urls
See Also:
IResourceSettings.setParentFolderPlaceholder(String)

getCachingStrategy

public IResourceCachingStrategy getCachingStrategy()
Description copied from interface: IResourceSettings
gets the resource caching strategy

Specified by:
getCachingStrategy in interface IResourceSettings
Returns:
strategy
See Also:
IResourceSettings.getCachingStrategy()

setCachingStrategy

public void setCachingStrategy(IResourceCachingStrategy strategy)
Description copied from interface: IResourceSettings
sets the resource caching strategy

Specified by:
setCachingStrategy in interface IResourceSettings
Parameters:
strategy - instance of resource caching strategy
See Also:
IResourceSettings.setCachingStrategy(org.apache.wicket.request.resource.caching.IResourceCachingStrategy)

setUseMinifiedResources

public void setUseMinifiedResources(boolean useMinifiedResources)
Description copied from interface: IResourceSettings
Sets whether to use pre-minified resources when available. Minified resources are detected by name. The minified version of x.js is expected to be called x.min.js. For css files, the same convention is used: x.min.css is the minified version of x.css. When this is null, minified resources will only be used in deployment configuration.

Specified by:
setUseMinifiedResources in interface IResourceSettings
Parameters:
useMinifiedResources - The new value for the setting

getUseMinifiedResources

public boolean getUseMinifiedResources()
Specified by:
getUseMinifiedResources in interface IResourceSettings
Returns:
Whether pre-minified resources will be used.

getHeaderItemComparator

public Comparator<? super ResourceAggregator.RecordedHeaderItem> getHeaderItemComparator()
Specified by:
getHeaderItemComparator in interface IResourceSettings
Returns:
The comparator used to sort header items.

setHeaderItemComparator

public void setHeaderItemComparator(Comparator<? super ResourceAggregator.RecordedHeaderItem> headerItemComparator)
Description copied from interface: IResourceSettings
Sets the comparator used by the resource aggregator for sorting header items. It should be noted that sorting header items may break resource dependencies. This comparator should therefore at least respect dependencies declared by resource references. By default, items are sorted using the PriorityFirstComparator.

Specified by:
setHeaderItemComparator in interface IResourceSettings
Parameters:
headerItemComparator - The comparator used to sort header items, when null, header items will not be sorted.

isEncodeJSessionId

public boolean isEncodeJSessionId()
Description copied from interface: IResourceSettings
A flag indicating whether static resources should have jsessionid encoded in their url.

Specified by:
isEncodeJSessionId in interface IResourceSettings
Returns:
true if the jsessionid should be encoded in the url for resources implementing IStaticCacheableResource when the cookies are disabled and there is an active http session.

setEncodeJSessionId

public void setEncodeJSessionId(boolean encodeJSessionId)
Description copied from interface: IResourceSettings
Sets a flag indicating whether the jsessionid should be encoded in the url for resources implementing IStaticCacheableResource when the cookies are disabled and there is an active http session.

Specified by:
setEncodeJSessionId in interface IResourceSettings
Parameters:
encodeJSessionId - true when the jsessionid should be encoded, false - otherwise


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