Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends
Document Class Reference

#include <dom.h>

Inheritance diagram for Document:
Inheritance graph
[legend]
Collaboration diagram for Document:
Collaboration graph
[legend]

List of all members.

Public Types

enum  NodeType {
  ELEMENT_NODE = 1, ATTRIBUTE_NODE, TEXT_NODE, CDATA_SECTION_NODE,
  ENTITY_REFERENCE_NODE, ENTITY_NODE, PROCESSING_INSTRUCTION_NODE, COMMENT_NODE,
  DOCUMENT_NODE, DOCUMENT_TYPE_NODE, DOCUMENT_FRAGMENT_NODE, NOTATION_NODE
}

Public Member Functions

 Document ()
ElementgetDocumentElement ()
NodecreateComment (const nsAString &aData)
NodecreateDocumentFragment ()
ProcessingInstructioncreateProcessingInstruction (const nsAString &aTarget, const nsAString &aData)
NodecreateTextNode (const nsAString &theData)
ElementcreateElement (const nsAString &tagName)
AttrcreateAttribute (const nsAString &name)
ElementcreateElementNS (const nsAString &aNamespaceURI, const nsAString &aTagName)
AttrcreateAttributeNS (const nsAString &aNamespaceURI, const nsAString &aName)
ElementgetElementById (const nsAString &aID)
NodeappendChild (Node *newChild)
nsresult getBaseURI (nsAString &aURI)
nsresult getNodeName (nsAString &aName) const
nsresult getNodeValue (nsAString &aValue)
unsigned short getNodeType () const
NodegetParentNode () const
NodegetFirstChild () const
NodegetLastChild () const
NodegetPreviousSibling () const
NodegetNextSibling () const
virtual NamedNodeMapgetAttributes ()
DocumentgetOwnerDocument () const
virtual void setNodeValue (const nsAString &nodeValue)
MBool hasChildNodes () const
nsresult getNamespaceURI (nsAString &aNSURI)
virtual MBool getLocalName (nsIAtom **aLocalName)
virtual PRInt32 getNamespaceID ()
virtual PRInt32 lookupNamespaceID (nsIAtom *)
virtual NodegetXPathParent ()
virtual PRInt32 compareDocumentPosition (Node *aOther)
Nodeitem (PRUint32 index)
PRUint32 getLength ()
void appendData (const PRUnichar *aData, int aLength)

Public Attributes

char * function
unsigned count
unsigned hits
Nodenext

Protected Member Functions

NodeDefinitionimplAppendChild (NodeDefinition *newChild)
NodeDefinitionimplRemoveChild (NodeDefinition *oldChild)
void DeleteChildren ()

Protected Attributes

nsString nodeName
nsString nodeValue
PRUint32 length

Private Member Functions

PRBool setElementID (const nsAString &aID, Element *aElement)
 private setter for element ID

Private Attributes

ElementdocumentElement
txIDMap mIDMap
nsString documentBaseURI

Friends

class txXMLParser
class Document
class txXPathTreeWalker
class txXPathNodeUtils

Detailed Description

Definition at line 406 of file dom.h.


Member Enumeration Documentation

enum Node::NodeType [inherited]
Enumerator:
ELEMENT_NODE 
ATTRIBUTE_NODE 
TEXT_NODE 
CDATA_SECTION_NODE 
ENTITY_REFERENCE_NODE 
ENTITY_NODE 
PROCESSING_INSTRUCTION_NODE 
COMMENT_NODE 
DOCUMENT_NODE 
DOCUMENT_TYPE_NODE 
DOCUMENT_FRAGMENT_NODE 
NOTATION_NODE 

Definition at line 90 of file dom.h.


Constructor & Destructor Documentation

Definition at line 57 of file Document.cpp.


Member Function Documentation

Node * Document::appendChild ( Node newChild) [virtual]

Reimplemented from NodeDefinition.

Definition at line 165 of file Document.cpp.

{
  unsigned short nodeType = newChild->getNodeType();

  // Convert to a NodeDefinition Pointer
  NodeDefinition* pNewChild = (NodeDefinition*)newChild;

  if (pNewChild->parentNode == this)
    {
      pNewChild = implRemoveChild(pNewChild);
      if (nodeType == Node::ELEMENT_NODE)
        documentElement = nsnull;
    }

  switch (nodeType)
    {
      case Node::PROCESSING_INSTRUCTION_NODE :
      case Node::COMMENT_NODE :
      case Node::DOCUMENT_TYPE_NODE :
        return implAppendChild(pNewChild);

      case Node::ELEMENT_NODE :
        if (!documentElement)
          {
            Node* returnVal = implAppendChild(pNewChild);
            documentElement = (Element*)pNewChild;
            return returnVal;
          }

      default:
        break;
    }

  return nsnull;
}

