зеркало из https://github.com/mozilla/pjs.git
bug 98704, xml/dom part of beating DOMHelper::getParentNode out of the tree, r=peterv, rs=brendan
This commit is contained in:
Родитель
732604001c
Коммит
f36f437f66
|
@ -1,4 +1,5 @@
|
|||
/*
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
|
@ -103,3 +104,18 @@ void Attr::setValue(const String& aNewValue)
|
|||
if (nsAttr)
|
||||
nsAttr->SetValue(aNewValue.getConstNSString());
|
||||
}
|
||||
|
||||
/*
|
||||
* Call nsIDOMAttr::GetOwnerElement to get the owning element
|
||||
*
|
||||
* @return the xpath parent
|
||||
*/
|
||||
Node* Attr::getXPathParent()
|
||||
{
|
||||
NSI_FROM_TX_NULL_CHECK(Attr)
|
||||
nsCOMPtr<nsIDOMElement> ownerElem;
|
||||
|
||||
if (NS_SUCCEEDED(nsAttr->GetOwnerElement(getter_AddRefs(ownerElem))))
|
||||
return ownerDocument->createWrapper(ownerElem);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/*
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
|
@ -390,3 +391,11 @@ String Node::getBaseURI()
|
|||
|
||||
return url;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the parent node according to the XPath datamodel
|
||||
*/
|
||||
Node* Node::getXPathParent()
|
||||
{
|
||||
return getParentNode();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/*
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
|
@ -240,6 +241,9 @@ class Node : public MozillaObjectWrapper
|
|||
//From DOM3 26-Jan-2001 WD
|
||||
virtual String getBaseURI();
|
||||
|
||||
// txXPathNode functions
|
||||
virtual Node* getXPathParent();
|
||||
|
||||
protected:
|
||||
String nodeName;
|
||||
String nodeValue;
|
||||
|
@ -409,6 +413,8 @@ class Attr : public Node
|
|||
const String& getValue();
|
||||
void setValue(const String& aNewValue);
|
||||
|
||||
// txXPathNode functions override
|
||||
Node* getXPathParent();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -23,10 +24,6 @@
|
|||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the NamedNodeMap class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
|
@ -109,3 +106,24 @@ NodeListDefinition::ListItem*
|
|||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
AttrMap::AttrMap()
|
||||
{
|
||||
ownerElement = NULL;
|
||||
}
|
||||
|
||||
Node* AttrMap::setNamedItem(Node* arg)
|
||||
{
|
||||
if (arg->getNodeType() != Node::ATTRIBUTE_NODE)
|
||||
return NULL;
|
||||
((Attr*)arg)->ownerElement = ownerElement;
|
||||
return NamedNodeMap::setNamedItem(arg);
|
||||
}
|
||||
|
||||
Node* AttrMap::removeNamedItem(const String& name)
|
||||
{
|
||||
Attr* node = (Attr*)NamedNodeMap::removeNamedItem(name);
|
||||
if (node)
|
||||
node->ownerElement = NULL;
|
||||
return node;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
|
@ -37,14 +38,7 @@ DOMHelper::DOMHelper() {};
|
|||
/**
|
||||
* Delets this DOMHelper
|
||||
**/
|
||||
DOMHelper::~DOMHelper() {
|
||||
ListIterator* iter = indexes.iterator();
|
||||
while (iter->hasNext()) {
|
||||
IndexState* idxState = (IndexState*)iter->next();
|
||||
delete idxState;
|
||||
}
|
||||
delete iter;
|
||||
} //-- ~DOMHelper
|
||||
DOMHelper::~DOMHelper() {}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -108,32 +102,8 @@ void DOMHelper::generateId(Node* node, String& dest) {
|
|||
* @param node the Node to return the parent of
|
||||
**/
|
||||
Node* DOMHelper::getParentNode(Node* node) {
|
||||
|
||||
if (!node) return 0;
|
||||
//XXX Namespace: the parent of a namespace node is the element
|
||||
if (node->getNodeType() != Node::ATTRIBUTE_NODE)
|
||||
return node->getParentNode();
|
||||
|
||||
#ifndef TX_EXE
|
||||
// XXX temporary fix for 70979
|
||||
nsCOMPtr<nsIDOMAttr> attr(do_QueryInterface(node->getNSObj()));
|
||||
nsCOMPtr<nsIDOMElement> tmpParent;
|
||||
|
||||
if (attr && NS_SUCCEEDED(attr->GetOwnerElement(getter_AddRefs(tmpParent))))
|
||||
return node->getOwnerDocument()->createWrapper(tmpParent);
|
||||
return NULL;
|
||||
#else
|
||||
TxObjectWrapper* wrapper = 0;
|
||||
|
||||
wrapper = (TxObjectWrapper*) parents.get(node);
|
||||
if (!wrapper) {
|
||||
continueIndexing(node);
|
||||
wrapper = (TxObjectWrapper*) parents.get(node);
|
||||
}
|
||||
|
||||
if (wrapper) return (Node*)wrapper->object;
|
||||
return 0;
|
||||
#endif
|
||||
return node->getXPathParent();
|
||||
} //-- getParentNode
|
||||
|
||||
|
||||
|
@ -141,94 +111,6 @@ Node* DOMHelper::getParentNode(Node* node) {
|
|||
//- Private Methods -/
|
||||
//-------------------/
|
||||
|
||||
/**
|
||||
* Adds the given child/parent mapping
|
||||
**/
|
||||
void DOMHelper::addParentReference(Node* child, Node* parent) {
|
||||
TxObjectWrapper* wrapper = (TxObjectWrapper*) parents.get(child);
|
||||
if (!wrapper) {
|
||||
wrapper = new TxObjectWrapper();
|
||||
parents.put(wrapper, child);
|
||||
}
|
||||
wrapper->object = parent;
|
||||
|
||||
} //-- addParentReference
|
||||
|
||||
/**
|
||||
* Continues indexing until the given node has been indexed
|
||||
* @param node the target Node
|
||||
**/
|
||||
void DOMHelper::continueIndexing(Node* node) {
|
||||
if (!node) return;
|
||||
|
||||
//-- get indexing information
|
||||
Document* doc = 0;
|
||||
if (node->getNodeType() == Node::DOCUMENT_NODE)
|
||||
doc = (Document*)node;
|
||||
else
|
||||
doc = node->getOwnerDocument();
|
||||
|
||||
ListIterator* iter = indexes.iterator();
|
||||
IndexState* idxState = 0;
|
||||
while (iter->hasNext()) {
|
||||
idxState = (IndexState*)iter->next();
|
||||
if (idxState->document == doc) break;
|
||||
idxState = 0;
|
||||
}
|
||||
|
||||
if (!idxState) {
|
||||
idxState = new IndexState();
|
||||
indexes.add(idxState);
|
||||
idxState->document = doc;
|
||||
idxState->next = doc->getDocumentElement();
|
||||
if (!idxState->next) idxState->done = MB_TRUE;
|
||||
}
|
||||
|
||||
if (idxState->done) return;
|
||||
|
||||
MBool found = MB_FALSE;
|
||||
MBool alreadyProcessed = MB_FALSE;
|
||||
|
||||
while (!found) {
|
||||
|
||||
if (!idxState->next) {
|
||||
idxState->done = MB_TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!alreadyProcessed) {
|
||||
//-- index attributes
|
||||
if (idxState->next->getNodeType() == Node::ELEMENT_NODE) {
|
||||
Element* element = (Element*)idxState->next;
|
||||
NamedNodeMap* atts = element->getAttributes();
|
||||
if (atts) {
|
||||
for (PRUint32 i = 0; i < atts->getLength(); i++) {
|
||||
Node* tmpNode = atts->item(i);
|
||||
addParentReference(tmpNode, element);
|
||||
if (node == tmpNode) found = MB_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-- set next node to check
|
||||
if ((!alreadyProcessed) && (idxState->next->hasChildNodes())) {
|
||||
Node* child = idxState->next->getFirstChild();
|
||||
idxState->next = child;
|
||||
}
|
||||
else if (idxState->next->getNextSibling()) {
|
||||
idxState->next = idxState->next->getNextSibling();
|
||||
alreadyProcessed = MB_FALSE;
|
||||
}
|
||||
else {
|
||||
idxState->next = getParentNode(idxState->next);
|
||||
alreadyProcessed = MB_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
} //-- continueIndexing
|
||||
|
||||
|
||||
/**
|
||||
* Returns the child number of the given node. Numbering
|
||||
* starts at 1 for all nodes except the Document node and
|
||||
|
@ -304,24 +186,6 @@ OrderInfo* DOMHelper::getDocumentOrder(Node* node) {
|
|||
|
||||
} //-- getDocumentOrder
|
||||
|
||||
//--------------------------------/
|
||||
//- implementation of IndexState -/
|
||||
//--------------------------------/
|
||||
|
||||
/**
|
||||
* Creates a new IndexState
|
||||
**/
|
||||
IndexState::IndexState() {
|
||||
document = 0;
|
||||
done = MB_FALSE;
|
||||
next = 0;
|
||||
} //-- IndexState
|
||||
|
||||
/**
|
||||
* Deletes this IndexState
|
||||
**/
|
||||
IndexState::~IndexState() {};
|
||||
|
||||
//-------------------------------/
|
||||
//- Implementation of OrderInfo -/
|
||||
//-------------------------------/
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/*
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
|
@ -107,19 +108,6 @@ public:
|
|||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
/**
|
||||
* Adds the given child/parent mapping to the list of parents
|
||||
**/
|
||||
void addParentReference(Node* child, Node* parent);
|
||||
|
||||
/**
|
||||
* Indexes until the given node has been indexed
|
||||
**/
|
||||
void continueIndexing(Node* node);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the DocumentOrder for the given Node
|
||||
* @param node a pointer to the Node in which to return the
|
||||
|
@ -128,53 +116,12 @@ private:
|
|||
**/
|
||||
OrderInfo* getDocumentOrder(Node* node);
|
||||
|
||||
|
||||
/**
|
||||
* A Hashtable of attribute's parent nodes
|
||||
**/
|
||||
Map parents;
|
||||
|
||||
/**
|
||||
* A Hashtable of Node/OrderInfo mappings
|
||||
**/
|
||||
Map orders;
|
||||
|
||||
/**
|
||||
* A list of IndexState objects (one for each Document)
|
||||
**/
|
||||
List indexes;
|
||||
|
||||
|
||||
}; //-- DOMHelper
|
||||
|
||||
/**
|
||||
* A class which holds information about the current state of
|
||||
* indexing
|
||||
**/
|
||||
class IndexState {
|
||||
|
||||
public:
|
||||
|
||||
IndexState();
|
||||
~IndexState();
|
||||
|
||||
/**
|
||||
* The Document that this IndexState is for
|
||||
**/
|
||||
Document* document;
|
||||
|
||||
/**
|
||||
* The next node to index
|
||||
**/
|
||||
Node* next;
|
||||
|
||||
/**
|
||||
* A boolean indicating if the indexing has completed
|
||||
**/
|
||||
MBool done;
|
||||
|
||||
}; //-- IndexState
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче