com.google.clearsilver.jsilver.compiler
Class BaseCompiledTemplate

java.lang.Object
  extended by com.google.clearsilver.jsilver.compiler.BaseCompiledTemplate
All Implemented Interfaces:
Template

public abstract class BaseCompiledTemplate
extends Object
implements Template

Base class providing help to generated templates. Note, many of the methods are public as they are also used by macros.


Nested Class Summary
 class BaseCompiledTemplate.CompiledMacro
           
 
Constructor Summary
BaseCompiledTemplate()
           
 
Method Summary
static boolean asBoolean(boolean value)
           
static boolean asBoolean(Data data)
           
static boolean asBoolean(int value)
           
static boolean asBoolean(String value)
           
static boolean asBoolean(Value value)
           
static int asInt(boolean value)
           
static int asInt(Data data)
           
static int asInt(int value)
           
static int asInt(String value)
           
static int asInt(Value value)
           
static String asString(boolean value)
           
static String asString(Data data)
           
static String asString(int value)
           
static String asString(String value)
           
static String asString(Value value)
           
static Value asValue(boolean value)
           
static Value asValue(int value)
           
static Value asValue(String value)
           
static Value asValue(Value value)
           
static Value asVariableValue(String variableName, DataContext context)
           
 RenderingContext createRenderingContext(Data data, Appendable out, ResourceLoader resourceLoader)
          Create a new RenderingContext.
static boolean exists(Data data)
           
 Iterable<? extends Data> getChildren(Data parent)
          Returns child nodes of parent.
 String getDisplayName()
          Name to use when displaying error or log messages.
 EscapeMode getEscapeMode()
          Return the EscapeMode in which this template was generated.
static String getNodeName(Data data)
          Gets the name of the node for writing.
protected  TemplateLoader getTemplateLoader()
           
 String getTemplateName()
          Name of template (e.g.
protected  void include(String templateName, boolean ignoreMissingFile, RenderingContext context)
          Code common to all three include commands.
 void render(Data data, Appendable out, ResourceLoader resourceLoader)
          Render the template.
 void setAutoEscapeOptions(AutoEscapeOptions autoEscapeOptions)
          Set auto escaping options so they can be passed to the rendering context.
 void setEscapeMode(EscapeMode mode)
          Sets the EscapeMode in which this template was generated.
 void setFunctionExecutor(FunctionExecutor functionExecutor)
           
 void setTemplateLoader(TemplateLoader templateLoader)
           
 void setTemplateName(String templateName)
           
static boolean validateLoopArgs(int start, int end, int increment)
          Verify that the loop arguments are valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.google.clearsilver.jsilver.template.Template
render
 

Constructor Detail

BaseCompiledTemplate

public BaseCompiledTemplate()
Method Detail

setFunctionExecutor

public void setFunctionExecutor(FunctionExecutor functionExecutor)

setTemplateName

public void setTemplateName(String templateName)

setTemplateLoader

public void setTemplateLoader(TemplateLoader templateLoader)

setAutoEscapeOptions

public void setAutoEscapeOptions(AutoEscapeOptions autoEscapeOptions)
Set auto escaping options so they can be passed to the rendering context.

See Also:
AutoEscapeOptions

render

public void render(Data data,
                   Appendable out,
                   ResourceLoader resourceLoader)
            throws IOException
Description copied from interface: Template
Render the template.

Specified by:
render in interface Template
Parameters:
data - Data to merge with template.
out - Target to write to.
resourceLoader - ResourceLoader to use instead of the default template one when loading files.
Throws:
IOException

createRenderingContext

public RenderingContext createRenderingContext(Data data,
                                               Appendable out,
                                               ResourceLoader resourceLoader)
Description copied from interface: Template
Create a new RenderingContext.

Specified by:
createRenderingContext in interface Template
Parameters:
data - Data to merge with template.
out - Target to write to.
resourceLoader - ResourceLoader to load files.

getTemplateName

public String getTemplateName()
Description copied from interface: Template
Name of template (e.g. mytemplate.cs).

Specified by:
getTemplateName in interface Template

setEscapeMode

public void setEscapeMode(EscapeMode mode)
Sets the EscapeMode in which this template was generated.

Parameters:
mode - EscapeMode

getEscapeMode

public EscapeMode getEscapeMode()
Description copied from interface: Template
Return the EscapeMode in which this template was generated.

Specified by:
getEscapeMode in interface Template
Returns:
EscapeMode

getDisplayName

public String getDisplayName()
Description copied from interface: Template
Name to use when displaying error or log messages. May return the same value as #getTemplateName, or may contain more information.

Specified by:
getDisplayName in interface Template

validateLoopArgs

public static boolean validateLoopArgs(int start,
                                       int end,
                                       int increment)
Verify that the loop arguments are valid. If not, we will skip the loop.


exists

public static boolean exists(Data data)

asInt

public static int asInt(String value)

asInt

public static int asInt(int value)

asInt

public static int asInt(boolean value)

asInt

public static int asInt(Value value)

asInt

public static int asInt(Data data)

asString

public static String asString(String value)

asString

public static String asString(int value)

asString

public static String asString(boolean value)

asString

public static String asString(Value value)

asString

public static String asString(Data data)

asValue

public static Value asValue(String value)

asValue

public static Value asValue(int value)

asValue

public static Value asValue(boolean value)

asValue

public static Value asValue(Value value)

asVariableValue

public static Value asVariableValue(String variableName,
                                    DataContext context)

asBoolean

public static boolean asBoolean(boolean value)

asBoolean

public static boolean asBoolean(String value)

asBoolean

public static boolean asBoolean(int value)

asBoolean

public static boolean asBoolean(Value value)

asBoolean

public static boolean asBoolean(Data data)

getNodeName

public static String getNodeName(Data data)
Gets the name of the node for writing. Used by cs name command. Returns empty string if not found.


getChildren

public Iterable<? extends Data> getChildren(Data parent)
Returns child nodes of parent. Parent may be null, in which case an empty iterable is returned.


getTemplateLoader

protected TemplateLoader getTemplateLoader()

include

protected void include(String templateName,
                       boolean ignoreMissingFile,
                       RenderingContext context)
Code common to all three include commands.

Parameters:
templateName - String representing name of file to include.
ignoreMissingFile - true if any FileNotFound error generated by the template loader should be ignored, false otherwise.
context - Rendering context to use for the included template.


Copyright © 2010-2012 Google. All Rights Reserved.