com.google.clearsilver.jsilver.template
Class DefaultRenderingContext

java.lang.Object
  extended by com.google.clearsilver.jsilver.template.DefaultRenderingContext
All Implemented Interfaces:
FunctionExecutor, RenderingContext

public class DefaultRenderingContext
extends Object
implements RenderingContext, FunctionExecutor

Default implementation of RenderingContext.


Field Summary
static Logger logger
           
 
Constructor Summary
DefaultRenderingContext(DataContext dataContext, ResourceLoader resourceLoader, Appendable out, FunctionExecutor globalFunctionExecutor, AutoEscapeOptions autoEscapeOptions)
           
 
Method Summary
 void escape(String name, String input, Appendable output)
          Escapes some text.
 Value executeFunction(String name, Value... args)
          Lookup a function by name, execute it and return the results.
 Macro findMacro(String name)
          Lookup a macro that's already been registered.
 EscapeMode getAutoEscapeMode()
          Read the currently set auto escape mode.
 AutoEscapeOptions getAutoEscapeOptions()
          Returns the configured AutoEscapeOptions to be used while rendering the current template.
 DataContext getDataContext()
          Return the DataContext object associated with this RenderingContext.
 Iterable<String> getIncludedTemplateNames()
          Returns the ordered, mutable stack of names of included templates.
 ResourceLoader getResourceLoader()
          Returns the ResourceLoader object to use to fetch files needed to render the current template.
 boolean isEscapingFunction(String name)
          Look up a function by name, and report whether it is an escaping function.
 boolean isRuntimeAutoEscaping()
          Indicates whether runtime auto escaping is in progress.
 void popAutoEscapeMode()
           
 void popEscapingFunction()
           
 void popExecutionContext()
           
 boolean popIncludeStackEntry(String templateName)
          Removes an entry with a name of the template from the stack.
 void pushAutoEscapeMode(EscapeMode mode)
          Push a new auto escaping mode onto the context.
 void pushEscapingFunction(String name)
          Push a new escaping function onto the context.
 void pushExecutionContext(Template template)
          Push a new template onto the current execution context.
 boolean pushIncludeStackEntry(String templateName)
          Adds an entry with a name of the template to the stack keeping all names of already included templates.
 void registerMacro(String name, Macro macro)
          Register a macro in the current rendering context.
 void setCurrentPosition(int line, int column)
          Sets the current position in the template.
 void startRuntimeAutoEscaping()
          Start an auto escaping context to parse and auto escape template contents as they are being rendered.
 void stopRuntimeAutoEscaping()
          Stop runtime auto escaping.
 void writeEscaped(String text)
          Write some text out, using the current escaping function.
 void writeUnescaped(CharSequence text)
          Write some text out, without doing any escaping.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

public static final Logger logger
Constructor Detail

DefaultRenderingContext

public DefaultRenderingContext(DataContext dataContext,
                               ResourceLoader resourceLoader,
                               Appendable out,
                               FunctionExecutor globalFunctionExecutor,
                               AutoEscapeOptions autoEscapeOptions)
Method Detail

executeFunction

public Value executeFunction(String name,
                             Value... args)
Lookup a function by name, execute it and return the results.

Specified by:
executeFunction in interface FunctionExecutor
Specified by:
executeFunction in interface RenderingContext

escape

public void escape(String name,
                   String input,
                   Appendable output)
            throws IOException
Description copied from interface: FunctionExecutor
Escapes some text.

Specified by:
escape in interface FunctionExecutor
Parameters:
name - Strategy for escaping text. If null or "none", text will be left as is.
input - Text to be escaped.
output - Where to write the result to.
Throws:
IOException

isEscapingFunction

public boolean isEscapingFunction(String name)
Description copied from interface: RenderingContext
Look up a function by name, and report whether it is an escaping function. Usually, the output of escaping functions will be written using writeUnescaped() instead of writeEscaped().

Specified by:
isEscapingFunction in interface FunctionExecutor
Specified by:
isEscapingFunction in interface RenderingContext
See Also:
EscapingEvaluator

pushEscapingFunction

public void pushEscapingFunction(String name)
Description copied from interface: RenderingContext
Push a new escaping function onto the context. All calls to writeEscape() will use this new function. When done with this function, call popEscapingFunction() to return to the previous escaping function. If the escaping function is not found, an exception will be thrown. To use no escaping function pass null as the escaperName.

Specified by:
pushEscapingFunction in interface RenderingContext
See Also:
RenderingContext.popEscapingFunction()

popEscapingFunction

public void popEscapingFunction()
Specified by:
popEscapingFunction in interface RenderingContext
See Also:
RenderingContext.pushEscapingFunction(String)

writeEscaped

public void writeEscaped(String text)
Description copied from interface: RenderingContext
Write some text out, using the current escaping function.

Specified by:
writeEscaped in interface RenderingContext
See Also:
RenderingContext.pushEscapingFunction(String), RenderingContext.popEscapingFunction()

writeUnescaped

