org.apache.tapestry.script
Class ScriptSessionImpl

java.lang.Object
  extended by org.apache.tapestry.script.ScriptSessionImpl
All Implemented Interfaces:
IScriptProcessor, ScriptSession

public class ScriptSessionImpl
extends Object
implements ScriptSession

The result of executing a script, the session is used during the parsing process as well. Following IScript.execute(IComponent, org.apache.tapestry.IRequestCycle, org.apache.tapestry.IScriptProcessor, java.util.Map), the session provides access to output symbols as well as the body and initialization blocks created by the script tokens.

Since:
0.2.9
Author:
Howard Lewis Ship

Constructor Summary
ScriptSessionImpl(org.apache.hivemind.Resource scriptTemplateResource, IComponent component, IRequestCycle cycle, IScriptProcessor processor, ExpressionEvaluator evaluator, ValueConverter valueConverter, Map symbols)
           
ScriptSessionImpl(org.apache.hivemind.Resource scriptTemplateResource, IRequestCycle cycle, IScriptProcessor processor, ExpressionEvaluator evaluator, ValueConverter valueConverter, Map symbols)
           
 
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 resource)
          Adds an external script.
 void addExternalScript(org.apache.hivemind.Resource resource)
          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.
 Object evaluate(String expression)
          Evaluates an OGNL expression, where the root object for the expression is the symbols map.
 Object evaluate(String expression, Class desiredType)
          Evaluates an expression and coerces the result to a particlar type.
 IRequestCycle getRequestCycle()
          Returns the current request cycle.
 org.apache.hivemind.Resource getScriptTemplateResource()
          Returns the resource for the script template.
 Map getSymbols()
          Returns the symbols (which may be created or updated during the execution of the script template).
 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.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ScriptSessionImpl

public ScriptSessionImpl(org.apache.hivemind.Resource scriptTemplateResource,
                         IRequestCycle cycle,
                         IScriptProcessor processor,
                         ExpressionEvaluator evaluator,
                         ValueConverter valueConverter,
                         Map symbols)

ScriptSessionImpl

public ScriptSessionImpl(org.apache.hivemind.Resource scriptTemplateResource,
                         IComponent component,
                         IRequestCycle cycle,
                         IScriptProcessor processor,
                         ExpressionEvaluator evaluator,
                         ValueConverter valueConverter,
                         Map symbols)
Method Detail

evaluate

public Object evaluate(String expression)
Description copied from interface: ScriptSession
Evaluates an OGNL expression, where the root object for the expression is the symbols map.

Specified by:
evaluate in interface ScriptSession

evaluate

public Object evaluate(String expression,
                       Class desiredType)
Description copied from interface: ScriptSession
Evaluates an expression and coerces the result to a particlar type.

Specified by:
evaluate in interface ScriptSession
See Also:
ValueConverter

getScriptTemplateResource

public org.apache.hivemind.Resource getScriptTemplateResource()
Description copied from interface: ScriptSession
Returns the resource for the script template.

Specified by:
getScriptTemplateResource in interface ScriptSession

getSymbols

public Map getSymbols()
Description copied from interface: ScriptSession
Returns the symbols (which may be created or updated during the execution of the script template).

Specified by:
getSymbols in interface ScriptSession

getRequestCycle

public IRequestCycle getRequestCycle()
Description copied from interface: ScriptSession
Returns the current request cycle.

Specified by:
getRequestCycle in interface ScriptSession

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)}

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.

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.

addExternalScript

public void addExternalScript(org.apache.hivemind.Resource resource)
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 resource)
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.
resource - The external script to add.

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)}.

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

toString

public String toString()
Overrides:
toString in class Object


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