org.loom.resolution
Class AbstractFileResolution

java.lang.Object
  extended by org.loom.resolution.AbstractHttpResolution
      extended by org.loom.resolution.AbstractFileResolution
All Implemented Interfaces:
CacheableResolution, HttpResolution, Resolution
Direct Known Subclasses:
InputStreamResolution, PersistentFileResolution, ZipFileResolution

public abstract class AbstractFileResolution
extends AbstractHttpResolution

Delivers a binary file to the browser


Constructor Summary
AbstractFileResolution()
           
 
Method Summary
 AbstractFileResolution addCookie(javax.servlet.http.Cookie cookie)
          Adds a cookie
 AbstractFileResolution addCookie(java.lang.String name, java.lang.String value)
          Adds a cookie that will not be stored on disk (will be deleted when the browser is closed).
 AbstractFileResolution addCookie(java.lang.String name, java.lang.String value, int maxAge)
          Adds a cookie
 AbstractFileResolution addHeader(java.lang.String name, java.lang.Object value)
          Add a http header.
 java.lang.String calculateContentDispositionHeader(java.lang.String filename)
           
 java.lang.String getFilename()
           
 java.lang.Long getFileSize()
           
 boolean isForceSave()
           
 boolean isGuessMimeType()
           
abstract  void resolve(LoomServletRequest request, LoomServletResponse response)
          Write the response contents
 AbstractFileResolution setCacheControl(CacheControl cacheControl)
          Sets the cache data to be sent to the browser
 AbstractFileResolution setCharset(java.lang.String charset)
          Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.
 AbstractFileResolution setContentType(java.lang.String contentType)
          Sets the content type of the response being sent to the client, if the response has not been committed yet.
 AbstractFileResolution setFilename(java.lang.String filename)
           
 AbstractFileResolution setFileSize(java.lang.Long fileSize)
           
 AbstractFileResolution setForceSave(boolean forceSave)
           
 AbstractFileResolution setGuessMimeType(boolean guessMimeType)
           
 AbstractFileResolution setHeader(java.lang.String name, java.lang.Object value)
          Set a String http header.
 AbstractFileResolution setHeaderIfNotPresent(java.lang.String name, java.lang.Object value)
          Set a String http header if it has not been set.
protected  void writeHeaders(LoomServletRequest request, LoomServletResponse response)
          Calculate default content size, content type, etc headers that will be applied if the user did not provide one previously.
 
Methods inherited from class org.loom.resolution.AbstractHttpResolution
addDateHeader, addIntHeader, containsHeader, getCacheControl, getCharset, getContentType, setDateHeader, setDateHeaderIfNotPresent, setIntHeader, setIntHeaderIfNotPresent, setJsonHeader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractFileResolution

public AbstractFileResolution()
Method Detail

resolve

public abstract void resolve(LoomServletRequest request,
                             LoomServletResponse response)
                      throws java.io.IOException,
                             javax.servlet.ServletException
Description copied from interface: Resolution
Write the response contents

Specified by:
resolve in interface Resolution
Specified by:
resolve in class AbstractHttpResolution
Parameters:
request - the current request object
response - the current response object
Throws:
java.io.IOException
javax.servlet.ServletException

writeHeaders

protected void writeHeaders(LoomServletRequest request,
                            LoomServletResponse response)
Calculate default content size, content type, etc headers that will be applied if the user did not provide one previously.

Overrides:
writeHeaders in class AbstractHttpResolution

calculateContentDispositionHeader

public java.lang.String calculateContentDispositionHeader(java.lang.String filename)

setForceSave

public AbstractFileResolution setForceSave(boolean forceSave)

isGuessMimeType

public boolean isGuessMimeType()

setGuessMimeType

public AbstractFileResolution setGuessMimeType(boolean guessMimeType)

isForceSave

public boolean isForceSave()

getFilename

public java.lang.String getFilename()

setFilename

public AbstractFileResolution setFilename(java.lang.String filename)

getFileSize

public java.lang.Long getFileSize()

setFileSize

public AbstractFileResolution setFileSize(java.lang.Long fileSize)

addCookie

public AbstractFileResolution addCookie(java.lang.String name,
                                        java.lang.String value)
Description copied from interface: HttpResolution
Adds a cookie that will not be stored on disk (will be deleted when the browser is closed).

Specified by:
addCookie in interface HttpResolution
Overrides:
addCookie in class AbstractHttpResolution
Parameters:
name - the name of the cookie
value - the value of the Cookie

addCookie

public AbstractFileResolution addCookie(java.lang.String name,
                                        java.lang.String value,
                                        int maxAge)
Description copied from interface: HttpResolution
Adds a cookie

Specified by:
addCookie in interface HttpResolution
Overrides:
addCookie in class AbstractHttpResolution
Parameters:
name - the name of the cookie
value - the value of the Cookie
maxAge - can be positive (number of seconds that it will be stored in the browser), zero (to delete the cookie from the browser) or a negative value (to indicate that the cookie should not be stored in disk and will be forgotten when the browser exists).

addCookie

public AbstractFileResolution addCookie(javax.servlet.http.Cookie cookie)
Description copied from interface: HttpResolution
Adds a cookie

Specified by:
addCookie in interface HttpResolution
Overrides:
addCookie in class AbstractHttpResolution
Parameters:
cookie - the cookie to be added to the response

addHeader

public AbstractFileResolution addHeader(java.lang.String name,
                                        java.lang.Object value)
Description copied from interface: HttpResolution
Add a http header. If the header already exists a new value will be added.

Specified by:
addHeader in interface HttpResolution
Overrides:
addHeader in class AbstractHttpResolution
Parameters:
name - the name of the http header
value - the value of the http header. Date, int and String are supported. Anything else will be cast to toString(). Null will be ignored.

setHeader

public AbstractFileResolution setHeader(java.lang.String name,
                                        java.lang.Object value)
Description copied from interface: HttpResolution
Set a String http header. If the header already exists it will be replaced.

Specified by:
setHeader in interface HttpResolution
Overrides:
setHeader in class AbstractHttpResolution
Parameters:
name - the name of the http header
value - the value of the http header

setHeaderIfNotPresent

public AbstractFileResolution setHeaderIfNotPresent(java.lang.String name,
                                                    java.lang.Object value)
Description copied from interface: HttpResolution
Set a String http header if it has not been set.

Specified by:
setHeaderIfNotPresent in interface HttpResolution
Overrides:
setHeaderIfNotPresent in class AbstractHttpResolution
Parameters:
name - the name of the http header
value - the value of the http header

setCharset

public AbstractFileResolution setCharset(java.lang.String charset)
Description copied from interface: HttpResolution
Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.

Specified by:
setCharset in interface HttpResolution
Overrides:
setCharset in class AbstractHttpResolution

setContentType

public AbstractFileResolution setContentType(java.lang.String contentType)
Description copied from interface: HttpResolution
Sets the content type of the response being sent to the client, if the response has not been committed yet. The given content type may include a character encoding specification, for example, text/html;charset=UTF-8. Notice that #setCharset(String) can also be used for this.

Specified by:
setContentType in interface HttpResolution
Overrides:
setContentType in class AbstractHttpResolution

setCacheControl

public AbstractFileResolution setCacheControl(CacheControl cacheControl)
Description copied from interface: CacheableResolution
Sets the cache data to be sent to the browser

Specified by:
setCacheControl in interface CacheableResolution
Specified by:
setCacheControl in interface HttpResolution
Overrides:
setCacheControl in class AbstractHttpResolution
Parameters:
cacheControl - the cache data.
Returns:
this same instance, to allow easy chaining of invocations