org.apache.tapestry.util
Class PageRenderSupportImpl

java.lang.Object
  extended by org.apache.tapestry.util.PageRenderSupportImpl
All Implemented Interfaces:
org.apache.hivemind.Locatable, IScriptProcessor, PageRenderSupport

public class PageRenderSupportImpl
extends Object
implements org.apache.hivemind.Locatable, PageRenderSupport

Implementation of PageRenderSupport. The Body component uses an instance of this class.

Since:
4.0
Author:
Howard M. Lewis Ship

Constructor Summary
PageRenderSupportImpl(AssetFactory assetFactory, String namespace, org.apache.hivemind.Location location, ResponseBuilder builder)
          Deprecated. To be removed in 4.1.2 - use the new PageRenderSupportImpl(org.apache.tapestry.asset.AssetFactory, String, org.apache.tapestry.services.ResponseBuilder, org.apache.tapestry.IRequestCycle) constructor instead.
PageRenderSupportImpl(AssetFactory assetFactory, String namespace, ResponseBuilder builder, IRequestCycle cycle)
           
 
Method Summary
 void addBodyScript(IComponent target, String script)
          Adds scripting code to the main body.
 void addBodyScript(String script)
          Adds scripting code to the main body.
 void addExternalScript(IComponent target, org.apache.hivemind.Resource scriptLocation)
          Adds an external script.
 void addExternalScript(org.apache.hivemind.Resource scriptLocation)
          Adds an external script.
 void addInitializationScript(IComponent target, String script)
          Adds initialization script.
 void addInitializationScript(String script)
          Adds initialization script.
 void addScriptAfterInitialization(IComponent target, String script)
          Works in the same way as IScriptProcessor.addInitializationScript(IComponent, String) - except this method causes the script being added to appear after all of the script content written out from the normal initialization script processing happens.
static String getContent(StringBuffer buffer)
           
 org.apache.hivemind.Location getLocation()
          Returns the location, which may be used in error messages.
 String getPreloadedImageReference(IComponent target, IAsset source)
          Operates in the same way that PageRenderSupport.getPreloadedImageReference(IComponent, String) does, except the source is the actual IAsset of an image to preload.
 String getPreloadedImageReference(IComponent target, String URL)
          Sets up the given URL to preload, and returns a reference to the loaded image, in the form of a snippet of JavaScript expression that can be inserted into some larger block of JavaScript as a function parameter, or as a property assignment.
 String getPreloadedImageReference(String URL)
          Sets up the given URL to preload, and returns a reference to the loaded image, in the form of a snippet of JavaScript expression that can be inserted into some larger block of JavaScript as a function parameter, or as a property assignment.
 String getUniqueString(String baseValue)
          Ensures that the given string is unique.
 boolean isBodyScriptAllowed(IComponent target)
          Determines if the specified component should have its javascript body added to the response.
 boolean isExternalScriptAllowed(IComponent target)
          Determines if the specified component should have its javascript external resource scripts added to the response.
 boolean isInitializationScriptAllowed(IComponent target)
          Determines if the specified component should have its javascript initialization added to the response.
 void writeBodyScript(IMarkupWriter writer, IRequestCycle cycle)
          Writes a single large JavaScript block containing: Any image initializations (via getPreloadedImageReference(IComponent, String)).
 void writeInitializationScript(IMarkupWriter writer)
          Writes any image initializations; this should be invoked at the end of the render, after all the related HTML will have already been streamed to the client and parsed by the web browser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PageRenderSupportImpl

public PageRenderSupportImpl(AssetFactory assetFactory,
                             String namespace,
                             org.apache.hivemind.Location location,
                             ResponseBuilder builder)
Deprecated. To be removed in 4.1.2 - use the new PageRenderSupportImpl(org.apache.tapestry.asset.AssetFactory, String, org.apache.tapestry.services.ResponseBuilder, org.apache.tapestry.IRequestCycle) constructor instead.

Creates a new instance bound to the specific location.

Parameters:
assetFactory - Used to generate asset urls.
namespace - Namespace that javascript / portlet related items should be in.
location - Location of what is primarily the Body component.
builder - The response delegate.

PageRenderSupportImpl

public PageRenderSupportImpl(AssetFactory assetFactory,
                             String namespace,
                             ResponseBuilder builder,
                             IRequestCycle cycle)
Method Detail

getLocation

public org.apache.hivemind.Location getLocation()
Returns the location, which may be used in error messages. In practical terms, this is the location of the Body component.

Specified by:
getLocation in interface org.apache.hivemind.Locatable

getPreloadedImageReference

public String getPreloadedImageReference(String URL)
Description copied from interface: PageRenderSupport
Sets up the given URL to preload, and returns a reference to the loaded image, in the form of a snippet of JavaScript expression that can be inserted into some larger block of JavaScript as a function parameter, or as a property assignment. A typical return value might be tapestry_preload[7].src.

Specified by:
getPreloadedImageReference in interface PageRenderSupport
Parameters:
URL - The url to the resource to be preloaded.
Returns:
Reference to preload image url.

getPreloadedImageReference

public String getPreloadedImageReference(IComponent target,
                                         IAsset source)
Description copied from interface: PageRenderSupport
Operates in the same way that PageRenderSupport.getPreloadedImageReference(IComponent, String) does, except the source is the actual IAsset of an image to preload.

Specified by:
getPreloadedImageReference in interface PageRenderSupport
Parameters:
target - The component the asset is being loaded for.
source - The asset image to preload.
Returns:
The url representing the image that can be safely retrieved by the browser to see it.

