com.google.clearsilver.jsilver.compiler
Class EscapingEvaluator

java.lang.Object
  extended by com.google.clearsilver.jsilver.syntax.analysis.AnalysisAdapter
      extended by com.google.clearsilver.jsilver.syntax.analysis.DepthFirstAdapter
          extended by com.google.clearsilver.jsilver.compiler.EscapingEvaluator
All Implemented Interfaces:
Analysis, Switch

public class EscapingEvaluator
extends DepthFirstAdapter

Generates a JavaExpression to determine whether a given CS expression should be escaped before displaying. If propagateEscapeStatus is enabled, string and numeric literals are not escaped, nor is the output of an escaping function. If not, any expression that contains an escaping function is not escaped. This maintains compatibility with the way ClearSilver works.


Constructor Summary
EscapingEvaluator(VariableTranslator variableTranslator)
           
 
Method Summary
 void caseAAddExpression(AAddExpression node)
          String concatenation.
 void caseAAndExpression(AAndExpression node)
           
 void caseADecimalExpression(ADecimalExpression node)
          Process AST node for a decimal integer (e.g.
 void caseADivideExpression(ADivideExpression node)
           
 void caseAEqExpression(AEqExpression node)
           
 void caseAExistsExpression(AExistsExpression node)
           
 void caseAFunctionExpression(AFunctionExpression node)
          Process AST node for a function (e.g.
 void caseAGteExpression(AGteExpression node)
           
 void caseAGtExpression(AGtExpression node)
           
 void caseAHexExpression(AHexExpression node)
          Process AST node for a hex integer (e.g.
 void caseALteExpression(ALteExpression node)
           
 void caseALtExpression(ALtExpression node)
           
 void caseAModuloExpression(AModuloExpression node)
           
 void caseAMultiplyExpression(AMultiplyExpression node)
           
 void caseANeExpression(ANeExpression node)
           
 void caseANegativeExpression(ANegativeExpression node)
           
 void caseANotExpression(ANotExpression node)
           
 void caseANumericAddExpression(ANumericAddExpression node)
           
 void caseANumericEqExpression(ANumericEqExpression node)
           
 void caseANumericExpression(ANumericExpression node)
           
 void caseANumericNeExpression(ANumericNeExpression node)
           
 void caseAOrExpression(AOrExpression node)
           
 void caseAStringExpression(AStringExpression node)
          Process AST node for a string (e.g.
 void caseASubtractExpression(ASubtractExpression node)
           
 void caseAVariableExpression(AVariableExpression node)
          Process AST node for a variable (e.g.
 JavaExpression computeEscaping(PExpression expression, boolean propagateEscapeStatus)
          Compute the escaping applied to the given expression.
 JavaExpression computeIfExemptFromEscaping(PExpression expression, boolean propagateEscapeStatus)
          Returns a JavaExpression that can be used to decide whether a given variable should be escaped.
 
Methods inherited from class com.google.clearsilver.jsilver.syntax.analysis.DepthFirstAdapter
caseAAltCommand, caseAAutoescapeCommand, caseACallCommand, caseACommaExpression, caseACommentCommand, caseAContentTypeCommand, caseACsOpenPosition, caseADataCommand, caseADecNumberVariable, caseADefCommand, caseADescendVariable, caseAEachCommand, caseAEscapeCommand, caseAEvarCommand, caseAExpandVariable, caseAHardIncludeCommand, caseAHardLincludeCommand, caseAHexNumberVariable, caseAIfCommand, caseAIncludeCommand, caseAInlineCommand, caseALincludeCommand, caseALoopCommand, caseALoopIncCommand, caseALoopToCommand, caseALvarCommand, caseAMultipleCommand, caseANameCommand, caseANameVariable, caseANoopCommand, caseANoopExpression, caseASequenceExpression, caseASetCommand, caseAUvarCommand, caseAVarCommand, caseAWithCommand, caseStart, defaultIn, defaultOut, inAAddExpression, inAAltCommand, inAAndExpression, inAAutoescapeCommand, inACallCommand, inACommaExpression, inACommentCommand, inAContentTypeCommand, inACsOpenPosition, inADataCommand, inADecimalExpression, inADecNumberVariable, inADefCommand, inADescendVariable, inADivideExpression, inAEachCommand, inAEqExpression, inAEscapeCommand, inAEvarCommand, inAExistsExpression, inAExpandVariable, inAFunctionExpression, inAGteExpression, inAGtExpression, inAHardIncludeCommand, inAHardLincludeCommand, inAHexExpression, inAHexNumberVariable, inAIfCommand, inAIncludeCommand, inAInlineCommand, inALincludeCommand, inALoopCommand, inALoopIncCommand, inALoopToCommand, inALteExpression, inALtExpression, inALvarCommand, inAModuloExpression, inAMultipleCommand, inAMultiplyExpression, inANameCommand, inANameVariable, inANeExpression, inANegativeExpression, inANoopCommand, inANoopExpression, inANotExpression, inANumericAddExpression, inANumericEqExpression, inANumericExpression, inANumericNeExpression, inAOrExpression, inASequenceExpression, inASetCommand, inAStringExpression, inASubtractExpression, inAUvarCommand, inAVarCommand, inAVariableExpression, inAWithCommand, inStart, outAAddExpression, outAAltCommand, outAAndExpression, outAAutoescapeCommand, outACallCommand, outACommaExpression, outACommentCommand, outAContentTypeCommand, outACsOpenPosition, outADataCommand, outADecimalExpression, outADecNumberVariable, outADefCommand, outADescendVariable, outADivideExpression, outAEachCommand, outAEqExpression, outAEscapeCommand, outAEvarCommand, outAExistsExpression, outAExpandVariable, outAFunctionExpression, outAGteExpression, outAGtExpression, outAHardIncludeCommand, outAHardLincludeCommand, outAHexExpression, outAHexNumberVariable, outAIfCommand, outAIncludeCommand, outAInlineCommand, outALincludeCommand, outALoopCommand, outALoopIncCommand, outALoopToCommand, outALteExpression, outALtExpression, outALvarCommand, outAModuloExpression, outAMultipleCommand, outAMultiplyExpression, outANameCommand, outANameVariable, outANeExpression, outANegativeExpression, outANoopCommand, outANoopExpression, outANotExpression, outANumericAddExpression, outANumericEqExpression, outANumericExpression, outANumericNeExpression, outAOrExpression, outASequenceExpression, outASetCommand, outAStringExpression, outASubtractExpression, outAUvarCommand, outAVarCommand, outAVariableExpression, outAWithCommand, outStart
 
Methods inherited from class com.google.clearsilver.jsilver.syntax.analysis.AnalysisAdapter
caseEOF, caseTAlt, caseTAnd, caseTArgWhitespace, caseTAssignment, caseTAutoescape, caseTBang, caseTBracketClose, caseTBracketOpen, caseTCall, caseTComma, caseTCommandDelimiter, caseTComment, caseTCommentStart, caseTContentType, caseTCsClose, caseTCsOpen, caseTData, caseTDecNumber, caseTDef, caseTDollar, caseTDot, caseTEach, caseTElse, caseTElseIf, caseTEq, caseTEscape, caseTEvar, caseTGt, caseTGte, caseTHardDelimiter, caseTHash, caseTHexNumber, caseTIf, caseTInclude, caseTInline, caseTLinclude, caseTLoop, caseTLt, caseTLte, caseTLvar, caseTMinus, caseTName, caseTNe, caseTOr, caseTParenClose, caseTParenOpen, caseTPercent, caseTPlus, caseTQuestion, caseTSet, caseTSlash, caseTStar, caseTString, caseTUvar, caseTVar, caseTWith, caseTWord, defaultCase, getIn, getOut, setIn, setOut
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EscapingEvaluator

public EscapingEvaluator(VariableTranslator variableTranslator)
Method Detail

computeIfExemptFromEscaping

public JavaExpression computeIfExemptFromEscaping(PExpression expression,
                                                  boolean propagateEscapeStatus)
Returns a JavaExpression that can be used to decide whether a given variable should be escaped.

Parameters:
expression - variable expression to be evaluated.
propagateEscapeStatus - Whether to propagate the variable's escape status.
Returns:
Returns a JavaExpression representing a boolean expression that evaluates to true if expression should be exempted from escaping and false otherwise.

computeEscaping

public JavaExpression computeEscaping(PExpression expression,
                                      boolean propagateEscapeStatus)
Compute the escaping applied to the given expression. Uses propagateEscapeStatus to determine how to treat constants, and whether escaping is required on a part of the expression or the whole expression.


caseAAddExpression

public void caseAAddExpression(AAddExpression node)
String concatenation. Do not escape the combined string, if either of the halves has been escaped.

Specified by:
caseAAddExpression in interface Analysis
Overrides:
caseAAddExpression in class DepthFirstAdapter

caseAFunctionExpression

public void caseAFunctionExpression(AFunctionExpression node)
Process AST node for a function (e.g. dosomething(...)).

Specified by:
caseAFunctionExpression in interface Analysis
Overrides:
caseAFunctionExpression in class DepthFirstAdapter

caseAVariableExpression

public void caseAVariableExpression(AVariableExpression node)
Process AST node for a variable (e.g. a.b.c).

Specified by:
caseAVariableExpression in interface Analysis
Overrides:
caseAVariableExpression in class DepthFirstAdapter

caseAStringExpression

public void caseAStringExpression(AStringExpression node)
Process AST node for a string (e.g. "hello").

Specified by:
caseAStringExpression in interface Analysis
Overrides:
caseAStringExpression in class DepthFirstAdapter

caseADecimalExpression

public void caseADecimalExpression(ADecimalExpression node)
Process AST node for a decimal integer (e.g. 123).

Specified by:
caseADecimalExpression in interface Analysis
Overrides:
caseADecimalExpression in class DepthFirstAdapter

caseAHexExpression

public void caseAHexExpression(AHexExpression node)
Process AST node for a hex integer (e.g. 0x1AB).

Specified by:
caseAHexExpression in interface Analysis
Overrides:
caseAHexExpression in class DepthFirstAdapter

caseANumericExpression

public void caseANumericExpression(ANumericExpression node)
Specified by:
caseANumericExpression in interface Analysis
Overrides:
caseANumericExpression in class DepthFirstAdapter

caseANotExpression

public void caseANotExpression(ANotExpression node)
Specified by:
caseANotExpression in interface Analysis
Overrides:
caseANotExpression in class DepthFirstAdapter

caseAExistsExpression

public void caseAExistsExpression(AExistsExpression node)
Specified by:
caseAExistsExpression in interface Analysis
Overrides:
caseAExistsExpression in class DepthFirstAdapter

caseAEqExpression

public void caseAEqExpression(AEqExpression node)
Specified by:
caseAEqExpression in interface Analysis
Overrides:
caseAEqExpression in class DepthFirstAdapter

caseANumericEqExpression

public void caseANumericEqExpression(ANumericEqExpression node)
Specified by:
caseANumericEqExpression in interface Analysis
Overrides:
caseANumericEqExpression in class DepthFirstAdapter

caseANeExpression

public void caseANeExpression(ANeExpression node)
Specified by:
caseANeExpression in interface Analysis
Overrides:
caseANeExpression in class DepthFirstAdapter

caseANumericNeExpression

public void caseANumericNeExpression(ANumericNeExpression node)
Specified by:
caseANumericNeExpression in interface Analysis
Overrides:
caseANumericNeExpression in class DepthFirstAdapter

caseALtExpression

public void caseALtExpression(ALtExpression node)
Specified by:
caseALtExpression in interface Analysis
Overrides:
caseALtExpression in class DepthFirstAdapter

caseAGtExpression

public void caseAGtExpression(AGtExpression node)
Specified by:
caseAGtExpression in interface Analysis
Overrides:
caseAGtExpression in class DepthFirstAdapter

caseALteExpression

public void caseALteExpression(ALteExpression node)
Specified by:
caseALteExpression in interface Analysis
Overrides:
caseALteExpression in class DepthFirstAdapter

caseAGteExpression

public void caseAGteExpression(AGteExpression node)
Specified by:
caseAGteExpression in interface Analysis
Overrides:
caseAGteExpression in class DepthFirstAdapter

caseAAndExpression

public void caseAAndExpression(AAndExpression node)
Specified by:
caseAAndExpression in interface Analysis
Overrides:
caseAAndExpression in class DepthFirstAdapter

caseAOrExpression

public void caseAOrExpression(AOrExpression node)
Specified by:
caseAOrExpression in interface Analysis
Overrides:
caseAOrExpression in class DepthFirstAdapter

caseANumericAddExpression

public void caseANumericAddExpression(ANumericAddExpression node)
Specified by:
caseANumericAddExpression in interface Analysis
Overrides:
caseANumericAddExpression in class DepthFirstAdapter

caseASubtractExpression

public void caseASubtractExpression(ASubtractExpression node)
Specified by:
caseASubtractExpression in interface Analysis
Overrides:
caseASubtractExpression in class DepthFirstAdapter

caseAMultiplyExpression

public void caseAMultiplyExpression(AMultiplyExpression node)
Specified by:
caseAMultiplyExpression in interface Analysis
Overrides:
caseAMultiplyExpression in class DepthFirstAdapter

caseADivideExpression

public void caseADivideExpression(ADivideExpression node)
Specified by:
caseADivideExpression in interface Analysis
Overrides:
caseADivideExpression in class DepthFirstAdapter

caseAModuloExpression

public void caseAModuloExpression(AModuloExpression node)
Specified by:
caseAModuloExpression in interface Analysis
Overrides:
caseAModuloExpression in class DepthFirstAdapter

caseANegativeExpression

public void caseANegativeExpression(ANegativeExpression node)
Specified by:
caseANegativeExpression in interface Analysis
Overrides:
caseANegativeExpression in class DepthFirstAdapter


Copyright © 2010-2012 Google. All Rights Reserved.