com.icesoft.faces.context
Class DOMContext

java.lang.Object
  extended bycom.icesoft.faces.context.DOMContext
All Implemented Interfaces:
java.io.Serializable

public class DOMContext
extends java.lang.Object
implements java.io.Serializable

DOMContext provides a component specific interface to the DOM renderer

See Also:
Serialized Form

Constructor Summary
protected DOMContext(com.icesoft.faces.context.DOMResponseWriter writer, org.w3c.dom.Document document, org.w3c.dom.Element parentElement)
          Construct a new DOMContext with the specified arguments
 
Method Summary
static DOMContext attachDOMContext(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent component)
          This method returns the DOMContext associated with the specified component
 org.w3c.dom.Element createElement(java.lang.String name)
          Creates an element of the type specified.
 org.w3c.dom.Element createRootElement(java.lang.String name)
           Creates an element of the type specified.
 org.w3c.dom.Text createTextNode(java.lang.String cData)
           Creates a Text node given the specified string.
static java.util.List findChildrenWithNodeName(org.w3c.dom.Element root, java.lang.String nodeName)
           
 org.w3c.dom.Node getCursor()
          Get the position in the document where the next DOM node will be rendererd.
 org.w3c.dom.Node getCursorParent()
          Get the position in the document where the next DOM node will be rendererd.
 org.w3c.dom.Document getDocument()
          Retrieve the org.w3c.dom.Document instance associated with this DOMContext
static DOMContext getDOMContext(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent component)
          Get the DOMContext associated with the component.
 org.w3c.dom.Node getRootNode()
          Get the rootNode member variable.
 boolean isInitialized()
          Determine whether this instance is initialized.
 boolean isStreamWriting()
          Convenience method used by renderers to determine if Stream writing is enabled.
static void removeChildren(org.w3c.dom.Node parent)
          Remove all children from Node parent
static void removeChildrenByTagName(org.w3c.dom.Element rootElement, java.lang.String name)
          Removes from the root element all children with node name equal to the nodeName parameter
 void setCursor(org.w3c.dom.Node cursor)
          Set the position in the document where the next DOM node will be rendererd.
 void setCursorParent(org.w3c.dom.Node cursorParent)
          Set the position at which the next rendered node will be appended
 void setInitialized(boolean initialized)
          Need to reset when not rendered
 void setRootNode(org.w3c.dom.Node rootNode)
           Set the rootNode member variable to the parameter Node.
 void stepInto(javax.faces.component.UIComponent component)
          Maintain the cursor and cursorParent such that the next rendered component will be rendered as a child of the parameter component.
 void stepOver()
          Maintain the cursor and cursorParent position; step to the position where the next sibling should be rendered.
 void streamWrite(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent component)
          Convenience method for streamWrite(facesContext, component, this.rootNode, null).
 void streamWrite(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent component, org.w3c.dom.Node root, org.w3c.dom.Node halter)
          Writes the DOM subtree anchored at root to the current ResponseWriter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMContext

protected DOMContext(com.icesoft.faces.context.DOMResponseWriter writer,
                     org.w3c.dom.Document document,
                     org.w3c.dom.Element parentElement)

Construct a new DOMContext with the specified arguments

Parameters:
writer - The response writer for this context
document - the Document associated with this context
parentElement - the parent Element for this context
Method Detail

isInitialized

public boolean isInitialized()

Determine whether this instance is initialized. An initialized instance is guaranteed to have a root node.

Returns:
boolean reflecting whether this instance is initialized.

setInitialized

public void setInitialized(boolean initialized)
Need to reset when not rendered

Parameters:
initialized -

attachDOMContext

public static DOMContext attachDOMContext(javax.faces.context.FacesContext facesContext,
                                          javax.faces.component.UIComponent component)

This method returns the DOMContext associated with the specified component

Parameters:
facesContext - an instance of FacesContext associated with the lifecycle
component - component associated with this DOMContext
Returns:
the attached DOMContext

getDOMContext

