bug 98704, xml/dom part of beating DOMHelper::getParentNode out of the tree, r=peterv, rs=brendan

This commit is contained in:
axel%pike.org 2005-11-02 07:36:33 +00:00
Родитель f4d8ed440a
Коммит 72eca118c2
4 изменённых файлов: 89 добавлений и 50 удалений

Просмотреть файл

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
@ -22,12 +23,6 @@
//
// Implementation of the Document Object Model Level 1 Core
// Implementation of the Attr class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
// LF 08/06/1999 fixed typo: defalut to default
//
#include "dom.h"
@ -139,3 +134,11 @@ Node* Attr::insertBefore(Node* newChild, Node* refChild)
return returnVal;
}
//
//Return the attributes owning element
//
Node* Attr::getXPathParent()
{
return ownerElement;
}

Просмотреть файл

@ -127,6 +127,9 @@ class Node : public TxObject
//From DOM3 26-Jan-2001 WD
virtual String getBaseURI() = 0;
//txXPathNode functions
virtual Node* getXPathParent() = 0;
};
//
@ -189,11 +192,31 @@ class NamedNodeMap : public NodeListDefinition
~NamedNodeMap();
Node* getNamedItem(const String& name);
virtual Node* setNamedItem(Node* arg);
virtual Node* removeNamedItem(const String& name);
private:
NodeListDefinition::ListItem* findListItemByName(const String& name);
};
//
// Subclass of NamedNodeMap that contains a list of attributes.
// Whenever an attribute is added to or removed from the map, the attributes
// ownerElement is updated.
//
class AttrMap : public NamedNodeMap
{
// Elenent needs to be friend to be able to set the AttrMaps ownerElement
friend Element;
public:
AttrMap();
Node* setNamedItem(Node* arg);
Node* removeNamedItem(const String& name);
private:
NodeListDefinition::ListItem* findListItemByName(const String& name);
Element* ownerElement;
};
//
@ -234,10 +257,14 @@ class NodeDefinition : public Node, public NodeList
Node* cloneNode(MBool deep, Node* dest);
MBool hasChildNodes() const;
//From DOM3 26-Jan-2001 WD
virtual String getBaseURI();
//Inherrited from NodeList
//txXPathNode functions
virtual Node* getXPathParent();
//Inherited from NodeList
Node* item(PRUint32 index);
PRUint32 getLength();
@ -247,7 +274,7 @@ class NodeDefinition : public Node, public NodeList
//than the generic node does.
String nodeName;
String nodeValue;
NamedNodeMap attributes;
AttrMap attributes;
void DeleteChildren();
@ -360,6 +387,8 @@ class Element : public NodeDefinition
//
class Attr : public NodeDefinition
{
// AttrMap needs to be friend to be able to update the ownerElement
friend AttrMap;
public:
Attr(const String& name, Document* owner);
@ -377,7 +406,11 @@ class Attr : public NodeDefinition
//children
Node* insertBefore(Node* newChild, Node* refChild);
//txXPathNode functions override
Node* getXPathParent();
private:
Element* ownerElement;
MBool specified;
};

Просмотреть файл

@ -1,4 +1,5 @@
/*
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
@ -23,11 +24,6 @@
// Implementation of the Document Object Model Level 1 Core
// Implementation of the Element class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
// LF 08/06/1999 fixed typo: defalut to default
//
#include "dom.h"
@ -39,6 +35,7 @@
Element::Element(const String& tagName, Document* owner) :
NodeDefinition(Node::ELEMENT_NODE, tagName, NULL_STRING, owner)
{
attributes.ownerElement = this;
}
//

Просмотреть файл

@ -1,4 +1,5 @@
/*
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
@ -359,48 +360,53 @@ MBool NodeDefinition::hasChildNodes() const
return MB_FALSE;
}
/**
Node* NodeDefinition::getXPathParent()
{
return parentNode;
}
/*
* Returns the base URI of the node. Acccounts for xml:base
* attributes.
*
* @return base URI for the node
**/
*/
String NodeDefinition::getBaseURI()
{
Node* node=this;
ArrayList baseUrls;
String url;
Node* xbAttr;
Node* node = this;
ArrayList baseUrls;
String url;
Node* xbAttr;
while (node) {
switch (node->getNodeType()) {
case Node::ELEMENT_NODE :
xbAttr = ((Element*)node)->getAttributeNode(XMLBASE_ATTR);
if (xbAttr)
baseUrls.add(new String(xbAttr->getNodeValue()));
break;
case Node::DOCUMENT_NODE :
baseUrls.add(new String(((Document*)node)->getBaseURI()));
break;
while(node) {
switch(node->getNodeType()) {
case Node::ELEMENT_NODE :
xbAttr = ((Element*)node)->getAttributeNode(XMLBASE_ATTR);
if(xbAttr)
baseUrls.add(new String(xbAttr->getNodeValue()));
break;
case Node::DOCUMENT_NODE :
baseUrls.add(new String(((Document*)node)->getBaseURI()));
break;
default:
break;
}
node = node->getParentNode();
default:
break;
}
node = node->getParentNode();
}
if(baseUrls.size()) {
url = *((String*)baseUrls.get(baseUrls.size()-1));
if (baseUrls.size()) {
url = *((String*)baseUrls.get(baseUrls.size()-1));
for(int i=baseUrls.size()-2;i>=0;i--) {
String dest;
URIUtils::resolveHref(*(String*)baseUrls.get(i), url, dest);
url = dest;
}
for (int i=baseUrls.size()-2;i>=0;i--) {
String dest;
URIUtils::resolveHref(*(String*)baseUrls.get(i), url, dest);
url = dest;
}
}
baseUrls.clear(MB_TRUE);
return url;
} //-- getBaseURI
baseUrls.clear(MB_TRUE);
return url;
} // getBaseURI