com.google.clearsilver.jsilver.data
Class DelegatedData

java.lang.Object
  extended by com.google.clearsilver.jsilver.data.DelegatedData
All Implemented Interfaces:
Data
Direct Known Subclasses:
ChainedData, UnmodifiableData

public class DelegatedData
extends Object
implements Data

Class that wraps a Data object and exports the same interface. Useful for extending the capabilities of an existing implementation.


Nested Class Summary
protected  class DelegatedData.DelegatedIterator
          Wrapping implementation of iterator that makes sure any Data object returned by the underlying iterator is wrapped with the right DelegatedData type.
 
Constructor Summary
DelegatedData(Data delegate)
           
 
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.
protected  Data getDelegate()
           
 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?
protected  Iterator<DelegatedData> newChildIterator()
          Subclasses can override this method to return specialized child iterators.
protected  DelegatedData newInstance(Data newDelegate)
          Subclasses will want to override this method to return a Data object of their specific type.
 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)
           
protected static Data unwrap(Data data)
           
 void write(Appendable out, int indent)
          Write out the String representation of this HDF node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DelegatedData

public DelegatedData(Data delegate)
Method Detail

newInstance

protected DelegatedData newInstance(Data newDelegate)
Subclasses will want to override this method to return a Data object of their specific type.

Parameters:
newDelegate - the Data object to wrap with a new delegator
Returns:
a DelegateData type or subclass.

getDelegate

protected Data getDelegate()

unwrap

protected static Data unwrap(Data data)

getName

public String getName()
Description copied from interface: Data
Returns the name of this HDF node. The root node has no name, so calling this on the root node will return null.

Specified by:
getName in interface Data

getValue

public String getValue()
Description copied from interface: Data
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.

Specified by:
getValue in interface Data

getIntValue

public int getIntValue()
Description copied from interface: Data
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.

Specified by:
getIntValue in interface Data

getBooleanValue

public boolean getBooleanValue()
Description copied from interface: Data
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.

Specified by:
getBooleanValue in interface Data

setValue

public void setValue(String value)
Description copied from interface: Data
Set the value of this node. Any symlink that may have been set for this node will be replaced.

Specified by:
setValue in interface Data

getFullPath

public String getFullPath()
Description copied from interface: Data
Returns the full path to this node via its parent links.

Specified by:
getFullPath in interface Data

setAttribute

public void setAttribute(String key,
                         String value)
Description copied from interface: Data
Sets an attribute key and value on the current node, replacing any existing value.

Specified by:
setAttribute in interface Data
Parameters:
key - the name of the attribute to add/modify.
value - the value to assign it. Value of null will clear the attribute.

getAttribute

public String getAttribute(String key)
Description copied from interface: Data
Returns the value of the node attribute with the given name, or null if there is no value.

Specified by:
getAttribute in interface Data

hasAttribute

public boolean hasAttribute(String key)
Description copied from interface: Data
Returns true if the node contains an attribute with the given name, false otherwise.

Specified by:
hasAttribute in interface Data

getAttributeCount

public int getAttributeCount()
Description copied from interface: Data
Returns the number of attributes on this node.

Specified by:
getAttributeCount in interface Data

getAttributes

public Iterable<Map.Entry<String,String>> getAttributes()
Description copied from interface: Data
Returns an iterable collection of attribute name/value pairs.

Specified by:
getAttributes in interface Data
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

public Data getRoot()
Description copied from interface: Data
Return the root of the tree where the current node lies. If the current node is the root, return this.

Specified by:
getRoot in interface Data

getParent

public Data getParent()
Description copied from interface: Data
Get the parent node.

Specified by:
getParent in interface Data

isFirstSibling

public boolean isFirstSibling()
Description copied from interface: Data
Is this the first of its siblings?

Specified by:
isFirstSibling in interface Data

isLastSibling

public boolean isLastSibling()
Description copied from interface: Data
Is this the last of its siblings?

Specified by:
isLastSibling in interface Data

getNextSibling

public Data getNextSibling()
Description copied from interface: Data
Retrieves the node representing the next sibling of this Data node, if any.

