public class ResourceSettings extends Object implements IPropertiesFactoryContext
resourcePollFrequency (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
,
DefaultButtonImageResourceFactory
and
especially LocalizedImageResource
.
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)
and
Component.getString(String key, org.apache.wicket.model.IModel model)
.
stringResourceLoaders - A chain of IStringResourceLoader
instances 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.
Constructor and Description |
---|
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)
|
Modifier and Type | Method and Description |
---|---|
ResourceSettings |
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.
|
ResourceSettings |
setCachingStrategy(IResourceCachingStrategy strategy)
sets the resource caching strategy
|
ICssCompressor |
setCssCompressor(ICssCompressor compressor)
Set the CSS compressor implemententation use e.g.
|
ResourceSettings |
setDefaultCacheDuration(Duration duration)
Set the the default cache duration for resources.
|
ResourceSettings |
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. |
ResourceSettings |
setFileCleaner(IFileCleaner fileUploadCleaner)
Sets a cleaner that can be used to remove files asynchronously.
|
ResourceSettings |
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.
|
ResourceSettings |
setLocalizer(Localizer localizer)
Sets the localizer which will be used to find property values.
|
ResourceSettings |
setPackageResourceGuard(IPackageResourceGuard packageResourceGuard)
Sets the
package resource guard . |
ResourceSettings |
setParentFolderPlaceholder(String sequence)
Placeholder string for '..' within resource urls (which will be crippled by the browser and
not work anymore).
|
ResourceSettings |
setPropertiesFactory(IPropertiesFactory factory)
Set the property factory which will be used to load property files
|
ResourceSettings |
setResourceFinders(List<IResourceFinder> resourceFinders)
Sets the finders to use when searching for resources.
|
ResourceSettings |
setResourcePollFrequency(Duration resourcePollFrequency)
Sets the resource polling frequency.
|
ResourceSettings |
setResourceStreamLocator(IResourceStreamLocator resourceStreamLocator)
/**
Sets the resource stream locator for this application
Consider wrapping
resourceStreamLocator in CachingResourceStreamLocator . |
ResourceSettings |
setResourceWatcher(IModificationWatcher watcher)
Sets the resource watcher
|
ResourceSettings |
setThrowExceptionOnMissingResource(boolean throwExceptionOnMissingResource) |
ResourceSettings |
setUseDefaultOnMissingResource(boolean useDefaultOnMissingResource) |
ResourceSettings |
setUseMinifiedResources(boolean useMinifiedResources)
Sets whether to use pre-minified resources when available.
|
public ResourceSettings(Application application)
FooApplication
let bar.Foo
extend Component
, this
results in the following ordering:
application
- public ResourceSettings addResourceFactory(String name, IResourceFactory resourceFactory)
name
- The name to give to the factoryresourceFactory
- The resource factory to addthis
object for chainingpublic Localizer getLocalizer()
IPropertiesFactoryContext
getStringResourceLoaders()
.getLocalizer
in interface IPropertiesFactoryContext
public IPackageResourceGuard getPackageResourceGuard()
package resource guard
.public IPropertiesFactory getPropertiesFactory()
public IResourceFactory getResourceFactory(String name)
name
- Name of the factory to getpublic List<IResourceFinder> getResourceFinders()
WebApplication
adds the classpath
directory META-INF/resources. To configure additional search paths or filesystem paths, add
to this list.public Duration getResourcePollFrequency()
public IResourceStreamLocator getResourceStreamLocator()
getResourceStreamLocator
in interface IPropertiesFactoryContext
public IModificationWatcher getResourceWatcher(boolean start)
getResourceWatcher
in interface IPropertiesFactoryContext
start
- boolean if the resource watcher should be started if not already started.public ResourceSettings setResourceWatcher(IModificationWatcher watcher)
watcher
- this
object for chainingpublic IFileCleaner getFileCleaner()
public ResourceSettings setFileCleaner(IFileCleaner fileUploadCleaner)
Used internally to delete the temporary files created by FileUpload functionality
fileUploadCleaner
- the actual cleaner implementation. Can be null
this
object for chainingpublic List<IStringResourceLoader> getStringResourceLoaders()
public boolean getThrowExceptionOnMissingResource()
public boolean getUseDefaultOnMissingResource()
public ResourceSettings setLocalizer(Localizer localizer)
localizer
- this
object for chainingpublic ResourceSettings setPackageResourceGuard(IPackageResourceGuard packageResourceGuard)
package resource guard
.packageResourceGuard
- The package resource guardthis
object for chainingpublic ResourceSettings setPropertiesFactory(IPropertiesFactory factory)
factory
- this
object for chainingpublic ResourceSettings setResourceFinders(List<IResourceFinder> resourceFinders)
getResourceFinders()
. Use this method if you want to completely exchange the list of
resource finders.resourceFinders
- The resourceFinders to setthis
object for chainingpublic ResourceSettings setResourcePollFrequency(Duration resourcePollFrequency)
resourcePollFrequency
- Frequency at which to poll resources or null
if polling should be
disabledthis
object for chainingpublic ResourceSettings setResourceStreamLocator(IResourceStreamLocator resourceStreamLocator)
resourceStreamLocator
in CachingResourceStreamLocator
.
This way the locator will not be asked more than once for IResourceStream
s which do
not exist.resourceStreamLocator
- new resource stream locatorthis
object for chaininggetResourceStreamLocator()
public ResourceSettings setThrowExceptionOnMissingResource(boolean throwExceptionOnMissingResource)
throwExceptionOnMissingResource
- this
object for chainingpublic ResourceSettings setUseDefaultOnMissingResource(boolean useDefaultOnMissingResource)
useDefaultOnMissingResource
- Whether to use a default value (if available) when a missing resource is requestedthis
object for chainingpublic final Duration getDefaultCacheDuration()
Duration.NONE
public final ResourceSettings setDefaultCacheDuration(Duration duration)
duration
- default cache duration in secondsthis
object for chainingDuration.NONE
,
WebResponse.MAX_CACHE_DURATION
public IJavaScriptCompressor getJavaScriptCompressor()
JavaScriptPackageResource
. Null is a valid value.public IJavaScriptCompressor setJavaScriptCompressor(IJavaScriptCompressor compressor)
JavaScriptPackageResource
. A typical implementation will remove comments and whitespace. But
a no-op implementation is available as well.compressor
- The implementation to be usedpublic ICssCompressor getCssCompressor()
CssPackageResource
. Null is a valid value.public ICssCompressor setCssCompressor(ICssCompressor compressor)
CssPackageResource
. A typical
implementation will remove comments and whitespace. But a no-op implementation is available
as well.compressor
- The implementation to be usedpublic String getParentFolderPlaceholder()
::
. Resources
are protected by a IPackageResourceGuard
implementation such as
PackageResourceGuard
which you may use or extend based
on your needs.public ResourceSettings setParentFolderPlaceholder(String sequence)
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.sequence
- character sequence which must not be ambiguous within urlsthis
object for chaininggetParentFolderPlaceholder()
public IResourceCachingStrategy getCachingStrategy()
public ResourceSettings setCachingStrategy(IResourceCachingStrategy strategy)
strategy
- instance of resource caching strategythis
object for chainingIResourceCachingStrategy
public ResourceSettings setUseMinifiedResources(boolean useMinifiedResources)
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.useMinifiedResources
- The new value for the settingthis
object for chainingpublic boolean getUseMinifiedResources()
public Comparator<? super ResourceAggregator.RecordedHeaderItem> getHeaderItemComparator()
public ResourceSettings setHeaderItemComparator(Comparator<? super ResourceAggregator.RecordedHeaderItem> headerItemComparator)
PriorityFirstComparator
.headerItemComparator
- The comparator used to sort header items, when null, header items will not be
sorted.this
object for chainingpublic boolean isEncodeJSessionId()
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.public ResourceSettings setEncodeJSessionId(boolean encodeJSessionId)
IStaticCacheableResource
when
the cookies are disabled and there is an active http session.encodeJSessionId
- true
when the jsessionid should be encoded, false
- otherwisethis
object for chainingCopyright © 2006–2022 Apache Software Foundation. All rights reserved.