com.taursys.dom
Class DOM_1_20000929_DocumentAdapter

java.lang.Object
  extended bycom.taursys.dom.DOM_1_20000929_DocumentAdapter
All Implemented Interfaces:
DocumentAdapter
Direct Known Subclasses:
DOM_2_20001113_DocumentAdapter

public class DOM_1_20000929_DocumentAdapter
extends java.lang.Object
implements DocumentAdapter

DocumentAdapter for DOM version 1 09/29/2000


Constructor Summary
DOM_1_20000929_DocumentAdapter(java.lang.Object newDoc)
          Constructs a new DOM_1_20000929_DocumentAdapter for given document.
 
Method Summary
protected  AbstractWriter createDefaultWriter()
          Creates the default AbstractWriter for this subcomponent.
static org.w3c.dom.Text findFirstTextNode(org.w3c.dom.Element ele)
          Returns first TEXT_NODE under given element else returns null
static java.lang.String getAttribute(java.lang.String attributeName, org.w3c.dom.Node node)
          Extracts the named attribute value from the node.
 org.w3c.dom.Document getDocument()
          Returns the Document/adaptee of this DocumentAdapter
 org.w3c.dom.Element getElementById(java.lang.String elementId)
          Returns the Element for the given mapped identifier else null if not found.
static java.lang.String getElementText(org.w3c.dom.Element element)
          Get the text from the given Element's text node.
 java.util.Hashtable getIdentifierMap()
          Returns a Hashtable of id's and their cooresponding Elements for this document.
 AbstractWriter getXMLWriter()
          Get the AbstractWriter used to render this document to a stream or writer.
static boolean hasChildElements(org.w3c.dom.Element parent)
          Indicates whether or not the given Element has child Elements.
 void importContents(DocumentAdapter sourceAdapter, java.lang.String sourceId, java.lang.String destId)
          Import the contents from the given sourceAdapter at the sourceId and replace the contents of the destId in this DocumentAdapter.
protected  void mapIdentifiers(org.w3c.dom.Node parent)
          Recursively maps all the identifiers for the given document starting at the given node
 void removeAttribute(java.lang.String elementId, java.lang.String attribute)
          Removes the given attribute from the element identified by the given id Does nothing if the id is not found.
 void setAttributeText(java.lang.String elementId, java.lang.String attribute, java.lang.String value)
          Stores given value as a text attribute of the element identified by the given id Does nothing if the id is not found.
 void setDocument(org.w3c.dom.Document newDoc)
          Sets the Document/adaptee for this DocumentAdapter.
static void setElementText(org.w3c.dom.Element element, java.lang.String value)
          Stores the given value as a text node of the given element.
 void setElementText(java.lang.String elementId, java.lang.String value)
          Sets the Text of the Element indicated by the given id to the given value.
 void setXMLWriter(AbstractWriter newXMLWriter)
          Set the AbstractWriter used to render this document to a stream or writer.
 void write(java.io.OutputStream stream)
          Write the document to the given OutputStream.
 void write(java.io.Writer writer)
          Write the document to the given Writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOM_1_20000929_DocumentAdapter

public DOM_1_20000929_DocumentAdapter(java.lang.Object newDoc)
Constructs a new DOM_1_20000929_DocumentAdapter for given document. Also maps all the identifiers for this document

Method Detail

createDefaultWriter

protected AbstractWriter createDefaultWriter()
Creates the default AbstractWriter for this subcomponent. This implementation creates a com.taursys.dom HTMLWriter if the current Document is an HTML document, otherwise it creates a com.taursys.dom.XMLWriter. You can override this method to create your own default AbstractWriter.


mapIdentifiers

protected void mapIdentifiers(org.w3c.dom.Node parent)
Recursively maps all the identifiers for the given document starting at the given node


write

public void write(java.io.OutputStream stream)
Write the document to the given OutputStream.

Specified by:
write in interface DocumentAdapter
Parameters:
stream - to render the document to

write

