com.google.clearsilver.jsilver
Class JSilverOptions

java.lang.Object
  extended by com.google.clearsilver.jsilver.JSilverOptions
All Implemented Interfaces:
Cloneable

public class JSilverOptions
extends Object
implements Cloneable

Options for JSilver. Note: Setter methods also return reference to this, allowing options to be defined in one statement. e.g. new JSilver(..., new JSilverOptions().setSomething(true).setAnother(false));

See Also:
JSilver

Constructor Summary
JSilverOptions()
           
 
Method Summary
 JSilverOptions clone()
           
 boolean getAllowGlobalDataModification()
           
 boolean getCacheTemplates()
           
 boolean getCompileTemplates()
           
 EscapeMode getEscapeMode()
           
 boolean getIgnoreAttributes()
           
 int getInitialBufferSize()
           
 boolean getKeepTemplateCacheFresh()
           
 int getLoadPathCacheSize()
           
 boolean getLogEscapedVariables()
           
 Map<Object,String> getPrecompiledTemplateMap()
           
 boolean getPropagateEscapeStatus()
           
 StringInternStrategy getStringInternStrategy()
          Returns StringInternStrategy object that is used for optimization of HDF parsing.
 boolean getStripHtmlWhiteSpace()
           
 boolean getStripStructuralWhiteSpace()
           
 boolean getUseOutputBufferPool()
           
 boolean getUseStrongCacheReferences()
           
 JSilverOptions setAllowGlobalDataModification(boolean allowGlobalDataModification)
          Use this method to disable wrapping the global HDF with an UnmodifiableData object which prevents modification.
 JSilverOptions setCacheTemplates(boolean cacheTemplates)
          Whether to cache templates.
 JSilverOptions setCompileTemplates(boolean compileTemplates)
          Compile templates to Java byte code.
 JSilverOptions setEscapeMode(EscapeMode escapeMode)
          Escape any template being rendered with the given escaping mode.
 JSilverOptions setIgnoreAttributes(boolean ignoreAttributes)
          If set, then HDF attributes in HDF files will be ignored and not stored in the Data object filled by the parser.
 JSilverOptions setInitialBufferSize(int initialBufferSize)
          Initial buffer size used when rendering directly to a string.
 JSilverOptions setKeepTemplateCacheFresh(boolean keepTemplateCacheFresh)
           
 JSilverOptions setLoadPathCacheSize(int loadPathCacheSize)
          Set the initial size of the load path cache container.
 JSilverOptions setLogEscapedVariables(boolean logEscapedVariables)
          Use this method to enable logging of all variables whose values are modified by auto escaping or <cs escape> commands.
 JSilverOptions setPrecompiledTemplateMap(Map<Object,String> precompiledTemplateMap)
          Optional mapping of TemplateLoader keys to Template instances that will be queried when loading a template.
 JSilverOptions setPropagateEscapeStatus(boolean propagateEscapeStatus)
          Only used for templates that are being auto escaped.
 void setStringInternStrategy(StringInternStrategy stringInternStrategy)
          Sets the StringInternStrategy object that will be used to optimize HDF parsing.
 JSilverOptions setStripHtmlWhiteSpace(boolean value)
          If true, then unnecessary whitespace will be stripped from the output.
 JSilverOptions setStripStructuralWhiteSpace(boolean value)
          If true, then structural whitespace will be stripped from the output.
 JSilverOptions setUseOutputBufferPool(boolean value)
          If true, then use a threadlocal buffer pool for holding rendered output when outputting to String.
 JSilverOptions setUseStrongCacheReferences(boolean value)
          If true, then the template cache will use strong persistent references for the values.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSilverOptions

public JSilverOptions()
Method Detail

setLoadPathCacheSize

public JSilverOptions setLoadPathCacheSize(int loadPathCacheSize)
Set the initial size of the load path cache container. Setting this to 0 causes load path cache to be disabled.


getLoadPathCacheSize

public int getLoadPathCacheSize()
See Also:
setLoadPathCacheSize(int)

