com.topcoder.shared.problem
Class NodeElement

java.lang.Object
  |
  +--com.topcoder.shared.problem.BaseElement
        |
        +--com.topcoder.shared.problem.NodeElement
All Implemented Interfaces:
java.lang.Cloneable, com.topcoder.shared.netCommon.CustomSerializable, Element, java.io.Serializable

public class NodeElement
extends com.topcoder.shared.problem.BaseElement
implements Element

A NodeElement represents an XML element. It has a name, a (possibly empty) set of attributes, and a sequence of children that consists of any number of Elements. This structure is necessary so that we do not lose the structure of writer-submitted text, so that we can treat the type element properly, for instance.

See Also:
Serialized Form

Constructor Summary
NodeElement()
          Empty constructor required by custom serialization.
NodeElement(java.lang.String name, java.util.HashMap attributes, java.util.ArrayList children, java.lang.String text)
          Creates the node from the given information.
 
Method Summary
 void customReadObject(com.topcoder.shared.netCommon.CSReader reader)
          Custom serialization
 void customWriteObject(com.topcoder.shared.netCommon.CSWriter writer)
          Custom serialization
static java.lang.String encodeHTML(java.lang.String text)
          Utility function for encoding HTML entities in text.
 java.util.HashMap getAttributes()
          Returns the attributes of the node (which may be empty).
 java.util.ArrayList getChildren()
          Returns the children of the node (which may be empty).
 java.lang.String getName()
          Returns the name of the node.
 ElementRenderer getRenderer()
          Returns this elements renderer.
 java.lang.String getText()
          Returns the text for the node.
 void setRenderer(ElementRenderer renderer)
          Sets the renderer for this element.
 java.lang.String toXML()
          Returns the node represented in XML format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.topcoder.shared.problem.Element
getRenderer, setRenderer
 

Constructor Detail

NodeElement

public NodeElement()
Empty constructor required by custom serialization.


NodeElement

public NodeElement(java.lang.String name,
                   java.util.HashMap attributes,
                   java.util.ArrayList children,
                   java.lang.String text)
Creates the node from the given information.

Parameters:
name - The name of the element.
attributes - A mapping of attribute names to attribute values.
children - A sequence of elements that are children of the element.
text - An XML fragment corresponding to the content of this element.
Method Detail

customWriteObject

public void customWriteObject(com.topcoder.shared.netCommon.CSWriter writer)
                       throws java.io.IOException
Custom serialization

Specified by:
customWriteObject in interface Element
Parameters:
writer - the writer to write to.
Throws:
java.io.IOException - if an I/O error has occurred in the stream that backs the writer.

customReadObject

public void customReadObject(com.topcoder.shared.netCommon.CSReader reader)
                      throws java.io.IOException,
                             java.io.ObjectStreamException
Custom serialization

Specified by:
customReadObject in interface Element
Parameters:
reader - the reader to read from.
Throws:
java.io.ObjectStreamException - if the information that is read is inconsistent (stream corrupted or incompatibility between writers and readers)
java.io.IOException - if an I/O error has occurred in the stream that backs the reader.

getText

public java.lang.String getText()
Returns the text for the node.

Returns:
the text for the node.

getAttributes

public java.util.HashMap getAttributes()
Returns the attributes of the node (which may be empty).

Returns:
the attributes of the node (which may be empty).

getName

public java.lang.String getName()
Returns the name of the node.

Returns:
the name of the node.

getChildren

public java.util.ArrayList getChildren()
Returns the children of the node (which may be empty).

Returns:
the children of the node (which may be empty).

toXML

public java.lang.String toXML()
Returns the node represented in XML format. Formatted like: <name attributekey="encoded attribute value">children.toXML</name>

Specified by:
toXML in interface Element
Returns:
the node represented in XML format.

setRenderer

public void setRenderer(ElementRenderer renderer)
Sets the renderer for this element.

Specified by:
setRenderer in interface Element
Parameters:
renderer - the element renderer.
See Also:
ElementRenderer

getRenderer

public ElementRenderer getRenderer()
Returns this elements renderer.

Specified by:
getRenderer in interface Element
Returns:
this elements renderer.
See Also:
ElementRenderer

encodeHTML

public static java.lang.String encodeHTML(java.lang.String text)
Utility function for encoding HTML entities in text. All occurrences of the <, >, and & characters are converted to &lt;, &gt;, and &amp;, respectively.

Parameters:
text - the text to encode.
Returns:
the encoded text.