Here is the call graph for this function:

void NodeDefinition::appendData ( const PRUnichar aData,
int  aLength 
) [inline, inherited]

Definition at line 282 of file dom.h.

    {
      nodeValue.Append(aData, aLength);
    };
PRInt32 NodeDefinition::compareDocumentPosition ( Node aOther) [virtual, inherited]

Implements Node.

Definition at line 409 of file NodeDefinition.cpp.

{
  OrderInfo* myOrder = getOrderInfo();
  OrderInfo* otherOrder = ((NodeDefinition*)aOther)->getOrderInfo();
  if (!myOrder || !otherOrder)
      return -1;

  if (myOrder->mRoot == otherOrder->mRoot) {
    int c = 0;
    while (c < myOrder->mSize && c < otherOrder->mSize) {
      if (myOrder->mOrder[c] < otherOrder->mOrder[c])
        return -1;
      if (myOrder->mOrder[c] > otherOrder->mOrder[c])
        return 1;
      ++c;
    }
    if (c < myOrder->mSize)
      return 1;
    if (c < otherOrder->mSize)
      return -1;
    return 0;
  }

  if (myOrder->mRoot < otherOrder->mRoot)
    return -1;

  return 1;
}

Here is the call graph for this function:

Attr * Document::createAttribute ( const nsAString &  name)

Definition at line 99 of file Document.cpp.

{
  return new Attr(name, this);
}

Here is the caller graph for this function:

Attr * Document::createAttributeNS ( const nsAString &  aNamespaceURI,
const nsAString &  aName 
)

Definition at line 104 of file Document.cpp.

{
  return new Attr(aNamespaceURI, aName, this);
}

Here is the caller graph for this function:

Node * Document::createComment ( const nsAString &  aData)

Definition at line 121 of file Document.cpp.

{
  return new NodeDefinition(Node::COMMENT_NODE, theData, this);
}

Here is the call graph for this function:

Definition at line 76 of file Document.cpp.

{
  return new DocumentFragment(this);
}
Element * Document::createElement ( const nsAString &  tagName)

Definition at line 85 of file Document.cpp.

{
  return new Element(tagName, this);
}
Element * Document::createElementNS ( const nsAString &  aNamespaceURI,
const nsAString &  aTagName 
)

Definition at line 90 of file Document.cpp.

{
  return new Element(aNamespaceURI, aTagName, this);
}
ProcessingInstruction * Document::createProcessingInstruction ( const nsAString &  aTarget,
const nsAString &  aData 
)

Definition at line 130 of file Document.cpp.

{
  return new ProcessingInstruction(target, data, this);
}
Node * Document::createTextNode ( const nsAString &  theData)

Definition at line 113 of file Document.cpp.

{
  return new NodeDefinition(Node::TEXT_NODE, theData, this);
}

Here is the call graph for this function:

void NodeDefinition::DeleteChildren ( ) [protected, inherited]

Definition at line 130 of file NodeDefinition.cpp.

{
  NodeDefinition* pCurrent = firstChild;
  NodeDefinition* pDestroyer;

  while (pCurrent)
    {
      pDestroyer = pCurrent;
      pCurrent = pCurrent->nextSibling;
      delete pDestroyer;
    }

  length = 0;
  firstChild = nsnull;
  lastChild = nsnull;
}

Here is the caller graph for this function:

NamedNodeMap * NodeDefinition::getAttributes ( ) [virtual, inherited]

Implements Node.

Reimplemented in Element.

Definition at line 189 of file NodeDefinition.cpp.

{
  return 0;
}
nsresult Document::getBaseURI ( nsAString &  aURI) [virtual]

Reimplemented from NodeDefinition.

Definition at line 201 of file Document.cpp.

