Module org.apache.wicket.core
Class AbstractResource.ResourceResponse
java.lang.Object
org.apache.wicket.request.resource.AbstractResource.ResourceResponse
- Enclosing class:
- AbstractResource
Represents data used to configure response and write resource data.
- Author:
- Matej Knopp
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
dataNeedsToBeWritten
(IResource.Attributes attributes) Check to determine if the resource data needs to be written.Disables caching.If the resource accepts rangesReturns how long this resource may be cached for.returns what kind of caches are allowed to cache the resource responselong
Gets the content range of the resource.get custom headersprotected String
void
setAcceptRange
(AbstractResource.ContentRangeType contentRangeType) Sets the accept range header (e.g.setCacheDuration
(Duration duration) Controls how long this response may be cached.Sets caching to maximum available duration.controls what kind of caches are allowed to cache the responsesetContentDisposition
(ContentDisposition contentDisposition) Determines whether the resource will be inline or an attachment.setContentLength
(long contentLength) Sets the content length (in bytes) of the data.void
setContentRange
(String contentRange) Sets the content range of the resource.setContentType
(String contentType) Sets the content type for the resource.Sets the error code for resource.Sets the error code and message for resource.setFileName
(String fileName) Sets the file name of the resource.setLastModified
(Instant lastModified) Sets the last modified data of the resource.setStatusCode
(Integer statusCode) Sets the status code for resource.setTextEncoding
(String textEncoding) Sets the text encoding for the resource.setWriteCallback
(AbstractResource.WriteCallback writeCallback) Sets theAbstractResource.WriteCallback
.
-
Constructor Details
-
ResourceResponse
public ResourceResponse()Construct.
-
-
Method Details
-
setError
Sets the error code for resource. If there is an error code set the data will not be rendered and the code will be sent to client.- Parameters:
errorCode
- error code- Returns:
this
, for chaining.
-
setError
Sets the error code and message for resource. If there is an error code set the data will not be rendered and the code and message will be sent to client.- Parameters:
errorCode
- error codeerrorMessage
- error message- Returns:
this
, for chaining.
-
getErrorCode
- Returns:
- error code or
null
-
setStatusCode
Sets the status code for resource.- Parameters:
statusCode
- status code- Returns:
this
, for chaining.
-
getStatusCode
- Returns:
- status code or
null
-
getErrorMessage
- Returns:
- error message or
null
-
setFileName
Sets the file name of the resource.- Parameters:
fileName
- file name- Returns:
this
, for chaining.
-
getFileName
- Returns:
- resource file name
-
setContentDisposition
public AbstractResource.ResourceResponse setContentDisposition(ContentDisposition contentDisposition) Determines whether the resource will be inline or an attachment.- Parameters:
contentDisposition
- content disposition (attachment or inline)- Returns:
this
, for chaining.- See Also:
-
getContentDisposition
- Returns:
- whether the resource is inline or attachment
-
setContentType
Sets the content type for the resource. If no content type is set it will be determined by the extension.- Parameters:
contentType
- content type (also known as mime type)- Returns:
this
, for chaining.
-
getContentType
- Returns:
- resource content type
-
getContentRange
Gets the content range of the resource. If no content range is set the client assumes the whole content.- Returns:
- the content range
-
setContentRange
Sets the content range of the resource. If no content range is set the client assumes the whole content. Please note that if the content range is set, the content length, the status code and the accept range must be set right, too.- Parameters:
contentRange
- the content range
-
getAcceptRange
If the resource accepts ranges- Returns:
- the type of range (e.g. bytes)
-
setAcceptRange
Sets the accept range header (e.g. bytes)- Parameters:
contentRangeType
- the content range header information
-
setTextEncoding
Sets the text encoding for the resource. This setting must only used if the resource response represents text.- Parameters:
textEncoding
- character encoding of text body- Returns:
this
, for chaining.
-
getTextEncoding
- Returns:
- text encoding for resource
-
setContentLength
Sets the content length (in bytes) of the data. Content length is optional but it's recommended to set it so that the browser can show download progress.- Parameters:
contentLength
- length of response body- Returns:
this
, for chaining.
-
getContentLength
- Returns:
- content length (in bytes)
-
setLastModified
Sets the last modified data of the resource. Even though this method is optional it is recommended to set the date. If the date is set properly Wicket can check theIf-Modified-Since
to determine if the actual data really needs to be sent to client.- Parameters:
lastModified
- last modification timestamp- Returns:
this
, for chaining.
-
getLastModified
- Returns:
- last modification timestamp
-
dataNeedsToBeWritten
Check to determine if the resource data needs to be written. This method checks theIf-Modified-Since
request header and compares it to lastModified property. In order for this method to worksetLastModified(Instant)
has to be called first.- Parameters:
attributes
- request attributes- Returns:
true
if the resource data does need to be written,false
otherwise.
-
disableCaching
Disables caching.- Returns:
this
, for chaining.
-
setCacheDurationToMaximum
Sets caching to maximum available duration.- Returns:
this
, for chaining.
-
setCacheDuration
Controls how long this response may be cached.- Parameters:
duration
- caching duration in seconds- Returns:
this
, for chaining.
-
getCacheDuration
Returns how long this resource may be cached for. The special value Duration.NONE means caching is disabled.- Returns:
- duration for caching
- See Also:
-
getCacheScope
returns what kind of caches are allowed to cache the resource response resources are only cached at all if caching is enabled by setting a cache duration.- Returns:
- cache scope
- See Also:
-
setCacheScope
controls what kind of caches are allowed to cache the response resources are only cached at all if caching is enabled by setting a cache duration.- Parameters:
scope
- scope for caching- Returns:
this
, for chaining.- See Also:
-
setWriteCallback
public AbstractResource.ResourceResponse setWriteCallback(AbstractResource.WriteCallback writeCallback) Sets theAbstractResource.WriteCallback
. The callback is responsible for generating the response data.It is necessary to set the
AbstractResource.WriteCallback
ifdataNeedsToBeWritten(org.apache.wicket.request.resource.IResource.Attributes)
returnstrue
andsetError(Integer)
has not been called.- Parameters:
writeCallback
- write callback- Returns:
this
, for chaining.
-
getWriteCallback
- Returns:
- write callback.
-
getHeaders
get custom headers- Returns:
- collection of the response headers
-