net.sf.tacos.ajax.contrib
Class PrototypeResponseBuilder

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

public class PrototypeResponseBuilder
extends Object
implements ResponseBuilder

Response renderer implementation of the prototype library. Prototype doesn't currently handle the notion of multiple partial responses, so this instance effectively dumps the entirety of its contents into one node in the response.

http://prototype.conio.net/

Author:
jkuhnert

Field Summary
protected  AjaxWebRequest ajaxRequest
          Ajax request
static String CONTENT_TYPE
          Content type
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
PrototypeResponseBuilder()
          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 Foreach 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.
 org.apache.tapestry.IMarkupWriter getScriptWriter()
          Return a valid writer instance that is setup to write to the ResponseBuilder.SCRIPT_BLOCK portion of the response.
 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

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

Constructor Detail

PrototypeResponseBuilder

public PrototypeResponseBuilder()
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

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 Foreach 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. //TODO: this is currently unused

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.

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

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)

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

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

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

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