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
Element Class Reference

#include <nsirequest.h>

Inheritance diagram for Element:
Inheritance graph
[legend]
Collaboration diagram for Element:
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

virtual ~Element ()
NamedNodeMapgetAttributes ()
void setAttribute (const nsAString &name, const nsAString &value)
void setAttributeNS (const nsAString &aNamespaceURI, const nsAString &aName, const nsAString &aValue)
AttrgetAttributeNode (const nsAString &name)
NodeappendChild (Node *newChild)
MBool getLocalName (nsIAtom **aLocalName)
PRInt32 getNamespaceID ()
MBool getAttr (nsIAtom *aLocalName, PRInt32 aNSID, nsAString &aValue)
MBool hasAttr (nsIAtom *aLocalName, PRInt32 aNSID)
PRBool getIDValue (nsAString &aValue)
 ID accessors.
nsresult getNodeName (nsAString &aName) const
nsresult getNodeValue (nsAString &aValue)
unsigned short getNodeType () const
NodegetParentNode () const
NodegetFirstChild () const
NodegetLastChild () const
NodegetPreviousSibling () const
NodegetNextSibling () const
DocumentgetOwnerDocument () const
virtual void setNodeValue (const nsAString &nodeValue)
MBool hasChildNodes () const
virtual nsresult getBaseURI (nsAString &aURI)
nsresult getNamespaceURI (nsAString &aNSURI)
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 theUrl [1024]
bool reqPend
bool reqStatus
bool reqSuspend
bool reqResume
bool reqCancel
bool reqSetLoadGroup
bool reqGetLoadGroup
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

void setIDValue (const nsAString &aValue)
 Element (const nsAString &tagName, Document *owner)
 Element (const nsAString &aNamespaceURI, const nsAString &aTagName, Document *aOwner)

Private Attributes

AttrMap mAttributes
nsString mIDValue
nsCOMPtr< nsIAtommLocalName
PRInt32 mNamespaceID

Friends

class Document
class txXPathTreeWalker
class txXPathNodeUtils

Detailed Description

Definition at line 97 of file nsirequest.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

Element::~Element ( ) [virtual]

Definition at line 85 of file Element.cpp.

Here is the call graph for this function:

Element::Element ( const nsAString &  tagName,
Document owner 
) [private]

