com.google.clearsilver.jsilver.values
Class Value

java.lang.Object
  extended by com.google.clearsilver.jsilver.values.Value
Direct Known Subclasses:
VariableValue

public abstract class Value
extends Object

Dynamic typing system used by JSilver interpreter. A value (e.g. "2") can act as a string, integer and boolean. Values can be literal or references to variables held elsewhere (e.g. in external data structures such as HDF).


Constructor Summary
Value(EscapeMode escapeMode, boolean partiallyEscaped)
           
 
Method Summary
abstract  boolean asBoolean()
          Fetch value as boolean.
abstract  int asNumber()
          Fetch value as number.
abstract  String asString()
          Fetch value as string.
 boolean equals(Object other)
           
abstract  boolean exists()
          Whether this value exists.
 EscapeMode getEscapeMode()
          Indicates the escaping that was applied to the expression represented by this value.
 int hashCode()
           
abstract  boolean isEmpty()
           
 boolean isPartiallyEscaped()
           
static Value literalConstant(boolean value, Value... inputs)
          Create a literal value using a boolean with a escapeMode of EscapeMode.ESCAPE_IS_CONSTANT and partiallyEscaped based on the partiallyEscaped values of the inputs.
static Value literalConstant(int value, Value... inputs)
          Create a literal value using an int with a escapeMode of EscapeMode.ESCAPE_IS_CONSTANT and partiallyEscaped based on the partiallyEscaped values of the inputs.
static Value literalConstant(String value, Value... inputs)
          Create a literal value using a string with a escapeMode of EscapeMode.ESCAPE_IS_CONSTANT and partiallyEscaped based on the partiallyEscaped values of the inputs.
static Value literalValue(boolean value, EscapeMode mode, boolean partiallyEscaped)
          Create a literal value using a boolean.
static Value literalValue(int value, EscapeMode mode, boolean partiallyEscaped)
          Create a literal value using an int.
static Value literalValue(String value, EscapeMode mode, boolean partiallyEscaped)
          Create a literal value using a String.
 String toString()
           
static Value variableValue(String name, DataContext dataContext)
          Create a value linked to a variable name.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Value

public Value(EscapeMode escapeMode,
             boolean partiallyEscaped)
Method Detail

asBoolean

public abstract boolean asBoolean()
Fetch value as boolean. All non empty strings and numbers != 0 are treated as true.


asString

public abstract String asString()
Fetch value as string.


asNumber

public abstract int asNumber()
Fetch value as number. If number is not parseable, 0 is returned (this is consistent with ClearSilver).


exists

public abstract boolean exists()
Whether this value exists. Literals always return true, but variable references will return false if the value behind it is null.


isEmpty

public abstract boolean isEmpty()

literalValue

public static Value literalValue(int value,
                                 EscapeMode mode,
                                 boolean partiallyEscaped)
Create a literal value using an int.


literalValue

public static Value literalValue(String value,
                                 EscapeMode mode,
                                 boolean partiallyEscaped)
Create a literal value using a String.


literalValue

public static Value literalValue(boolean value,
                                 EscapeMode mode,
                                 boolean partiallyEscaped)
Create a literal value using a boolean.


literalConstant

public static Value literalConstant(int value,
                                    Value... inputs)
Create a literal value using an int with a escapeMode of EscapeMode.ESCAPE_IS_CONSTANT and partiallyEscaped based on the partiallyEscaped values of the inputs.

Parameters:
value - integer value of the literal
inputs - Values that were used to compute the integer value.

literalConstant

public static Value literalConstant(String value,
                                    Value... inputs)
Create a literal value using a string with a escapeMode of EscapeMode.ESCAPE_IS_CONSTANT and partiallyEscaped based on the partiallyEscaped values of the inputs.

Parameters:
value - String value of the literal
inputs - Values that were used to compute the string value.

literalConstant

public static Value literalConstant(boolean value,
                                    Value... inputs)
Create a literal value using a boolean with a escapeMode of EscapeMode.ESCAPE_IS_CONSTANT and partiallyEscaped based on the partiallyEscaped values of the inputs.

Parameters:
value - boolean value of the literal
inputs - Values that were used to compute the boolean value.

variableValue

public static Value variableValue(String name,
                                  DataContext dataContext)
Create a value linked to a variable name.

Parameters:
name - The pathname of the variable relative to the given DataContext
dataContext - The DataContext defining the scope and Data objects to use when dereferencing the name.
Returns:
A Value object that allows access to the variable name, the variable Data object (if it exists) and to the value of the variable.

equals

public boolean equals(Object other)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

isPartiallyEscaped

public boolean isPartiallyEscaped()

getEscapeMode

public EscapeMode getEscapeMode()
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.

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


Copyright © 2010-2012 Google. All Rights Reserved.