setCacheTemplates

public JSilverOptions setCacheTemplates(boolean cacheTemplates)
Whether to cache templates. This will only ever load and parse a template from disk once. Best switched on for production but left off for production (so you can update templates without restarting).


getCacheTemplates

public boolean getCacheTemplates()
See Also:
setCacheTemplates(boolean)

setCompileTemplates

public JSilverOptions setCompileTemplates(boolean compileTemplates)
Compile templates to Java byte code. This slows down the initial render as it performs a compilation step, but then subsequent render are faster. Compiled templates are always cached. WARNING: This functionality is experimental. Use with caution.


getCompileTemplates

public boolean getCompileTemplates()
See Also:
setCompileTemplates(boolean)

setIgnoreAttributes

public JSilverOptions setIgnoreAttributes(boolean ignoreAttributes)
If set, then HDF attributes in HDF files will be ignored and not stored in the Data object filled by the parser. Default is false. Many applications use HDF attributes only in template preprocessing (like translation support) and never in production servers where the templates are rendered. By disabling attribute parsing, these applications can save on memory for storing HDF structures read from files.


getIgnoreAttributes

public boolean getIgnoreAttributes()
See Also:
setIgnoreAttributes(boolean)

setInitialBufferSize

public JSilverOptions setInitialBufferSize(int initialBufferSize)
Initial buffer size used when rendering directly to a string.


getInitialBufferSize

public int getInitialBufferSize()
See Also:
setInitialBufferSize(int)

setPrecompiledTemplateMap

public JSilverOptions setPrecompiledTemplateMap(Map<Object,String> precompiledTemplateMap)
Optional mapping of TemplateLoader keys to Template instances that will be queried when loading a template. If the Template is found it is returned. If not, the next template loader is consulted.

Parameters:
precompiledTemplateMap - map of TemplateLoader keys to corresponding class names that should be valid BaseCompiledTemplate subclasses. Set to null (default) to not load precompiled templates.

getPrecompiledTemplateMap

public Map<Object,String> getPrecompiledTemplateMap()
Returns:
a mapping of TemplateLoader keys to corresponding BaseCompiledTemplate class names, or null (default) if no precompiled templates should be preloaded.
See Also:
setPrecompiledTemplateMap(java.util.Map)

setUseStrongCacheReferences

public JSilverOptions setUseStrongCacheReferences(boolean value)
If true, then the template cache will use strong persistent references for the values. If false (default) it will use soft references. Warning: The cache size is unbounded so only use this option if you have sufficient memory to load all the Templates into memory.


getUseStrongCacheReferences

public boolean getUseStrongCacheReferences()
See Also:
setUseStrongCacheReferences(boolean)

getEscapeMode

public EscapeMode getEscapeMode()
See Also:
setEscapeMode(com.google.clearsilver.jsilver.autoescape.EscapeMode)

setEscapeMode

public JSilverOptions setEscapeMode(EscapeMode escapeMode)
Escape any template being rendered with the given escaping mode. If the mode is ESCAPE_HTML, ESCAPE_URL or ESCAPE_JS, the corresponding escaping will be all variables in the template. If the mode is ESCAPE_AUTO, enable auto escaping on templates. For each variable in the template, this will determine what type of escaping should be applied to the variable, and automatically apply this escaping. This flag can be overriden by setting appropriate HDF variables before loading a template. If Config.AutoEscape is 1, auto escaping is enabled. If Config.VarEscapeMode is set to one of 'html', 'js' or 'url', the corresponding escaping is applied to all variables.

Parameters:
escapeMode -

getPropagateEscapeStatus

public boolean getPropagateEscapeStatus()
See Also:
setPropagateEscapeStatus(boolean)

setPropagateEscapeStatus

public JSilverOptions setPropagateEscapeStatus(boolean propagateEscapeStatus)
Only used for templates that are being auto escaped. If true and auto escaping is enabled, variables created by <cs set> or <cs call> commands are not auto escaped if they are assigned constant or escaped values. This is disabled by default.

