Make final fix for bug 74786 (String cleanup) easier by simplifying the Transformiix DOM. r=sicking, sr=jst. r=Pike on the parts not part of the Mozilla build.

This commit is contained in:
peterv%netscape.com 2003-01-08 22:40:42 +00:00
Родитель 1bb1a7faf6
Коммит 59a6aaa243
21 изменённых файлов: 299 добавлений и 1177 удалений

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

@ -67,13 +67,9 @@ LOBJS =../source/base/ArrayList.$(OBJ_SUFFIX) \
../source/base/txURIUtils.$(OBJ_SUFFIX) \
../source/xml/dom/mozImpl/MozillaAttr.$(OBJ_SUFFIX) \
../source/xml/dom/mozImpl/MozillaDocument.$(OBJ_SUFFIX) \
../source/xml/dom/mozImpl/MozillaDocumentType.$(OBJ_SUFFIX) \
../source/xml/dom/mozImpl/MozillaElement.$(OBJ_SUFFIX) \
../source/xml/dom/mozImpl/MozillaEntity.$(OBJ_SUFFIX) \
../source/xml/dom/mozImpl/MozillaNamedNodeMap.$(OBJ_SUFFIX) \
../source/xml/dom/mozImpl/MozillaNode.$(OBJ_SUFFIX) \
../source/xml/dom/mozImpl/MozillaNodeList.$(OBJ_SUFFIX) \
../source/xml/dom/mozImpl/MozillaNotation.$(OBJ_SUFFIX) \
../source/xml/dom/mozImpl/MozillaProcInstruction.$(OBJ_SUFFIX) \
../source/xpath/AdditiveExpr.$(OBJ_SUFFIX) \
../source/xpath/AttributeValueTemplate.$(OBJ_SUFFIX) \

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

@ -1160,13 +1160,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaNodeList.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>XMLDOMUtils.cpp</PATH>
@ -1328,27 +1321,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaNotation.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaDocumentType.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaEntity.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>Names.cpp</PATH>
@ -1878,21 +1850,6 @@
<PATH>MozillaElement.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaDocumentType.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaEntity.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaNodeList.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaNamedNodeMap.cpp</PATH>
@ -1908,11 +1865,6 @@
<PATH>MozillaNode.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaNotation.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>XMLParser.cpp</PATH>
@ -3116,13 +3068,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaNodeList.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>XMLDOMUtils.cpp</PATH>
@ -3284,27 +3229,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaNotation.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaDocumentType.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaEntity.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>Names.cpp</PATH>
@ -3850,21 +3774,6 @@
<PATH>MozillaElement.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaDocumentType.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaEntity.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaNodeList.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaNamedNodeMap.cpp</PATH>
@ -3880,11 +3789,6 @@
<PATH>MozillaNode.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaNotation.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>NSPR20.shlb</PATH>
@ -4186,24 +4090,12 @@
<PATH>MozillaDocument.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaDocumentType.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaElement.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaEntity.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
@ -4216,18 +4108,6 @@
<PATH>MozillaNode.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaNodeList.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>MozillaNotation.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>

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