Definition at line 53 of file Element.cpp.

                                                          :
         NodeDefinition(Node::ELEMENT_NODE, tagName, EmptyString(), owner)
{
  mAttributes.ownerElement = this;
  mNamespaceID = kNameSpaceID_Unknown;

  int idx = tagName.FindChar(':');
  if (idx == kNotFound) {
    mLocalName = do_GetAtom(tagName);
  }
  else {
    mLocalName = do_GetAtom(Substring(tagName, idx + 1,
                                      tagName.Length() - (idx + 1)));
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Element::Element ( const nsAString &  aNamespaceURI,
const nsAString &  aTagName,
Document aOwner 
) [private]

Definition at line 69 of file Element.cpp.

                                   :
         NodeDefinition(Node::ELEMENT_NODE, aTagName, EmptyString(), aOwner)
{
  Element(aTagName, aOwner);
  if (aNamespaceURI.IsEmpty())
    mNamespaceID = kNameSpaceID_None;
  else
    mNamespaceID = txStandaloneNamespaceManager::getNamespaceID(aNamespaceURI);
}

Here is the call graph for this function:


Member Function Documentation

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

Reimplemented from NodeDefinition.

Definition at line 90 of file Element.cpp.

{
  switch (newChild->getNodeType())
    {
      case Node::ELEMENT_NODE :
      case Node::TEXT_NODE :
      case Node::COMMENT_NODE :
      case Node::PROCESSING_INSTRUCTION_NODE :
        {
          // Remove the "newChild" if it is already a child of this node
          NodeDefinition* pNewChild = (NodeDefinition*)newChild;
          if (pNewChild->getParentNode() == this)
            pNewChild = implRemoveChild(pNewChild);

          return implAppendChild(pNewChild);
        }

      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:

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:

MBool Element::getAttr ( nsIAtom aLocalName,
PRInt32  aNSID,
nsAString &  aValue 
)

Definition at line 235 of file Element.cpp.

{
  aValue.Truncate();
  AttrMap::ListItem* item = mAttributes.firstItem;
  while (item) {
    Attr* attrNode = (Attr*)item->node;
    nsCOMPtr<nsIAtom> localName;
    if (attrNode->getLocalName(getter_AddRefs(localName)) &&
        aNSID == attrNode->getNamespaceID() &&
        aLocalName == localName) {
      attrNode->getNodeValue(aValue);
      return MB_TRUE;
    }
    item = item->next;
  }
  return MB_FALSE;
}

Here is the call graph for this function:

Attr * Element::getAttributeNode ( const nsAString &  name)

Definition at line 225 of file Element.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from NodeDefinition.

Definition at line 160 of file Element.cpp.

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

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, inherited]

Implements Node.

Definition at line 169 of file NodeDefinition.cpp.

{
  return firstChild;
}

Here is the caller graph for this function:

PRBool Element::getIDValue ( nsAString &  aValue)

ID accessors.

Getter used for id() patterns, private setter for parser

Definition at line 278 of file Element.cpp.

{
  if (mIDValue.IsEmpty()) {
    return PR_FALSE;
  }
  aValue = mIDValue;
  return PR_TRUE;
}
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 Element::getLocalName ( nsIAtom **  aLocalName) [virtual]

Reimplemented from NodeDefinition.

Definition at line 117 of file Element.cpp.

{
  if (!aLocalName)
    return MB_FALSE;
  *aLocalName = mLocalName;
  NS_ADDREF(*aLocalName);
  return MB_TRUE;
}

Here is the call graph for this function:

Reimplemented from NodeDefinition.

Definition at line 129 of file Element.cpp.

{
  if (mNamespaceID>=0)
    return mNamespaceID;
  int idx = nodeName.FindChar(':');
  if (idx == kNotFound) {
    Node* node = this;
    while (node && node->getNodeType() == Node::ELEMENT_NODE) {
      nsAutoString nsURI;
      if (((Element*)node)->getAttr(txXMLAtoms::xmlns, kNameSpaceID_XMLNS,
                                    nsURI)) {
        // xmlns = "" sets the default namespace ID to kNameSpaceID_None;
        if (!nsURI.IsEmpty()) {
          mNamespaceID = txStandaloneNamespaceManager::getNamespaceID(nsURI);
        }
        else {
          mNamespaceID = kNameSpaceID_None;
        }
        return mNamespaceID;
      }
      node = node->getParentNode();
    }
    mNamespaceID = kNameSpaceID_None;
  }
  else {
    nsCOMPtr<nsIAtom> prefix = do_GetAtom(Substring(nodeName, 0, idx));
    mNamespaceID = lookupNamespaceID(prefix);
  }
  return mNamespaceID;
}

Here is the call graph for this function:

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 Element::hasAttr ( nsIAtom aLocalName,
PRInt32  aNSID 
)

Definition at line 258 of file Element.cpp.

{
  AttrMap::ListItem* item = mAttributes.firstItem;
  while (item) {
    Attr* attrNode = (Attr*)item->node;
    nsCOMPtr<nsIAtom> localName;
    if (attrNode->getLocalName(getter_AddRefs(localName)) &&
        aNSID == attrNode->getNamespaceID() &&
        aLocalName == localName) {
      return MB_TRUE;
    }
    item = item->next;
  }
  return MB_FALSE;
}

Here is the call 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:

void Element::setAttribute ( const nsAString &  name,
const nsAString &  value 
)

Definition at line 170 of file Element.cpp.

{
  // Check to see if an attribute with this name already exists. If it does
  // overwrite its value, if not, add it.
  Attr* tempAttribute = getAttributeNode(name);
  if (tempAttribute) {
    tempAttribute->setNodeValue(value);
  }
  else {
    tempAttribute = getOwnerDocument()->createAttribute(name);
    tempAttribute->setNodeValue(value);
    tempAttribute->ownerElement = this;
    mAttributes.append(tempAttribute);
  }
}

Here is the call graph for this function:

void Element::setAttributeNS ( const nsAString &  aNamespaceURI,
const nsAString &  aName,
const nsAString &  aValue 
)

Definition at line 186 of file Element.cpp.

{
  // Check to see if an attribute with this name already exists. If it does
  // overwrite its value, if not, add it.
  PRInt32 namespaceID =
      txStandaloneNamespaceManager::getNamespaceID(aNamespaceURI);
  nsCOMPtr<nsIAtom> localName = do_GetAtom(XMLUtils::getLocalPart(aName));

  Attr* foundNode = 0;
  AttrMap::ListItem* item = mAttributes.firstItem;
  while (item) {
    foundNode = (Attr*)item->node;
    nsCOMPtr<nsIAtom> attrName;
    if (foundNode->getLocalName(getter_AddRefs(attrName)) &&
        namespaceID == foundNode->getNamespaceID() &&
        localName == attrName) {
      break;
    }
    foundNode = 0;
    item = item->next;
  }

  if (foundNode) {
    foundNode->setNodeValue(aValue);
  }
  else {
    Attr* temp = getOwnerDocument()->createAttributeNS(aNamespaceURI,
                                                       aName);
    temp->setNodeValue(aValue);
    temp->ownerElement = this;
    mAttributes.append(temp);
  }
}

Here is the call graph for this function:

void Element::setIDValue ( const nsAString &  aValue) [private]

Definition at line 288 of file Element.cpp.

Here is the caller 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]

Reimplemented from NodeDefinition.

Definition at line 476 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.

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.

Definition at line 482 of file dom.h.

Definition at line 483 of file dom.h.

Definition at line 484 of file dom.h.

Definition at line 485 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.

Definition at line 104 of file nsirequest.h.

Definition at line 106 of file nsirequest.h.

Definition at line 100 of file nsirequest.h.

Definition at line 103 of file nsirequest.h.

Definition at line 105 of file nsirequest.h.

Definition at line 101 of file nsirequest.h.

Definition at line 102 of file nsirequest.h.

char Element::theUrl[1024]

Definition at line 99 of file nsirequest.h.


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