org.apache.wicket.request.resource
Class AbstractResource.ResourceResponse

java.lang.Object
  extended by org.apache.wicket.request.resource.AbstractResource.ResourceResponse
Enclosing class:
AbstractResource

public static class AbstractResource.ResourceResponse
extends java.lang.Object

Represents data used to configure response and write resource data.

Author:
Matej Knopp

Constructor Summary
AbstractResource.ResourceResponse()
          Construct.
 
Method Summary
 boolean dataNeedsToBeWritten(IResource.Attributes attributes)
          Check to determine if the resource data needs to be written.
 void disableCaching()
          disable caching
 Duration getCacheDuration()
          returns how long this resource may be cached

The special value Duration.NONE means caching is disabled.

 WebResponse.CacheScope 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.

 ContentDisposition getContentDisposition()
           
 long getContentLength()
           
 java.lang.String getContentType()
           
 java.lang.Integer getErrorCode()
           
 java.lang.String getErrorMessage()
           
 java.lang.String getFileName()
           
 HttpHeaderCollection getHeaders()
          get custom headers
 Time getLastModified()
           
protected  java.lang.String getTextEncoding()
           
 AbstractResource.WriteCallback getWriteCallback()
           
 void setCacheDuration(Duration duration)
          Controls how long this response may be cached
 void setCacheDurationToMaximum()
          set caching to maximum available duration
 void setCacheScope(WebResponse.CacheScope scope)
          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.

 void setContentDisposition(ContentDisposition contentDisposition)
          Determines whether the resource will be inline or an attachment.
 void setContentLength(long contentLength)
          Sets the content length (in bytes) of the data.
 void setContentType(java.lang.String contentType)
          Sets the content type for the resource.
 void setError(java.lang.Integer errorCode)
          Sets the error code for resource.
 void setError(java.lang.Integer errorCode, java.lang.String errorMessage)
          Sets the error code and message for resource.
 void setFileName(java.lang.String fileName)
          Sets the file name of the resource.
 void setLastModified(Time lastModified)
          Sets the last modified data of the resource.
 void setTextEncoding(java.lang.String textEncoding)
          Sets the text encoding for the resource.
 void setWriteCallback(AbstractResource.WriteCallback writeCallback)
          Sets the AbstractResource.WriteCallback.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractResource.ResourceResponse

public AbstractResource.ResourceResponse()
Construct.

Method Detail

setError

public void setError(java.lang.Integer errorCode)
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

setError

public void setError(java.lang.Integer errorCode,
                     java.lang.String errorMessage)
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 code
errorMessage - error message

getErrorCode

public java.lang.Integer getErrorCode()
Returns:
error code or null

getErrorMessage

public java.lang.String getErrorMessage()
Returns:
error message or null

setFileName

public void setFileName(java.lang.String fileName)
Sets the file name of the resource.

Parameters:
fileName - file name

getFileName

public java.lang.String getFileName()
Returns:
resource file name

setContentDisposition

public void setContentDisposition(ContentDisposition contentDisposition)
Determines whether the resource will be inline or an attachment.

Parameters:
contentDisposition - content disposition (attachment or inline)
See Also:
ContentDisposition

getContentDisposition

public ContentDisposition getContentDisposition()
Returns:
whether the resource is inline or attachment

setContentType

public void setContentType(java.lang.String contentType)
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)

getContentType

public java.lang.String getContentType()
Returns:
resource content type

setTextEncoding

public void setTextEncoding(java.lang.String textEncoding)
Sets the text encoding for the resource. The encoding is only used if the content type indicates a textual resource.

Parameters:
textEncoding - character encoding of text body

getTextEncoding

protected java.lang.String getTextEncoding()
Returns:
text encoding for resource

setContentLength

public void setContentLength(long contentLength)
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

getContentLength

public long getContentLength()
Returns:
content length (in bytes)

setLastModified

public void setLastModified(Time lastModified)
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 the If-Modified-Since to determine if the actuall data really needs to be sent to client.

Parameters:
lastModified - last modification timestamp

getLastModified

public Time getLastModified()
Returns:
last modification timestamp

dataNeedsToBeWritten

public boolean dataNeedsToBeWritten(IResource.Attributes attributes)
Check to determine if the resource data needs to be written. This method checks the If-Modified-Since request header and compares it to lastModified property. In order for this method to work setLastModified(Time) has to be called first.

Parameters:
attributes - request attributes
Returns:
true if the resource data does need to be written, false otherwise.

disableCaching

public void disableCaching()
disable caching


setCacheDurationToMaximum

public void setCacheDurationToMaximum()
set caching to maximum available duration


setCacheDuration

public void setCacheDuration(Duration duration)
Controls how long this response may be cached

Parameters:
duration - caching duration in seconds

getCacheDuration

public Duration getCacheDuration()
returns how long this resource may be cached

The special value Duration.NONE means caching is disabled.

Returns:
duration for caching
See Also:
IResourceSettings.setDefaultCacheDuration(org.apache.wicket.util.time.Duration), IResourceSettings.getDefaultCacheDuration()

getCacheScope

public WebResponse.CacheScope 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:
getCacheDuration(), setCacheDuration(org.apache.wicket.util.time.Duration), WebResponse.CacheScope

setCacheScope

public void setCacheScope(WebResponse.CacheScope scope)
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
See Also:
getCacheDuration(), setCacheDuration(org.apache.wicket.util.time.Duration), WebResponse.CacheScope

setWriteCallback

public void setWriteCallback(AbstractResource.WriteCallback writeCallback)
Sets the AbstractResource.WriteCallback. The callback is responsible for generating the response data.

It is necessary to set the AbstractResource.WriteCallback if dataNeedsToBeWritten(org.apache.wicket.request.resource.IResource.Attributes) returns true and setError(Integer) has not been called.

Parameters:
writeCallback - write callback

getWriteCallback

public AbstractResource.WriteCallback getWriteCallback()
Returns:
write callback.

getHeaders

public HttpHeaderCollection getHeaders()
get custom headers

Returns:
collection of the response headers


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