public void writeUnescaped(CharSequence text)
Description copied from interface: RenderingContext
Write some text out, without doing any escaping. Use this only for trusted content.

Specified by:
writeUnescaped in interface RenderingContext

pushExecutionContext

public void pushExecutionContext(Template template)
Description copied from interface: RenderingContext
Push a new template onto the current execution context. This is to generate stack traces when things go wrong deep in templates, to allow users to figure out how they got there.

Specified by:
pushExecutionContext in interface RenderingContext
See Also:
RenderingContext.popExecutionContext()

popExecutionContext

public void popExecutionContext()
Specified by:
popExecutionContext in interface RenderingContext
See Also:
RenderingContext.pushExecutionContext(Template)

setCurrentPosition

public void setCurrentPosition(int line,
                               int column)
Description copied from interface: RenderingContext
Sets the current position in the template. Used to help generate error messages.

Specified by:
setCurrentPosition in interface RenderingContext

registerMacro

public void registerMacro(String name,
                          Macro macro)
Description copied from interface: RenderingContext
Register a macro in the current rendering context. This macro will be available to all other templates, regardless of implementation.

Specified by:
registerMacro in interface RenderingContext

findMacro

public Macro findMacro(String name)
Description copied from interface: RenderingContext
Lookup a macro that's already been registered. Throws JSilverInterpreterException if macro not found.

Specified by:
findMacro in interface RenderingContext

getDataContext

public DataContext getDataContext()
Description copied from interface: RenderingContext
Return the DataContext object associated with this RenderingContext.

Specified by:
getDataContext in interface RenderingContext

getResourceLoader

public ResourceLoader getResourceLoader()
Description copied from interface: RenderingContext
Returns the ResourceLoader object to use to fetch files needed to render the current template.

Specified by:
getResourceLoader in interface RenderingContext

getAutoEscapeOptions

public AutoEscapeOptions getAutoEscapeOptions()
Description copied from interface: RenderingContext
Returns the configured AutoEscapeOptions to be used while rendering the current template.

Specified by:
getAutoEscapeOptions in interface RenderingContext

getAutoEscapeMode

public EscapeMode getAutoEscapeMode()
Description copied from interface: RenderingContext
Read the currently set auto escape mode.

Specified by:
getAutoEscapeMode in interface RenderingContext
Returns:
EscapeMode

pushAutoEscapeMode

public void pushAutoEscapeMode(EscapeMode mode)
Description copied from interface: RenderingContext
Push a new auto escaping mode onto the context. Any template loads via include() or evaluateVariable() will use this auto escaping mode when loading the template.

Specified by:
pushAutoEscapeMode in interface RenderingContext
See Also:
RenderingContext.popAutoEscapeMode()

popAutoEscapeMode

public void popAutoEscapeMode()
Specified by:
popAutoEscapeMode in interface RenderingContext
See Also:
RenderingContext.pushAutoEscapeMode(com.google.clearsilver.jsilver.autoescape.EscapeMode)

isRuntimeAutoEscaping

public boolean isRuntimeAutoEscaping()
Description copied from interface: RenderingContext
Indicates whether runtime auto escaping is in progress.

Specified by:
isRuntimeAutoEscaping in interface RenderingContext
Returns:
true if runtime auto escaping is enabled.
See Also:
RenderingContext.isRuntimeAutoEscaping()

startRuntimeAutoEscaping

public void startRuntimeAutoEscaping()
Start an auto escaping context to parse and auto escape template contents as they are being rendered.

Specified by:
startRuntimeAutoEscaping in interface RenderingContext
Throws:
JSilverInterpreterException - if startRuntimeAutoEscaping is called while runtime autoescaping is already in progress.
See Also:
RenderingContext.stopRuntimeAutoEscaping()

stopRuntimeAutoEscaping

public void stopRuntimeAutoEscaping()
Description copied from interface: RenderingContext
Stop runtime auto escaping.

Specified by:
stopRuntimeAutoEscaping in interface RenderingContext
See Also:
RenderingContext.startRuntimeAutoEscaping()

pushIncludeStackEntry

public boolean pushIncludeStackEntry(String templateName)
Description copied from interface: RenderingContext
Adds an entry with a name of the template to the stack keeping all names of already included templates. The name is added only if it is not already on the stack.

Specified by:
pushIncludeStackEntry in interface RenderingContext
Parameters:
templateName - name of the template to be added to the stack. If null a NullPointerException will be thrown.
Returns:
true if the templateName was added.

popIncludeStackEntry

public boolean popIncludeStackEntry(String templateName)
Description copied from interface: RenderingContext
Removes an entry with a name of the template from the stack.

Specified by:
popIncludeStackEntry in interface RenderingContext
Returns:
true if the templateName was on the stack.

getIncludedTemplateNames

public Iterable<String> getIncludedTemplateNames()
Description copied from interface: RenderingContext
Returns the ordered, mutable stack of names of included templates.

Specified by:
getIncludedTemplateNames in interface RenderingContext


Copyright © 2010-2012 Google. All Rights Reserved.