@ -33,6 +33,7 @@
#include "txURIUtils.h"
#ifndef TX_EXE
//#include "nsDOMAttribute.h"
#include "nsNetUtil.h"
#include "nsIScriptSecurityManager.h"
#include "nsIDocument.h"
@ -344,19 +345,31 @@ PRBool URIUtils::CanCallerAccess(nsIDOMNode *aNode)
// fails we QI to nsIDocument. If both those QI's fail we won't let
// the caller access this unknown node.
nsCOMPtr<nsIPrincipal> principal;
nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
if (!content) {
// nsCOMPtr<nsIDOMAttributePrivate> attr = do_QueryInterface(aNode);
// if (attr) {
// nsCOMPtr<nsIDOMDocument> domDoc;
// aNode->GetOwnerDocument(getter_AddRefs(domDoc));
// if (!domDoc) {
// }
// }
}
if (!content) {
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aNode);
if (!doc) {
// aNode is neither a nsIContent nor an nsIDocument, something
// weird is going on...
// aNode is neither a nsIContent nor an nsIDOMAttributePrivate nor
// an nsIDocument, something weird is going on...
NS_ERROR("aNode is neither an nsIContent nor an nsIDocument!");
NS_ERROR("aNode is neither an nsIContent nor an "
"nsIDOMAttributePrivate nor an nsIDocument!");
return PR_FALSE;
}
doc->GetPrincipal(getter_AddRefs(principal));
}
else {

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

@ -55,22 +55,12 @@ OBJS =../base/ArrayList.$(OBJ_SUFFIX) \
../base/TxString.$(OBJ_SUFFIX) \
../base/txURIUtils.$(OBJ_SUFFIX) \
../xml/dom/standalone/Attr.$(OBJ_SUFFIX) \
../xml/dom/standalone/CDATASection.$(OBJ_SUFFIX) \
../xml/dom/standalone/DocumentType.$(OBJ_SUFFIX) \
../xml/dom/standalone/EntityReference.$(OBJ_SUFFIX) \
../xml/dom/standalone/CharacterData.$(OBJ_SUFFIX) \
../xml/dom/standalone/Comment.$(OBJ_SUFFIX) \
../xml/dom/standalone/DocumentFragment.$(OBJ_SUFFIX) \
../xml/dom/standalone/DOMImplementation.$(OBJ_SUFFIX) \
../xml/dom/standalone/NodeListDefinition.$(OBJ_SUFFIX) \
../xml/dom/standalone/NodeDefinition.$(OBJ_SUFFIX) \
../xml/dom/standalone/Element.$(OBJ_SUFFIX) \
../xml/dom/standalone/NamedNodeMap.$(OBJ_SUFFIX) \
../xml/dom/standalone/Document.$(OBJ_SUFFIX) \
../xml/dom/standalone/Entity.$(OBJ_SUFFIX) \
../xml/dom/standalone/Notation.$(OBJ_SUFFIX) \
../xml/dom/standalone/ProcessingInstruction.$(OBJ_SUFFIX) \
../xml/dom/standalone/Text.$(OBJ_SUFFIX) \
../xpath/AdditiveExpr.$(OBJ_SUFFIX) \
../xpath/AttributeValueTemplate.$(OBJ_SUFFIX) \
../xpath/BooleanExpr.$(OBJ_SUFFIX) \

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

@ -38,13 +38,9 @@ REQUIRES = string \
CPPSRCS = MozillaAttr.cpp \
MozillaDocument.cpp \
MozillaDocumentType.cpp \
MozillaElement.cpp \
MozillaEntity.cpp \
MozillaNamedNodeMap.cpp \
MozillaNode.cpp \
MozillaNodeList.cpp \
MozillaNotation.cpp \
MozillaProcInstruction.cpp
include $(topsrcdir)/config/rules.mk

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

@ -35,10 +35,7 @@
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentFragment.h"
#include "nsIDOMElement.h"
#include "nsIDOMEntity.h"
#include "nsIDOMNotation.h"
#include "nsIDOMProcessingInstruction.h"
#include "nsIDOMDocumentType.h"
#include "nsIDOMElement.h"
#include "nsIDOMText.h"
@ -266,28 +263,12 @@ Element* Document::getDocumentElement()
return createElement(element);
}
/**
* Call nsIDOMDocument::GetDoctype to get the document's DocumentType.
*
* @return the DocumentType
*/
DocumentType* Document::getDoctype()
{
NSI_FROM_TX(Document);
nsCOMPtr<nsIDOMDocumentType> docType;
nsDocument->GetDoctype(getter_AddRefs(docType));
if (!docType) {
return nsnull;
}
return createDocumentType(docType);
}
/**
* Call nsIDOMDocument::CreateDocumentFragment to create a DocumentFragment.
*
* @return the DocumentFragment
*/
DocumentFragment* Document::createDocumentFragment()
Node* Document::createDocumentFragment()
{
NSI_FROM_TX(Document);
nsCOMPtr<nsIDOMDocumentFragment> fragment;
@ -415,7 +396,7 @@ Attr* Document::createAttribute(nsIDOMAttr* aAttr)
*
* @return the Text node
*/
Text* Document::createTextNode(const String& aData)
Node* Document::createTextNode(const String& aData)
{
NSI_FROM_TX(Document);
nsCOMPtr<nsIDOMText> text;
@ -434,7 +415,7 @@ Text* Document::createTextNode(const String& aData)
*
* @return the Comment node
*/
Comment* Document::createComment(const String& aData)
Node* Document::createComment(const String& aData)
{
NSI_FROM_TX(Document);
nsCOMPtr<nsIDOMComment> comment;
@ -478,15 +459,6 @@ ProcessingInstruction* Document::createProcessingInstruction(
*/
IMPL_CREATE_WRAPPER(ProcessingInstruction)
/**
* Create a wrapper for a nsIDOMEntity, reuses an existing wrapper if possible.
*
* @param aEntity the nsIDOMEntity you want to wrap
*
* @return the Entity
*/
IMPL_CREATE_WRAPPER(Entity)
/**
* Create a wrapper for a nsIDOMNode, reuses an existing wrapper if possible.
*
@ -496,36 +468,6 @@ IMPL_CREATE_WRAPPER(Entity)
*/
IMPL_CREATE_WRAPPER(Node)
/**
* Create a wrapper for a nsIDOMNotation, reuses an existing wrapper if
* possible.
*
* @param aNotation the nsIDOMNotation you want to wrap
*
* @return the Notation
*/
IMPL_CREATE_WRAPPER(Notation)
/**
* Create a wrapper for a nsIDOMDocumentType, reuses an existing wrapper if
* possible.
*
* @param aDoctype the nsIDOMDocumentType you want to wrap
*
* @return the DocumentType
*/
IMPL_CREATE_WRAPPER(DocumentType)
/**
* Create a wrapper for a nsIDOMNodeList, reuses an existing wrapper if
* possible.
*
* @param aList the nsIDOMNodeList you want to wrap
*
* @return the NodeList
*/
IMPL_CREATE_WRAPPER(NodeList)
/**
* Create a wrapper for a nsIDOMNamedNodeMap, reuses an existing wrapper if
* possible.
@ -577,7 +519,6 @@ Node* Document::createWrapper(nsIDOMNode* aNode)
Element* txElement = createElement(element);
NS_RELEASE(element);
return txElement;
break;
}
case nsIDOMNode::ATTRIBUTE_NODE:
{
@ -586,25 +527,17 @@ Node* Document::createWrapper(nsIDOMNode* aNode)
Attr* txAttr = createAttribute(attr);
NS_RELEASE(attr);
return txAttr;
break;
}
case nsIDOMNode::CDATA_SECTION_NODE:
case nsIDOMNode::COMMENT_NODE:
case nsIDOMNode::DOCUMENT_FRAGMENT_NODE:
case nsIDOMNode::DOCUMENT_TYPE_NODE:
case nsIDOMNode::ENTITY_REFERENCE_NODE:
case nsIDOMNode::ENTITY_NODE:
case nsIDOMNode::NOTATION_NODE:
case nsIDOMNode::TEXT_NODE:
{
return createNode(aNode);
break;
}
case nsIDOMNode::ENTITY_NODE:
{
nsIDOMEntity* entity;
CallQueryInterface(aNode, &entity);
Entity* txEntity = createEntity(entity);
NS_RELEASE(entity);
return txEntity;
break;
}
case nsIDOMNode::PROCESSING_INSTRUCTION_NODE:
{
@ -613,7 +546,6 @@ Node* Document::createWrapper(nsIDOMNode* aNode)
ProcessingInstruction* txPi = createProcessingInstruction(pi);
NS_RELEASE(pi);
return txPi;
break;
}
case nsIDOMNode::DOCUMENT_NODE:
{
@ -622,24 +554,6 @@ Node* Document::createWrapper(nsIDOMNode* aNode)
}
NS_ASSERTION(0, "We don't support creating new documents.");
return nsnull;
break;
}
case nsIDOMNode::DOCUMENT_TYPE_NODE:
{
nsIDOMDocumentType* docType;
CallQueryInterface(aNode, &docType);
DocumentType* txDocType = createDocumentType(docType);
NS_RELEASE(docType);
return txDocType;
break;
}
case nsIDOMNode::NOTATION_NODE:
{
nsIDOMNotation* notation;
CallQueryInterface(aNode, &notation);
Notation* txNotation = createNotation(notation);
NS_RELEASE(notation);
return txNotation;
}
default:
{

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

@ -115,22 +115,6 @@ Node* Node::getParentNode()
return mOwnerDocument->createWrapper(tmpParent);
}
/**
* Call nsIDOMNode::GetChildNodes to get the node's childnodes.
*
* @return the node's children
*/
NodeList* Node::getChildNodes()
{
NSI_FROM_TX(Node);
nsCOMPtr<nsIDOMNodeList> tmpNodeList;
nsNode->GetChildNodes(getter_AddRefs(tmpNodeList));
if (!tmpNodeList) {
return nsnull;
}
return mOwnerDocument->createNodeList(tmpNodeList);
}
/**
* Call nsIDOMNode::GetFirstChild to get the node's first child.
*

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

@ -52,32 +52,6 @@ ProcessingInstruction::~ProcessingInstruction()
{
}
/**
* Call nsIDOMProcessingInstruction::GetTarget to retrieve the target of the
* processing instruction.
*
* @return the target of the processing instruction
*/
const String& ProcessingInstruction::getTarget()
{
NSI_FROM_TX(ProcessingInstruction);
nsProcessingInstruction->GetTarget(mTarget);
return mTarget;
}
/**
* Call nsIDOMProcessingInstruction::GetData to retrieve the data of the
* processing instruction.
*
* @return the data of the processing instruction
*/
const String& ProcessingInstruction::getData()
{
NSI_FROM_TX(ProcessingInstruction);
nsProcessingInstruction->GetData(mData);
return mData;
}
/**
* Returns the local name atomized
*

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

@ -63,33 +63,18 @@ extern nsINameSpaceManager* gTxNameSpaceManager;
class nsIDOMAttr;
class nsIDOMDocument;
class nsIDOMDocumentType;
class nsIDOMElement;
class nsIDOMEntity;
class nsIDOMNamedNodeMap;
class nsIDOMNode;
class nsIDOMNodeList;
class nsIDOMNotation;
class nsIDOMProcessingInstruction;
class Attr;
class Document;
class DocumentType;
class Element;
class Entity;
class NamedNodeMap;
class Node;
class NodeList;
class Notation;
class ProcessingInstruction;
// These don't have specific implementation classes.
typedef Node CDataSection;
typedef Node Comment;
typedef Node DocumentFragment;
typedef Node EntityReference;
typedef Node Text;
/**
* This macro creates a nsCOMPtr to a specific interface for the
* wrapper's Mozilla object. The nsCOMPtr will be named like the
@ -188,7 +173,6 @@ public:
virtual const String& getNodeValue();
virtual unsigned short getNodeType() const;
virtual Node* getParentNode();
virtual NodeList* getChildNodes();
virtual Node* getFirstChild();
virtual Node* getLastChild();
virtual Node* getPreviousSibling();
@ -201,10 +185,10 @@ public:
virtual MBool hasChildNodes() const;
//Introduced in DOM2
// Introduced in DOM2
virtual String getNamespaceURI();
//From DOM3 26-Jan-2001 WD
// From DOM3 26-Jan-2001 WD
virtual String getBaseURI();
// txXPathNode functions
@ -234,20 +218,6 @@ private:
OrderInfo* getOrderInfo();
};
/**
* Wrapper class for nsIDOMNodeList.
*/
class NodeList : public MozillaObjectWrapper
{
public:
NodeList(nsIDOMNodeList* aNodeList, Document* aOwner);
~NodeList();
Node* item(PRUint32 aIndex);
PRUint32 getLength();
};
/**
* Wrapper class for nsIDOMNamedNodeMap.
*/
@ -272,7 +242,6 @@ public:
~Document();
Element* getDocumentElement();
DocumentType* getDoctype();
// Determine what kind of node this is, and create the appropriate
// wrapper for it.
@ -284,21 +253,17 @@ public:
// Note the addition of the factory functions to "wrap"
// nsIDOM* objects.
Attr* createAttribute(nsIDOMAttr* aAttr);
DocumentType* createDocumentType(nsIDOMDocumentType* aDoctype);
Element* createElement(nsIDOMElement* aElement);
Entity* createEntity(nsIDOMEntity* aEntity);
NamedNodeMap* createNamedNodeMap(nsIDOMNamedNodeMap* aMap);
Node* createNode(nsIDOMNode* aNode);
NodeList* createNodeList(nsIDOMNodeList* aList);
Notation* createNotation(nsIDOMNotation* aNotation);
ProcessingInstruction* createProcessingInstruction(
nsIDOMProcessingInstruction* aPi);
Comment* createComment(const String& aData);
DocumentFragment* createDocumentFragment();
ProcessingInstruction* createProcessingInstruction(
const String& aTarget, const String& aData);
Text* createTextNode(const String& aData);
Node* createComment(const String& aData);
Node* createDocumentFragment();
ProcessingInstruction* createProcessingInstruction(const String& aTarget,
const String& aData);
Node* createTextNode(const String& aData);
// Introduced in DOM Level 2
Element* createElementNS(const String& aNamespaceURI,
@ -403,64 +368,8 @@ public:
Document* aOwner);
~ProcessingInstruction();
const String& getTarget();
const String& getData();
// txXPathNode functions
MBool getLocalName(txAtom** aLocalName);
private:
String mTarget;
String mData;
};
/**
* Wrapper class for nsIDOMNotation.
*/
class Notation : public Node
{
public:
Notation(nsIDOMNotation* aNotation, Document* aOwner);
~Notation();
const String& getPublicId();
const String& getSystemId();
private:
String publicId;
String systemId;
};
/**
* Wrapper class for nsIDOMEntity.
*/
class Entity : public Node
{
public:
Entity(nsIDOMEntity* aEntity, Document* aOwner);
~Entity();
const String& getPublicId();
const String& getSystemId();
const String& getNotationName();
private:
String publicId;
String systemId;
String notationName;
};
/**
* Wrapper class for nsIDOMDocumentType.
*/
class DocumentType : public Node
{
public:
DocumentType(nsIDOMDocumentType* aDocumentType, Document* aOwner);
~DocumentType();
NamedNodeMap* getEntities();
NamedNodeMap* getNotations();
};
#endif

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

@ -35,8 +35,6 @@
Attr::Attr(const String& name, Document* owner):
NodeDefinition(Node::ATTRIBUTE_NODE, name, NULL_STRING, owner)
{
specified = MB_FALSE;
int idx = nodeName.indexOf(':');
if (idx == kNotFound) {
mLocalName = TX_GET_ATOM(nodeName);
@ -75,7 +73,6 @@ Attr::Attr(const String& aNamespaceURI,
else
mNamespaceID = txNamespaceManager::getNamespaceID(aNamespaceURI);
specified = MB_TRUE;
String localPart;
XMLUtils::getLocalPart(nodeName, localPart);
mLocalName = TX_GET_ATOM(localPart);
@ -89,22 +86,6 @@ Attr::~Attr()
TX_IF_RELEASE_ATOM(mLocalName);
}
//
//Retrieve the name of the attribute from the nodeName data member
//
const String& Attr::getName() const
{
return nodeName;
}
//
//Retrieve the specified flag
//
MBool Attr::getSpecified() const
{
return specified;
}
//
//Retrieve the value of the attribute. This is a comma-deliminated string
//representation of the Attribute's children.
@ -136,8 +117,6 @@ void Attr::setValue(const String& newValue)
NodeDefinition::DeleteChildren();
appendChild(getOwnerDocument()->createTextNode(newValue));
specified = MB_TRUE;
}
@ -162,30 +141,29 @@ const String& Attr::getNodeValue()
return getValue();
}
//
//First check to see if the new node is an allowable child for an Attr. If it
//is, call NodeDefinition's implementation of Insert Before. If not, return
//is, call NodeDefinition's implementation of AppendChild. If not, return
//null as an error.
//
Node* Attr::insertBefore(Node* newChild, Node* refChild)
Node* Attr::appendChild(Node* newChild)
{
Node* returnVal = NULL;
switch (newChild->getNodeType())
{
case Node::TEXT_NODE :
case Node::ENTITY_REFERENCE_NODE:
returnVal = NodeDefinition::insertBefore(newChild, refChild);
{
// Remove the "newChild" if it is already a child of this node
NodeDefinition* pNewChild = (NodeDefinition*)newChild;
if (pNewChild->getParentNode() == this)
pNewChild = implRemoveChild(pNewChild);
if (returnVal)
specified = MB_TRUE;
break;
return implAppendChild(pNewChild);
}
default:
returnVal = NULL;
break;
}
return returnVal;
return nsnull;
}
//

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

@ -37,11 +37,9 @@
//Construct a Document. Currently no parameters are required, but the the
//node constructor is called to identify the node type.
//
Document::Document(DocumentType* theDoctype) :
NodeDefinition(Node::DOCUMENT_NODE, String(NS_LITERAL_STRING("#document")), NULL_STRING, NULL)
Document::Document() : NodeDefinition(Node::DOCUMENT_NODE, NULL_STRING, NULL)
{
documentElement = NULL;
doctype = theDoctype;
}
//
@ -52,150 +50,14 @@ Element* Document::getDocumentElement()
return documentElement;
}
//
//Return the document type of this document object
//
DocumentType* Document::getDoctype()
{
return doctype;
}
//
//Return a constant reference to the DOM's Implementation
//
const DOMImplementation& Document::getImplementation()
{
return implementation;
}
//
//Ensure that no Element node is inserted if the document already has an
//associated Element child.
//
Node* Document::insertBefore(Node* newChild, Node* refChild)
{
Node* returnVal = NULL;
NodeDefinition* pCurrentNode = NULL;
NodeDefinition* pNextNode = NULL;
//Convert to a NodeDefinition Pointer
NodeDefinition* pNewChild = (NodeDefinition*)newChild;
NodeDefinition* pRefChild = (NodeDefinition*)refChild;
//Check to see if the reference node is a child of this node
if ((refChild != NULL) && (pRefChild->getParentNode() != this))
return NULL;
switch (pNewChild->getNodeType())
{
case Node::DOCUMENT_FRAGMENT_NODE :
pCurrentNode = (NodeDefinition*)pNewChild->getFirstChild();
while (pCurrentNode)
{
pNextNode = (NodeDefinition*)pCurrentNode->getNextSibling();
//Make sure that if the current node is an Element, the document
//doesn't already have one.
if ((pCurrentNode->getNodeType() != Node::ELEMENT_NODE) ||
((pCurrentNode->getNodeType() == Node::ELEMENT_NODE) &&
(documentElement == NULL)))
{
pCurrentNode = (NodeDefinition*)pNewChild->removeChild(pCurrentNode);
implInsertBefore(pCurrentNode, pRefChild);
if (pCurrentNode->getNodeType() == Node::ELEMENT_NODE)
documentElement = (Element*)pCurrentNode;
}
pCurrentNode = pNextNode;
}
returnVal = newChild;
break;
case Node::PROCESSING_INSTRUCTION_NODE :
case Node::COMMENT_NODE :
case Node::DOCUMENT_TYPE_NODE :
returnVal = implInsertBefore(pNewChild, pRefChild);
break;
case Node::ELEMENT_NODE :
if (!documentElement)
{
documentElement = (Element*)pNewChild;
returnVal = implInsertBefore(pNewChild, pRefChild);
}
else
returnVal = NULL;
break;
default:
returnVal = NULL;
}
return returnVal;
}
//
//Ensure that if the newChild is an Element and the Document already has an
//element, then oldChild should be specifying the existing element. If not
//then the replacement can not take place.
//
Node* Document::replaceChild(Node* newChild, Node* oldChild)
{
Node* replacedChild = NULL;
if (newChild->getNodeType() != Node::ELEMENT_NODE)
{
//The new child is not an Element, so perform replacement
replacedChild = NodeDefinition::replaceChild(newChild, oldChild);
//If old node was an Element, then the document's element has been
//replaced with a non-element node. Therefore clear the documentElement
//pointer
if (replacedChild && (oldChild->getNodeType() == Node::ELEMENT_NODE))
documentElement = NULL;
return replacedChild;
}
else
{
//A node is being replaced with an Element. If the document does not
//have an elemet yet, then just allow the replacemetn to take place.
if (!documentElement)
replacedChild = NodeDefinition::replaceChild(newChild, oldChild);
else if (oldChild->getNodeType() == Node::ELEMENT_NODE)
replacedChild = NodeDefinition::replaceChild(newChild, oldChild);
if (replacedChild)
documentElement = (Element*)newChild;
return replacedChild;
}
}
//
//Update the documentElement pointer if the associated Element node is being
//removed.
//
Node* Document::removeChild(Node* oldChild)
{
Node* removedChild = NULL;
removedChild = NodeDefinition::removeChild(oldChild);
if (removedChild && (removedChild->getNodeType() == Node::ELEMENT_NODE))
documentElement = NULL;
return removedChild;
}
//
//Construct an empty document fragment.
// NOTE: The caller is responsible for cleaning up this fragment's memory
// when it is no longer needed.
//
DocumentFragment* Document::createDocumentFragment()
Node* Document::createDocumentFragment()
{
return new DocumentFragment(String(NS_LITERAL_STRING("#document-fragment")), NULL_STRING, this);
return new DocumentFragment(this);
}
//
@ -230,25 +92,17 @@ Attr* Document::createAttributeNS(const String& aNamespaceURI,
//
//Construct a text node with the given data
//
Text* Document::createTextNode(const String& theData)
Node* Document::createTextNode(const String& theData)
{
return new Text(theData, this);
return new NodeDefinition(Node::TEXT_NODE, theData, this);
}
//
//Construct a comment node with the given data
//
Comment* Document::createComment(const String& theData)
Node* Document::createComment(const String& theData)
{
return new Comment(theData, this);
}
//
//Construct a CDATASection node with the given data
//
CDATASection* Document::createCDATASection(const String& theData)
{
return new CDATASection(theData, this);
return new NodeDefinition(Node::COMMENT_NODE, theData, this);
}
//
@ -261,14 +115,6 @@ ProcessingInstruction*
return new ProcessingInstruction(target, data, this);
}
//
//Construct an EntityReference with the given name
//
EntityReference* Document::createEntityReference(const String& name)
{
return new EntityReference(name, this);
}
//
//Return an Element by ID, introduced by DOM2
//
@ -281,6 +127,42 @@ Element* Document::getElementById(const String aID)
return NULL;
}
Node* Document::appendChild(Node* newChild)
{
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;
}
String Document::getBaseURI()
{
return documentBaseURI;

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

@ -73,6 +73,30 @@ Element::~Element()
TX_IF_RELEASE_ATOM(mLocalName);
}
Node* Element::appendChild(Node* newChild)
{
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;
}
//
//Return the elements local (unprefixed) name.
//
@ -122,61 +146,11 @@ PRInt32 Element::getNamespaceID()
return mNamespaceID;
}
//
//First check to see if the new node is an allowable child for an Element. If
//it is, call NodeDefinition's implementation of Insert Before. If not, return
//null as an error
//
Node* Element::insertBefore(Node* newChild, Node* refChild)
{
Node* returnVal = NULL;
switch (newChild->getNodeType())
{
case Node::ELEMENT_NODE :
case Node::TEXT_NODE :
case Node::COMMENT_NODE :
case Node::PROCESSING_INSTRUCTION_NODE :
case Node::CDATA_SECTION_NODE :
case Node::DOCUMENT_FRAGMENT_NODE : //-- added 19990813 (kvisco)
case Node::ENTITY_REFERENCE_NODE:
returnVal = NodeDefinition::insertBefore(newChild, refChild);
break;
default:
returnVal = NULL;
}
return returnVal;
}
//
//Return the tagName for this element. This is simply the nodeName.
//
const String& Element::getTagName()
{
return nodeName;
}
NamedNodeMap* Element::getAttributes()
{
return &mAttributes;
}
//
//Retreive an attribute's value by name. If the attribute does not exist,
//return a reference to the pre-created, constatnt "NULL STRING".
//
const String& Element::getAttribute(const String& name)
{
Node* tempNode = mAttributes.getNamedItem(name);
if (tempNode)
return mAttributes.getNamedItem(name)->getNodeValue();
else
return NULL_STRING;
}
//
//Add an attribute to this Element. Create a new Attr object using the
//name and value specified. Then add the Attr to the the Element's
@ -238,15 +212,6 @@ void Element::setAttributeNS(const String& aNamespaceURI,
}
}
//
//Remove an attribute from the mAttributes NamedNodeMap, and free its memory.
// NOTE: How do default values enter into this picture
//
void Element::removeAttribute(const String& name)
{
delete mAttributes.removeNamedItem(name);
}
//
//Return the attribute specified by name
//
@ -302,34 +267,3 @@ MBool Element::hasAttr(txAtom* aLocalName, PRInt32 aNSID)
}
return MB_FALSE;
}
//
//Set a new attribute specifed by the newAttr node. If an attribute with that
//name already exists, the existing Attr is removed from the list and return to
//the caller, else NULL is returned.
//
Attr* Element::setAttributeNode(Attr* newAttr)
{
Attr* pOldAttr = (Attr*)mAttributes.removeNamedItem(newAttr->getNodeName());
mAttributes.setNamedItem(newAttr);
return pOldAttr;
}
//
//Remove the Attribute from the attributes list and return to the caller. If
//the node is not found, return NULL.
//
Attr* Element::removeAttributeNode(Attr* oldAttr)
{
return (Attr*)mAttributes.removeNamedItem(oldAttr->getNodeName());
}
NodeList* Element::getElementsByTagName(const String& name)
{
return 0;
}
void Element::normalize()
{
}

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

