Class ResourceSettings
- java.lang.Object
-
- org.apache.wicket.settings.ResourceSettings
-
- All Implemented Interfaces:
IPropertiesFactoryContext
public class ResourceSettings extends java.lang.Object implements IPropertiesFactoryContext
Class for resource related settingsresourcePollFrequency (defaults to no polling frequency) - Frequency at which resources should be polled for changes.
resourceFinders - Add/modify this to alter the search path for resources.
useDefaultOnMissingResource (defaults to true) - Set to true to return a default value if available when a required string resource is not found. If set to false then the throwExceptionOnMissingResource flag is used to determine how to behave. If no default is available then this is the same as if this flag were false
A ResourceStreamLocator - An Application's ResourceStreamLocator is used to find resources such as images or markup files. You can supply your own ResourceStreamLocator if your prefer to store your application's resources in a non-standard location (such as a different filesystem location, a particular JAR file or even a database) by overriding the getResourceLocator() method.
Resource Factories - Resource factories can be used to create resources dynamically from specially formatted HTML tag attribute values. For more details, see
IResourceFactory,DefaultButtonImageResourceFactoryand especiallyLocalizedImageResource.A Localizer The getLocalizer() method returns an object encapsulating all of the functionality required to access localized resources. For many localization problems, even this will not be required, as there are convenience methods available to all components:
Component.getString(String key)andComponent.getString(String key, org.apache.wicket.model.IModel model).stringResourceLoaders - A chain of
IStringResourceLoaderinstances that are searched in order to obtain string resources used during localization. By default the chain is set up to first search for resources against a particular component (e.g. page etc.) and then against the application.- Author:
- Jonathan Locke, Chris Turner, Eelco Hillenius, Juergen Donnerstag, Johan Compagner, Igor Vaynberg (ivaynberg), Martijn Dashorst, James Carman
-
-
Constructor Summary
Constructors Constructor Description ResourceSettings(Application application)Configures Wicket's default ResourceLoaders.
For an example inFooApplicationletbar.FooextendComponent, 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ResourceSettingsaddResourceFactory(java.lang.String name, IResourceFactory resourceFactory)Adds a resource factory to the list of factories to consult when generating resources automaticallyIResourceCachingStrategygetCachingStrategy()gets the resource caching strategyICssCompressorgetCssCompressor()Get the CSS compressor to remove comments and whitespace characters from css resourcesorg.apache.wicket.util.time.DurationgetDefaultCacheDuration()Get the the default cache duration for resources.org.apache.wicket.util.file.IFileCleanergetFileCleaner()java.util.Comparator<? super ResourceAggregator.RecordedHeaderItem>getHeaderItemComparator()IJavaScriptCompressorgetJavaScriptCompressor()Get the javascript compressor to remove comments and whitespace characters from javascriptsLocalizergetLocalizer()Get the application's localizer.IPackageResourceGuardgetPackageResourceGuard()Gets thepackage resource guard.java.lang.StringgetParentFolderPlaceholder()Placeholder string for '..' within resource urls (which will be crippled by the browser and not work anymore).IPropertiesFactorygetPropertiesFactory()Get the property factory which will be used to load property filesIResourceFactorygetResourceFactory(java.lang.String name)java.util.List<org.apache.wicket.util.file.IResourceFinder>getResourceFinders()Gets the resource finders to use when searching for resources.org.apache.wicket.util.time.DurationgetResourcePollFrequency()IResourceStreamLocatorgetResourceStreamLocator()org.apache.wicket.util.watch.IModificationWatchergetResourceWatcher(boolean start)java.util.List<IStringResourceLoader>getStringResourceLoaders()booleangetThrowExceptionOnMissingResource()booleangetUseDefaultOnMissingResource()booleangetUseMinifiedResources()booleanisEncodeJSessionId()A flag indicating whether static resources should have jsessionid encoded in their url.ResourceSettingssetCachingStrategy(IResourceCachingStrategy strategy)sets the resource caching strategyICssCompressorsetCssCompressor(ICssCompressor compressor)Set the CSS compressor implemententation use e.g.ResourceSettingssetDefaultCacheDuration(org.apache.wicket.util.time.Duration duration)Set the the default cache duration for resources.ResourceSettingssetEncodeJSessionId(boolean encodeJSessionId)Sets a flag indicating whether the jsessionid should be encoded in the url for resources implementingIStaticCacheableResourcewhen the cookies are disabled and there is an active http session.ResourceSettingssetFileCleaner(org.apache.wicket.util.file.IFileCleaner fileUploadCleaner)Sets a cleaner that can be used to remove files asynchronously.ResourceSettingssetHeaderItemComparator(java.util.Comparator<? super ResourceAggregator.RecordedHeaderItem> headerItemComparator)Sets the comparator used by the resource aggregator for sorting header items.IJavaScriptCompressorsetJavaScriptCompressor(IJavaScriptCompressor compressor)Set the javascript compressor implemententation use e.g.ResourceSettingssetLocalizer(Localizer localizer)Sets the localizer which will be used to find property values.ResourceSettingssetPackageResourceGuard(IPackageResourceGuard packageResourceGuard)Sets thepackage resource guard.ResourceSettingssetParentFolderPlaceholder(java.lang.String sequence)Placeholder string for '..' within resource urls (which will be crippled by the browser and not work anymore).ResourceSettingssetPropertiesFactory(IPropertiesFactory factory)Set the property factory which will be used to load property filesResourceSettingssetResourceFinders(java.util.List<org.apache.wicket.util.file.IResourceFinder> resourceFinders)Sets the finders to use when searching for resources.ResourceSettingssetResourcePollFrequency(org.apache.wicket.util.time.Duration resourcePollFrequency)Sets the resource polling frequency.ResourceSettingssetResourceStreamLocator(IResourceStreamLocator resourceStreamLocator)/** Sets the resource stream locator for this application Consider wrappingresourceStreamLocatorinCachingResourceStreamLocator.ResourceSettingssetResourceWatcher(org.apache.wicket.util.watch.IModificationWatcher watcher)Sets the resource watcherResourceSettingssetThrowExceptionOnMissingResource(boolean throwExceptionOnMissingResource)ResourceSettingssetUseDefaultOnMissingResource(boolean useDefaultOnMissingResource)ResourceSettingssetUseMinifiedResources(boolean useMinifiedResources)Sets whether to use pre-minified resources when available.
-
-
-
Constructor Detail
-
ResourceSettings
public ResourceSettings(Application application)
Configures Wicket's default ResourceLoaders.
For an example inFooApplicationletbar.FooextendComponent, 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 ResourceSettings addResourceFactory(java.lang.String name, IResourceFactory resourceFactory)
Adds a resource factory to the list of factories to consult when generating resources automatically- Parameters:
name- The name to give to the factoryresourceFactory- The resource factory to add- Returns:
thisobject for chaining
-
getLocalizer
public Localizer getLocalizer()
Description copied from interface:IPropertiesFactoryContextGet the application's localizer. to modify the way Wicket resolves keys to localized messages you can add custom resource loaders to the list returned bygetStringResourceLoaders().- Specified by:
getLocalizerin interfaceIPropertiesFactoryContext- Returns:
- The application wide localizer instance
-
getPackageResourceGuard
public IPackageResourceGuard getPackageResourceGuard()
Gets thepackage resource guard.- Returns:
- The package resource guard
-
getPropertiesFactory
public IPropertiesFactory getPropertiesFactory()
Get the property factory which will be used to load property files- Returns:
- PropertiesFactory
-
getResourceFactory
public IResourceFactory getResourceFactory(java.lang.String name)
- Parameters:
name- Name of the factory to get- Returns:
- The IResourceFactory with the given name.
-
getResourceFinders
public java.util.List<org.apache.wicket.util.file.IResourceFinder> getResourceFinders()
Gets the resource finders to use when searching for resources. By default, a finder that looks in the classpath root is configured.WebApplicationadds the classpath directory META-INF/resources. To configure additional search paths or filesystem paths, add to this list.- Returns:
- Returns the resourceFinders.
-
getResourcePollFrequency
public org.apache.wicket.util.time.Duration getResourcePollFrequency()
- Returns:
- Returns the resourcePollFrequency.
-
getResourceStreamLocator
public IResourceStreamLocator getResourceStreamLocator()
- Specified by:
getResourceStreamLocatorin interfaceIPropertiesFactoryContext- Returns:
- Resource locator for this application
-
getResourceWatcher
public org.apache.wicket.util.watch.IModificationWatcher getResourceWatcher(boolean start)
- Specified by:
getResourceWatcherin interfaceIPropertiesFactoryContext- 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.
-
setResourceWatcher
public ResourceSettings setResourceWatcher(org.apache.wicket.util.watch.IModificationWatcher watcher)
Sets the resource watcher- Parameters:
watcher-- Returns:
thisobject for chaining
-
getFileCleaner
public org.apache.wicket.util.file.IFileCleaner getFileCleaner()
- Returns:
- the a cleaner which can be used to remove files asynchronously.
-
setFileCleaner
public ResourceSettings setFileCleaner(org.apache.wicket.util.file.IFileCleaner fileUploadCleaner)
Sets a cleaner that can be used to remove files asynchronously.Used internally to delete the temporary files created by FileUpload functionality
- Parameters:
fileUploadCleaner- the actual cleaner implementation. Can benull- Returns:
thisobject for chaining
-
getStringResourceLoaders
public java.util.List<IStringResourceLoader> getStringResourceLoaders()
- Returns:
- mutable list of all available string resource loaders
-
getThrowExceptionOnMissingResource
public boolean getThrowExceptionOnMissingResource()
-
getUseDefaultOnMissingResource
public boolean getUseDefaultOnMissingResource()
- Returns:
- Whether to use a default value (if available) when a missing resource is requested
-
setLocalizer
public ResourceSettings setLocalizer(Localizer localizer)
Sets the localizer which will be used to find property values.- Parameters:
localizer-- Returns:
thisobject for chaining- Since:
- 1.3.0
-
setPackageResourceGuard
public ResourceSettings setPackageResourceGuard(IPackageResourceGuard packageResourceGuard)
Sets thepackage resource guard.- Parameters:
packageResourceGuard- The package resource guard- Returns:
thisobject for chaining
-
setPropertiesFactory
public ResourceSettings setPropertiesFactory(IPropertiesFactory factory)
Set the property factory which will be used to load property files- Parameters:
factory-- Returns:
thisobject for chaining
-
setResourceFinders
public ResourceSettings setResourceFinders(java.util.List<org.apache.wicket.util.file.IResourceFinder> resourceFinders)
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 bygetResourceFinders(). Use this method if you want to completely exchange the list of resource finders.- Parameters:
resourceFinders- The resourceFinders to set- Returns:
thisobject for chaining
-
setResourcePollFrequency
public ResourceSettings setResourcePollFrequency(org.apache.wicket.util.time.Duration resourcePollFrequency)
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.- Parameters:
resourcePollFrequency- Frequency at which to poll resources ornullif polling should be disabled- Returns:
thisobject for chaining
-
setResourceStreamLocator
public ResourceSettings setResourceStreamLocator(IResourceStreamLocator resourceStreamLocator)
/** Sets the resource stream locator for this application Consider wrappingresourceStreamLocatorinCachingResourceStreamLocator. This way the locator will not be asked more than once forIResourceStreams which do not exist.- Parameters:
resourceStreamLocator- new resource stream locator- Returns:
thisobject for chaining- See Also:
getResourceStreamLocator()
-
setThrowExceptionOnMissingResource
public ResourceSettings setThrowExceptionOnMissingResource(boolean throwExceptionOnMissingResource)
- Parameters:
throwExceptionOnMissingResource-- Returns:
thisobject for chaining
-
setUseDefaultOnMissingResource
public ResourceSettings setUseDefaultOnMissingResource(boolean useDefaultOnMissingResource)
- Parameters:
useDefaultOnMissingResource- Whether to use a default value (if available) when a missing resource is requested- Returns:
thisobject for chaining
-
getDefaultCacheDuration
public final org.apache.wicket.util.time.Duration getDefaultCacheDuration()
Get the the default cache duration for resources.- Returns:
- cache duration (Duration.NONE will be returned if caching is disabled)
- See Also:
Duration.NONE
-
setDefaultCacheDuration
public final ResourceSettings setDefaultCacheDuration(org.apache.wicket.util.time.Duration duration)
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.- Parameters:
duration- default cache duration in seconds- Returns:
thisobject for chaining- See Also:
Duration.NONE,WebResponse.MAX_CACHE_DURATION
-
getJavaScriptCompressor
public IJavaScriptCompressor getJavaScriptCompressor()
Get the javascript compressor to remove comments and whitespace characters from javascripts- 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)
Set the javascript compressor implemententation use e.g. byJavaScriptPackageResource. A typical implementation will remove comments and whitespace. But a no-op implementation is available as well.- Parameters:
compressor- The implementation to be used- Returns:
- The old value
-
getCssCompressor
public ICssCompressor getCssCompressor()
Get the CSS compressor to remove comments and whitespace characters from css resources- 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)
Set the CSS compressor implemententation use e.g. byCssPackageResource. A typical implementation will remove comments and whitespace. But a no-op implementation is available as well.- Parameters:
compressor- The implementation to be used- Returns:
- The old value
-
getParentFolderPlaceholder
public java.lang.String getParentFolderPlaceholder()
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 aIPackageResourceGuardimplementation such asPackageResourceGuardwhich you may use or extend based on your needs.- Returns:
- placeholder
-
setParentFolderPlaceholder
public ResourceSettings setParentFolderPlaceholder(java.lang.String sequence)
Placeholder string for '..' within resource urls (which will be crippled by the browser and not work anymore). Note that by default the placeholder string isnulland 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 aIPackageResourceGuardimplementation such asPackageResourceGuardwhich you may use or extend based on your needs.- Parameters:
sequence- character sequence which must not be ambiguous within urls- Returns:
thisobject for chaining- See Also:
getParentFolderPlaceholder()
-
getCachingStrategy
public IResourceCachingStrategy getCachingStrategy()
gets the resource caching strategy- Returns:
- strategy
-
setCachingStrategy
public ResourceSettings setCachingStrategy(IResourceCachingStrategy strategy)
sets the resource caching strategy- Parameters:
strategy- instance of resource caching strategy- Returns:
thisobject for chaining- See Also:
IResourceCachingStrategy
-
setUseMinifiedResources
public ResourceSettings setUseMinifiedResources(boolean useMinifiedResources)
Sets whether to use pre-minified resources when available. Minified resources are detected by name. The minified version ofx.jsis expected to be calledx.min.js. For css files, the same convention is used:x.min.cssis the minified version ofx.css. When this is null, minified resources will only be used in deployment configuration.- Parameters:
useMinifiedResources- The new value for the setting- Returns:
thisobject for chaining
-
getUseMinifiedResources
public boolean getUseMinifiedResources()
- Returns:
- Whether pre-minified resources will be used.
-
getHeaderItemComparator
public java.util.Comparator<? super ResourceAggregator.RecordedHeaderItem> getHeaderItemComparator()
- Returns:
- The comparator used to sort header items.
-
setHeaderItemComparator
public ResourceSettings setHeaderItemComparator(java.util.Comparator<? super ResourceAggregator.RecordedHeaderItem> headerItemComparator)
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 thePriorityFirstComparator.- Parameters:
headerItemComparator- The comparator used to sort header items, when null, header items will not be sorted.- Returns:
thisobject for chaining
-
isEncodeJSessionId
public boolean isEncodeJSessionId()
A flag indicating whether static resources should have jsessionid encoded in their url.- Returns:
trueif the jsessionid should be encoded in the url for resources implementingIStaticCacheableResourcewhen the cookies are disabled and there is an active http session.
-
setEncodeJSessionId
public ResourceSettings setEncodeJSessionId(boolean encodeJSessionId)
Sets a flag indicating whether the jsessionid should be encoded in the url for resources implementingIStaticCacheableResourcewhen the cookies are disabled and there is an active http session.- Parameters:
encodeJSessionId-truewhen the jsessionid should be encoded,false- otherwise- Returns:
thisobject for chaining
-
-