See Also:
setEscapeMode(com.google.clearsilver.jsilver.autoescape.EscapeMode)

setStringInternStrategy

public void setStringInternStrategy(StringInternStrategy stringInternStrategy)
Sets the StringInternStrategy object that will be used to optimize HDF parsing.

Set value should not be null as it can cause NullPointerException.

Parameters:
stringInternStrategy - - StringInternStrategy object

getStringInternStrategy

public StringInternStrategy getStringInternStrategy()
Returns StringInternStrategy object that is used for optimization of HDF parsing.

The returned value should never be null.

Returns:
currently used StringInternStrategy object.

setUseOutputBufferPool

public JSilverOptions setUseOutputBufferPool(boolean value)
If true, then use a threadlocal buffer pool for holding rendered output when outputting to String. Assumes that render() is called from a thread and that thread will not reenter render() while it is running. If false, a new buffer is allocated for each request where an Appendable output object was not provided.


getUseOutputBufferPool

public boolean getUseOutputBufferPool()
See Also:
setUseOutputBufferPool(boolean)

setStripHtmlWhiteSpace

public JSilverOptions setStripHtmlWhiteSpace(boolean value)
If true, then unnecessary whitespace will be stripped from the output. 'Unnecessary' is meant in terms of HTML output. See HtmlWhiteSpaceStripper for more info.


getStripHtmlWhiteSpace

public boolean getStripHtmlWhiteSpace()
See Also:
setStripHtmlWhiteSpace(boolean)

setStripStructuralWhiteSpace

public JSilverOptions setStripStructuralWhiteSpace(boolean value)
If true, then structural whitespace will be stripped from the output. This allows templates to be written to more closely match normal programming languages. See StructuralWhitespaceStripper for more info.


getStripStructuralWhiteSpace

public boolean getStripStructuralWhiteSpace()
See Also:
setStripHtmlWhiteSpace(boolean)

setAllowGlobalDataModification

public JSilverOptions setAllowGlobalDataModification(boolean allowGlobalDataModification)
Use this method to disable wrapping the global HDF with an UnmodifiableData object which prevents modification. This flag is here in case there are corner cases or performance reasons that someone may want to disable this protection. Should not be set to true unless incompatibilities or performance issues found. Note, that setting to true could introduce bugs in templates that acquire local references to the global data structure and then try to modify them, which is not the intended behavior. Allowing global data modification during rendering is not compatible with the recently fixed JNI Clearsilver library. TODO: Remove once legacy mode is no longer needed.

Parameters:
allowGlobalDataModification - true if you want to avoid wrapping the global HDF so that all writes to it during rendering are prevented and throw an exception.
Returns:
this object.

getAllowGlobalDataModification

public boolean getAllowGlobalDataModification()
See Also:
setAllowGlobalDataModification(boolean)

setKeepTemplateCacheFresh

public JSilverOptions setKeepTemplateCacheFresh(boolean keepTemplateCacheFresh)
Parameters:
keepTemplateCacheFresh - true to have the template cache call ResourceLoader.getResourceVersionId(String) to check if it should refresh its cache entries (this incurs a small performance penalty each time the cache is accessed)
Returns:
this object

getKeepTemplateCacheFresh

public boolean getKeepTemplateCacheFresh()
See Also:
setKeepTemplateCacheFresh(boolean)

clone

public JSilverOptions clone()
Overrides:
clone in class Object

getLogEscapedVariables

public boolean getLogEscapedVariables()
See Also:
setLogEscapedVariables(boolean)

setLogEscapedVariables

public JSilverOptions setLogEscapedVariables(boolean logEscapedVariables)
Use this method to enable logging of all variables whose values are modified by auto escaping or <cs escape> commands. These will be logged at Level.WARNING. This is useful for detecting variables that should be exempt from auto escaping.

It is recommended to only enable this flag during testing or debugging and not for production jobs.

See Also:
setEscapeMode(com.google.clearsilver.jsilver.autoescape.EscapeMode)


Copyright © 2010-2012 Google. All Rights Reserved.