Specified by:
getNextSibling in interface Data
Returns:
the next sibling Data object or null if this is the last sibling.

getChildCount

public int getChildCount()
Description copied from interface: Data
Returns number of child nodes.

Specified by:
getChildCount in interface Data

newChildIterator

protected Iterator<DelegatedData> newChildIterator()
Subclasses can override this method to return specialized child iterators. For example, if they don't want to support the remove() operation.

Returns:
Iterator of children of delegate Data object that returns wrapped Data nodes.

getChildren

public Iterable<? extends Data> getChildren()
Description copied from interface: Data
Returns children of this node.

Specified by:
getChildren in interface Data

getChild

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

Specified by:
getChild in interface Data

createChild

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

Specified by:
createChild in interface Data

removeTree

public void removeTree(String path)
Description copied from interface: Data
Remove the specified subtree.

Specified by:
removeTree in interface Data

setSymlink

public void setSymlink(String sourcePath,
                       String destinationPath)
Description copied from interface: Data
Set the source node to be a symbolic link to the destination.

Specified by:
setSymlink in interface Data

setSymlink

public void setSymlink(String sourcePath,
                       Data destination)
Description copied from interface: Data
Set the source node to be a symbolic link to the destination.

Specified by:
setSymlink in interface Data

setSymlink

public void setSymlink(Data symLink)
Description copied from interface: Data
Set this node to be a symbolic link to another node.

Specified by:
setSymlink in interface Data

getSymlink

public Data getSymlink()
Description copied from interface: Data
Retrieve the symbolic link this node points to. Will return reference to self if not a symlink.

Specified by:
getSymlink in interface Data

copy

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

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

copy

public void copy(Data from)
Description copied from interface: Data
Does a deep copy the attributes and values from one node to another

Specified by:
copy in interface Data
Parameters:
from - Data object whose value should be copied over.

getValue

public String getValue(String path,
                       String defaultValue)
Description copied from interface: Data
Retrieves the value at the specified path in this HDF node's subtree.

Specified by:
getValue in interface Data

getIntValue

public int getIntValue(String path,
                       int defaultValue)
Description copied from interface: Data
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.

Specified by:
getIntValue in interface Data

getValue

public String getValue(String path)
Description copied from interface: Data
Retrieves the value at the specified path in this HDF node's subtree. If not found, returns null.

Specified by:
getValue in interface Data

getIntValue

public int getIntValue(String path)
Description copied from interface: Data
Retrieves the value at the specified path in this HDF node's subtree. If not found or invalid, returns 0.

Specified by:
getIntValue in interface Data

getBooleanValue

public boolean getBooleanValue(String path)
Description copied from interface: Data
Retrieves the value at the specified path in this HDF node's subtree. If not found or invalid, returns false.

Specified by:
getBooleanValue in interface Data

setValue

public void setValue(String path,
                     String value)
Description copied from interface: Data
Sets the value at the specified path in this HDF node's subtree.

Specified by:
setValue in interface Data

toString

public String toString()
Specified by:
toString in interface Data
Overrides:
toString in class Object

toString

public void toString(StringBuilder out,
                     int indent)
Specified by:
toString in interface Data

write

public void write(Appendable out,
                  int indent)
           throws IOException
Description copied from interface: Data
Write out the String representation of this HDF node.

Specified by:
write in interface Data
Throws:
IOException

optimize

public void optimize()
Description copied from interface: Data
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.

Specified by:
optimize in interface Data

setEscapeMode

public void setEscapeMode(EscapeMode mode)
Description copied from interface: Data
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.

Specified by:
setEscapeMode in interface Data
See Also:
Data.getEscapeMode()

getEscapeMode

public EscapeMode getEscapeMode()
Description copied from interface: Data
Indicates the escaping, if any that was applied to this HDF node.

Specified by:
getEscapeMode in interface Data
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:
Data.setEscapeMode(com.google.clearsilver.jsilver.autoescape.EscapeMode), EscapeMode


Copyright © 2010-2012 Google. All Rights Reserved.