public void write(java.io.Writer writer)
Write the document to the given Writer.

Specified by:
write in interface DocumentAdapter
Parameters:
writer - to render the document to

setXMLWriter

public void setXMLWriter(AbstractWriter newXMLWriter)
Set the AbstractWriter used to render this document to a stream or writer. The default is XMLWriter.

Parameters:
newXMLWriter - the AbstractWriter used to render this document

getXMLWriter

public AbstractWriter getXMLWriter()
Get the AbstractWriter used to render this document to a stream or writer. The default is XMLWriter.

Returns:
the AbstractWriter used to render this document

setElementText

public void setElementText(java.lang.String elementId,
                           java.lang.String value)
Sets the Text of the Element indicated by the given id to the given value. Does nothing if the id is not found. If the given value is null, it renders the attribute as blank ("").

Specified by:
setElementText in interface DocumentAdapter

setAttributeText

public void setAttributeText(java.lang.String elementId,
                             java.lang.String attribute,
                             java.lang.String value)
Stores given value as a text attribute of the element identified by the given id Does nothing if the id is not found. If the given value is null, it renders the attribute as blank ("").

Specified by:
setAttributeText in interface DocumentAdapter

removeAttribute

public void removeAttribute(java.lang.String elementId,
                            java.lang.String attribute)
Removes the given attribute from the element identified by the given id Does nothing if the id is not found.

Specified by:
removeAttribute in interface DocumentAdapter

importContents

public void importContents(DocumentAdapter sourceAdapter,
                           java.lang.String sourceId,
                           java.lang.String destId)
                    throws DocumentAdapterException
Import the contents from the given sourceAdapter at the sourceId and replace the contents of the destId in this DocumentAdapter. All the child contents of the sourceId are copied (not including the element with the sourceId). The id's are then re-mapped for this document.

Specified by:
importContents in interface DocumentAdapter
Parameters:
sourceAdapter - the source DocumentAdapter for the import
sourceId - the parent element to import contents from
destId - the parent element to import the contents to
Throws:
java.lang.IllegalArgumentException - if any arguments are null
DocumentAdapterException - if sourceId or destId is invalid

getDocument

public org.w3c.dom.Document getDocument()
Returns the Document/adaptee of this DocumentAdapter

Specified by:
getDocument in interface DocumentAdapter

setDocument

public void setDocument(org.w3c.dom.Document newDoc)
Sets the Document/adaptee for this DocumentAdapter. Also maps the identifiers for this document.


getElementById

public org.w3c.dom.Element getElementById(java.lang.String elementId)
Returns the Element for the given mapped identifier else null if not found.

Specified by:
getElementById in interface DocumentAdapter

getIdentifierMap

public java.util.Hashtable getIdentifierMap()
Returns a Hashtable of id's and their cooresponding Elements for this document. This is built by mapIdentifiers method.

Specified by:
getIdentifierMap in interface DocumentAdapter
Returns:
a Hashtable of id's and their cooresponding Elements

getAttribute

public static java.lang.String getAttribute(java.lang.String attributeName,
                                            org.w3c.dom.Node node)
Extracts the named attribute value from the node. Returns value or null.


setElementText

public static void setElementText(org.w3c.dom.Element element,
                                  java.lang.String value)
Stores the given value as a text node of the given element. If the element already has a text node, the value is stored in that node, otherwise a new text node is created with the given value and attached to the element.


getElementText

public static java.lang.String getElementText(org.w3c.dom.Element element)
Get the text from the given Element's text node.

Parameters:
element - the element to get the text from
Returns:
the text from the given Element's text node or null.

findFirstTextNode

public static org.w3c.dom.Text findFirstTextNode(org.w3c.dom.Element ele)
Returns first TEXT_NODE under given element else returns null


hasChildElements

public static boolean hasChildElements(org.w3c.dom.Element parent)
Indicates whether or not the given Element has child Elements.

Returns:
true if has children else false


Copyright © 2007 Martin T Phelan. All Rights Reserved.