@ -31,22 +31,12 @@ REQUIRES = string \
$(NULL)
CPPSRCS = Attr.cpp \
CDATASection.cpp \
CharacterData.cpp \
Comment.cpp \
DOMImplementation.cpp \
Document.cpp \
DocumentFragment.cpp \
DocumentType.cpp \
Element.cpp \
Entity.cpp \
EntityReference.cpp \
NamedNodeMap.cpp \
NodeDefinition.cpp \
NodeListDefinition.cpp \
Notation.cpp \
ProcessingInstruction.cpp \
Text.cpp
ProcessingInstruction.cpp
include $(topsrcdir)/config/rules.mk

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

@ -38,21 +38,46 @@
NodeDefinition::NodeDefinition(NodeType type, const String& name,
const String& value, Document* owner)
{
nodeName = name;
nodeValue = value;
nodeType = type;
Init(type, value, owner);
}
parentNode = NULL;
previousSibling = NULL;
nextSibling = NULL;;
firstChild = NULL;
lastChild = NULL;
ownerDocument = owner;
length = 0;
mOrderInfo = 0;
NodeDefinition::NodeDefinition(NodeType aType, const String& aValue,
Document* aOwner)
{
switch (aType)
{
case CDATA_SECTION_NODE:
{
nodeName.Append(NS_LITERAL_STRING("#cdata-section"));
break;
}
case COMMENT_NODE:
{
nodeName.Append(NS_LITERAL_STRING("#comment"));
break;
}
case DOCUMENT_NODE:
{
nodeName.Append(NS_LITERAL_STRING("#document"));
break;
}
case DOCUMENT_FRAGMENT_NODE:
{
nodeName.Append(NS_LITERAL_STRING("#document-fragment"));
break;
}
case TEXT_NODE:
{
nodeName.Append(NS_LITERAL_STRING("#text"));
break;
}
default:
{
break;
}
}
Init(aType, aValue, aOwner);
}
//
@ -64,6 +89,25 @@ NodeDefinition::~NodeDefinition()
delete mOrderInfo;
}
void
NodeDefinition::Init(NodeType aType, const String& aValue,
Document* aOwner)
{
nodeType = aType;
nodeValue = aValue;
ownerDocument = aOwner;
parentNode = NULL;
previousSibling = NULL;
nextSibling = NULL;;
firstChild = NULL;
lastChild = NULL;
length = 0;
mOrderInfo = 0;
}
//
//Remove and delete all children of this node
//
@ -104,11 +148,6 @@ Node* NodeDefinition::getParentNode() const
return parentNode;
}
NodeList* NodeDefinition::getChildNodes()
{
return this;
}
Node* NodeDefinition::getFirstChild() const
{
return firstChild;
@ -165,181 +204,56 @@ void NodeDefinition::setNodeValue(const String& newNodeValue)
nodeValue = newNodeValue;
}
//
//Insert the "newChild" node before the "refChild" node. Return a pointer to
//the inserted child. If the node to insert is a document fragment, then
//insert each child of the document fragment, and return the document fragment
//which should be empty if all the inserts suceeded.
//This function's responsibility is to check for and handle document fragments
//vs. plain nodes.
// *** NOTE: Need to check the document types before inserting.
//
// The decision to return the possibly empty document fragment
// was an implementation choice. The spec did not dictate what
// whould occur.
//
Node* NodeDefinition::insertBefore(Node* newChild,
Node* refChild)
{
NodeDefinition* pCurrentNode = NULL;
NodeDefinition* pNextNode = NULL;
//Convert to a NodeDefinition Pointer
NodeDefinition* pNewChild = (NodeDefinition*)newChild;
NodeDefinition* pRefChild = (NodeDefinition*)refChild;
//Check to see if the reference node is a child of this node
if ((refChild != NULL) && (pRefChild->parentNode != this))
return NULL;
if (newChild->getNodeType() == Node::DOCUMENT_FRAGMENT_NODE)
{
pCurrentNode = pNewChild->firstChild;
while (pCurrentNode)
{
pNextNode = pCurrentNode->nextSibling;
pCurrentNode = (NodeDefinition*)pNewChild->removeChild(pCurrentNode);
implInsertBefore(pCurrentNode, pRefChild);
pCurrentNode = pNextNode;
}
return newChild;
}
else
return implInsertBefore(pNewChild, pRefChild);
}
//
//The code that actually insert one node before another.
//
Node* NodeDefinition::implInsertBefore(NodeDefinition* pNewChild,
NodeDefinition* pRefChild)
{
//Remove the "newChild" if it is already a child of this node
if (pNewChild->parentNode == this)
pNewChild = (NodeDefinition*)removeChild(pNewChild);
//The new child should not be a child of any other node
if ((pNewChild->previousSibling == NULL) &&
(pNewChild->nextSibling == NULL) &&
(pNewChild->parentNode == NULL))
{
if (pRefChild == NULL)
{
//Append
pNewChild->previousSibling = lastChild;
if (lastChild)
lastChild->nextSibling = pNewChild;
lastChild = pNewChild;
}
else
{
//Insert before the reference node
if (pRefChild->previousSibling)
pRefChild->previousSibling->nextSibling = pNewChild;
pNewChild->nextSibling = pRefChild;
pNewChild->previousSibling = pRefChild->previousSibling;
pRefChild->previousSibling = pNewChild;
}
pNewChild->parentNode = this;
if (pNewChild->previousSibling == NULL)
firstChild = pNewChild;
length++;
return pNewChild;
}
return NULL;
}
//
//Replace "oldChild" with "newChild". Return the replaced node, or NULL
//otherwise.
// *** NOTE: Need to check that the documents match ***
//
Node* NodeDefinition::replaceChild(Node* newChild,
Node* oldChild)
{
NodeDefinition* pOldChild = (NodeDefinition*)oldChild;
NodeDefinition* pNextSibling = NULL;
//If the newChild is replacing itself then we don't need to do anything
if (pOldChild == newChild)
return pOldChild;
//If "oldChild" is a child of this node, remove it from the list.
pOldChild = (NodeDefinition*)removeChild(oldChild);
//If the removal was successful... Else, return null
if (pOldChild)
{
//Try to insert the new node before the old node's next sibling. If
//successful, just returned the replaced child. If not succesful,
//reinsert the old node, and return NULL.
pNextSibling = pOldChild->nextSibling;
if (!insertBefore(newChild, pNextSibling))
{
insertBefore(pOldChild, pNextSibling);
pOldChild = NULL;
}
}
return pOldChild;
}
//
//Remove the specified "oldChild" from this node's children. First make sure
//the specified node is a child of this node. Return the removed node, NULL
//otherwise.
//
Node* NodeDefinition::removeChild(Node* oldChild)
{
NodeDefinition* pOldChild = (NodeDefinition*)oldChild;
//If "oldChild" is a child of this node, adjust pointers to remove it, and
//clear "oldChild"'s sibling and parent pointers.
if (pOldChild->parentNode == this)
{
if (pOldChild != firstChild)
pOldChild->previousSibling->nextSibling = pOldChild->nextSibling;
else
firstChild = pOldChild->nextSibling;
if (pOldChild != lastChild)
pOldChild->nextSibling->previousSibling = pOldChild->previousSibling;
else
lastChild = pOldChild->previousSibling;
pOldChild->nextSibling = NULL;
pOldChild->previousSibling = NULL;
pOldChild->parentNode = NULL;
length--;
return pOldChild;
}
return NULL;
}
//
//Append a new child node. First make sure the new child is not already a
//child of another node. Return the appended node.
// *** NOTE *** Need to eventually check to make sure the documents match ***
//
Node* NodeDefinition::appendChild(Node* newChild)
{
return insertBefore(newChild, NULL);
return nsnull;
}
Node* NodeDefinition::cloneNode(MBool deep, Node* dest)
NodeDefinition* NodeDefinition::implAppendChild(NodeDefinition* newChild)
{
return 0;
// 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;
}
NodeDefinition* NodeDefinition::implRemoveChild(NodeDefinition* oldChild)
{
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;
}
MBool NodeDefinition::hasChildNodes() const

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