getPreloadedImageReference

public String getPreloadedImageReference(IComponent target,
                                         String URL)
Description copied from interface: PageRenderSupport
Sets up the given URL to preload, and returns a reference to the loaded image, in the form of a snippet of JavaScript expression that can be inserted into some larger block of JavaScript as a function parameter, or as a property assignment. A typical return value might be tapestry_preload[7].src.

Specified by:
getPreloadedImageReference in interface PageRenderSupport
Parameters:
target - The component url being loaded for.
URL - The asset URL to preload.
Returns:
Reference to preload image url.

addBodyScript

public void addBodyScript(String script)
Description copied from interface: IScriptProcessor
Adds scripting code to the main body. During the render, multiple scripts may render multiple bodies; all are concatinated together to form a single block. The Body component will write the body script contents just inside the <body> tag.

Specified by:
addBodyScript in interface IScriptProcessor
See Also:
#addBodyScript(IComponent, String)}

addBodyScript

public void addBodyScript(IComponent target,
                          String script)
Description copied from interface: IScriptProcessor
Adds scripting code to the main body. During the render, multiple scripts may render multiple bodies; all are concatinated together to form a single block. The Body component will write the body script contents just inside the <body> tag.

Specified by:
addBodyScript in interface IScriptProcessor
Parameters:
target - The component this script is being added for.
script - The script to add to the body response.

isBodyScriptAllowed

public boolean isBodyScriptAllowed(IComponent target)
Determines if the specified component should have its javascript body added to the response.

Specified by:
isBodyScriptAllowed in interface IScriptProcessor
Parameters:
target - The component to allow/disallow body script content from.
Returns:
True if the component script should be allowed.

isExternalScriptAllowed

public boolean isExternalScriptAllowed(IComponent target)
Determines if the specified component should have its javascript external resource scripts added to the response.

Specified by:
isExternalScriptAllowed in interface IScriptProcessor
Parameters:
target - The component to check for inclusion/exclusion.
Returns:
True if external scripts from this component should be added to the response.

isInitializationScriptAllowed

public boolean isInitializationScriptAllowed(IComponent target)
Determines if the specified component should have its javascript initialization added to the response.

Specified by:
isInitializationScriptAllowed in interface IScriptProcessor
Parameters:
target - The component to allow/disallow initialization script content from.
Returns:
True if the component script should be allowed.

addInitializationScript

public void addInitializationScript(String script)
Description copied from interface: IScriptProcessor
Adds initialization script. Initialization script is executed once, when the containing page loads. Initialization script content is written only after all HTML content that could be referenced from the script (in effect, just before the </body> tag).

Specified by:
addInitializationScript in interface IScriptProcessor
See Also:
#addInitializationScript(IComponent, String)}

addInitializationScript

public void addInitializationScript(IComponent target,
                                    String script)
Description copied from interface: IScriptProcessor
Adds initialization script. Initialization script is executed once, when the containing page loads. Initialization script content is written only after all HTML content that could be referenced from the script (in effect, just before the </body> tag).

Specified by:
addInitializationScript in interface IScriptProcessor
Parameters:
target - The component the script is being added for.
script - The script to add.

addScriptAfterInitialization

public void addScriptAfterInitialization(IComponent target,
                                         String script)
Description copied from interface: IScriptProcessor
Works in the same way as IScriptProcessor.addInitializationScript(IComponent, String) - except this method causes the script being added to appear after all of the script content written out from the normal initialization script processing happens. This is useful if you have some initialization script logic that absolutely must happen at the very end of the rest of things.

Specified by:
addScriptAfterInitialization in interface IScriptProcessor
Parameters:
target - The component the script is being added for.
script - The script to add.
See Also:
#addInitializationScript(IComponent, String)}.

addExternalScript

public void addExternalScript(org.apache.hivemind.Resource scriptLocation)
Description copied from interface: IScriptProcessor
Adds an external script. The processor is expected to ensure that external scripts are only loaded a single time per page.

Specified by:
addExternalScript in interface IScriptProcessor
See Also:
#addExternalScript(IComponent, Resource)}

addExternalScript

public void addExternalScript(IComponent target,
                              org.apache.hivemind.Resource scriptLocation)
Description copied from interface: IScriptProcessor
Adds an external script. The processor is expected to ensure that external scripts are only loaded a single time per page. The target will be checked to filter the scripts added for those types of responses that require them.

Specified by:
addExternalScript in interface IScriptProcessor
Parameters:
target - The component the script is being added for.
scriptLocation - The external script to add.

getUniqueString

public String getUniqueString(String baseValue)
Description copied from interface: IScriptProcessor
Ensures that the given string is unique. The string is either returned unchanged, or a suffix is appended to ensure uniqueness.

Specified by:
getUniqueString in interface IScriptProcessor

writeBodyScript

public void writeBodyScript(IMarkupWriter writer,
                            IRequestCycle cycle)
Writes a single large JavaScript block containing:

Parameters:
writer - The markup writer to use.
cycle - The current request.
See Also:
writeInitializationScript(IMarkupWriter)

writeInitializationScript

public void writeInitializationScript(IMarkupWriter writer)
Writes any image initializations; this should be invoked at the end of the render, after all the related HTML will have already been streamed to the client and parsed by the web browser. Earlier versions of Tapestry uses a window.onload event handler.

Parameters:
writer - The markup writer to use.

getContent

public static String getContent(StringBuffer buffer)


Copyright © 2006-2008 Apache Software Foundation. All Rights Reserved.