com.google.clearsilver.jsilver.values
Class VariableValue

java.lang.Object
  extended by com.google.clearsilver.jsilver.values.Value
      extended by com.google.clearsilver.jsilver.values.VariableValue

public class VariableValue
extends Value

A value linked to a variable reference. When this value is evaluated in an expression a Data object will be fetched from the provided DataContext and and its value returned or null if there is no Data object associated with the given name.

See Also:
Value, Data

Constructor Summary
VariableValue(String name, DataContext dataContext)
           
 
Method Summary
 boolean asBoolean()
          Fetch value as boolean.
 int asNumber()
          Fetch value as number.
 String asString()
          Fetch value as string.
 boolean exists()
          Whether this value exists.
 EscapeMode getEscapeMode()
          Indicates the escaping that was applied to the expression represented by this value.
 String getName()
           
 Data getReference()
           
 boolean isEmpty()
           
 String toString()
           
protected  String value()
           
 
Methods inherited from class com.google.clearsilver.jsilver.values.Value
equals, hashCode, isPartiallyEscaped, literalConstant, literalConstant, literalConstant, literalValue, literalValue, literalValue, variableValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VariableValue

public VariableValue(String name,
                     DataContext dataContext)
Method Detail

getName

public String getName()

getReference

public Data getReference()

value

protected String value()

exists

public boolean exists()
Description copied from class: Value
Whether this value exists. Literals always return true, but variable references will return false if the value behind it is null.

Specified by:
exists in class Value

toString

public String toString()
Overrides:
toString in class Value

getEscapeMode

public EscapeMode getEscapeMode()
Description copied from class: Value
Indicates the escaping that was applied to the expression represented by this value.

May be checked by the JSilver code before applying autoescaping. It differs from isEscaped, which is true iff any part of the variable expression contains an escaping function, even if the entire expression has not been escaped. Both methods are required, isEscaped to determine whether <?cs escape > commands should be applied, and getEscapeMode for autoescaping. This is done to maintain compatibility with ClearSilver's behaviour.

Overrides:
getEscapeMode in class Value
Returns:
EscapeMode.ESCAPE_IS_CONSTANT if the value represents a constant string literal. Or the appropriate EscapeMode if the value is the output of an escaping function.
See Also:
EscapeMode

asBoolean

public boolean asBoolean()
Description copied from class: Value
Fetch value as boolean. All non empty strings and numbers != 0 are treated as true.

Specified by:
asBoolean in class Value

asString

public String asString()
Description copied from class: Value
Fetch value as string.

Specified by:
asString in class Value

asNumber

public int asNumber()
Description copied from class: Value
Fetch value as number. If number is not parseable, 0 is returned (this is consistent with ClearSilver).

Specified by:
asNumber in class Value

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in class Value


Copyright © 2010-2012 Google. All Rights Reserved.