Back to index

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

#include <dom.h>

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

List of all members.

Classes

struct  OrderInfo

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

virtual ~NodeDefinition ()
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)
virtual NodeappendChild (Node *newChild)
MBool hasChildNodes () const
virtual nsresult getBaseURI (nsAString &aURI)
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

 NodeDefinition (NodeType type, const nsAString &name, const nsAString &value, Document *owner)
 NodeDefinition (NodeType aType, const nsAString &aValue, Document *aOwner)
NodeDefinitionimplAppendChild (NodeDefinition *newChild)
NodeDefinitionimplRemoveChild (NodeDefinition *oldChild)
void DeleteChildren ()

Protected Attributes

nsString nodeName
nsString nodeValue
PRUint32 length

Private Member Functions

void Init (NodeType aType, const nsAString &aValue, Document *aOwner)
OrderInfogetOrderInfo ()

Private Attributes

NodeType nodeType
NodeDefinitionparentNode
NodeDefinitionpreviousSibling
NodeDefinitionnextSibling
DocumentownerDocument
NodeDefinitionfirstChild
NodeDefinitionlastChild
OrderInfomOrderInfo

Friends

class Document
class txXPathTreeWalker
class txXPathNodeUtils

Detailed Description

Definition at line 239 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 102 of file NodeDefinition.cpp.

{
  DeleteChildren();
  delete mOrderInfo;
}

Here is the call graph for this function:

NodeDefinition::NodeDefinition ( NodeType  type,
const nsAString &  name,
const nsAString &  value,
Document owner 
) [protected]

Definition at line 54 of file NodeDefinition.cpp.

{
  nodeName = name;
  Init(type, value, owner);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NodeDefinition::NodeDefinition ( NodeType  aType,
const nsAString &  aValue,
Document aOwner 
) [protected]

Definition at line 61 of file NodeDefinition.cpp.

{
  switch (aType)
  {
    case CDATA_SECTION_NODE:
    {
      nodeName.AssignLiteral("#cdata-section");
      break;
    }
    case COMMENT_NODE:
    {
      nodeName.AssignLiteral("#comment");
      break;
    }
    case DOCUMENT_NODE:
    {
      nodeName.AssignLiteral("#document");
      break;
    }
    case DOCUMENT_FRAGMENT_NODE:
    {
      nodeName.AssignLiteral("#document-fragment");
      break;
    }
    case TEXT_NODE:
    {
      nodeName.AssignLiteral("#text");
      break;
    }
    default:
    {
      break;
    }
  }
  Init(aType, aValue, aOwner);
}

Here is the call graph for this function:


Member Function Documentation

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

Implements Node.

Reimplemented in Attr, Element, Document, and DocumentFragment.

Definition at line 225 of file NodeDefinition.cpp.

{
  return nsnull;
}
void NodeDefinition::appendData ( const PRUnichar aData,
int  aLength 
) [inline]

Definition at line 282 of file dom.h.

    {
      nodeValue.Append(aData, aLength);
    };

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:

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:

Implements Node.

Reimplemented in Element.

Definition at line 189 of file NodeDefinition.cpp.

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

Implements Node.

Reimplemented in Document.

Definition at line 367 of file NodeDefinition.cpp.

{
  Node* node = this;
  nsStringArray baseUrls;
  nsAutoString url;

  while (node) {
    switch (node->getNodeType()) {
      case Node::ELEMENT_NODE :
        if (((Element*)node)->getAttr(txXMLAtoms::base, kNameSpaceID_XML,
                                      url))
          baseUrls.AppendString(url);
        break;

      case Node::DOCUMENT_NODE :
        node->getBaseURI(url);
        baseUrls.AppendString(url);
        break;
    
      default:
        break;
    }
    node = node->getXPathParent();
  }

  PRInt32 count = baseUrls.Count();
  if (count) {
    baseUrls.StringAt(--count, aURI);

    while (count > 0) {
      nsAutoString dest;
      URIUtils::resolveHref(*baseUrls[--count], aURI, dest);
      aURI = dest;
    }
  }
  
  return NS_OK;
} // getBaseURI

Here is the call graph for this function:

Here is the caller graph for this function:

Node * NodeDefinition::getFirstChild ( ) const [virtual]

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]

Implements Node.

Definition at line 174 of file NodeDefinition.cpp.

{
  return lastChild;
}

Implements NodeList.

Definition at line 215 of file NodeDefinition.cpp.

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

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;
}

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]