@ -52,57 +52,11 @@ ProcessingInstruction::~ProcessingInstruction()
TX_IF_RELEASE_ATOM(mLocalName);
}
//
//Return the Target of the processing instruction. This is simply the
//nodeName.
//
const String& ProcessingInstruction::getTarget() const
{
return nodeName;
}
//
//Return the Data of the processing instruction. This is simply the value
//of the node, "nodeValue"
//
const String& ProcessingInstruction::getData() const
{
return nodeValue;
}
//
//Set the Data element of the processing instruction.
void ProcessingInstruction::setData(const String& theData)
{
nodeValue = theData;
}
//
//ProcessingInstruction nodes can not have any children, so just return null
//from all child manipulation functions.
//
Node* ProcessingInstruction::insertBefore(Node* newChild, Node* refChild)
{
return NULL;
}
Node* ProcessingInstruction::replaceChild(Node* newChild, Node* oldChild)
{
return NULL;
}
Node* ProcessingInstruction::removeChild(Node* oldChild)
{
return NULL;
}
Node* ProcessingInstruction::appendChild(Node* newChild)
{
return NULL;
}
MBool ProcessingInstruction::getLocalName(txAtom** aLocalName)
{
if (!aLocalName)

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

@ -50,17 +50,11 @@ typedef 0 NULL;
#define kTxAttrIndexOffset 0x40000000;
#define kTxChildIndexOffset 0x80000000;
class NodeList;
class NamedNodeMap;
class Document;
class Element;
class Attr;
class Text;
class Comment;
class CDATASection;
class ProcessingInstruction;
class EntityReference;
class DocumentType;
/*
* NULL string for use by Element::getAttribute() for when the attribute
@ -77,22 +71,6 @@ const String NULL_STRING;
// kNameSpaceID_XSLT is 6 for module, see nsINameSpaceManager.h
#define kNameSpaceID_XSLT 3
//
//Definition and Implementation the DOMImplementation class
//
class DOMImplementation
{
public:
DOMImplementation();
~DOMImplementation();
MBool hasFeature(String feature, const String& version) const;
private:
String implFeature;
String implVersion;
};
//
// Abstract Class defining the interface for a Node. See NodeDefinition below
// for the actual implementation of the WC3 node.
@ -124,7 +102,6 @@ class Node : public TxObject
virtual const String& getNodeValue() = 0;
virtual unsigned short getNodeType() const = 0;
virtual Node* getParentNode() const = 0;
virtual NodeList* getChildNodes() = 0;
virtual Node* getFirstChild() const = 0;
virtual Node* getLastChild() const = 0;
virtual Node* getPreviousSibling() const = 0;
@ -136,11 +113,7 @@ class Node : public TxObject
virtual void setNodeValue(const String& nodeValue) = 0;
//Node manipulation functions
virtual Node* insertBefore(Node* newChild, Node* refChild) = 0;
virtual Node* replaceChild(Node* newChild, Node* oldChild) = 0;
virtual Node* removeChild(Node* oldChild) = 0;
virtual Node* appendChild(Node* newChild) = 0;
virtual Node* cloneNode(MBool deep, Node* dest) = 0;
virtual MBool hasChildNodes() const = 0;
@ -256,8 +229,6 @@ class AttrMap : public NamedNodeMap
class NodeDefinition : public Node, public NodeList
{
public:
NodeDefinition(NodeType type, const String& name,
const String& value, Document* owner);
virtual ~NodeDefinition(); //Destructor, delete all children of node
//Read functions
@ -265,7 +236,6 @@ class NodeDefinition : public Node, public NodeList
virtual const String& getNodeValue();
unsigned short getNodeType() const;
Node* getParentNode() const;
NodeList* getChildNodes();
Node* getFirstChild() const;
Node* getLastChild() const;
Node* getPreviousSibling() const;
@ -277,11 +247,7 @@ class NodeDefinition : public Node, public NodeList
virtual void setNodeValue(const String& nodeValue);
//Child node manipulation functions
virtual Node* insertBefore(Node* newChild, Node* refChild);
virtual Node* replaceChild(Node* newChild, Node* oldChild);
virtual Node* removeChild(Node* oldChild);
virtual Node* appendChild(Node* newChild);
Node* cloneNode(MBool deep, Node* dest);
MBool hasChildNodes() const;
@ -302,17 +268,33 @@ class NodeDefinition : public Node, public NodeList
Node* item(PRUint32 index);
PRUint32 getLength();
//Only to be used from XMLParser
void appendData(PRUnichar* aData, int aLength)
{
nodeValue.Append(aData, aLength);
};
protected:
friend class Document;
NodeDefinition(NodeType type, const String& name,
const String& value, Document* owner);
NodeDefinition(NodeType aType, const String& aValue,
Document* aOwner);
//Name, value, and attributes for this node. Available to derrived
//classes, since those derrived classes have a better idea how to use them,
//than the generic node does.
String nodeName;
String nodeValue;
NodeDefinition* implAppendChild(NodeDefinition* newChild);
NodeDefinition* implRemoveChild(NodeDefinition* oldChild);
void DeleteChildren();
Node* implInsertBefore(NodeDefinition* newChild, NodeDefinition* refChild);
private:
void Init(NodeType aType, const String& aValue, Document* aOwner);
//Type of node this is
NodeType nodeType;
@ -351,11 +333,36 @@ class NodeDefinition : public Node, public NodeList
class DocumentFragment : public NodeDefinition
{
public:
DocumentFragment(const String& name, const String& value, Document* owner);
Node* appendChild(Node* newChild)
{
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);
//Override insertBefore to limit Elements to having only certain nodes as
//children
Node* insertBefore(Node* newChild, Node* refChild);
return implAppendChild(pNewChild);
}
default:
break;
}
return nsnull;
};
private:
friend class Document;
DocumentFragment(Document* aOwner) :
NodeDefinition(Node::DOCUMENT_FRAGMENT_NODE, NULL_STRING, aOwner)
{
};
};
//
@ -364,38 +371,30 @@ class DocumentFragment : public NodeDefinition
class Document : public NodeDefinition
{
public:
Document(DocumentType* theDoctype = NULL);
Document();
Element* getDocumentElement();
DocumentType* getDoctype();
const DOMImplementation& getImplementation();
//Factory functions for various node types
DocumentFragment* createDocumentFragment();
Node* createComment(const String& aData);
Node* createDocumentFragment();
ProcessingInstruction* createProcessingInstruction(const String& aTarget,
const String& aData);
Node* createTextNode(const String& theData);
Element* createElement(const String& tagName);
Attr* createAttribute(const String& name);
Text* createTextNode(const String& theData);
Comment* createComment(const String& theData);
CDATASection* createCDATASection(const String& theData);
ProcessingInstruction* createProcessingInstruction(const String& target,
const String& data);
EntityReference* createEntityReference(const String& name);
//Override functions to enforce the One Element rule for documents, as well
//as limit documents to certain types of nodes.
Node* insertBefore(Node* newChild, Node* refChild);
Node* replaceChild(Node* newChild, Node* oldChild);
Node* removeChild(Node* oldChild);
// Introduced in DOM Level 2
Element* createElementNS(const String& aNamespaceURI,
const String& aTagName);
Attr* createAttributeNS(const String& aNamespaceURI,
const String& aName);
Element* getElementById(const String aID);
// Node manipulation functions
Node* appendChild(Node* newChild);
//Override to return documentBaseURI
String getBaseURI();
@ -404,8 +403,6 @@ class Document : public NodeDefinition
private:
Element* documentElement;
DocumentType* doctype;
DOMImplementation implementation;
// This class is friend to be able to set the documentBaseURI
friend class XMLParser;
@ -418,28 +415,17 @@ class Document : public NodeDefinition
class Element : public NodeDefinition
{
public:
Element(const String& tagName, Document* owner);
Element(const String& aNamespaceURI, const String& aTagName,
Document* aOwner);
virtual ~Element();
//Override insertBefore to limit Elements to having only certain nodes as
//children
Node* insertBefore(Node* newChild, Node* refChild);
const String& getTagName();
NamedNodeMap* getAttributes();
const String& getAttribute(const String& name);
void setAttribute(const String& name, const String& value);
void setAttributeNS(const String& aNamespaceURI,
const String& aName,
const String& aValue);
void removeAttribute(const String& name);
Attr* getAttributeNode(const String& name);
Attr* setAttributeNode(Attr* newAttr);
Attr* removeAttributeNode(Attr* oldAttr);
NodeList* getElementsByTagName(const String& name);
void normalize();
// Node manipulation functions
Node* appendChild(Node* newChild);
//txXPathNode functions override
MBool getLocalName(txAtom** aLocalName);
@ -448,6 +434,11 @@ class Element : public NodeDefinition
MBool hasAttr(txAtom* aLocalName, PRInt32 aNSID);
private:
friend class Document;
Element(const String& tagName, Document* owner);
Element(const String& aNamespaceURI, const String& aTagName,
Document* aOwner);
AttrMap mAttributes;
txAtom* mLocalName;
PRInt32 mNamespaceID;
@ -460,17 +451,9 @@ class Element : public NodeDefinition
//
class Attr : public NodeDefinition
{
// These need to be friend to be able to update the ownerElement
friend class AttrMap;
friend class Element;
public:
Attr(const String& name, Document* owner);
Attr(const String& aNamespaceURI, const String& aName,
Document* aOwner);
virtual ~Attr();
const String& getName() const;
MBool getSpecified() const;
const String& getValue();
void setValue(const String& newValue);
@ -479,9 +462,8 @@ class Attr : public NodeDefinition
void setNodeValue(const String& nodeValue);
const String& getNodeValue();
//Override insertBefore to limit Attr to having only certain nodes as
//children
Node* insertBefore(Node* newChild, Node* refChild);
// Node manipulation functions
Node* appendChild(Node* newChild);
//txXPathNode functions override
MBool getLocalName(txAtom** aLocalName);
@ -489,93 +471,21 @@ class Attr : public NodeDefinition
Node* getXPathParent();
private:
friend class Document;
Attr(const String& name, Document* owner);
Attr(const String& aNamespaceURI, const String& aName,
Document* aOwner);
// These need to be friend to be able to update the ownerElement
friend class AttrMap;
friend class Element;
Element* ownerElement;
MBool specified;
txAtom* mLocalName;
PRInt32 mNamespaceID;
};
//
//Definition and Implementation of CharacterData. This class mearly provides
//the interface and some default implementation. It is not intended to be
//instantiated by users of the DOM
//
class CharacterData : public NodeDefinition
{
public:
const String& getData() const;
void setData(const String& source);
PRUint32 getLength() const;
String& substringData(PRUint32 offset, PRUint32 count, String& dest);
void appendData(const String& arg);
void insertData(PRUint32 offset, const String& arg);
void deleteData(PRUint32 offset, PRUint32 count);
void replaceData(PRUint32 offset, PRUint32 count, const String& arg);
protected:
CharacterData(NodeType type, const String& name,
const String& value, Document* owner);
};
//
//Definition and Implementation of a Text node. The bulk of the functionality
//comes from CharacterData and NodeDefinition.
//
class Text : public CharacterData
{
public:
Text(const String& theData, Document* owner);
Text* splitText(PRUint32 offset);
//Override "child manipulation" function since Text Nodes can not have
//any children.
Node* insertBefore(Node* newChild, Node* refChild);
Node* replaceChild(Node* newChild, Node* oldChild);
Node* removeChild(Node* oldChild);
Node* appendChild(Node* newChild);
protected:
Text(NodeType type, const String& name, const String& value,
Document* owner);
};
//
//Definition and Implementation of a Comment node. All of the functionality is
//inherrited from CharacterData and NodeDefinition.
//
class Comment : public CharacterData
{
public:
Comment(const String& theData, Document* owner);
//Override "child manipulation" function since Comment Nodes can not have
//any children.
Node* insertBefore(Node* newChild, Node* refChild);
Node* replaceChild(Node* newChild, Node* oldChild);
Node* removeChild(Node* oldChild);
Node* appendChild(Node* newChild);
};
//
//Definition and Implementation of a CDATASection node. All of the
//functionality is inherrited from Text, CharacterData, and NodeDefinition
//
class CDATASection : public Text
{
public:
CDATASection(const String& theData, Document* owner);
//Override "child manipulation" function since CDATASection Nodes can not
//have any children.
Node* insertBefore(Node* newChild, Node* refChild);
Node* replaceChild(Node* newChild, Node* oldChild);
Node* removeChild(Node* oldChild);
Node* appendChild(Node* newChild);
};
//
//Definition and Implemention of a ProcessingInstruction node. Most
//functionality is inherrited from NodeDefinition.
@ -587,115 +497,19 @@ class CDATASection : public Text
class ProcessingInstruction : public NodeDefinition
{
public:
ProcessingInstruction(const String& theTarget, const String& theData,
Document* owner);
~ProcessingInstruction();
const String& getTarget() const;
const String& getData() const;
void setData(const String& theData);
//Override "child manipulation" function since ProcessingInstruction Nodes
//can not have any children.
Node* insertBefore(Node* newChild, Node* refChild);
Node* replaceChild(Node* newChild, Node* oldChild);
Node* removeChild(Node* oldChild);
Node* appendChild(Node* newChild);
//txXPathNode functions override
MBool getLocalName(txAtom** aLocalName);
private:
friend class Document;
ProcessingInstruction(const String& theTarget, const String& theData,
Document* owner);
txAtom* mLocalName;
};
//
//Definition and Implementation of a Notation. Most functionality
//is inherrited from NodeDefinition.
//
class Notation : public NodeDefinition
{
public:
Notation(const String& name, const String& pubID,
const String& sysID);
const String& getPublicId() const;
const String& getSystemId() const;
//Override "child manipulation" function since Notation Nodes
//can not have any children.
Node* insertBefore(Node* newChild, Node* refChild);
Node* replaceChild(Node* newChild, Node* oldChild);
Node* removeChild(Node* oldChild);
Node* appendChild(Node* newChild);
private:
String publicId;
String systemId;
};
//
//Definition and Implementation of an Entity
//
class Entity : public NodeDefinition
{
public:
Entity(const String& name, const String& pubID,
const String& sysID, const String& notName);
const String& getPublicId() const;
const String& getSystemId() const;
const String& getNotationName() const;
//Override insertBefore to limit Entity to having only certain nodes as
//children
Node* insertBefore(Node* newChild, Node* refChild);
private:
String publicId;
String systemId;
String notationName;
};
//
//Definition and Implementation of an EntityReference
//
class EntityReference : public NodeDefinition
{
public:
EntityReference(const String& name, Document* owner);
//Override insertBefore to limit EntityReference to having only certain
//nodes as children
Node* insertBefore(Node* newChild, Node* refChild);
};
//
//Definition and Implementation of the DocumentType
//
class DocumentType : public NodeDefinition
{
public:
DocumentType(const String& name, NamedNodeMap* theEntities,
NamedNodeMap* theNotations);
~DocumentType();
NamedNodeMap* getEntities();
NamedNodeMap* getNotations();
//Override "child manipulation" function since Notation Nodes
//can not have any children.
Node* insertBefore(Node* newChild, Node* refChild);
Node* replaceChild(Node* newChild, Node* oldChild);
Node* removeChild(Node* oldChild);
Node* appendChild(Node* newChild);
private:
NamedNodeMap* entities;
NamedNodeMap* notations;
};
class txNamespaceManager
{
public:

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

@ -217,11 +217,11 @@ int endElement(void *userData, const XML_Char* name)
void charData(void* userData, const XML_Char* s, int len)
{
ParserState* ps = (ParserState*)userData;
String data((PRUnichar*)s, len);
Node* prevSib = ps->currentNode->getLastChild();
if (prevSib && prevSib->getNodeType()==Node::TEXT_NODE){
((CharacterData*)prevSib)->appendData(data);
((NodeDefinition*)prevSib)->appendData((PRUnichar*)s, len);
} else {
String data((PRUnichar*)s, len);
ps->currentNode->appendChild(ps->document->createTextNode(data));
};
} //-- charData

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

@ -192,7 +192,8 @@ txXSLTProcessor::copyNode(Node* aSourceNode, ProcessorState* aPs)
{
ProcessingInstruction* pi = (ProcessingInstruction*)aSourceNode;
NS_ASSERTION(aPs->mResultHandler, "mResultHandler must not be NULL!");
aPs->mResultHandler->processingInstruction(pi->getTarget(), pi->getData());
aPs->mResultHandler->processingInstruction(pi->getNodeName(),
pi->getNodeValue());
break;
}
case Node::TEXT_NODE:

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

@ -51,7 +51,6 @@
#include "nsIDOMNode.h"
#include "txXMLEventHandler.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentFragment.h"
#include "nsIXSLTProcessorObsolete.h"
/* bacd8ad0-552f-11d3-a9f7-000064657374 */

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

@ -52,7 +52,7 @@ txRtfHandler::txRtfHandler(Document* aDocument,
if (!mResultTreeFragment)
return;
DocumentFragment* fragment = mDocument->createDocumentFragment();
Node* fragment = mDocument->createDocumentFragment();
NS_ASSERTION(fragment, "Out of memory creating a document fragmen");
// XXX ErrorReport: Out of memory
mResultTreeFragment->append(fragment);
@ -88,7 +88,7 @@ void txRtfHandler::characters(const String& aData)
if (!mCurrentNode)
return;
Text* text = mDocument->createTextNode(aData);
Node* text = mDocument->createTextNode(aData);
mCurrentNode->appendChild(text);
}
@ -98,7 +98,7 @@ void txRtfHandler::comment(const String& aData)
if (!mCurrentNode)
return;
Comment* comment = mDocument->createComment(aData);
Node* comment = mDocument->createComment(aData);
mCurrentNode->appendChild(comment);
}

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

@ -258,10 +258,10 @@ void txStandaloneXSLTProcessor::getHrefFromStylesheetPI(Document& xmlDocument,
String tmpHref;
while (node) {
if (node->getNodeType() == Node::PROCESSING_INSTRUCTION_NODE) {
String target = ((ProcessingInstruction*)node)->getTarget();
String target = node->getNodeName();
if (STYLESHEET_PI.Equals(target) ||
STYLESHEET_PI_OLD.Equals(target)) {
String data = ((ProcessingInstruction*)node)->getData();
String data = node->getNodeValue();
type.Truncate();
tmpHref.Truncate();
parseStylesheetPI(data, type, tmpHref);