com.google.clearsilver.jsilver.data
Class TypeConverter

java.lang.Object
  extended by com.google.clearsilver.jsilver.data.TypeConverter

public class TypeConverter
extends Object

Static methods for converting stuff in a ClearSilver compatible way.


Method Summary
static boolean asBoolean(Data data)
          Helper method to safely convert an arbitrary data instance (including null) into a valid boolean representation.
static boolean asBoolean(String value)
          Parses and returns the given string as a boolean in a ClearSilver compatible way.
static int asNumber(Data data)
          Helper method to safely convert an arbitrary data instance (including null) into a valid integer representation.
static int asNumber(String value)
          Parses and returns the given string as an integer in a ClearSilver compatible way.
static String asString(Data data)
          Helper method to safely convert an arbitrary data instance (including null) into a valid (non-null) string representation.
static boolean exists(Data data)
          Determines if the given data node exists in a ClearSilver compatible way.
static int parseNumber(String value)
          Parses a non-null string in a ClearSilver compatible way.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

exists

public static boolean exists(Data data)
Determines if the given data node exists in a ClearSilver compatible way.


asString

public static String asString(Data data)
Helper method to safely convert an arbitrary data instance (including null) into a valid (non-null) string representation.


parseNumber

public static int parseNumber(String value)
                       throws NumberFormatException
Parses a non-null string in a ClearSilver compatible way. The is the underlying parsing function which can fail for badly formatted strings. It is really important that anyone doing parsing of strings calls this function (rather than doing it themselves). This is an area where JSilver and ClearSilver have some notable differences. ClearSilver relies on the template compiler to parse strings in the template and a different parser at runtime for HDF values. JSilver uses the same code for both cases. In ClearSilver HDF: Numbers are parsed sequentially and partial results are returned when an invalid character is reached. This means that "123abc" parses to 123. Additionally, ClearSilver doesn't do hex in HDF values, so "a.b=0x123" will just resolve to 0. In ClearSilver templates: Hex is supported, including negative values. In JSilver: A string must be a complete, valid numeric value for parsing. This means "123abc" is invalid and will default to 0. In JSilver: Positive hex values are supported for both HDF and templates but negative values aren't. This means a template containing something like "" will parse correctly but fail to render.

Throws:
NumberFormatException - is the string is badly formatted

asNumber

public static int asNumber(String value)
Parses and returns the given string as an integer in a ClearSilver compatible way.


asNumber

public static int asNumber(Data data)
Helper method to safely convert an arbitrary data instance (including null) into a valid integer representation.


asBoolean

public static boolean asBoolean(String value)
Parses and returns the given string as a boolean in a ClearSilver compatible way.


asBoolean

public static boolean asBoolean(Data data)
Helper method to safely convert an arbitrary data instance (including null) into a valid boolean representation.



Copyright © 2010-2012 Google. All Rights Reserved.