Implements Node.

Definition at line 293 of file NodeDefinition.cpp.

Here is the call graph for this function:

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

Implements Node.

Definition at line 184 of file NodeDefinition.cpp.

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

Implements Node.

Definition at line 147 of file NodeDefinition.cpp.

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

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]

Implements Node.

Reimplemented in Attr.

Definition at line 153 of file NodeDefinition.cpp.

{
  aValue = nodeValue;
  return NS_OK;
}

Definition at line 441 of file NodeDefinition.cpp.

{
  if (mOrderInfo)
    return mOrderInfo;

  mOrderInfo = new OrderInfo;
  if (!mOrderInfo)
    return 0;

  Node* parent = getXPathParent();
  if (!parent) {
    mOrderInfo->mOrder = 0;
    mOrderInfo->mSize = 0;
    mOrderInfo->mRoot = this;
    return mOrderInfo;
  }

  OrderInfo* parentOrder = ((NodeDefinition*)parent)->getOrderInfo();
  mOrderInfo->mSize = parentOrder->mSize + 1;
  mOrderInfo->mRoot = parentOrder->mRoot;
  mOrderInfo->mOrder = new PRUint32[mOrderInfo->mSize];
  if (!mOrderInfo->mOrder) {
    delete mOrderInfo;
    mOrderInfo = 0;
    return 0;
  }
  memcpy(mOrderInfo->mOrder,
         parentOrder->mOrder,
         parentOrder->mSize * sizeof(PRUint32*));

  // Get childnumber of this node
  int lastElem = parentOrder->mSize;
  switch (getNodeType()) {
    case Node::ATTRIBUTE_NODE:
    {
      NS_ASSERTION(parent->getNodeType() == Node::ELEMENT_NODE,
                   "parent to attribute is not an element");

      Element* elem = (Element*)parent;
      PRUint32 i;
      NamedNodeMap* attrs = elem->getAttributes();
      for (i = 0; i < attrs->getLength(); ++i) {
        if (attrs->item(i) == this) {
          mOrderInfo->mOrder[lastElem] = i + kTxAttrIndexOffset;
          return mOrderInfo;
        }
      }
      break;
    }
    // XXX Namespace: need to take care of namespace nodes here
    default:
    {
      PRUint32 i = 0;
      Node * child = parent->getFirstChild();
      while (child) {
        if (child == this) {
          mOrderInfo->mOrder[lastElem] = i + kTxChildIndexOffset;
          return mOrderInfo;
        }
        ++i;
        child = child->getNextSibling();
      }
      break;
    }
  }

  NS_ASSERTION(0, "unable to get childnumber");
  mOrderInfo->mOrder[lastElem] = 0;
  return mOrderInfo;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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]

Implements Node.

Definition at line 164 of file NodeDefinition.cpp.

{
  return parentNode;
}

Here is the caller graph for this function:

Implements Node.

Definition at line 179 of file NodeDefinition.cpp.

{
  return previousSibling;
}

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]

Implements Node.

Definition at line 277 of file NodeDefinition.cpp.

{
  if (firstChild)
    return MB_TRUE;
  else
    return MB_FALSE;
}

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:

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:

void NodeDefinition::Init ( NodeType  aType,
const nsAString &  aValue,
Document aOwner 
) [private]

Definition at line 109 of file NodeDefinition.cpp.

Here is the caller graph for this function:

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

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:

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:

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

Implements Node.

Reimplemented in Attr.

Definition at line 220 of file NodeDefinition.cpp.

{
  nodeValue = newNodeValue;
}

Friends And Related Function Documentation

friend class Document [friend]

Reimplemented in ProcessingInstruction, Attr, Element, and DocumentFragment.

Definition at line 285 of file dom.h.

friend class txXPathNodeUtils [friend]

Definition at line 290 of file dom.h.

friend class txXPathTreeWalker [friend]

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 322 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.

Definition at line 323 of file dom.h.

PRUint32 NodeList::length [protected, inherited]

Definition at line 154 of file dom.h.

Definition at line 334 of file dom.h.

Node* Node::next [inherited]

Definition at line 114 of file trace.cpp.

Definition at line 316 of file dom.h.

Definition at line 299 of file dom.h.

Definition at line 311 of file dom.h.

Definition at line 300 of file dom.h.

Definition at line 319 of file dom.h.

Definition at line 314 of file dom.h.

Definition at line 315 of file dom.h.


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