1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
5
* The contents of this file are subject to the Mozilla Public License
6
* Version 1.0 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/MPL/
10
* The program provided "as is" without any warranty express or
11
* implied, including the warranty of non-infringement and the implied
12
* warranties of merchantibility and fitness for a particular purpose.
13
* The Copyright owner will not be liable for any damages suffered by
14
* you as a result of using the Program. In no event will the Copyright
15
* owner be liable for any special, indirect or consequential damages or
16
* lost profits even if the Copyright owner has been advised of the
17
* possibility of their occurrence.
19
* Please see release.txt distributed with this file for more information.
22
// Tom Kneeland (3/29/99)
24
// Implementation of the Document Object Model Level 1 Core
25
// Implementation of the NamedNodeMap class
30
NamedNodeMap::NamedNodeMap()
34
NamedNodeMap::~NamedNodeMap()
38
Node* NamedNodeMap::getNamedItem(const nsAString& name)
40
ListItem* pSearchItem = findListItemByName(name);
43
return pSearchItem->node;
48
Node* NamedNodeMap::setNamedItem(Node* arg)
50
//Since the DOM does not specify any ording for the NamedNodeMap, just
51
//try and remove the new node (arg). If successful, return a pointer to
52
//the removed item. Reguardless of wheter the node already existed or not,
53
//insert the new node at the end of the list.
54
nsAutoString nodeName;
55
arg->getNodeName(nodeName);
56
Node* pReplacedNode = removeNamedItem(nodeName);
58
NodeListDefinition::append(arg);
63
Node* NamedNodeMap::removeNamedItem(const nsAString& name)
65
NodeListDefinition::ListItem* pSearchItem;
68
pSearchItem = findListItemByName(name);
72
if (pSearchItem != firstItem)
73
pSearchItem->prev->next = pSearchItem->next;
75
firstItem = pSearchItem->next;
77
if (pSearchItem != lastItem)
78
pSearchItem->next->prev = pSearchItem->prev;
80
lastItem = pSearchItem->prev;
82
pSearchItem->next = nsnull;
83
pSearchItem->prev = nsnull;
86
returnNode = pSearchItem->node;
96
NodeListDefinition::ListItem*
97
NamedNodeMap::findListItemByName(const nsAString& name)
99
NodeListDefinition::ListItem* pSearchItem = firstItem;
103
nsAutoString nodeName;
104
pSearchItem->node->getNodeName(nodeName);
105
if (name.Equals(nodeName))
108
pSearchItem = pSearchItem->next;
116
ownerElement = nsnull;
123
Node* AttrMap::setNamedItem(Node* arg)
125
if (arg->getNodeType() != Node::ATTRIBUTE_NODE)
127
((Attr*)arg)->ownerElement = ownerElement;
128
return NamedNodeMap::setNamedItem(arg);
131
Node* AttrMap::removeNamedItem(const nsAString& name)
133
Attr* node = (Attr*)NamedNodeMap::removeNamedItem(name);
135
node->ownerElement = nsnull;
139
void AttrMap::clear()
141
ListItem* pDeleteItem;
142
ListItem* pListTraversal = firstItem;
144
while (pListTraversal) {
145
pDeleteItem = pListTraversal;
146
pListTraversal = pListTraversal->next;
147
delete pDeleteItem->node;