public static DOMContext getDOMContext(javax.faces.context.FacesContext facesContext,
                                       javax.faces.component.UIComponent component)

Get the DOMContext associated with the component. Do not attach the DOMContext instance to its parent element.

Parameters:
facesContext -
component - the UIComponent instance whose DOMContext we are retrieving
Returns:
DOMContext

createElement

public org.w3c.dom.Element createElement(java.lang.String name)

Creates an element of the type specified. Note that the instance returned implements the Element interface, so attributes can be specified directly on the returned object.
In addition, if there are known attributes with default values, Attr nodes representing them are automatically created and attached to the element.

Parameters:
name - the specified Element type to create
Returns:
the created element

createTextNode

public org.w3c.dom.Text createTextNode(java.lang.String cData)

Creates a Text node given the specified string.

Returns:
The new Text object.

setRootNode

public void setRootNode(org.w3c.dom.Node rootNode)

Set the rootNode member variable to the parameter Node.

Parameters:
rootNode -

createRootElement

public org.w3c.dom.Element createRootElement(java.lang.String name)

Creates an element of the type specified. Note that the instance returned implements the Element interface, so attributes can be specified directly on the returned object.
In addition, if there are known attributes with default values, Attr nodes representing them are automatically created and attached to the element. Set the rootNode member variable of this instance to the newly-created Element.

Parameters:
name -
Returns:

getRootNode

public org.w3c.dom.Node getRootNode()

Get the rootNode member variable.

Returns:
rootNode the root node of this DOMContext instance

setCursor

public void setCursor(org.w3c.dom.Node cursor)
Set the position in the document where the next DOM node will be rendererd.

Parameters:
cursor -

getCursor

public org.w3c.dom.Node getCursor()
Get the position in the document where the next DOM node will be rendererd.


setCursorParent

public void setCursorParent(org.w3c.dom.Node cursorParent)
Set the position at which the next rendered node will be appended

Parameters:
cursorParent -

getCursorParent

public org.w3c.dom.Node getCursorParent()
Get the position in the document where the next DOM node will be rendererd.


stepOver

public void stepOver()
Maintain the cursor and cursorParent position; step to the position where the next sibling should be rendered.


stepInto

public void stepInto(javax.faces.component.UIComponent component)
Maintain the cursor and cursorParent such that the next rendered component will be rendered as a child of the parameter component.

Parameters:
component -

getDocument

public org.w3c.dom.Document getDocument()
Retrieve the org.w3c.dom.Document instance associated with this DOMContext

Returns:

removeChildren

public static void removeChildren(org.w3c.dom.Node parent)
Remove all children from Node parent


removeChildrenByTagName

public static void removeChildrenByTagName(org.w3c.dom.Element rootElement,
                                           java.lang.String name)
Removes from the root element all children with node name equal to the nodeName parameter

Parameters:
rootElement -
name -

findChildrenWithNodeName

public static java.util.List findChildrenWithNodeName(org.w3c.dom.Element root,
                                                      java.lang.String nodeName)

streamWrite

public void streamWrite(javax.faces.context.FacesContext facesContext,
                        javax.faces.component.UIComponent component,
                        org.w3c.dom.Node root,
                        org.w3c.dom.Node halter)
                 throws java.io.IOException

Writes the DOM subtree anchored at root to the current ResponseWriter. Serialization is halted at the node halter (writing only the opening tag) and will be resumed from this node on the next call to this function.

Parameters:
facesContext - current FacesContext
component - JSF component being rendered
root - node indicating subtree of DOM to eventually serialize
halter - node upon which to halt serialization on this pass
Throws:
java.io.IOException

streamWrite

public void streamWrite(javax.faces.context.FacesContext facesContext,
                        javax.faces.component.UIComponent component)
                 throws java.io.IOException

Convenience method for streamWrite(facesContext, component, this.rootNode, null).

Parameters:
facesContext - current FacesContext
component - JSF component being rendered
Throws:
java.io.IOException

isStreamWriting

public boolean isStreamWriting()

Convenience method used by renderers to determine if Stream writing is enabled.