Package helma.framework
Class ResponseTrans
java.lang.Object
java.io.Writer
helma.framework.ResponseTrans
- All Implemented Interfaces:
Closeable
,Flushable
,Serializable
,Appendable
,AutoCloseable
A Transmitter for a response to the servlet client. Objects of this
class are directly exposed to JavaScript as global property res.
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionResponseTrans
(Application app, RequestTrans req) Creates a new ResponseTrans object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDateHeader
(String name, Date value) Proxy to HttpServletResponse.addDateHeader()void
Proxy to HttpServletResponse.addHeader()void
Cache a skin for the length of this response.void
close()
This has to be called after writing to this response has finished and before it is shipped back to the web server.void
This has to be called after writing to this response has finished and before it is shipped back to the web server.int
Get the number of cookies set in this response.void
Insert string somewhere in the response buffer.void
Add a dependency to this response.void
Digest all dependencies to a checksum to see if the response has changed.void
Replace special characters with entities, including<
,>
and"
, thus allowing no HTML tags.void
encodeForm
(Object what) Encode HTML entities, but leave newlines alone.void
Replace special characters with entities, including<
,>
and"
, thus allowing no HTML tags.void
flush()
void
Replace special characters with entities but pass through HTML tagsvoid
Get a value from the responses map by key.Return the skin currently being rendered, or none.Get the response buffer, creating it if it doesn't existgetCachedSkin
(Object id) Look up a cached skin.Get the charset/encoding for this responsebyte[]
Get the body content for this response as byte array, encoded using the response's charset.int
Get the number of bytes of the response body.Get the response's MIME content typeGet the cookies set in this response.Get debug messages to append to the response, if any.getError()
Get the error message to display to the user, if any.getETag()
Get the ETag header value for this response.long
Get the value of the Last-Modified header for this response.Get the macro handlers map for this response transmitter.Get the message to display to the user, if any.Get the meta info map for this response transmitter.boolean
Check if this response should generate a Not-Modified response.getRealm()
Get the HTTP authentication realmGet the data map for this response transmitter.javax.servlet.http.HttpServletResponse
Returns the ServletResponse instance for this ResponseTrans.Object[]
Get the path in which to look for skins.int
Get the HTTP response status codeboolean
Returns true if this response may be cached by the clientReturns the content of the current string buffer and switches back to the previos one.pushBuffer
(StringBuffer buf) This is called before a skin is rendered as string (renderSkinAsString) to redirect the output to a new string buffer.void
void
reportError
(String errorMessage) Write a vanilla error report.void
reportError
(Throwable throwable) Write a vanilla error report.void
reset()
Reset the response object to its initial empty state.void
Reset the current response buffer.void
Reset all previously set cookies.void
setCacheable
(boolean cache) Set the cacheability of this responsevoid
setCharset
(String charset) Set the charset/encoding for this responsevoid
setContentType
(String contentType) Set the response's MIME content typevoid
setCookie
(String key, String value, int days, String path, String domain, boolean isHttpOnly, boolean isSecure) Set a cookie.void
setDateHeader
(String name, Date value) Proxy to HttpServletResponse.setDateHeader()void
setDebugBuffer
(StringBuffer debugBuffer) Set debug messages to append to the response.void
Set a message to display to the user.void
Set the ETag header value for this response.void
Proxy to HttpServletResponse.setHeader()void
setLastModified
(long modified) Set the Last-Modified header for this responsevoid
setMessage
(String message) Set a message to display to the user.void
Set the HTTP authentication realmvoid
setSkinpath
(Object[] arr) Set the path in which to look for skins.void
setStatus
(int status) Set the HTTP response status codeswitchActiveSkin
(Skin skin) Set the skin currently being rendered, returning the previously active skin.void
If we just attached to evaluation we call this instead of close because only the primary thread is responsible for closing the resultvoid
write
(char[] chars) Appends a char array to the response buffer.void
write
(char[] chars, int offset, int length) Appends a part from a char array to the response buffer.void
write
(int c) Appends a signle character to the response buffer.void
Appends a objct to the response unchanged.void
Append a string to the response unchanged.void
Appends a part from a string to the response buffer.void
writeBinary
(byte[] bytes) Allow to directly set the byte array for the response.void
writeln()
Writes a platform dependent newline sequence to response buffer.void
Write object to response buffer and append a platform dependent newline sequence.void
void
writeXmlRpcResponse
(Object result) Methods inherited from class java.io.Writer
append, append, append, nullWriter
-
Constructor Details
-
ResponseTrans
Creates a new ResponseTrans object.- Parameters:
req
- the RequestTrans for this response
-
-
Method Details
-
get
Get a value from the responses map by key. -
getResponseData
Get the data map for this response transmitter. -
getMacroHandlers
Get the macro handlers map for this response transmitter. -
getMetaData
Get the meta info map for this response transmitter. -
getServletResponse
public javax.servlet.http.HttpServletResponse getServletResponse()Returns the ServletResponse instance for this ResponseTrans. Returns null for internal and XML-RPC requests. -
resetBuffer
public void resetBuffer()Reset the current response buffer. -
reset
public void reset()Reset the response object to its initial empty state. -
pushBuffer
This is called before a skin is rendered as string (renderSkinAsString) to redirect the output to a new string buffer.- Parameters:
buf
- the StringBuffer to use, or null- Returns:
- the new StringBuffer instance
-
popString
Returns the content of the current string buffer and switches back to the previos one. -
popBuffer
-
getBuffer
Get the response buffer, creating it if it doesn't exist -
write
Append a string to the response unchanged. -
write
Appends a objct to the response unchanged. The object is first converted to a string. -
write
public void write(char[] chars, int offset, int length) Appends a part from a char array to the response buffer. -
write
public void write(char[] chars) Appends a char array to the response buffer. -
write
public void write(int c) Appends a signle character to the response buffer. -
write
Appends a part from a string to the response buffer. -
writeln
Write object to response buffer and append a platform dependent newline sequence. -
writeln
public void writeln()Writes a platform dependent newline sequence to response buffer. -
debug
Insert string somewhere in the response buffer. Caller has to make sure that buffer exists and its length is larger than offset. str may be null, in which case nothing happens. -
encode
Replace special characters with entities, including<
,>
and"
, thus allowing no HTML tags. -
format
Replace special characters with entities but pass through HTML tags -
encodeXml
Replace special characters with entities, including<
,>
and"
, thus allowing no HTML tags. -
encodeForm
Encode HTML entities, but leave newlines alone. This is for the content of textarea forms. -
redirect
- Parameters:
url
- ...- Throws:
RedirectException
- ...
-
getRedirect
- Returns:
- ...
-
forward
- Parameters:
url
- ...- Throws:
RedirectException
- ...
-
getForward
- Returns:
- ...
-
writeBinary
public void writeBinary(byte[] bytes) Allow to directly set the byte array for the response. Calling this more than once will overwrite the previous output.- Parameters:
bytes
- an arbitrary byte array
-
addHeader
Proxy to HttpServletResponse.addHeader()- Parameters:
name
- the header namevalue
- the header value
-
addDateHeader
Proxy to HttpServletResponse.addDateHeader()- Parameters:
name
- the header namevalue
- the header value
-
setHeader
Proxy to HttpServletResponse.setHeader()- Parameters:
name
- the header namevalue
- the header value
-
setDateHeader
Proxy to HttpServletResponse.setDateHeader()- Parameters:
name
- the header namevalue
- the header value
-
reportError
Write a vanilla error report. Callers should make sure the ResponeTrans is new or has been reset.- Parameters:
throwable
- the error
-
reportError
Write a vanilla error report. Callers should make sure the ResponeTrans is new or has been reset.- Parameters:
errorMessage
- the error message
-
writeXmlRpcResponse
-
writeXmlRpcError
-
flush
public void flush() -
close
This has to be called after writing to this response has finished and before it is shipped back to the web server. Transforms the string buffer into a byte array for transmission.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classWriter
- Throws:
UnsupportedEncodingException
-
close
This has to be called after writing to this response has finished and before it is shipped back to the web server. Transforms the string buffer into a byte array for transmission.- Parameters:
defaultCharset
- the charset to use if no explicit charset has been set on the response- Throws:
UnsupportedEncodingException
- if the charset is not a valid encoding name
-
waitForClose
public void waitForClose()If we just attached to evaluation we call this instead of close because only the primary thread is responsible for closing the result -
getContent
public byte[] getContent()Get the body content for this response as byte array, encoded using the response's charset.- Returns:
- the response body
-
getContentLength
public int getContentLength()Get the number of bytes of the response body.- Returns:
- the length of the response body
-
getContentType
Get the response's MIME content type- Returns:
- the MIME type for this response
-
setContentType
Set the response's MIME content type- Parameters:
contentType
- MIME type for this response
-
setLastModified
public void setLastModified(long modified) Set the Last-Modified header for this response- Parameters:
modified
- the Last-Modified header in milliseconds
-
getLastModified
public long getLastModified()Get the value of the Last-Modified header for this response.- Returns:
- the Last-Modified header in milliseconds
-
setETag
Set the ETag header value for this response.- Parameters:
value
- the ETag header value
-
getETag
Get the ETag header value for this response.- Returns:
- the ETag header value
-
getNotModified
public boolean getNotModified()Check if this response should generate a Not-Modified response.- Returns:
- true if the the response wasn't modified since the client last saw it.
-
dependsOn
Add a dependency to this response.- Parameters:
what
- an item this response's output depends on.
-
digestDependencies
public void digestDependencies()Digest all dependencies to a checksum to see if the response has changed. -
setSkinpath
Set the path in which to look for skins. This may contain file locations and HopObjects.- Parameters:
arr
- the skin path
-
getSkinpath
Get the path in which to look for skins. This may contain file locations and HopObjects.- Returns:
- the skin path
-
getCachedSkin
Look up a cached skin.- Parameters:
id
- the skin key- Returns:
- the skin, or null if no skin is cached for the given key
-
cacheSkin
Cache a skin for the length of this response.- Parameters:
id
- the skin keyskin
- the skin to cache
-
switchActiveSkin
Set the skin currently being rendered, returning the previously active skin.- Parameters:
skin
- the new active skin- Returns:
- the previously active skin
-
getActiveSkin
Return the skin currently being rendered, or none.- Returns:
- the currently active skin
-
setCookie
public void setCookie(String key, String value, int days, String path, String domain, boolean isHttpOnly, boolean isSecure) Set a cookie.- Parameters:
key
- the cookie keyvalue
- the cookie valuedays
- the cookie's lifespan in dayspath
- the URL path to apply the cookie todomain
- the domain to apply the cookie toisHttpOnly
- marks the cookie as HttpOnlyisSecure
- limits the cookie for use with secure protocols
-
resetCookies
public void resetCookies()Reset all previously set cookies. -
countCookies
public int countCookies()Get the number of cookies set in this response.- Returns:
- the number of cookies
-
getCookies
Get the cookies set in this response.- Returns:
- the cookies
-
getMessage
Get the message to display to the user, if any.- Returns:
- the message
-
setMessage
Set a message to display to the user.- Parameters:
message
- the message
-
getError
Get the error message to display to the user, if any.- Returns:
- the error message
-
setError
Set a message to display to the user.- Parameters:
error
- the error message
-
getErrorMessage
-
getDebugBuffer
Get debug messages to append to the response, if any.- Returns:
- the response's debug buffer
-
setDebugBuffer
Set debug messages to append to the response.- Parameters:
debugBuffer
- the response's debug buffer
-
getCharset
Get the charset/encoding for this response- Returns:
- the charset name
-
setCharset
Set the charset/encoding for this response- Parameters:
charset
- the charset name
-
isCacheable
public boolean isCacheable()Returns true if this response may be cached by the client- Returns:
- true if the response may be cached
-
setCacheable
public void setCacheable(boolean cache) Set the cacheability of this response- Parameters:
cache
- true if the response may be cached
-
getStatus
public int getStatus()Get the HTTP response status code- Returns:
- the HTTP response code
-
setStatus
public void setStatus(int status) Set the HTTP response status code- Parameters:
status
- the HTTP response code
-
getRealm
Get the HTTP authentication realm- Returns:
- the name of the authentication realm
-
setRealm
Set the HTTP authentication realm- Parameters:
realm
- the name of the authentication realm
-