com.google.clearsilver.jsilver.data
Interface Data

All Known Implementing Classes:
AbstractData, ChainedData, DefaultData, DelegatedData, LocalAndGlobalData, NestedMapData, UnmodifiableData

public interface Data

Represents a hierarchical data set of primitives. This is the JSilver equivalent to ClearSilver's HDF object.


Method Summary
 void copy(Data from)
          Does a deep copy the attributes and values from one node to another
 void copy(String toPath, Data from)
          Does a deep copy of the attributes and values from one node to another.
 Data createChild(String path)
          Retrieves the HDF object that is the root of the subtree at hdfpath, create the subtree if it doesn't exist
 String getAttribute(String key)
          Returns the value of the node attribute with the given name, or null if there is no value.
 int getAttributeCount()
          Returns the number of attributes on this node.
 Iterable<Map.Entry<String,String>> getAttributes()
          Returns an iterable collection of attribute name/value pairs.
 boolean getBooleanValue()
          Returns the boolean value of this HDF node, or false if this node has no value.
 boolean getBooleanValue(String path)
          Retrieves the value at the specified path in this HDF node's subtree.
 Data getChild(String path)
          Retrieves the object that is the root of the subtree at hdfpath, returning null if the subtree doesn't exist
 int getChildCount()
          Returns number of child nodes.
 Iterable<? extends Data> getChildren()
          Returns children of this node.
 EscapeMode getEscapeMode()
          Indicates the escaping, if any that was applied to this HDF node.
 String getFullPath()
          Returns the full path to this node via its parent links.
 int getIntValue()
          Returns the integer value of this HDF node, or 0 if this node has no value.
 int getIntValue(String path)
          Retrieves the value at the specified path in this HDF node's subtree.
 int getIntValue(String path, int defaultValue)
          Retrieves the integer value at the specified path in this HDF node's subtree.
 String getName()
          Returns the name of this HDF node.
 Data getNextSibling()
          Retrieves the node representing the next sibling of this Data node, if any.
 Data getParent()
          Get the parent node.
 Data getRoot()
          Return the root of the tree where the current node lies.
 Data getSymlink()
          Retrieve the symbolic link this node points to.
 String getValue()
          Returns the value of this HDF node, or null if this node has no value.
 String getValue(String path)
          Retrieves the value at the specified path in this HDF node's subtree.
 String getValue(String path, String defaultValue)
          Retrieves the value at the specified path in this HDF node's subtree.
 boolean hasAttribute(String key)
          Returns true if the node contains an attribute with the given name, false otherwise.
 boolean isFirstSibling()
          Is this the first of its siblings?
 boolean isLastSibling()
          Is this the last of its siblings?
 void optimize()
          Optimizes the Data structure for performance.
 void removeTree(String path)
          Remove the specified subtree.
 void setAttribute(String key, String value)
          Sets an attribute key and value on the current node, replacing any existing value.
 void setEscapeMode(EscapeMode mode)
          Set the escaping that was applied to this HDF node.
 void setSymlink(Data symLink)
          Set this node to be a symbolic link to another node.
 void setSymlink(String sourcePath, Data destination)
          Set the source node to be a symbolic link to the destination.
 void setSymlink(String sourcePath, String destinationPath)
          Set the source node to be a symbolic link to the destination.
 void setValue(String value)
          Set the value of this node.
 void setValue(String path, String value)
          Sets the value at the specified path in this HDF node's subtree.
 String toString()
           
 void toString(StringBuilder out, int indent)
           
 void write(Appendable out, int indent)
          Write out the String representation of this HDF node.
 

Method Detail

getName

String getName()
Returns the name of this HDF node. The root node has no name, so calling this on the root node will return null.


getValue

String getValue()
Returns the value of this HDF node, or null if this node has no value. Every node in the tree can have a value, a child, and a next peer.


getIntValue

int getIntValue()
Returns the integer value of this HDF node, or 0 if this node has no value. Note: The fact that this method returns a primitive type, rather than an Integer means that its value cannot be used to determine whether the data node exists or not. Note also that, when implementing a Data object that caches these values, care must be taken to ensure that a node with an integer value of '0' is not mistaken for a non-existent node.


getBooleanValue

boolean getBooleanValue()
Returns the boolean value of this HDF node, or false if this node has no value. Note: The fact that this method returns a primitive type, rather than a Boolean means that its value cannot be used to determine whether the data node exists or not. Note also that, when implementing a Data object that caches these values, care must be taken to ensure that a node with a boolean value of 'false' is not mistaken for a non-existent node.


setValue

void setValue(String value)
Set the value of this node. Any symlink that may have been set for this node will be replaced.