{
  aURI = documentBaseURI;
  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 66 of file Document.cpp.

{
  return documentElement;
}
Element * Document::getElementById ( const nsAString &  aID)

Definition at line 141 of file Document.cpp.

{
  txIDEntry* entry = mIDMap.GetEntry(aID);
  if (entry)
    return entry->mElement;
  return nsnull;
}
Node * NodeDefinition::getFirstChild ( ) const [virtual, inherited]

Implements Node.

Definition at line 169 of file NodeDefinition.cpp.

{
  return firstChild;
}

Here is the caller graph for this function:

Node * NodeDefinition::getLastChild ( ) const [virtual, inherited]

Implements Node.

Definition at line 174 of file NodeDefinition.cpp.

{
  return lastChild;
}
PRUint32 NodeDefinition::getLength ( ) [virtual, inherited]

Implements NodeList.

Definition at line 215 of file NodeDefinition.cpp.

{
  return length;
}
MBool NodeDefinition::getLocalName ( nsIAtom **  aLocalName) [virtual, inherited]

Implements Node.

Reimplemented in ProcessingInstruction, Attr, and Element.

Definition at line 285 of file NodeDefinition.cpp.

{
  if (!aLocalName)
    return MB_FALSE;
  *aLocalName = 0;
  return MB_TRUE;
}
PRInt32 NodeDefinition::getNamespaceID ( ) [virtual, inherited]

Implements Node.

Reimplemented in Attr, and Element.

Definition at line 299 of file NodeDefinition.cpp.

{
  return kNameSpaceID_None;
}

Here is the caller graph for this function:

nsresult NodeDefinition::getNamespaceURI ( nsAString &  aNSURI) [virtual, inherited]

Implements Node.

Definition at line 293 of file NodeDefinition.cpp.

Here is the call graph for this function:

Node * NodeDefinition::getNextSibling ( ) const [virtual, inherited]

Implements Node.

Definition at line 184 of file NodeDefinition.cpp.

{
  return nextSibling;
}
nsresult NodeDefinition::getNodeName ( nsAString &  aName) const [virtual, inherited]

Implements Node.

Definition at line 147 of file NodeDefinition.cpp.

{
  aName = nodeName;
  return NS_OK;
}
unsigned short NodeDefinition::getNodeType ( ) const [virtual, inherited]

Implements Node.

Definition at line 159 of file NodeDefinition.cpp.

{
  return nodeType;
}

Here is the caller graph for this function:

nsresult NodeDefinition::getNodeValue ( nsAString &  aValue) [virtual, inherited]

Implements Node.

Reimplemented in Attr.

Definition at line 153 of file NodeDefinition.cpp.

{
  aValue = nodeValue;
  return NS_OK;
}
Document * NodeDefinition::getOwnerDocument ( ) const [virtual, inherited]

Implements Node.

Definition at line 194 of file NodeDefinition.cpp.

{
  return ownerDocument;
}

Here is the caller graph for this function:

Node * NodeDefinition::getParentNode ( ) const [virtual, inherited]

Implements Node.

Definition at line 164 of file NodeDefinition.cpp.

{
  return parentNode;
}

Here is the caller graph for this function:

Node * NodeDefinition::getPreviousSibling ( ) const [virtual, inherited]

Implements Node.

Definition at line 179 of file NodeDefinition.cpp.

{
  return previousSibling;
}
Node * NodeDefinition::getXPathParent ( ) [virtual, inherited]

Implements Node.

Reimplemented in Attr.

Definition at line 356 of file NodeDefinition.cpp.

{
  return parentNode;
}

Here is the caller graph for this function:

MBool NodeDefinition::hasChildNodes ( ) const [virtual, inherited]

Implements Node.

Definition at line 277 of file NodeDefinition.cpp.

{
  if (firstChild)
    return MB_TRUE;
  else
    return MB_FALSE;
}
NodeDefinition * NodeDefinition::implAppendChild ( NodeDefinition newChild) [protected, inherited]

Definition at line 230 of file NodeDefinition.cpp.

{
  // The new child should not be a child of any other node
  if (!newChild->previousSibling && !newChild->nextSibling &&
      !newChild->parentNode)
    {
      newChild->previousSibling = lastChild;

      if (lastChild)
        lastChild->nextSibling = newChild;

      lastChild = newChild;

      newChild->parentNode = this;

      if (!newChild->previousSibling)
        firstChild = newChild;

      ++length;

      return newChild;
    }

  return nsnull;
}

Here is the caller graph for this function:

NodeDefinition * NodeDefinition::implRemoveChild ( NodeDefinition oldChild) [protected, inherited]

Definition at line 256 of file NodeDefinition.cpp.

{
  if (oldChild != firstChild)
    oldChild->previousSibling->nextSibling = oldChild->nextSibling;
  else
    firstChild = oldChild->nextSibling;

  if (oldChild != lastChild)
    oldChild->nextSibling->previousSibling = oldChild->previousSibling;
  else
    lastChild = oldChild->previousSibling;

  oldChild->nextSibling = nsnull;
  oldChild->previousSibling = nsnull;
  oldChild->parentNode = nsnull;

  --length;

  return oldChild;
}

Here is the caller graph for this function:

Node * NodeDefinition::item ( PRUint32  index) [virtual, inherited]

Implements NodeList.

Definition at line 199 of file NodeDefinition.cpp.

{
  PRUint32 selectLoop;
  NodeDefinition* pSelectNode = firstChild;

  if (index < length)
    {
      for (selectLoop=0;selectLoop<index;selectLoop++)
        pSelectNode = pSelectNode->nextSibling;

      return pSelectNode;
    }

  return nsnull;
}

Here is the caller graph for this function:

PRInt32 NodeDefinition::lookupNamespaceID ( nsIAtom aPrefix) [virtual, inherited]

Implements Node.

Definition at line 310 of file NodeDefinition.cpp.

{
  // this is http://www.w3.org/2000/xmlns/,
  // ID = kNameSpaceID_XMLNS, see txStandaloneNamespaceManager::Init
  if (aPrefix == txXMLAtoms::xmlns)
    return kNameSpaceID_XMLNS; 
  // this is http://www.w3.org/XML/1998/namespace,
  // ID = kNameSpaceID_XML, see txStandaloneNamespaceManager::Init
  if (aPrefix == txXMLAtoms::xml)
    return kNameSpaceID_XML; 

  Node* node = this;
  if (node->getNodeType() != Node::ELEMENT_NODE)
    node = node->getXPathParent();

  nsAutoString name(NS_LITERAL_STRING("xmlns:"));
  if (aPrefix && (aPrefix != txXMLAtoms::_empty)) {
      //  We have a prefix, search for xmlns:prefix attributes.
      nsAutoString prefixString;
      aPrefix->ToString(prefixString);
      name.Append(prefixString);
  }
  else {
      // No prefix, look up the default namespace by searching for xmlns
      // attributes. Remove the trailing :, set length to 5 (xmlns).
      name.Truncate(5);
  }
  Attr* xmlns;
  while (node && node->getNodeType() == Node::ELEMENT_NODE) {
    if ((xmlns = ((Element*)node)->getAttributeNode(name))) {
      /*
       * xmlns:foo = "" makes "" a valid URI, so get that.
       * xmlns = "" resolves to 0 (null Namespace) (caught above)
       * in Element::getNamespaceID()
       */
      nsAutoString nsURI;
      xmlns->getNodeValue(nsURI);
      return txStandaloneNamespaceManager::getNamespaceID(nsURI);
    }
    node = node->getXPathParent();
  }
  if (!aPrefix || (aPrefix == txXMLAtoms::_empty))
      return kNameSpaceID_None;
  return kNameSpaceID_Unknown;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool Document::setElementID ( const nsAString &  aID,
Element aElement 
) [private]

private setter for element ID

Definition at line 153 of file Document.cpp.

{
  txIDEntry* id = mIDMap.AddEntry(aID);
  // make sure IDs are unique
  if (id->mElement) {
    return PR_FALSE;
  }
  id->mElement = aElement;
  id->mElement->setIDValue(aID);
  return PR_TRUE;
}

Here is the call graph for this function:

void NodeDefinition::setNodeValue ( const nsAString &  nodeValue) [virtual, inherited]

Implements Node.

Reimplemented in Attr.

Definition at line 220 of file NodeDefinition.cpp.

{
  nodeValue = newNodeValue;
}

Friends And Related Function Documentation

friend class Document [friend, inherited]

Reimplemented in ProcessingInstruction, Attr, Element, and DocumentFragment.

Definition at line 285 of file dom.h.

friend class txXMLParser [friend]

Definition at line 443 of file dom.h.

friend class txXPathNodeUtils [friend, inherited]

Definition at line 290 of file dom.h.

friend class txXPathTreeWalker [friend, inherited]

Definition at line 289 of file dom.h.


Member Data Documentation

unsigned Node::count [inherited]

Definition at line 112 of file trace.cpp.

Definition at line 445 of file dom.h.

Definition at line 439 of file dom.h.

char* Node::function [inherited]

Definition at line 110 of file trace.cpp.

unsigned Node::hits [inherited]

Definition at line 113 of file trace.cpp.

PRUint32 NodeList::length [protected, inherited]

Definition at line 154 of file dom.h.

txIDMap Document::mIDMap [private]

Definition at line 444 of file dom.h.

Node* Node::next [inherited]

Definition at line 114 of file trace.cpp.

nsString NodeDefinition::nodeName [protected, inherited]

Definition at line 299 of file dom.h.

nsString NodeDefinition::nodeValue [protected, inherited]

Definition at line 300 of file dom.h.


The documentation for this class was generated from the following files: