com.go.teaservlet
Interface ApplicationResponse

All Superinterfaces:
javax.servlet.http.HttpServletResponse, javax.servlet.ServletResponse

public interface ApplicationResponse
extends javax.servlet.http.HttpServletResponse

An ordinary HttpServletResponse, but with additional operations specific to the TeaServlet.

Version:
21 , 01/07/12
Author:
Brian S O'Neill

Inner Class Summary
static interface ApplicationResponse.Command
           
static interface ApplicationResponse.DetachedData
           
 
Fields inherited from interface javax.servlet.http.HttpServletResponse
SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CONFLICT, SC_CONTINUE, SC_CREATED, SC_EXPECTATION_FAILED, SC_FORBIDDEN, SC_GATEWAY_TIMEOUT, SC_GONE, SC_HTTP_VERSION_NOT_SUPPORTED, SC_INTERNAL_SERVER_ERROR, SC_LENGTH_REQUIRED, SC_METHOD_NOT_ALLOWED, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_MULTIPLE_CHOICES, SC_NO_CONTENT, SC_NON_AUTHORITATIVE_INFORMATION, SC_NOT_ACCEPTABLE, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_PARTIAL_CONTENT, SC_PAYMENT_REQUIRED, SC_PRECONDITION_FAILED, SC_PROXY_AUTHENTICATION_REQUIRED, SC_REQUEST_ENTITY_TOO_LARGE, SC_REQUEST_TIMEOUT, SC_REQUEST_URI_TOO_LONG, SC_REQUESTED_RANGE_NOT_SATISFIABLE, SC_RESET_CONTENT, SC_SEE_OTHER, SC_SERVICE_UNAVAILABLE, SC_SWITCHING_PROTOCOLS, SC_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE, SC_USE_PROXY
 
Method Summary
 ApplicationResponse.DetachedData execDetached(ApplicationResponse.Command command)
          Execute the given command and detach everything sent to the ApplicationResponse in a way that's safe to do asynchronously.
 ApplicationResponse.DetachedData execDetached(Substitution s)
          Execute the given template substitution and detach everything sent to the ApplicationResponse in a way that's safe to do asynchronously.
 void finish()
          Commits this response and fully writes out the buffered contents unless there was a redirect or an error.
 HttpContext getHttpContext()
          Provides direct access to the HttpContext that the template has access to.
 CharToByteBuffer getResponseBuffer()
          Returns the internal buffer that stores the response.
 boolean insertCommand(ApplicationResponse.Command command)
          Insert an arbitrary command into this response.
 boolean isRedirectOrError()
          Returns whether a redirect or error will be sent to the client.
 void stealOutput(Substitution s, OutputReceiver receiver)
          Execute the given template substitution, but steal any output that would have gone directly to the response buffer.
 
Methods inherited from interface javax.servlet.http.HttpServletResponse
addCookie, addDateHeader, addHeader, addIntHeader, containsHeader, encodeRedirectUrl, encodeRedirectURL, encodeUrl, encodeURL, sendError, sendError, sendRedirect, setDateHeader, setHeader, setIntHeader, setStatus, setStatus
 
Methods inherited from interface javax.servlet.ServletResponse
flushBuffer, getBufferSize, getCharacterEncoding, getLocale, getOutputStream, getWriter, isCommitted, reset, resetBuffer, setBufferSize, setContentLength, setContentType, setLocale
 

Method Detail

isRedirectOrError

public boolean isRedirectOrError()
Returns whether a redirect or error will be sent to the client. This is set to true when sendError or sendRedirect is called on the response.

getResponseBuffer

public CharToByteBuffer getResponseBuffer()
Returns the internal buffer that stores the response. Applications can use this to directly supply character or byte data to be output.

getHttpContext

public HttpContext getHttpContext()
Provides direct access to the HttpContext that the template has access to. This allows functions to directly control locale and formatting settings as well as perform string conversion against the current format settings.

The returned HttpContext instance is actually an auto-generated class that merges all the application contexts into one. Application context instances are requested only when the merged context first needs to invoke a function from that context.

Application functions can access functions provided by other applications, possibly using the Java reflection APIs. Also, the merged class implements as many context interfaces as possible. Therefore, casting the context to an expected type can also be used to access other application functions.


stealOutput

public void stealOutput(Substitution s,
                        OutputReceiver receiver)
                 throws java.lang.Exception
Execute the given template substitution, but steal any output that would have gone directly to the response buffer. Applications can use this to specially handle the output of special objects. For example, an application can supply functions that allow templates to create downloadable images. By stealing the output, printed text can go to the image instead of corrupting the encoding.

Note: stealOutput is designed to run in the same thread that executed the main template. If the substitution needs to run in a separate thread, consider execDetached(com.go.tea.runtime.Substitution) instead.

Parameters:
s - template substitution block that will be executed
receiver - receives all the output generated by the substitution
Throws:
any - exception thrown by the substitution or receiver

execDetached

public ApplicationResponse.DetachedData execDetached(Substitution s)
                                              throws java.lang.Exception
Execute the given template substitution and detach everything sent to the ApplicationResponse in a way that's safe to do asynchronously. This is useful for certain caching strategies. The substitution is detached and executed with a new context instance and output buffer.
Parameters:
s - template substitution block that will be executed
Returns:
the detached response data, which is essentially a copy
Throws:
any - exception thrown by the substitution or buffer

execDetached

public ApplicationResponse.DetachedData execDetached(ApplicationResponse.Command command)
                                              throws java.lang.Exception
Execute the given command and detach everything sent to the ApplicationResponse in a way that's safe to do asynchronously. This is useful for certain caching strategies. The ApplicationResponse given to the command contains a new context instance and output buffer.
Parameters:
s - template substitution block that will be executed
Returns:
the detached response data, which is essentially a copy
Throws:
any - exception thrown by the command or buffer

insertCommand

public boolean insertCommand(ApplicationResponse.Command command)
                      throws java.lang.Exception
Insert an arbitrary command into this response. If this response is saving its state in a DetachedData instance, then the command will be executed every time the DetachedData is played back. If this response isn't detached, the command is not executed and false is returned.
Returns:
false if command cannot be inserted because no detached execution is in progress.

finish

public void finish()
            throws java.io.IOException
Commits this response and fully writes out the buffered contents unless there was a redirect or an error. Subsequent calls to finish have no affect.
Throws:
java.lang.IllegalArgumentException - if a Writer was already used for writing to the response.