getFullPath

String getFullPath()
Returns the full path to this node via its parent links.


setAttribute

void setAttribute(String key,
                  String value)
Sets an attribute key and value on the current node, replacing any existing value.

Parameters:
key - the name of the attribute to add/modify.
value - the value to assign it. Value of null will clear the attribute.

getAttribute

String getAttribute(String key)
Returns the value of the node attribute with the given name, or null if there is no value.


hasAttribute

boolean hasAttribute(String key)
Returns true if the node contains an attribute with the given name, false otherwise.


getAttributeCount

int getAttributeCount()
Returns the number of attributes on this node.


getAttributes

Iterable<Map.Entry<String,String>> getAttributes()
Returns an iterable collection of attribute name/value pairs.

Returns:
an object that can be iterated over to get all the attribute name/value pairs. Should return empty iterator if there are no attributes.

getRoot

Data getRoot()
Return the root of the tree where the current node lies. If the current node is the root, return this.


getParent

Data getParent()
Get the parent node.


isFirstSibling

boolean isFirstSibling()
Is this the first of its siblings?


isLastSibling

boolean isLastSibling()
Is this the last of its siblings?


getNextSibling

Data getNextSibling()
Retrieves the node representing the next sibling of this Data node, if any.

Returns:
the next sibling Data object or null if this is the last sibling.

getChildCount

int getChildCount()
Returns number of child nodes.


getChildren

Iterable<? extends Data> getChildren()
Returns children of this node.


getChild

Data getChild(String path)
Retrieves the object that is the root of the subtree at hdfpath, returning null if the subtree doesn't exist


createChild

Data createChild(String path)
Retrieves the HDF object that is the root of the subtree at hdfpath, create the subtree if it doesn't exist


removeTree

void removeTree(String path)
Remove the specified subtree.


setSymlink

void setSymlink(String sourcePath,
                String destinationPath)
Set the source node to be a symbolic link to the destination.


setSymlink

void setSymlink(String sourcePath,
                Data destination)
Set the source node to be a symbolic link to the destination.


setSymlink

void setSymlink(Data symLink)
Set this node to be a symbolic link to another node.


getSymlink

Data getSymlink()
Retrieve the symbolic link this node points to. Will return reference to self if not a symlink.


copy

void copy(String toPath,
          Data from)
Does a deep copy of the attributes and values from one node to another.

Parameters:
toPath - destination path for the deep copy.
from - Data object that should be copied over.

copy

void copy(Data from)
Does a deep copy the attributes and values from one node to another

Parameters:
from - Data object whose value should be copied over.

getValue

String getValue(String path,
                String defaultValue)
Retrieves the value at the specified path in this HDF node's subtree.


getIntValue

int getIntValue(String path,
                int defaultValue)
Retrieves the integer value at the specified path in this HDF node's subtree. If the value does not exist, or cannot be converted to an integer, default_value will be returned.


getValue

String getValue(String path)
Retrieves the value at the specified path in this HDF node's subtree. If not found, returns null.


getIntValue

int getIntValue(String path)
Retrieves the value at the specified path in this HDF node's subtree. If not found or invalid, returns 0.


getBooleanValue

boolean getBooleanValue(String path)
Retrieves the value at the specified path in this HDF node's subtree. If not found or invalid, returns false.


setValue

void setValue(String path,
              String value)
Sets the value at the specified path in this HDF node's subtree.


toString

String toString()
Overrides:
toString in class Object

toString

void toString(StringBuilder out,
              int indent)

write

void write(Appendable out,
           int indent)
           throws IOException
Write out the String representation of this HDF node.

Throws:
IOException

optimize

void optimize()
Optimizes the Data structure for performance. This is a somewhat expensive operation that should improve CPU and/or memory usage for long-lived Data objects. For example, it may internalize all Strings to reduce redundant copies.


getEscapeMode

EscapeMode getEscapeMode()
Indicates the escaping, if any that was applied to this HDF node.

Returns:
EscapeMode that was applied to this node's value. EscapeMode.ESCAPE_NONE if the value is not escaped. EscapeMode.ESCAPE_IS_CONSTANT if value is a string or numeric literal.
See Also:
setEscapeMode(com.google.clearsilver.jsilver.autoescape.EscapeMode), EscapeMode

setEscapeMode

void setEscapeMode(EscapeMode mode)
Set the escaping that was applied to this HDF node. This method may be called by the template renderer, for instance, when a "set" command sets the node to a constant string. It may also be explicitly called if populating the HDF with pre-escaped or trusted values.

See Also:
getEscapeMode()


Copyright © 2010-2012 Google. All Rights Reserved.