net.sf.tacos.ajax.contrib
Class DojoResponseBuilder

java.lang.Object
  extended by net.sf.tacos.ajax.contrib.DojoResponseBuilder
All Implemented Interfaces:
ResponseBuilder

public class DojoResponseBuilder
extends Object
implements ResponseBuilder

Renders responses to the dojo toolkit library.

Author:
jkuhnert

Field Summary
protected  AjaxWebRequest ajaxRequest
          Ajax request
static String CONTENT_TYPE
          Content type
protected  org.apache.tapestry.NestedMarkupWriter exceptionWriter
          Exception writer
protected  org.apache.tapestry.NestedMarkupWriter includeWriter
          JavaScript header include writer
static String JS_INCLUDES_ID
          JavaScript includes response element id
protected  org.apache.tapestry.NestedMarkupWriter postprocessWriter
          Postprocess writer
protected  org.apache.tapestry.NestedMarkupWriter preprocessWriter
          Preprocess writer
protected  org.apache.tapestry.NestedMarkupWriter statusWriter
          Status Text writer
protected  org.apache.tapestry.IMarkupWriter writer
          XML Markup writer to write to
protected  Map writers
          Map of component id's to their nested markup writer instances, which we have to use or else the writer will conflic with our xml nodes
 
Fields inherited from interface net.sf.tacos.ajax.ResponseBuilder
SCRIPT_BLOCK
 
Constructor Summary
DojoResponseBuilder()
          Default constructor
 
Method Summary
 void addExceptionResponse(org.apache.tapestry.IPage exceptionPage, org.apache.tapestry.IRequestCycle cycle)
          Adds the specified Exception page to Ajax response.
 void addPostProcessScript(String script)
          Script that will be executed just after any content replacements in the response, but before anything in the normal script blocks.
 void addPreProcessScript(String script)
          Adds the specified script string to the preprocessing section of the client response.
 void addResponseBlock(String id, String data)
          Adds an arbitrary block of markup to this responses response.
 void addStatusResponse(String status)
          Adds an xml response block of type "statustext".
protected  org.apache.tapestry.IComponent checkComponentContainers(org.apache.tapestry.IComponent comp)
          Certain components that a requested component refresh are contained by might prevent the successfull render of a component directly, such as a PartialForBean component.
 void cleanupAfterRender()
          Invoked by AjaxDirectService after a request cycle so invokers can cleanup resources.
 boolean componentWriterExists(String id)
          Checks for the existance of a previously created component IMarkupWriter, this is currently only used in manual block writing semantics, specifically in the Tree components rendering logic.
 AjaxWebRequest getAjaxRequest()
          The ajax request
protected  String getComponentId(org.apache.tapestry.IComponent comp)
          Gets the id of the specified component, choosing the "id" element binding over any other id.
 org.apache.tapestry.IMarkupWriter getComponentWriter(String id)
          Gets a NestedMarkupWriter for the specified component to write to and caches the buffer for later write to the stream via the cleanupAfterRender().
 String getContentType()
          Should return the content type response that this builder generates.
protected  org.apache.tapestry.IMarkupWriter getExceptionWriter()
          Returns (and creates if necessary) a writer for writing response when exception occurs.
protected  org.apache.tapestry.IMarkupWriter getIncludeWriter()
          Returns a valid instance of the JavaScript writer set aside specifically to make include requests of package js files.
 org.apache.tapestry.IMarkupWriter getScriptWriter()
          Return a valid writer instance that is setup to write to the ResponseBuilder.SCRIPT_BLOCK portion of the response.
