~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/extensions/transformiix/source/xml/dom/standalone/NamedNodeMap.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
2
 *
 
3
 * (C) Copyright The MITRE Corporation 1999  All rights reserved.
 
4
 *
 
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/
 
9
 *
 
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.
 
18
 *
 
19
 * Please see release.txt distributed with this file for more information.
 
20
 *
 
21
 */
 
22
// Tom Kneeland (3/29/99)
 
23
//
 
24
//  Implementation of the Document Object Model Level 1 Core
 
25
//    Implementation of the NamedNodeMap class
 
26
//
 
27
 
 
28
#include "dom.h"
 
29
 
 
30
NamedNodeMap::NamedNodeMap()
 
31
{
 
32
}
 
33
 
 
34
NamedNodeMap::~NamedNodeMap()
 
35
{
 
36
}
 
37
 
 
38
Node* NamedNodeMap::getNamedItem(const nsAString& name)
 
39
{
 
40
  ListItem* pSearchItem = findListItemByName(name);
 
41
 
 
42
  if (pSearchItem)
 
43
    return pSearchItem->node;
 
44
  else
 
45
    return nsnull;
 
46
}
 
47
 
 
48
Node* NamedNodeMap::setNamedItem(Node* arg)
 
49
{
 
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);
 
57
 
 
58
  NodeListDefinition::append(arg);
 
59
 
 
60
  return pReplacedNode;
 
61
}
 
62
 
 
63
Node* NamedNodeMap::removeNamedItem(const nsAString& name)
 
64
{
 
65
  NodeListDefinition::ListItem* pSearchItem;
 
66
  Node* returnNode;
 
67
 
 
68
  pSearchItem = findListItemByName(name);
 
69
 
 
70
  if (pSearchItem)
 
71
    {
 
72
      if (pSearchItem != firstItem)
 
73
        pSearchItem->prev->next = pSearchItem->next;
 
74
      else
 
75
        firstItem = pSearchItem->next;
 
76
 
 
77
      if (pSearchItem != lastItem)
 
78
        pSearchItem->next->prev = pSearchItem->prev;
 
79
      else
 
80
        lastItem = pSearchItem->prev;
 
81
 
 
82
      pSearchItem->next = nsnull;
 
83
      pSearchItem->prev = nsnull;
 
84
 
 
85
      length--;
 
86
      returnNode = pSearchItem->node;
 
87
      delete pSearchItem;
 
88
 
 
89
      return returnNode;
 
90
    }
 
91
 
 
92
 
 
93
  return nsnull;
 
94
}
 
95
 
 
96
NodeListDefinition::ListItem*
 
97
  NamedNodeMap::findListItemByName(const nsAString& name)
 
98
{
 
99
  NodeListDefinition::ListItem* pSearchItem = firstItem;
 
100
 
 
101
  while (pSearchItem)
 
102
    {
 
103
      nsAutoString nodeName;
 
104
      pSearchItem->node->getNodeName(nodeName);
 
105
      if (name.Equals(nodeName))
 
106
        return pSearchItem;
 
107
 
 
108
      pSearchItem = pSearchItem->next;
 
109
    }
 
110
 
 
111
  return nsnull;
 
112
}
 
113
 
 
114
AttrMap::AttrMap()
 
115
{
 
116
    ownerElement = nsnull;
 
117
}
 
118
 
 
119
AttrMap::~AttrMap()
 
120
{
 
121
}
 
122
 
 
123
Node* AttrMap::setNamedItem(Node* arg)
 
124
{
 
125
  if (arg->getNodeType() != Node::ATTRIBUTE_NODE)
 
126
    return nsnull;
 
127
  ((Attr*)arg)->ownerElement = ownerElement;
 
128
  return NamedNodeMap::setNamedItem(arg);
 
129
}
 
130
 
 
131
Node* AttrMap::removeNamedItem(const nsAString& name)
 
132
{
 
133
  Attr* node = (Attr*)NamedNodeMap::removeNamedItem(name);
 
134
  if (node)
 
135
    node->ownerElement = nsnull;
 
136
  return node;
 
137
}
 
138
 
 
139
void AttrMap::clear()
 
140
{
 
141
  ListItem* pDeleteItem;
 
142
  ListItem* pListTraversal = firstItem;
 
143
 
 
144
  while (pListTraversal) {
 
145
    pDeleteItem = pListTraversal;
 
146
    pListTraversal = pListTraversal->next;
 
147
    delete pDeleteItem->node;
 
148
    delete pDeleteItem;
 
149
  }
 
150
  firstItem = 0;
 
151
  lastItem = 0;
 
152
  length = 0;
 
153
}