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

« back to all changes in this revision

Viewing changes to mozilla/extensions/transformiix/source/xml/dom/standalone/Document.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
/*
 
2
 * (C) Copyright The MITRE Corporation 1999  All rights reserved.
 
3
 *
 
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/
 
8
 *
 
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.
 
17
 *
 
18
 * Please see release.txt distributed with this file for more information.
 
19
 *
 
20
 */
 
21
// Tom Kneeland (3/29/99)
 
22
//
 
23
//  Implementation of the Document Object Model Level 1 Core
 
24
//    Implementation of the Document class
 
25
//
 
26
// Modification History:
 
27
// Who  When        What
 
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
 
32
//
 
33
 
 
34
#include "dom.h"
 
35
 
 
36
//
 
37
//Construct a Document.  Currently no parameters are required, but the the
 
38
//node constructor is called to identify the node type.
 
39
//
 
40
Document::Document() : NodeDefinition(Node::DOCUMENT_NODE, nsString(), NULL)
 
41
{
 
42
  mIDMap.Init(0);
 
43
  documentElement = nsnull;
 
44
}
 
45
 
 
46
//
 
47
//Return the one and only element for this document
 
48
//
 
49
Element* Document::getDocumentElement()
 
50
{
 
51
  return documentElement;
 
52
}
 
53
 
 
54
//
 
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.
 
58
//
 
59
Node* Document::createDocumentFragment()
 
60
{
 
61
  return new DocumentFragment(this);
 
62
}
 
63
 
 
64
//
 
65
//Construct an element with the specified tag name.
 
66
//    NOTE:  The caller is responsible for cleaning up the element's menory
 
67
//
 
68
Element* Document::createElement(const nsAString& tagName)
 
69
{
 
70
  return new Element(tagName, this);
 
71
}
 
72
 
 
73
Element* Document::createElementNS(const nsAString& aNamespaceURI,
 
74
                                   const nsAString& aTagName)
 
75
{
 
76
  return new Element(aNamespaceURI, aTagName, this);
 
77
}
 
78
 
 
79
//
 
80
//Construct an attribute with the specified name
 
81
//
 
82
Attr* Document::createAttribute(const nsAString& name)
 
83
{
 
84
  return new Attr(name, this);
 
85
}
 
86
 
 
87
Attr* Document::createAttributeNS(const nsAString& aNamespaceURI,
 
88
                                  const nsAString& aName)
 
89
{
 
90
  return new Attr(aNamespaceURI, aName, this);
 
91
}
 
92
 
 
93
//
 
94
//Construct a text node with the given data
 
95
//
 
96
Node* Document::createTextNode(const nsAString& theData)
 
97
{
 
98
  return new NodeDefinition(Node::TEXT_NODE, theData, this);
 
99
}
 
100
 
 
101
//
 
102
//Construct a comment node with the given data
 
103
//
 
104
Node* Document::createComment(const nsAString& theData)
 
105
{
 
106
  return new NodeDefinition(Node::COMMENT_NODE, theData, this);
 
107
}
 
108
 
 
109
//
 
110
//Construct a ProcessingInstruction node with the given targe and data.
 
111
//
 
112
ProcessingInstruction*
 
113
  Document::createProcessingInstruction(const nsAString& target,
 
114
                                        const nsAString& data)
 
115
{
 
116
  return new ProcessingInstruction(target, data, this);
 
117
}
 
118
 
 
119
//
 
120
//Return an Element by ID, introduced by DOM2
 
121
//
 
122
DHASH_WRAPPER(txIDMap, txIDEntry, nsAString&)
 
123
 
 
124
Element* Document::getElementById(const nsAString& aID)
 
125
{
 
126
  txIDEntry* entry = mIDMap.GetEntry(aID);
 
127
  if (entry)
 
128
    return entry->mElement;
 
129
  return nsnull;
 
130
}
 
131
 
 
132
/**
 
133
 * private setter for element ID
 
134
 */
 
135
PRBool
 
136
Document::setElementID(const nsAString& aID, Element* aElement)
 
137
{
 
138
  txIDEntry* id = mIDMap.AddEntry(aID);
 
139
  // make sure IDs are unique
 
140
  if (id->mElement) {
 
141
    return PR_FALSE;
 
142
  }
 
143
  id->mElement = aElement;
 
144
  id->mElement->setIDValue(aID);
 
145
  return PR_TRUE;
 
146
}
 
147
 
 
148
Node* Document::appendChild(Node* newChild)
 
149
{
 
150
  unsigned short nodeType = newChild->getNodeType();
 
151
 
 
152
  // Convert to a NodeDefinition Pointer
 
153
  NodeDefinition* pNewChild = (NodeDefinition*)newChild;
 
154
 
 
155
  if (pNewChild->parentNode == this)
 
156
    {
 
157
      pNewChild = implRemoveChild(pNewChild);
 
158
      if (nodeType == Node::ELEMENT_NODE)
 
159
        documentElement = nsnull;
 
160
    }
 
161
 
 
162
  switch (nodeType)
 
163
    {
 
164
      case Node::PROCESSING_INSTRUCTION_NODE :
 
165
      case Node::COMMENT_NODE :
 
166
      case Node::DOCUMENT_TYPE_NODE :
 
167
        return implAppendChild(pNewChild);
 
168
 
 
169
      case Node::ELEMENT_NODE :
 
170
        if (!documentElement)
 
171
          {
 
172
            Node* returnVal = implAppendChild(pNewChild);
 
173
            documentElement = (Element*)pNewChild;
 
174
            return returnVal;
 
175
          }
 
176
 
 
177
      default:
 
178
        break;
 
179
    }
 
180
 
 
181
  return nsnull;
 
182
}
 
183
 
 
184
nsresult Document::getBaseURI(nsAString& aURI)
 
185
{
 
186
  aURI = documentBaseURI;
 
187
  return NS_OK;
 
188
}
 
189
 
 
190
PRInt32 Document::namespaceURIToID(const nsAString& aNamespaceURI)
 
191
{
 
192
  return txNamespaceManager::getNamespaceID(aNamespaceURI);
 
193
}
 
194
 
 
195
void Document::namespaceIDToURI(PRInt32 aNamespaceID, nsAString& aNamespaceURI)
 
196
{
 
197
  txNamespaceManager::getNamespaceURI(aNamespaceID, aNamespaceURI);
 
198
}