protected  org.apache.tapestry.IMarkupWriter getStatusWriter()
          Returns (and creates if necessary) a writer for writing status response text into.
 org.apache.tapestry.IMarkupWriter getWriter()
          The writer
 org.apache.tapestry.IMarkupWriter getWriter(org.apache.tapestry.IComponent component, org.apache.tapestry.IRequestCycle cycle, org.apache.tapestry.IMarkupWriter cwriter)
          Invoked by enhanced IRender.render(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle) methods before rendering to replace their incoming IMarkupWriter instance with the one provided by this class, which may return the same writer or a special writer depending on the circumstances.
 void prepareForRender()
          Called before invoking either ResponseBuilder.updateComponentsDirect(IRequestCycle, IPage, IPage, IComponent), or if in full render mode invoking renderRequest(
 void removeComponentWriter(String id)
          Removes the specified IMarkupWriter from this reponse, if it exists.
 void renderResponse(org.apache.tapestry.IRequestCycle cycle, org.apache.tapestry.IPage activePage, org.apache.tapestry.IPage componentPage, org.apache.tapestry.IComponent component)
          Called to render a complete response to the client, in the case of of direct component updates being set to false.
 void setAjaxRequest(AjaxWebRequest ajaxRequest)
          Sets the associated ajax request.
 void setWriter(org.apache.tapestry.IMarkupWriter writer)
          Sets the text/xml response writer.
 void updateComponentsDirect(org.apache.tapestry.IRequestCycle cycle, org.apache.tapestry.IPage activePage, org.apache.tapestry.IPage componentPage, org.apache.tapestry.IComponent component)
          Called to update all components in cycle directly, without causing any other component to render output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENT_TYPE

public static final String CONTENT_TYPE
Content type

See Also:
Constant Field Values

JS_INCLUDES_ID

public static final String JS_INCLUDES_ID
JavaScript includes response element id

See Also:
Constant Field Values

ajaxRequest

protected AjaxWebRequest ajaxRequest
Ajax request


writer

protected org.apache.tapestry.IMarkupWriter writer
XML Markup writer to write to


writers

protected Map writers
Map of component id's to their nested markup writer instances, which we have to use or else the writer will conflic with our xml nodes


includeWriter

protected org.apache.tapestry.NestedMarkupWriter includeWriter
JavaScript header include writer


statusWriter

protected org.apache.tapestry.NestedMarkupWriter statusWriter
Status Text writer


preprocessWriter

protected org.apache.tapestry.NestedMarkupWriter preprocessWriter
Preprocess writer


postprocessWriter

protected org.apache.tapestry.NestedMarkupWriter postprocessWriter
Postprocess writer


exceptionWriter

protected org.apache.tapestry.NestedMarkupWriter exceptionWriter
Exception writer

Constructor Detail

DojoResponseBuilder

public DojoResponseBuilder()
Default constructor

Method Detail

getWriter

public org.apache.tapestry.IMarkupWriter getWriter(org.apache.tapestry.IComponent component,
                                                   org.apache.tapestry.IRequestCycle cycle,
                                                   org.apache.tapestry.IMarkupWriter cwriter)
Invoked by enhanced IRender.render(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle) methods before rendering to replace their incoming IMarkupWriter instance with the one provided by this class, which may return the same writer or a special writer depending on the circumstances.

Specified by:
getWriter in interface ResponseBuilder
cwriter - Current writer rendering response
Returns:
A valid IMarkupWriter, which may be a NullWriter, an ajax xml response stream, or a normal html response stream.

updateComponentsDirect

public void updateComponentsDirect(org.apache.tapestry.IRequestCycle cycle,
                                   org.apache.tapestry.IPage activePage,
                                   org.apache.tapestry.IPage componentPage,
                                   org.apache.tapestry.IComponent component)
Called to update all components in cycle directly, without causing any other component to render output.

Specified by:
updateComponentsDirect in interface ResponseBuilder

getComponentId

protected String getComponentId(org.apache.tapestry.IComponent comp)
Gets the id of the specified component, choosing the "id" element binding over any other id.

Parameters:
comp -
Returns:
The id of the component.

checkComponentContainers

protected org.apache.tapestry.IComponent checkComponentContainers(org.apache.tapestry.IComponent comp)
Certain components that a requested component refresh are contained by might prevent the successfull render of a component directly, such as a PartialForBean component. This method checks all of the components in a page to see if the specified component has a container of one of these types.

Parameters:
comp - The IComponent to check containers of
Returns:
The most logical topmost IComponent that should be rendered before this component may be rendered.

prepareForRender

public void prepareForRender()
Called before invoking either ResponseBuilder.updateComponentsDirect(IRequestCycle, IPage, IPage, IComponent), or if in full render mode invoking renderRequest(

Specified by:
prepareForRender in interface ResponseBuilder

renderResponse

public void renderResponse(org.apache.tapestry.IRequestCycle cycle,
                           org.apache.tapestry.IPage activePage,
                           org.apache.tapestry.IPage componentPage,
                           org.apache.tapestry.IComponent component)
Called to render a complete response to the client, in the case of of direct component updates being set to false.

Specified by:
renderResponse in interface ResponseBuilder

cleanupAfterRender

public void cleanupAfterRender()
Invoked by AjaxDirectService after a request cycle so invokers can cleanup resources.

In the case of full page/non direct component invocations this causes all the buffered component IMarkupWriter instances to have their contents written to the response stream.

Specified by:
cleanupAfterRender in interface ResponseBuilder

getComponentWriter

public org.apache.tapestry.IMarkupWriter getComponentWriter(String id)
Gets a NestedMarkupWriter for the specified component to write to and caches the buffer for later write to the stream via the cleanupAfterRender().

Specified by:
getComponentWriter in interface ResponseBuilder
Parameters:
id -
Returns:
Writer component will write to.

removeComponentWriter

public void removeComponentWriter(String id)
Removes the specified IMarkupWriter from this reponse, if it exists.

Specified by:
removeComponentWriter in interface ResponseBuilder

getIncludeWriter

protected org.apache.tapestry.IMarkupWriter getIncludeWriter()
Returns a valid instance of the JavaScript writer set aside specifically to make include requests of package js files.

Returns:
A valid writer.

getStatusWriter

protected org.apache.tapestry.IMarkupWriter getStatusWriter()
Returns (and creates if necessary) a writer for writing status response text into.

Returns:
A valid writer.

addPreProcessScript

public void addPreProcessScript(String script)
Adds the specified script string to the preprocessing section of the client response.

Specified by:
addPreProcessScript in interface ResponseBuilder

addPostProcessScript

public void addPostProcessScript(String script)
Script that will be executed just after any content replacements in the response, but before anything in the normal script blocks.

Specified by:
addPostProcessScript in interface ResponseBuilder

componentWriterExists

public boolean componentWriterExists(String id)
Checks for the existance of a previously created component IMarkupWriter, this is currently only used in manual block writing semantics, specifically in the Tree components rendering logic.

Specified by:
componentWriterExists in interface ResponseBuilder
Returns:

addResponseBlock

public void addResponseBlock(String id,
                             String data)
Adds an arbitrary block of markup to this responses response. If the specified component/block id is already associated with a writer this data will be appended to the already existing writer, else a new block will be created.

This method is especially useful for situations where javascript should be inserted into the response for an element that may not otherwise render any content.

Specified by:
addResponseBlock in interface ResponseBuilder
Parameters:
id - The component/block id to associate with response.
data - The content to write

addStatusResponse

public void addStatusResponse(String status)
Adds an xml response block of type "statustext".

Specified by:
addStatusResponse in interface ResponseBuilder
See Also:
AjaxWebRequest.addStatusResponse(String)

getScriptWriter

public org.apache.tapestry.IMarkupWriter getScriptWriter()
Return a valid writer instance that is setup to write to the ResponseBuilder.SCRIPT_BLOCK portion of the response.

Specified by:
getScriptWriter in interface ResponseBuilder
Returns:
A valid markup writer.

getAjaxRequest

public AjaxWebRequest getAjaxRequest()
The ajax request

Specified by:
getAjaxRequest in interface ResponseBuilder
Returns:

setAjaxRequest

public void setAjaxRequest(AjaxWebRequest ajaxRequest)
Sets the associated ajax request.

Specified by:
setAjaxRequest in interface ResponseBuilder

getWriter

public org.apache.tapestry.IMarkupWriter getWriter()
The writer

Specified by:
getWriter in interface ResponseBuilder
Returns:

setWriter

public void setWriter(org.apache.tapestry.IMarkupWriter writer)
Sets the text/xml response writer.

Specified by:
setWriter in interface ResponseBuilder

getContentType

public String getContentType()
Should return the content type response that this builder generates. Ie "text/plain" or "text/xml". These content types must also exist in the hivemodule.xml contribution tapestry.markup.MarkupFilters.

Specified by:
getContentType in interface ResponseBuilder
Returns:
A valid content type required by this builder.

addExceptionResponse

public void addExceptionResponse(org.apache.tapestry.IPage exceptionPage,
                                 org.apache.tapestry.IRequestCycle cycle)
Adds the specified Exception page to Ajax response.

Specified by:
addExceptionResponse in interface ResponseBuilder

getExceptionWriter

protected org.apache.tapestry.IMarkupWriter getExceptionWriter()
Returns (and creates if necessary) a writer for writing response when exception occurs.

Returns:
A valid writer.