2
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
4
* The contents of this file are subject to the Mozilla Public License
5
* Version 1.0 (the "License"); you may not use this file except in
6
* compliance with the License. You may obtain a copy of the License at
7
* http://www.mozilla.org/MPL/
9
* The program provided "as is" without any warranty express or
10
* implied, including the warranty of non-infringement and the implied
11
* warranties of merchantibility and fitness for a particular purpose.
12
* The Copyright owner will not be liable for any damages suffered by
13
* you as a result of using the Program. In no event will the Copyright
14
* owner be liable for any special, indirect or consequential damages or
15
* lost profits even if the Copyright owner has been advised of the
16
* possibility of their occurrence.
18
* Please see release.txt distributed with this file for more information.
21
// Tom Kneeland (3/29/99)
23
// Implementation of the Document Object Model Level 1 Core
24
// Implementation of the Document class
26
// Modification History:
28
// TK 03/29/99 Created
29
// LF 08/06/1999 Removed Default argument initializer from
30
// Document() constructor
31
// LF 08/06/1999 fixed typo: defalut to default
37
//Construct a Document. Currently no parameters are required, but the the
38
//node constructor is called to identify the node type.
40
Document::Document() : NodeDefinition(Node::DOCUMENT_NODE, nsString(), NULL)
43
documentElement = nsnull;
47
//Return the one and only element for this document
49
Element* Document::getDocumentElement()
51
return documentElement;
55
//Construct an empty document fragment.
56
// NOTE: The caller is responsible for cleaning up this fragment's memory
57
// when it is no longer needed.
59
Node* Document::createDocumentFragment()
61
return new DocumentFragment(this);
65
//Construct an element with the specified tag name.
66
// NOTE: The caller is responsible for cleaning up the element's menory
68
Element* Document::createElement(const nsAString& tagName)
70
return new Element(tagName, this);
73
Element* Document::createElementNS(const nsAString& aNamespaceURI,
74
const nsAString& aTagName)
76
return new Element(aNamespaceURI, aTagName, this);
80
//Construct an attribute with the specified name
82
Attr* Document::createAttribute(const nsAString& name)
84
return new Attr(name, this);
87
Attr* Document::createAttributeNS(const nsAString& aNamespaceURI,
88
const nsAString& aName)
90
return new Attr(aNamespaceURI, aName, this);
94
//Construct a text node with the given data
96
Node* Document::createTextNode(const nsAString& theData)
98
return new NodeDefinition(Node::TEXT_NODE, theData, this);
102
//Construct a comment node with the given data
104
Node* Document::createComment(const nsAString& theData)
106
return new NodeDefinition(Node::COMMENT_NODE, theData, this);
110
//Construct a ProcessingInstruction node with the given targe and data.
112
ProcessingInstruction*
113
Document::createProcessingInstruction(const nsAString& target,
114
const nsAString& data)
116
return new ProcessingInstruction(target, data, this);
120
//Return an Element by ID, introduced by DOM2
122
DHASH_WRAPPER(txIDMap, txIDEntry, nsAString&)
124
Element* Document::getElementById(const nsAString& aID)
126
txIDEntry* entry = mIDMap.GetEntry(aID);
128
return entry->mElement;
133
* private setter for element ID
136
Document::setElementID(const nsAString& aID, Element* aElement)
138
txIDEntry* id = mIDMap.AddEntry(aID);
139
// make sure IDs are unique
143
id->mElement = aElement;
144
id->mElement->setIDValue(aID);
148
Node* Document::appendChild(Node* newChild)
150
unsigned short nodeType = newChild->getNodeType();
152
// Convert to a NodeDefinition Pointer
153
NodeDefinition* pNewChild = (NodeDefinition*)newChild;
155
if (pNewChild->parentNode == this)
157
pNewChild = implRemoveChild(pNewChild);
158
if (nodeType == Node::ELEMENT_NODE)
159
documentElement = nsnull;
164
case Node::PROCESSING_INSTRUCTION_NODE :
165
case Node::COMMENT_NODE :
166
case Node::DOCUMENT_TYPE_NODE :
167
return implAppendChild(pNewChild);
169
case Node::ELEMENT_NODE :
170
if (!documentElement)
172
Node* returnVal = implAppendChild(pNewChild);
173
documentElement = (Element*)pNewChild;
184
nsresult Document::getBaseURI(nsAString& aURI)
186
aURI = documentBaseURI;
190
PRInt32 Document::namespaceURIToID(const nsAString& aNamespaceURI)
192
return txNamespaceManager::getNamespaceID(aNamespaceURI);
195
void Document::namespaceIDToURI(PRInt32 aNamespaceID, nsAString& aNamespaceURI)
197
txNamespaceManager::getNamespaceURI(aNamespaceID, aNamespaceURI);