1 /**
2 * Phoebe DOM Implementation.
3 *
4 * This is a C++ approximation of the W3C DOM model, which follows
5 * fairly closely the specifications in the various .idl files, copies of
6 * which are provided for reference. Most important is this one:
7 *
8 * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
9 *
10 * Authors:
11 * Bob Jamison
12 *
13 * Copyright (C) 2005 Bob Jamison
14 *
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
31 #include "domimpl.h"
33 namespace org
34 {
35 namespace w3c
36 {
37 namespace dom
38 {
41 /**
42 * Test if the given substring exists for the length of the string
43 * in a given buffer
44 */
45 /*
46 static bool match(const DOMString &buf, char *str)
47 {
48 int pos = 0;
49 while (*str)
50 {
51 if (buf[pos++] != *str++)
52 return false;
53 }
54 return true;
55 }
56 */
60 /*#########################################################################
61 ## DOMImplementationSourceImpl
62 #########################################################################*/
65 /**
66 *
67 */
68 DOMImplementationSourceImpl::DOMImplementationSourceImpl()
69 {
70 domImpl = new DOMImplementationImpl();
71 }
73 /**
74 *
75 */
76 DOMImplementationSourceImpl::~DOMImplementationSourceImpl()
77 {
78 delete domImpl;
79 }
81 /**
82 *
83 */
84 DOMImplementation *DOMImplementationSourceImpl::getDOMImplementation(
85 const DOMString &features)
86 {
87 return domImpl;
88 }
90 /**
91 *
92 */
93 DOMImplementationList DOMImplementationSourceImpl::getDOMImplementationList(
94 const DOMString &features)
95 {
96 return domImplList;
97 }
105 /*#########################################################################
106 ## DOMImplementationImpl
107 #########################################################################*/
110 /**
111 *
112 */
113 DOMImplementationImpl::DOMImplementationImpl()
114 {
115 }
117 /**
118 *
119 */
120 DOMImplementationImpl::~DOMImplementationImpl()
121 {
122 }
124 /**
125 *
126 */
127 bool DOMImplementationImpl::hasFeature(const DOMString& feature,
128 const DOMString& version)
129 {
130 return false;
131 }
134 /**
135 *
136 */
137 DocumentType *DOMImplementationImpl::createDocumentType(const DOMString& qualifiedName,
138 const DOMString& publicId,
139 const DOMString& systemId)
140 throw(DOMException)
141 {
142 DocumentTypeImpl *typeImpl = new DocumentTypeImpl(qualifiedName,
143 publicId, systemId);
144 return typeImpl;
145 }
147 /**
148 *
149 */
150 Document *DOMImplementationImpl::createDocument(
151 const DOMString& namespaceURI,
152 const DOMString& qualifiedName,
153 DocumentType *doctype)
154 throw(DOMException)
155 {
156 DocumentImpl *doc = new DocumentImpl(this,
157 namespaceURI,
158 qualifiedName,
159 doctype);
160 return doc;
161 }
163 /**
164 *
165 */
166 DOMObject *DOMImplementationImpl::getFeature(const DOMString& feature,
167 const DOMString& version)
169 {
170 return NULL;
171 }
177 /*#########################################################################
178 ## NodeImpl
179 #########################################################################*/
181 /**
182 * Utility for finding the first Element above
183 * a given node. Used by several methods below
184 */
185 static Node *getAncestorElement(Node *node)
186 {
187 if (!node)
188 return NULL;
189 node = node->getParentNode();
190 //Either quit because I am an element, or because I am null
191 while (node)
192 {
193 if (node->getNodeType() == Node::ELEMENT_NODE)
194 return node;
195 node = node->getParentNode();
196 }
197 return node;
198 }
200 /**
201 *
202 */
203 DOMString NodeImpl::getNodeName()
204 {
205 return nodeName;
206 }
208 /**
209 *
210 */
211 DOMString NodeImpl::getNodeValue() throw (DOMException)
212 {
213 return nodeValue;
214 }
216 /**
217 *
218 */
219 void NodeImpl::setNodeValue(const DOMString& val) throw (DOMException)
220 {
221 nodeValue = val;
222 }
224 /**
225 *
226 */
227 unsigned short NodeImpl::getNodeType()
228 {
229 return nodeType;
230 }
232 /**
233 *
234 */
235 Node *NodeImpl::getParentNode()
236 {
237 return parent;
238 }
240 /**
241 *
242 */
243 NodeList NodeImpl::getChildNodes()
244 {
245 NodeList list;
246 for (NodeImpl *node = firstChild ; node ; node=node->next)
247 list.add(node);
248 return list;
249 }
251 /**
252 *
253 */
254 Node *NodeImpl::getFirstChild()
255 {
256 return firstChild;
257 }
259 /**
260 *
261 */
262 Node *NodeImpl::getLastChild()
263 {
264 return lastChild;
265 }
267 /**
268 *
269 */
270 Node *NodeImpl::getPreviousSibling()
271 {
272 return prev;
273 }
275 /**
276 *
277 */
278 Node *NodeImpl::getNextSibling()
279 {
280 return next;
281 }
283 /**
284 *
285 */
286 NamedNodeMap &NodeImpl::getAttributes()
287 {
288 NamedNodeMap &attrs = attributes;
289 return attrs;
290 }
293 /**
294 *
295 */
296 Document *NodeImpl::getOwnerDocument()
297 {
298 return ownerDocument;
299 }
301 /**
302 *
303 */
304 Node *NodeImpl::insertBefore(const Node *newChild,
305 const Node *refChild)
306 throw(DOMException)
307 {
308 Node *node = NULL;
309 return node;
310 }
312 /**
313 *
314 */
315 Node *NodeImpl::replaceChild(const Node *newChild,
316 const Node *oldChild)
317 throw(DOMException)
318 {
319 Node *node = NULL;
320 return node;
321 }
323 /**
324 *
325 */
326 Node *NodeImpl::removeChild(const Node *oldChild)
327 throw(DOMException)
328 {
329 Node *node = NULL;
330 return node;
331 }
333 /**
334 *
335 */
336 Node *NodeImpl::appendChild(const Node *newChild)
337 throw(DOMException)
338 {
339 if (!newChild)
340 return NULL;
342 Node *child = (Node *)newChild;
343 NodeImpl *childImpl = dynamic_cast<NodeImpl *> (child);
345 childImpl->parent = this;
346 childImpl->ownerDocument = ownerDocument;
348 if (!firstChild || !lastChild)
349 {
350 //Set up our first member
351 firstChild = childImpl;
352 lastChild = childImpl;
353 }
354 else
355 {
356 //link at the last position
357 lastChild->next = childImpl;
358 childImpl->prev = lastChild;
359 lastChild = childImpl;
360 }
362 return child;
363 }
365 /**
366 *
367 */
368 bool NodeImpl::hasChildNodes()
369 {
370 return (firstChild != NULL);
371 }
373 /**
374 *
375 */
376 Node *NodeImpl::cloneNode(bool deep)
377 {
378 NodeImpl *node = new NodeImpl(ownerDocument, nodeName);
379 node->parent = parent;
380 node->prev = prev;
381 node->next = next;
382 node->userData = userData;
383 node->nodeValue = nodeValue;
385 if (deep)
386 {
387 node->firstChild = node->lastChild = NULL;
388 for (NodeImpl *child = firstChild ; child ; child=child->next)
389 {
390 node->appendChild(child->cloneNode(deep));
391 }
392 }
393 else
394 {
395 node->firstChild = firstChild;
396 node->lastChild = lastChild;
397 }
399 return node;
400 }
402 /**
403 * Concatenate adjoining text subnodes, remove null-length nodes
404 */
405 void NodeImpl::normalize()
406 {
407 //First, concatenate adjoining text nodes
408 NodeImpl *next = NULL;
409 for (NodeImpl *child = firstChild ; child ; child=next)
410 {
411 if (child->getNodeType() != Node::TEXT_NODE)
412 continue;
413 next = NULL;
414 DOMString sval = child->getNodeValue();
415 for (NodeImpl *sibling = child->next ; sibling ; sibling=next)
416 {
417 next = sibling->next;
418 if (sibling->getNodeType() != Node::TEXT_NODE)
419 break;
420 sval.append(sibling->getNodeValue());
421 //unlink and delete
422 child->next = sibling->next;
423 if (sibling->next)
424 sibling->next->prev = child;
425 delete sibling;
426 }
427 child->setNodeValue(sval);
428 }
430 //Next, we remove zero-length text subnodes
431 next = NULL;
432 for (NodeImpl *child = firstChild ; child ; child=next)
433 {
434 next = child->next;
435 if (child->getNodeType() != Node::TEXT_NODE)
436 continue;
437 if (child->getNodeValue().size() == 0)
438 {
439 //unlink and delete
440 if (child->prev)
441 child->prev->next = child->next;
442 if (child->next)
443 child->next->prev = child->prev;
444 delete child;
445 }
446 }
448 }
450 /**
451 *
452 */
453 bool NodeImpl::isSupported(const DOMString& feature,
454 const DOMString& version)
455 {
456 //again, no idea
457 return false;
458 }
460 /**
461 *
462 */
463 DOMString NodeImpl::getNamespaceURI()
464 {
465 return namespaceURI;
466 }
468 /**
469 *
470 */
471 DOMString NodeImpl::getPrefix()
472 {
473 return prefix;
474 }
476 /**
477 *
478 */
479 void NodeImpl::setPrefix(const DOMString& val) throw(DOMException)
480 {
481 prefix = val;
482 if (prefix.size()>0)
483 nodeName = prefix + ":" + localName;
484 else
485 nodeName = localName;
486 }
488 /**
489 *
490 */
491 DOMString NodeImpl::getLocalName()
492 {
493 return localName;
494 }
496 /**
497 *
498 */
499 bool NodeImpl::hasAttributes()
500 {
501 return (attributes.getLength() > 0);
502 }
504 /**
505 *
506 */
507 DOMString NodeImpl::getBaseURI()
508 {
509 return baseURI;
510 }
512 /**
513 *
514 */
515 unsigned short NodeImpl::compareDocumentPosition(const Node *otherArg)
516 {
517 if (!otherArg || this == otherArg)
518 return 0;//no flags
520 Node *node;
521 Node *other = (Node *)otherArg;
523 //Look above me
524 for (node=getParentNode() ; node ; node=node->getParentNode())
525 if (node == other)
526 return DOCUMENT_POSITION_CONTAINED_BY;
528 //Look above the other guy. See me?
529 for (node=other->getParentNode() ; node ; node=node->getParentNode())
530 if (node == this)
531 return DOCUMENT_POSITION_CONTAINS;
534 return DOCUMENT_POSITION_DISCONNECTED |
535 DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
536 }
538 /**
539 *
540 */
541 DOMString NodeImpl::getTextContext() throw(DOMException)
542 {
543 //no idea
544 return DOMString("");
545 }
548 /**
549 *
550 */
551 void NodeImpl::setTextContext(const DOMString &val) throw(DOMException)
552 {
553 //no idea
554 }
557 /**
558 * From DOM3 Namespace algorithms
559 */
560 DOMString NodeImpl::lookupPrefix(const DOMString &theNamespaceURI)
561 {
563 if (theNamespaceURI.size()==0)
564 {
565 return DOMString("");
566 }
568 switch (nodeType)
569 {
570 case Node::ELEMENT_NODE:
571 {
572 ElementImpl *elem = (ElementImpl *)this;
573 return lookupNamespacePrefix(theNamespaceURI, elem);
574 }
575 case Node::DOCUMENT_NODE:
576 {
577 Document *doc = (Document *)this;
578 Element *elem = doc->getDocumentElement();
579 return elem->lookupPrefix(theNamespaceURI);
580 }
581 case Node::ENTITY_NODE :
582 case Node::NOTATION_NODE:
583 case Node::DOCUMENT_FRAGMENT_NODE:
584 case Node::DOCUMENT_TYPE_NODE:
585 return DOMString(""); // type is unknown
586 case Node::ATTRIBUTE_NODE:
587 {
588 Attr *attr = (Attr *)this;
589 Element *elem = (Element *)attr->getOwnerElement();
590 if ( elem )
591 {
592 return elem->lookupPrefix(theNamespaceURI);
593 }
594 return DOMString("");
595 }
596 default:
597 {
598 //Get ancestor element, if any
599 if ( Node *ancestor = getAncestorElement(this) )
600 {
601 return ancestor->lookupPrefix(theNamespaceURI);
602 }
603 return DOMString("");
604 }
605 }//switch
606 return DOMString("");
607 }
610 /**
611 *
612 */
613 bool NodeImpl::isDefaultNamespace(const DOMString &theNamespaceURI)
614 {
615 switch (nodeType)
616 {
617 case ELEMENT_NODE:
618 if ( namespaceURI.size()>0 && prefix.size()==0 )
619 {
620 return (namespaceURI == theNamespaceURI);
621 }
622 if ( Node *attr = attributes.getNamedItem("xmlns"))
623 {
624 return (attr->getNodeValue() == theNamespaceURI);
625 }
628 if ( Node *ancestor = getAncestorElement(this) )
629 {
630 return ancestor->isDefaultNamespace(theNamespaceURI);
631 }
632 else
633 {
634 return false;
635 }
636 case DOCUMENT_NODE:
637 { //just use braces for local declaration
638 Document *doc = (Document *)this;
639 Element *elem = doc->getDocumentElement();
640 return elem->isDefaultNamespace(theNamespaceURI);
641 }
642 case ENTITY_NODE:
643 case NOTATION_NODE:
644 case DOCUMENT_TYPE_NODE:
645 case DOCUMENT_FRAGMENT_NODE:
646 return false;
647 case ATTRIBUTE_NODE:
648 {//braces only for scope
649 Attr *attr = (Attr *)this;
650 Element *ownerElement = attr->getOwnerElement();
651 if ( ownerElement )
652 {
653 return ownerElement->isDefaultNamespace(theNamespaceURI);
654 }
655 else
656 {
657 return false;
658 }
659 }
660 default:
661 if ( Node *ancestor = getAncestorElement(this) )
662 {
663 return ancestor->isDefaultNamespace(theNamespaceURI);
664 }
665 else
666 {
667 return false;
668 }
669 }//switch
671 return false;
672 }
675 /**
676 *
677 */
678 DOMString NodeImpl::lookupNamespaceURI(const DOMString &thePrefix)
679 {
680 switch (nodeType)
681 {
682 case ELEMENT_NODE:
683 {
684 if ( namespaceURI.size()>0 && prefix == thePrefix )
685 {
686 DOMString nsURI = namespaceURI;
687 return (nsURI);
688 }
689 if ( hasAttributes() )
690 {
691 NamedNodeMap attributes = getAttributes();
692 int nrAttrs = attributes.getLength();
693 for (int i=0 ; i<nrAttrs ; i++)
694 {
695 Node *attr = attributes.item(i);
696 if (attr->getPrefix() == "xmlns" && attr->getLocalName() == thePrefix )
697 { // non default namespace
698 if (attr->getNodeValue().size()>0)
699 {
700 return (attr->getNodeValue());
701 }
702 return DOMString("");
703 }
704 else if (attr->getLocalName() == "xmlns" && thePrefix.size()==0)
705 { // default namespace
706 if (attr->getNodeValue().size()>0)
707 {
708 return (attr->getNodeValue());
709 }
710 return DOMString("");
711 }
712 }
713 }
715 if ( Node *ancestor = getAncestorElement(this) )
716 {
717 return ancestor->lookupNamespaceURI(thePrefix);
718 }
719 return DOMString("");
720 }
721 case DOCUMENT_NODE:
722 {
723 Document *doc = (Document *)this;
724 Element *elem = doc->getDocumentElement();
725 return elem->lookupNamespaceURI(thePrefix);
726 }
727 case ENTITY_NODE:
728 case NOTATION_NODE:
729 case DOCUMENT_TYPE_NODE:
730 case DOCUMENT_FRAGMENT_NODE:
731 return DOMString("");
733 case ATTRIBUTE_NODE:
734 {
735 if (Element *ownerElement = ((Attr *)this)->getOwnerElement())
736 {
737 return ownerElement->lookupNamespaceURI(thePrefix);
738 }
739 else
740 {
741 return DOMString("");
742 }
743 }
744 default:
745 if ( Node *ancestor = getAncestorElement(this) )
746 {
747 return ancestor->lookupNamespaceURI(thePrefix);
748 }
749 else
750 {
751 return DOMString("");
752 }
753 }//switch
754 }
757 /**
758 *
759 */
760 bool NodeImpl::isEqualNode(const Node *nodeArg)
761 {
762 if (!nodeArg)
763 return false;
765 if (this == nodeArg)
766 return true;
768 Node *node = (Node *)nodeArg;
770 if (getNodeType() != node->getNodeType() ||
771 getNodeName() != node->getNodeName() ||
772 getLocalName() != node->getLocalName() ||
773 getNamespaceURI() != node->getNamespaceURI() ||
774 getPrefix() != node->getPrefix() ||
775 getNodeValue() != node->getNodeValue() ||
776 getBaseURI() != node->getBaseURI() )
777 return false;
779 return true;
780 }
784 /**
785 *
786 */
787 DOMObject *NodeImpl::getFeature(const DOMString &feature,
788 const DOMString &version)
789 {
790 //dont know
791 return NULL;
792 }
794 /**
795 *
796 */
797 DOMUserData *NodeImpl::setUserData(const DOMString &key,
798 const DOMUserData *data,
799 const UserDataHandler *handler)
800 {
801 UserDataEntry *entry = userDataEntries;
802 UserDataEntry *prev = NULL;
803 while (entry)
804 {
805 if (entry->key == key)
806 {
807 DOMUserData *oldData = entry->data;
808 entry->data = (DOMUserData *)data;
809 entry->handler = (UserDataHandler *)handler;
810 return oldData;
811 }
812 prev = entry;
813 entry = entry->next;
814 }
816 //Make a new one
817 UserDataEntry *newEntry = new UserDataEntry(key, data, handler);
818 if (!prev)
819 userDataEntries = newEntry;
820 else
821 prev->next = newEntry;
823 return NULL;
824 }
826 /**
827 *
828 */
829 DOMUserData *NodeImpl::getUserData(const DOMString &key)
830 {
831 UserDataEntry *entry = userDataEntries;
832 while (entry)
833 {
834 if (entry->key == key)
835 return entry->data;
836 entry = entry->next;
837 }
838 return NULL;
839 }
843 //##################
844 //# Non-API methods
845 //##################
847 /**
848 *
849 */
850 void NodeImpl::setNodeName(const DOMString &qualifiedName)
851 {
852 nodeName = qualifiedName;
853 prefix = "";
854 localName = "";
855 for (unsigned int i=0 ; i<qualifiedName.size() ; i++)
856 {
857 int ch = qualifiedName[i];
858 if (ch == ':')
859 {
860 prefix = localName;
861 localName = "";
862 }
863 else
864 {
865 localName.push_back(ch);
866 }
867 }
868 }
870 /**
871 *
872 */
873 void NodeImpl::setNamespaceURI(const DOMString &theNamespaceURI)
874 {
875 namespaceURI = theNamespaceURI;
876 }
879 /**
880 * From DOM3 Namespace algorithms
881 */
882 DOMString NodeImpl::lookupNamespacePrefix(const DOMString &theNamespaceURI,
883 Node *originalElement)
884 {
885 if (!originalElement)
886 return DOMString("");
888 if ( namespaceURI.size()>0 && namespaceURI==theNamespaceURI &&
889 prefix.size()>0 &&
890 originalElement->lookupNamespaceURI(prefix) == theNamespaceURI)
891 {
892 return (prefix);
893 }
895 if ( hasAttributes() )
896 {
897 NamedNodeMap attributes = getAttributes();
898 int nrAttrs = attributes.getLength();
899 for (int i=0 ; i<nrAttrs ; i++)
900 {
901 Node *attr = attributes.item(i);
902 DOMString attrLocalName = attr->getLocalName();
903 if (attr->getPrefix() == "xmlns" &&
904 attr->getNodeValue() == theNamespaceURI &&
905 originalElement->lookupNamespaceURI(attrLocalName)
906 == theNamespaceURI)
907 {
908 return (attrLocalName);
909 }
910 }
911 }
913 //Get ancestor element, if any
914 NodeImpl *ancestor = parent;
915 while (ancestor && ancestor->getNodeType()!= Node::ELEMENT_NODE)
916 ancestor = ancestor->parent;
918 if ( ancestor )
919 {
920 return ancestor->lookupNamespacePrefix(theNamespaceURI, originalElement);
921 }
923 return DOMString("");
924 }
927 /**
928 *
929 */
930 NodeImpl::NodeImpl()
931 {
932 init();
933 }
938 /**
939 *
940 */
941 NodeImpl::NodeImpl(DocumentImpl *owner)
942 {
943 init();
944 ownerDocument = owner;
945 }
947 /**
948 *
949 */
950 NodeImpl::NodeImpl(DocumentImpl *owner, const DOMString &nodeName)
951 {
952 init();
953 ownerDocument = owner;
954 setNodeName(nodeName);
955 }
957 /**
958 *
959 */
960 NodeImpl::NodeImpl(DocumentImpl *owner, const DOMString &theNamespaceURI,
961 const DOMString &qualifiedName)
962 {
963 init();
964 ownerDocument = owner;
965 //if (owner)
966 // namespaceURI = owner->stringCache(theNamespaceURI);
967 setNodeName(qualifiedName);
968 }
972 /**
973 *
974 */
975 void NodeImpl::init()
976 {
977 nodeType = 0; //none yet
978 nodeValue = "";
979 setNodeName("");
980 namespaceURI = "";
981 parent = NULL;
982 prev = NULL;
983 next = NULL;
984 userData = NULL;
985 firstChild = NULL;
986 lastChild = NULL;
987 ownerDocument = NULL;
988 userDataEntries = NULL;
989 }
991 /**
992 *
993 */
994 void NodeImpl::assign(const NodeImpl &other)
995 {
996 ownerDocument = other.ownerDocument;
997 prefix = other.prefix;
998 localName = other.localName;
999 nodeName = other.nodeName;
1000 nodeValue = other.nodeValue;
1001 namespaceURI = other.namespaceURI;
1002 attributes = other.attributes;
1003 }
1006 /**
1007 *
1008 */
1009 NodeImpl::~NodeImpl()
1010 {
1011 if (userDataEntries)
1012 delete userDataEntries;
1013 }
1017 /*#########################################################################
1018 ## CharacterDataImpl
1019 #########################################################################*/
1022 /**
1023 *
1024 */
1025 CharacterDataImpl::CharacterDataImpl() : NodeImpl()
1026 {
1027 }
1029 /**
1030 *
1031 */
1032 CharacterDataImpl::CharacterDataImpl(DocumentImpl *owner,
1033 const DOMString &theValue) : NodeImpl()
1034 {
1035 ownerDocument = owner;
1036 nodeValue = theValue;
1037 }
1039 /**
1040 *
1041 */
1042 CharacterDataImpl::~CharacterDataImpl()
1043 {
1044 }
1046 /**
1047 *
1048 */
1049 DOMString CharacterDataImpl::getData() throw(DOMException)
1050 {
1051 return nodeValue;
1052 }
1054 /**
1055 *
1056 */
1057 void CharacterDataImpl::setData(const DOMString& val) throw(DOMException)
1058 {
1059 nodeValue = val;
1060 }
1062 /**
1063 *
1064 */
1065 unsigned long CharacterDataImpl::getLength()
1066 {
1067 return nodeValue.size();
1068 }
1070 /**
1071 *
1072 */
1073 DOMString CharacterDataImpl::substringData(unsigned long offset,
1074 unsigned long count)
1075 throw(DOMException)
1076 {
1077 return nodeValue.substr(offset, count);
1078 }
1080 /**
1081 *
1082 */
1083 void CharacterDataImpl::appendData(const DOMString& arg) throw(DOMException)
1084 {
1085 nodeValue += arg;
1086 }
1088 /**
1089 *
1090 */
1091 void CharacterDataImpl::insertData(unsigned long offset,
1092 const DOMString& arg)
1093 throw(DOMException)
1094 {
1095 nodeValue.insert(offset, arg);
1096 }
1098 /**
1099 *
1100 */
1101 void CharacterDataImpl::deleteData(unsigned long offset,
1102 unsigned long count)
1103 throw(DOMException)
1104 {
1105 nodeValue.erase(offset, count);
1106 }
1108 /**
1109 *
1110 */
1111 void CharacterDataImpl::replaceData(unsigned long offset,
1112 unsigned long count,
1113 const DOMString& arg)
1114 throw(DOMException)
1115 {
1116 nodeValue.replace(offset, count, arg);
1117 }
1124 /*#########################################################################
1125 ## AttrImpl
1126 #########################################################################*/
1128 /**
1129 *
1130 */
1131 DOMString AttrImpl::getName()
1132 {
1133 return nodeName;
1134 }
1136 /**
1137 *
1138 */
1139 bool AttrImpl::getSpecified()
1140 {
1141 return (nodeValue.size() > 0);
1142 }
1144 /**
1145 *
1146 */
1147 DOMString AttrImpl::getValue()
1148 {
1149 return nodeValue;
1150 }
1152 /**
1153 *
1154 */
1155 void AttrImpl::setValue(const DOMString& val) throw(DOMException)
1156 {
1157 nodeValue = val;
1158 }
1160 /**
1161 *
1162 */
1163 Element *AttrImpl::getOwnerElement()
1164 {
1165 return ownerElement;
1166 }
1169 /**
1170 *
1171 */
1172 TypeInfo *AttrImpl::getSchemaTypeInfo()
1173 {
1174 return NULL;
1175 }
1178 /**
1179 *
1180 */
1181 bool AttrImpl::getIsId()
1182 {
1183 return (nodeName == "id");
1184 }
1188 //##################
1189 //# Non-API methods
1190 //##################
1193 void AttrImpl::setOwnerElement(const Element *elem)
1194 {
1195 ownerElement = (Element *)elem;
1196 }
1198 /**
1199 *
1200 */
1201 AttrImpl::AttrImpl(DocumentImpl *owner, const DOMString &theName)
1202 : NodeImpl()
1203 {
1204 nodeType = ATTRIBUTE_NODE;
1205 ownerDocument = owner;
1206 setNodeName(theName);
1207 }
1209 /**
1210 *
1211 */
1212 AttrImpl::AttrImpl(DocumentImpl *owner,
1213 const DOMString &theNamespaceURI,
1214 const DOMString &theQualifiedName)
1215 : NodeImpl()
1216 {
1217 nodeType = ATTRIBUTE_NODE;
1218 ownerDocument = owner;
1219 //if (owner)
1220 // namespaceURI = owner->stringCache(theNamespaceURI);
1221 setNodeName(theQualifiedName);
1222 }
1224 /**
1225 *
1226 */
1227 AttrImpl::~AttrImpl()
1228 {
1229 }
1235 /*#########################################################################
1236 ## ElementImpl
1237 #########################################################################*/
1240 /**
1241 *
1242 */
1243 DOMString ElementImpl::getTagName()
1244 {
1245 if (prefix.size() > 0)
1246 return prefix + ":" + nodeName;
1247 else
1248 return nodeName;
1249 }
1251 /**
1252 *
1253 */
1254 DOMString ElementImpl::getAttribute(const DOMString& name)
1255 {
1256 Node *node = attributes.getNamedItem(name);
1257 if (!node || node->getNodeType() != ATTRIBUTE_NODE)
1258 return DOMString("");
1259 Attr *attr = dynamic_cast<Attr *>(node);
1260 return attr->getValue();
1261 }
1263 /**
1264 *
1265 */
1266 void ElementImpl::setAttribute(const DOMString& name,
1267 const DOMString& value)
1268 throw(DOMException)
1269 {
1270 AttrImpl *attr = new AttrImpl(ownerDocument, name);
1271 attr->setValue(value);
1272 attr->setOwnerElement(this);
1273 attributes.setNamedItem(attr);
1274 }
1276 /**
1277 *
1278 */
1279 void ElementImpl::removeAttribute(const DOMString& name)
1280 throw(DOMException)
1281 {
1282 attributes.removeNamedItem(name);
1283 }
1285 /**
1286 *
1287 */
1288 Attr *ElementImpl::getAttributeNode(const DOMString& name)
1289 {
1290 Node *node = attributes.getNamedItem(name);
1291 if (!node || node->getNodeType() != ATTRIBUTE_NODE)
1292 return NULL;
1293 Attr *attr = dynamic_cast<Attr *>(node);
1294 return attr;
1295 }
1297 /**
1298 *
1299 */
1300 Attr *ElementImpl::setAttributeNode(Attr *attr)
1301 throw(DOMException)
1302 {
1303 attributes.setNamedItem(attr);
1304 return attr;
1305 }
1307 /**
1308 *
1309 */
1310 Attr *ElementImpl::removeAttributeNode(Attr *attr)
1311 throw(DOMException)
1312 {
1313 if (!attr)
1314 return NULL;
1315 attributes.removeNamedItem(attr->getName());
1316 return attr;
1317 }
1320 /**
1321 *
1322 */
1323 void ElementImpl::getElementsByTagNameRecursive(NodeList &list,
1324 const DOMString& name, Element *elem)
1325 {
1326 if (!elem)
1327 return;
1329 if (name == elem->getTagName())
1330 list.add(elem);
1331 for (Node *node = elem->getFirstChild() ; node ; node=node->getNextSibling())
1332 {
1333 if (node->getNodeType() != Node::ELEMENT_NODE)
1334 continue;
1335 Element *childElem = dynamic_cast<Element *>(node);
1336 getElementsByTagNameRecursive(list, name, childElem);
1337 }
1338 }
1341 /**
1342 *
1343 */
1344 NodeList ElementImpl::getElementsByTagName(const DOMString& tagName)
1345 {
1346 NodeList list;
1347 getElementsByTagNameRecursive(list, tagName, this);
1348 return list;
1349 }
1351 /**
1352 *
1353 */
1354 DOMString ElementImpl::getAttributeNS(const DOMString& namespaceURI,
1355 const DOMString& localName)
1356 {
1357 Node *node = attributes.getNamedItemNS(namespaceURI, localName);
1358 if (!node || node->getNodeType()!=ATTRIBUTE_NODE)
1359 return DOMString("");
1360 Attr *attr = dynamic_cast<Attr *>(node);
1361 return attr->getValue();
1362 }
1364 /**
1365 *
1366 */
1367 void ElementImpl::setAttributeNS(const DOMString& namespaceURI,
1368 const DOMString& qualifiedName,
1369 const DOMString& value)
1370 throw(DOMException)
1371 {
1372 AttrImpl *attr = new AttrImpl(ownerDocument, namespaceURI, qualifiedName);
1373 attr->setValue(value);
1374 attr->setOwnerElement(this);
1375 attributes.setNamedItemNS(attr);
1376 }
1378 /**
1379 *
1380 */
1381 void ElementImpl::removeAttributeNS(const DOMString& namespaceURI,
1382 const DOMString& localName)
1383 throw(DOMException)
1384 {
1385 attributes.removeNamedItemNS(namespaceURI, localName);
1386 }
1388 /**
1389 *
1390 */
1391 Attr *ElementImpl::getAttributeNodeNS(const DOMString& namespaceURI,
1392 const DOMString& localName)
1393 {
1394 Node *node = attributes.getNamedItemNS(namespaceURI, localName);
1395 if (!node || node->getNodeType() != ATTRIBUTE_NODE)
1396 return NULL;
1397 Attr *attr = dynamic_cast<Attr *>(node);
1398 return attr;
1399 }
1401 /**
1402 *
1403 */
1404 Attr *ElementImpl::setAttributeNodeNS(Attr *attr)
1405 throw(DOMException)
1406 {
1407 attributes.setNamedItemNS(attr);
1408 return attr;
1409 }
1412 /**
1413 *
1414 */
1415 void ElementImpl::getElementsByTagNameNSRecursive(NodeList &list,
1416 const DOMString& namespaceURI, const DOMString& tagName, Element *elem)
1417 {
1418 if (!elem)
1419 return;
1421 if (namespaceURI == elem->getNamespaceURI() && tagName == elem->getTagName())
1422 list.add(elem);
1423 for (Node *node = elem->getFirstChild() ; node ; node=node->getNextSibling())
1424 {
1425 if (node->getNodeType() != Node::ELEMENT_NODE)
1426 continue;
1427 Element *childElem = dynamic_cast<Element *>(node);
1428 getElementsByTagNameNSRecursive(list, namespaceURI, tagName, childElem);
1429 }
1430 }
1432 /**
1433 *
1434 */
1435 NodeList ElementImpl::getElementsByTagNameNS(const DOMString& namespaceURI,
1436 const DOMString& localName)
1437 {
1438 NodeList list;
1439 getElementsByTagNameNSRecursive(list, namespaceURI, localName, this);
1440 return list;
1441 }
1443 /**
1444 *
1445 */
1446 bool ElementImpl::hasAttribute(const DOMString& attrName)
1447 {
1448 Node *node = attributes.getNamedItem(attrName);
1449 if (!node || node->getNodeType() != ATTRIBUTE_NODE)
1450 return false;
1451 return true;
1452 }
1454 /**
1455 *
1456 */
1457 bool ElementImpl::hasAttributeNS(const DOMString& namespaceURI,
1458 const DOMString& localName)
1459 {
1460 Node *node = attributes.getNamedItemNS(namespaceURI, localName);
1461 if (!node || node->getNodeType() != ATTRIBUTE_NODE)
1462 return false;
1463 return true;
1464 }
1466 /**
1467 *
1468 */
1469 TypeInfo *ElementImpl::getSchemaTypeInto()
1470 {
1471 //fixme
1472 return NULL;
1473 }
1476 /**
1477 *
1478 */
1479 void ElementImpl::setIdAttribute(const DOMString &name,
1480 bool isId) throw (DOMException)
1481 {
1482 //fixme
1483 }
1485 /**
1486 *
1487 */
1488 void ElementImpl::setIdAttributeNS(const DOMString &namespaceURI,
1489 const DOMString &localName,
1490 bool isId) throw (DOMException)
1491 {
1492 //fixme
1493 }
1495 /**
1496 *
1497 */
1498 void ElementImpl::setIdAttributeNode(const Attr *idAttr,
1499 bool isId) throw (DOMException)
1500 {
1501 //fixme
1502 }
1505 //##################
1506 //# Non-API methods
1507 //##################
1510 /**
1511 *
1512 */
1513 ElementImpl::ElementImpl() : NodeImpl()
1514 {
1515 nodeType = ELEMENT_NODE;
1516 }
1518 /**
1519 *
1520 */
1521 ElementImpl::ElementImpl(DocumentImpl *owner, const DOMString &tagName)
1522 : NodeImpl()
1523 {
1524 nodeType = ELEMENT_NODE;
1525 ownerDocument = owner;
1526 setNodeName(tagName);
1527 }
1529 /**
1530 *
1531 */
1532 ElementImpl::ElementImpl(DocumentImpl *owner,
1533 const DOMString &theNamespaceURI,
1534 const DOMString &qualifiedName) :
1535 NodeImpl()
1536 {
1537 nodeType = ELEMENT_NODE;
1538 ownerDocument = owner;
1539 setNodeName(qualifiedName);
1540 }
1542 /**
1543 *
1544 */
1545 ElementImpl::~ElementImpl()
1546 {
1547 }
1550 /**
1551 *
1552 */
1553 void ElementImpl::normalizeNamespaces()
1554 {
1555 //printf("### NORMALIZE\n");
1557 NamedNodeMap attrs = getAttributes();
1559 //#######################################
1560 //# Pick up local namespace declarations
1561 //#######################################
1562 bindingsClear(); //Reset bindings on this node
1564 int nrAttrs = attrs.getLength();
1565 for (int i=0; i<nrAttrs ; i++)
1566 {
1567 Node *attrNode = attrs.item(i);
1568 if (attrNode->getNodeType() != Node::ATTRIBUTE_NODE)
1569 continue;
1570 AttrImpl *attr = dynamic_cast<AttrImpl *>(attrNode);
1571 DOMString attrNS = attr->getNamespaceURI();
1572 DOMString attrName = attr->getLocalName();
1573 DOMString attrPrefix = attr->getPrefix();
1574 DOMString attrValue = attr->getNodeValue();
1575 if (attrName != "xmlns" && attrPrefix != "xmlns")
1576 continue;
1578 //is the namespace declaration is invalid?
1579 if (attrValue == XMLNSNAME || attrName == attrPrefix)
1580 {
1581 // Note: The prefix xmlns is used only to declare namespace bindings and
1582 // is by definition bound to the namespace name http://www.w3.org/2000/xmlns/.
1583 // It must not be declared. No other prefix may be bound to this namespace name.
1585 //==> Report an error.
1586 printf("normalizeNamespaces() error: Namespace %s cannot be reassigned\n",
1587 XMLNSNAME);
1589 }
1590 else
1591 {
1592 //==> Record the namespace declaration
1593 attr->setNamespaceURI(XMLNSNAME);
1594 if (attrPrefix.size() > 0)
1595 bindingsAdd(attrPrefix, attrValue);
1596 else
1597 bindingsAdd("*", attrValue);//default
1599 }
1600 }
1603 //#######################################
1604 //# Fixup element's namespace
1605 //#######################################
1606 if ( namespaceURI.size() > 0 )
1607 {
1608 DOMString key = prefix;
1609 if (key.size() == 0)
1610 key = "*";
1611 DOMString binding = bindingsFind(key);
1612 //Element's prefix/namespace pair (or default namespace, if no prefix)
1613 // are within the scope of a binding
1614 if ( binding == namespaceURI )
1615 {
1616 //==> do nothing, declaration in scope is inherited
1618 // See section "B.1.1: Scope of a binding" for an example
1620 }
1621 else
1622 {
1624 /*
1625 ==> Create a local namespace declaration attr for this namespace,
1626 with Element's current prefix (or a default namespace, if
1627 no prefix). If there's a conflicting local declaration
1628 already present, change its value to use this namespace.
1630 See section "B.1.2: Conflicting namespace declaration" for an example
1631 */
1632 DOMString attrName = "xmlns";
1633 if (prefix.size() > 0)
1634 {
1635 attrName.append(":");
1636 attrName.append(prefix);
1637 }
1638 setAttribute(attrName, namespaceURI);
1639 // NOTE that this may break other nodes within this Element's
1640 // subtree, if they're already using this prefix.
1641 // They will be repaired when we reach them.
1642 }
1643 }
1644 else // Element has no namespace URI:
1645 {
1646 //###############################################
1647 //# Bob -- alter this from the specs a bit.
1648 //# Since the XmlReader does not set namespaces,
1649 //# do it here
1650 //###############################################
1651 DOMString localName = getLocalName();
1652 if ( localName.size()==0 )
1653 {
1654 // DOM Level 1 node
1655 /*
1656 ==> if in process of validation against a namespace aware schema
1657 (i.e XML Schema) report a fatal error: the processor can not recover
1658 in this situation.
1659 Otherwise, report an error: no namespace fixup will be performed on this node.
1660 */
1661 printf("normalizeNamespaces() error: no localName\n");
1662 }
1663 else
1664 {
1665 // Element has no pseudo-prefix
1666 //there's a conflicting local default namespace declaration already present
1667 if ( prefix.size()==0 )
1668 {
1669 //==> change its value to use this empty namespace.
1670 namespaceURI = bindingsFind("*");
1671 //setAttribute("xmlns", "");
1672 }
1673 else //#BOB . I added this.
1674 {
1675 namespaceURI = bindingsFind(prefix);
1676 }
1677 // NOTE that this may break other nodes within this Element's
1678 // subtree, if they're already using the default namespaces.
1679 // They will be repaired when we reach them.
1680 }
1681 }
1684 //#######################################
1685 //# Examine and polish the attributes
1686 //#######################################
1687 nrAttrs = attrs.getLength();
1688 for (int i=0; i<nrAttrs ; i++)// all non-namespace Attrs of Element
1689 {
1690 Node *attrNode = attrs.item(i);
1691 if (attrNode->getNodeType() != Node::ATTRIBUTE_NODE)
1692 continue;
1693 Attr *attr = dynamic_cast<Attr *>(attrNode);
1694 DOMString attrNS = attr->getNamespaceURI();
1695 DOMString attrPrefix = attr->getPrefix();
1696 DOMString attrValue = attr->getNodeValue();
1697 if (attrNS == XMLNSNAME)
1698 continue;
1700 if ( attrNS.size()>0 ) //Attr[i] has a namespace URI
1701 {
1702 DOMString attrBinding = bindingsFind(attrPrefix);
1703 /*
1704 if attribute has no prefix (default namespace decl does not apply to attributes)
1705 OR
1706 attribute prefix is not declared
1707 OR
1708 conflict: attribute has a prefix that conflicts with a binding
1709 already active in scope
1710 */
1711 if ( attrPrefix.size() == 0 || attrBinding.size() == 0)
1712 {
1713 //namespaceURI matches an in scope declaration of one or more prefixes)
1714 DOMString prefixForNS = lookupNamespacePrefix(attrNS, this);
1715 if ( prefixForNS.size() > 0 )
1716 {
1717 // pick the most local binding available;
1718 // if there is more than one pick one arbitrarily
1720 //==> change attribute's prefix.
1721 attr->setPrefix(prefixForNS);
1722 }
1723 else
1724 {
1725 // the current prefix is not null and it has no in scope declaration)
1726 if ( attrPrefix.size() > 0 || attrBinding.size() == 0 )
1727 {
1728 //==> declare this prefix
1729 DOMString newAttrName = "xmlns:";
1730 newAttrName.append(attrPrefix);
1731 setAttribute(newAttrName, attrNS);
1732 bindingsAdd(attrPrefix, attrNS);
1733 }
1734 else
1735 {
1736 // find a prefix following the pattern "NS" +index (starting at 1)
1737 // make sure this prefix is not declared in the current scope.
1738 // create a local namespace declaration attribute
1740 //==> declare this prefix
1741 char buf[16];
1742 sprintf(buf, "%d" , ownerDocument->namespaceIndex++);
1743 DOMString newPrefix = "NS";
1744 newPrefix.append(buf);
1745 DOMString newAttrName = "xmlns:";
1746 newAttrName.append(newPrefix);
1747 setAttribute(newAttrName, attrNS);
1748 bindingsAdd(newPrefix, attrNS);
1749 //==> change attribute's prefix.
1750 }
1751 }
1752 }
1753 }
1754 else // Attr has no namespace URI
1755 {
1756 // Attr has no localName
1757 if ( attr->getLocalName().size() == 0 )
1758 {
1759 // DOM Level 1 node
1760 /*
1761 ==> if in process of validation against a namespace aware schema
1762 (i.e XML Schema) report a fatal error: the processor can not recover
1763 in this situation.
1764 Otherwise, report an error: no namespace fixup will be performed on this node.
1765 */
1766 printf("normalizeNamespaces: no local name for attribute\n");
1767 }
1768 else
1769 {
1770 // attr has no namespace URI and no prefix
1771 // no action is required, since attrs don't use default
1772 //==> do nothing
1773 }
1774 }
1775 } // end for-all-Attrs
1778 //#######################################
1779 //# Recursively normalize children
1780 //#######################################
1781 for (Node *child=getFirstChild() ; child ; child=child->getNextSibling())
1782 {
1783 if (child->getNodeType() != Node::ELEMENT_NODE)
1784 continue;
1785 ElementImpl *childElement = dynamic_cast<ElementImpl *>(child);
1786 childElement->normalizeNamespaces();
1787 }
1789 }
1792 /*#########################################################################
1793 ## TextImpl
1794 #########################################################################*/
1797 /**
1798 *
1799 */
1800 TextImpl::TextImpl() : CharacterDataImpl()
1801 {
1802 nodeType = TEXT_NODE;
1803 nodeName = "#text";
1804 }
1807 /**
1808 *
1809 */
1810 TextImpl::TextImpl(DocumentImpl *owner, const DOMString &value)
1811 : CharacterDataImpl()
1812 {
1813 nodeType = TEXT_NODE;
1814 nodeName = "#text";
1815 ownerDocument = owner;
1816 nodeValue = value;
1817 }
1820 /**
1821 *
1822 */
1823 TextImpl::~TextImpl()
1824 {
1825 }
1827 /**
1828 *
1829 */
1830 Text *TextImpl::splitText(unsigned long offset)
1831 throw(DOMException)
1832 {
1833 return NULL;
1834 }
1836 /**
1837 *
1838 */
1839 bool TextImpl::getIsElementContentWhitespace()
1840 {
1841 return false;
1842 }
1844 /**
1845 *
1846 */
1847 DOMString TextImpl::getWholeText()
1848 {
1849 return nodeValue;
1850 }
1853 /**
1854 *
1855 */
1856 Text *TextImpl::replaceWholeText(const DOMString &content)
1857 throw(DOMException)
1858 {
1859 return NULL;
1860 }
1863 /*#########################################################################
1864 ## CommentImpl
1865 #########################################################################*/
1867 /**
1868 *
1869 */
1870 CommentImpl::CommentImpl() : CharacterDataImpl()
1871 {
1872 nodeType = COMMENT_NODE;
1873 nodeName = "#comment";
1874 }
1877 /**
1878 *
1879 */
1880 CommentImpl::CommentImpl(DocumentImpl *owner, const DOMString &value)
1881 : CharacterDataImpl()
1882 {
1883 nodeType = COMMENT_NODE;
1884 nodeName = "#comment";
1885 ownerDocument = owner;
1886 nodeValue = value;
1887 }
1890 /**
1891 *
1892 */
1893 CommentImpl::~CommentImpl()
1894 {
1895 }
1900 /*#########################################################################
1901 ## TypeInfoImpl
1902 #########################################################################*/
1905 /**
1906 *
1907 */
1908 TypeInfoImpl::TypeInfoImpl(const DOMString &typeNamespaceArg,
1909 const DOMString &typeNameArg,
1910 const DerivationMethod derivationMethodArg)
1911 {
1912 typeNamespace = typeNamespaceArg;
1913 typeName = typeNameArg;
1914 derivationMethod = derivationMethodArg;
1915 }
1918 /**
1919 *
1920 */
1921 TypeInfoImpl::~TypeInfoImpl()
1922 {
1923 }
1926 /**
1927 *
1928 */
1929 DOMString TypeInfoImpl::getTypeName()
1930 {
1931 return typeName;
1932 }
1934 /**
1935 *
1936 */
1937 DOMString TypeInfoImpl::getTypeNamespace()
1938 {
1939 return typeNamespace;
1940 }
1942 /**
1943 *
1944 */
1945 bool TypeInfoImpl::isDerivedFrom(const DOMString &typeNamespaceArg,
1946 const DOMString &typeNameArg,
1947 const DerivationMethod derivationMethodArg)
1948 {
1949 if (typeNamespaceArg == typeNamespace &&
1950 typeName == typeNameArg &&
1951 derivationMethod == derivationMethodArg)
1952 return true;
1953 return false;
1954 }
1958 /*#########################################################################
1959 ## UserDataHandlerImpl
1960 #########################################################################*/
1964 /**
1965 *
1966 */
1967 UserDataHandlerImpl::UserDataHandlerImpl()
1968 {
1969 }
1972 /**
1973 *
1974 */
1975 UserDataHandlerImpl::~UserDataHandlerImpl()
1976 {
1977 }
1979 /**
1980 *
1981 */
1982 void UserDataHandlerImpl::handle(unsigned short operation,
1983 const DOMString &key,
1984 const DOMUserData *data,
1985 const Node *src,
1986 const Node *dst)
1987 {
1988 //do nothing. do we need anything here?
1989 }
1993 /*#########################################################################
1994 ## DOMErrorImpl
1995 #########################################################################*/
1999 /**
2000 *
2001 */
2002 DOMErrorImpl::DOMErrorImpl()
2003 {
2004 }
2007 /**
2008 *
2009 */
2010 DOMErrorImpl::~DOMErrorImpl()
2011 {
2012 }
2014 /**
2015 *
2016 */
2017 unsigned short DOMErrorImpl::getSeverity()
2018 {
2019 return severity;
2020 }
2022 /**
2023 *
2024 */
2025 DOMString DOMErrorImpl::getMessage()
2026 {
2027 return message;
2028 }
2030 /**
2031 *
2032 */
2033 DOMString DOMErrorImpl::getType()
2034 {
2035 return type;
2036 }
2038 /**
2039 *
2040 */
2041 DOMObject *DOMErrorImpl::getRelatedException()
2042 {
2043 return NULL;
2044 }
2046 /**
2047 *
2048 */
2049 DOMObject *DOMErrorImpl::getRelatedData()
2050 {
2051 return NULL;
2052 }
2054 /**
2055 *
2056 */
2057 DOMLocator *DOMErrorImpl::getLocation()
2058 {
2059 //really should fill this in
2060 return NULL;
2061 }
2066 /*#########################################################################
2067 ## DOMErrorHandlerImpl
2068 #########################################################################*/
2072 /**
2073 *
2074 */
2075 DOMErrorHandlerImpl::DOMErrorHandlerImpl()
2076 {
2077 }
2080 /**
2081 *
2082 */
2083 DOMErrorHandlerImpl::~DOMErrorHandlerImpl()
2084 {
2085 }
2087 /**
2088 *
2089 */
2090 bool DOMErrorHandlerImpl::handleError(const DOMError *error)
2091 {
2092 if (!error)
2093 return false;
2094 return true;
2095 }
2100 /*#########################################################################
2101 ## DOMLocatorImpl
2102 #########################################################################*/
2105 /**
2106 *
2107 */
2108 DOMLocatorImpl::DOMLocatorImpl()
2109 {
2110 }
2113 /**
2114 *
2115 */
2116 DOMLocatorImpl::~DOMLocatorImpl()
2117 {
2118 }
2121 /**
2122 *
2123 */
2124 long DOMLocatorImpl::getLineNumber()
2125 {
2126 return lineNumber;
2127 }
2129 /**
2130 *
2131 */
2132 long DOMLocatorImpl::getColumnNumber()
2133 {
2134 return columnNumber;
2135 }
2137 /**
2138 *
2139 */
2140 long DOMLocatorImpl::getByteOffset()
2141 {
2142 return byteOffset;
2143 }
2145 /**
2146 *
2147 */
2148 long DOMLocatorImpl::getUtf16Offset()
2149 {
2150 return utf16Offset;
2151 }
2154 /**
2155 *
2156 */
2157 Node *DOMLocatorImpl::getRelatedNode()
2158 {
2159 return relatedNode;
2160 }
2163 /**
2164 *
2165 */
2166 DOMString DOMLocatorImpl::getUri()
2167 {
2168 return uri;
2169 }
2173 /*#########################################################################
2174 ## DOMConfigurationImpl
2175 #########################################################################*/
2178 /**
2179 *
2180 */
2181 DOMConfigurationImpl::DOMConfigurationImpl()
2182 {
2183 }
2186 /**
2187 *
2188 */
2189 DOMConfigurationImpl::~DOMConfigurationImpl()
2190 {
2191 }
2193 /**
2194 *
2195 */
2196 void DOMConfigurationImpl::setParameter(const DOMString &name,
2197 const DOMUserData *value) throw (DOMException)
2198 {
2199 }
2201 /**
2202 *
2203 */
2204 DOMUserData *DOMConfigurationImpl::getParameter(const DOMString &name)
2205 throw (DOMException)
2206 {
2207 return NULL;
2208 }
2210 /**
2211 *
2212 */
2213 bool DOMConfigurationImpl::canSetParameter(const DOMString &name,
2214 const DOMUserData *data)
2215 {
2216 return false;
2217 }
2219 /**
2220 *
2221 */
2222 DOMStringList *DOMConfigurationImpl::getParameterNames()
2223 {
2224 return NULL;
2225 }
2229 /*#########################################################################
2230 ## CDATASectionImpl
2231 #########################################################################*/
2233 /**
2234 *
2235 */
2236 CDATASectionImpl::CDATASectionImpl() : TextImpl()
2237 {
2238 nodeType = CDATA_SECTION_NODE;
2239 nodeName = "#cdata-section";
2240 }
2242 /**
2243 *
2244 */
2245 CDATASectionImpl::CDATASectionImpl(DocumentImpl *owner, const DOMString &theValue)
2246 : TextImpl()
2247 {
2248 nodeType = CDATA_SECTION_NODE;
2249 nodeName = "#cdata-section";
2250 ownerDocument = owner;
2251 nodeValue = theValue;
2252 }
2255 /**
2256 *
2257 */
2258 CDATASectionImpl::~CDATASectionImpl()
2259 {
2260 }
2266 /*#########################################################################
2267 ## DocumentTypeImpl
2268 #########################################################################*/
2270 /**
2271 *
2272 */
2273 DocumentTypeImpl::DocumentTypeImpl(const DOMString& theName,
2274 const DOMString& thePublicId,
2275 const DOMString& theSystemId)
2276 : NodeImpl()
2277 {
2278 nodeType = DOCUMENT_TYPE_NODE;
2279 nodeName = theName;
2280 publicId = thePublicId;
2281 systemId = theSystemId;
2282 }
2284 /**
2285 *
2286 */
2287 DocumentTypeImpl::~DocumentTypeImpl()
2288 {
2289 }
2291 /**
2292 *
2293 */
2294 DOMString DocumentTypeImpl::getName()
2295 {
2296 return nodeName;
2297 }
2299 /**
2300 *
2301 */
2302 NamedNodeMap DocumentTypeImpl::getEntities()
2303 {
2304 return entities;
2305 }
2307 /**
2308 *
2309 */
2310 NamedNodeMap DocumentTypeImpl::getNotations()
2311 {
2312 return notations;
2313 }
2315 /**
2316 *
2317 */
2318 DOMString DocumentTypeImpl::getPublicId()
2319 {
2320 return publicId;
2321 }
2323 /**
2324 *
2325 */
2326 DOMString DocumentTypeImpl::getSystemId()
2327 {
2328 return systemId;
2329 }
2331 /**
2332 *
2333 */
2334 DOMString DocumentTypeImpl::getInternalSubset()
2335 {
2336 return DOMString("");
2337 }
2344 /*#########################################################################
2345 ## NotationImpl
2346 #########################################################################*/
2350 /**
2351 *
2352 */
2353 NotationImpl::NotationImpl(DocumentImpl *owner) : NodeImpl()
2354 {
2355 nodeType = NOTATION_NODE;
2356 ownerDocument = owner;
2357 }
2360 /**
2361 *
2362 */
2363 NotationImpl::~NotationImpl()
2364 {
2365 }
2367 /**
2368 *
2369 */
2370 DOMString NotationImpl::getPublicId()
2371 {
2372 return publicId;
2373 }
2375 /**
2376 *
2377 */
2378 DOMString NotationImpl::getSystemId()
2379 {
2380 return systemId;
2381 }
2390 /*#########################################################################
2391 ## EntityImpl
2392 #########################################################################*/
2395 /**
2396 *
2397 */
2398 EntityImpl::EntityImpl() : NodeImpl()
2399 {
2400 nodeType = ENTITY_NODE;
2401 }
2404 /**
2405 *
2406 */
2407 EntityImpl::EntityImpl(DocumentImpl *owner) : NodeImpl()
2408 {
2409 nodeType = ENTITY_NODE;
2410 ownerDocument = owner;
2411 }
2414 /**
2415 *
2416 */
2417 EntityImpl::~EntityImpl()
2418 {
2419 }
2421 /**
2422 *
2423 */
2424 DOMString EntityImpl::getPublicId()
2425 {
2426 return publicId;
2427 }
2429 /**
2430 *
2431 */
2432 DOMString EntityImpl::getSystemId()
2433 {
2434 return systemId;
2435 }
2437 /**
2438 *
2439 */
2440 DOMString EntityImpl::getNotationName()
2441 {
2442 return notationName;
2443 }
2445 /**
2446 *
2447 */
2448 DOMString EntityImpl::getInputEncoding()
2449 {
2450 return inputEncoding;
2451 }
2453 /**
2454 *
2455 */
2456 DOMString EntityImpl::getXmlEncoding()
2457 {
2458 return xmlEncoding;
2459 }
2461 /**
2462 *
2463 */
2464 DOMString EntityImpl::getXmlVersion()
2465 {
2466 return xmlVersion;
2467 }
2474 /*#########################################################################
2475 ## EntityReferenceImpl
2476 #########################################################################*/
2480 /**
2481 *
2482 */
2483 EntityReferenceImpl::EntityReferenceImpl() : NodeImpl()
2484 {
2485 nodeType = ENTITY_REFERENCE_NODE;
2486 }
2489 /**
2490 *
2491 */
2492 EntityReferenceImpl::EntityReferenceImpl(DocumentImpl *owner,
2493 const DOMString &theName)
2494 : NodeImpl()
2495 {
2496 nodeType = ENTITY_REFERENCE_NODE;
2497 nodeName = theName;
2498 ownerDocument = owner;
2499 }
2502 /**
2503 *
2504 */
2505 EntityReferenceImpl::~EntityReferenceImpl()
2506 {
2507 }
2511 /*#########################################################################
2512 ## ProcessingInstructionImpl
2513 #########################################################################*/
2518 /**
2519 *
2520 */
2521 ProcessingInstructionImpl::ProcessingInstructionImpl(): NodeImpl()
2522 {
2523 nodeType = PROCESSING_INSTRUCTION_NODE;
2524 }
2528 /**
2529 *
2530 */
2531 ProcessingInstructionImpl::ProcessingInstructionImpl(DocumentImpl *owner,
2532 const DOMString &target,
2533 const DOMString &data)
2534 : NodeImpl()
2535 {
2536 nodeType = PROCESSING_INSTRUCTION_NODE;
2537 ownerDocument = owner;
2538 nodeName = target;
2539 nodeValue = data;
2540 }
2543 /**
2544 *
2545 */
2546 ProcessingInstructionImpl::~ProcessingInstructionImpl()
2547 {
2548 }
2553 /**
2554 *
2555 */
2556 DOMString ProcessingInstructionImpl::getTarget()
2557 {
2558 return nodeName;
2559 }
2561 /**
2562 *
2563 */
2564 DOMString ProcessingInstructionImpl::getData()
2565 {
2566 return nodeValue;
2567 }
2569 /**
2570 *
2571 */
2572 void ProcessingInstructionImpl::setData(const DOMString& val) throw(DOMException)
2573 {
2574 //do something here
2575 }
2583 /*#########################################################################
2584 ## DocumentFragmentImpl
2585 #########################################################################*/
2587 /**
2588 *
2589 */
2590 DocumentFragmentImpl::DocumentFragmentImpl() : NodeImpl()
2591 {
2592 nodeType = DOCUMENT_FRAGMENT_NODE;
2593 nodeName = "#document-fragment";
2594 }
2597 /**
2598 *
2599 */
2600 DocumentFragmentImpl::DocumentFragmentImpl(DocumentImpl *owner) : NodeImpl()
2601 {
2602 nodeType = DOCUMENT_FRAGMENT_NODE;
2603 nodeName = "#document-fragment";
2604 ownerDocument = owner;
2605 }
2608 /**
2609 *
2610 */
2611 DocumentFragmentImpl::~DocumentFragmentImpl()
2612 {
2613 }
2620 /*#########################################################################
2621 ## DocumentImpl
2622 #########################################################################*/
2626 /**
2627 *
2628 */
2629 DocumentType *DocumentImpl::getDoctype()
2630 {
2631 return doctype;
2632 }
2634 /**
2635 *
2636 */
2637 DOMImplementation *DocumentImpl::getImplementation()
2638 {
2639 return parent;
2640 }
2642 /**
2643 *
2644 */
2645 Element *DocumentImpl::getDocumentElement()
2646 {
2647 return documentElement;
2648 }
2650 /**
2651 *
2652 */
2653 Element *DocumentImpl::createElement(const DOMString& tagName)
2654 throw(DOMException)
2655 {
2656 ElementImpl *impl = new ElementImpl(this, tagName);
2657 return impl;
2658 }
2660 /**
2661 *
2662 */
2663 DocumentFragment *DocumentImpl::createDocumentFragment()
2664 {
2665 DocumentFragmentImpl *frag = new DocumentFragmentImpl(this);
2666 return frag;
2667 }
2669 /**
2670 *
2671 */
2672 Text *DocumentImpl::createTextNode(const DOMString& data)
2673 {
2674 TextImpl *text = new TextImpl(this, data);
2675 return text;
2676 }
2678 /**
2679 *
2680 */
2681 Comment *DocumentImpl::createComment(const DOMString& data)
2682 {
2683 CommentImpl *comment = new CommentImpl(this, data);
2684 return comment;
2685 }
2687 /**
2688 *
2689 */
2690 CDATASection *DocumentImpl::createCDATASection(const DOMString& data)
2691 throw(DOMException)
2692 {
2693 CDATASectionImpl *cdata = new CDATASectionImpl(this, data);
2694 return cdata;
2695 }
2697 /**
2698 *
2699 */
2700 ProcessingInstruction *DocumentImpl::createProcessingInstruction(const DOMString& target,
2701 const DOMString& data)
2702 throw(DOMException)
2703 {
2704 ProcessingInstructionImpl *cdata =
2705 new ProcessingInstructionImpl(this, target, data);
2706 return cdata;
2707 }
2709 /**
2710 *
2711 */
2712 Attr *DocumentImpl::createAttribute(const DOMString& attrName)
2713 throw(DOMException)
2714 {
2715 AttrImpl *attr = new AttrImpl(this, attrName);
2716 return attr;
2717 }
2719 /**
2720 *
2721 */
2722 EntityReference *DocumentImpl::createEntityReference(const DOMString& erName)
2723 throw(DOMException)
2724 {
2725 EntityReferenceImpl *ref = new EntityReferenceImpl(this, erName);
2726 return ref;
2727 }
2730 /**
2731 *
2732 */
2733 NodeList DocumentImpl::getElementsByTagName(const DOMString& tagname)
2734 {
2735 NodeList list;
2736 ElementImpl::getElementsByTagNameRecursive(list,
2737 tagname, documentElement);
2738 return list;
2739 }
2742 /**
2743 *
2744 */
2745 Node *DocumentImpl::importNode(const Node *importedNode,
2746 bool deep)
2747 throw(DOMException)
2748 {
2749 return NULL;
2750 }
2752 /**
2753 *
2754 */
2755 Element *DocumentImpl::createElementNS(const DOMString& namespaceURI,
2756 const DOMString& qualifiedName)
2757 throw(DOMException)
2758 {
2759 ElementImpl *elem = new ElementImpl(this, namespaceURI, qualifiedName);
2760 return elem;
2761 }
2763 /**
2764 *
2765 */
2766 Attr *DocumentImpl::createAttributeNS(const DOMString& namespaceURI,
2767 const DOMString& qualifiedName)
2768 throw(DOMException)
2769 {
2770 AttrImpl *attr = new AttrImpl(this, namespaceURI, qualifiedName);
2771 return attr;
2772 }
2775 /**
2776 *
2777 */
2778 NodeList DocumentImpl::getElementsByTagNameNS(const DOMString& namespaceURI,
2779 const DOMString& localName)
2780 {
2781 NodeList list;
2782 ElementImpl::getElementsByTagNameNSRecursive(list, namespaceURI,
2783 localName, documentElement);
2784 return list;
2785 }
2787 /**
2788 *
2789 */
2790 Element *DocumentImpl::getElementById(const DOMString& elementId)
2791 {
2792 for (NamedElementItem *entry = elementsById.next; entry ; entry=entry->next)
2793 if (entry->name == elementId)
2794 return entry->elem;
2795 return NULL;
2796 }
2799 /**
2800 *
2801 */
2802 DOMString DocumentImpl::getInputEncoding()
2803 {
2804 return inputEncoding;
2805 }
2808 /**
2809 *
2810 */
2811 DOMString DocumentImpl::getXmlEncoding()
2812 {
2813 return xmlEncoding;
2814 }
2816 /**
2817 *
2818 */
2819 bool DocumentImpl::getXmlStandalone()
2820 {
2821 return xmlStandalone;
2822 }
2824 /**
2825 *
2826 */
2827 void DocumentImpl::setXmlStandalone(bool val) throw (DOMException)
2828 {
2829 xmlStandalone = val;
2830 }
2832 /**
2833 *
2834 */
2835 DOMString DocumentImpl::getXmlVersion()
2836 {
2837 return xmlVersion;
2838 }
2840 /**
2841 *
2842 */
2843 void DocumentImpl::setXmlVersion(const DOMString &version) throw (DOMException)
2844 {
2845 xmlVersion = version;
2846 }
2848 /**
2849 *
2850 */
2851 bool DocumentImpl::getStrictErrorChecking()
2852 {
2853 return strictErrorChecking;
2854 }
2856 /**
2857 *
2858 */
2859 void DocumentImpl::setStrictErrorChecking(bool val)
2860 {
2861 strictErrorChecking = val;
2862 }
2865 /**
2866 *
2867 */
2868 DOMString DocumentImpl::getDocumentURI()
2869 {
2870 if (!documentURI)
2871 return DOMString("");
2872 DOMString docURI = *documentURI;
2873 return docURI;
2874 }
2876 /**
2877 *
2878 */
2879 void DocumentImpl::setDocumentURI(const DOMString &uri)
2880 {
2881 //documentURI = stringCache(uri);
2882 }
2884 /**
2885 *
2886 */
2887 Node *DocumentImpl::adoptNode(const Node *source) throw (DOMException)
2888 {
2889 return (Node *)source;
2890 }
2892 /**
2893 *
2894 */
2895 DOMConfiguration *DocumentImpl::getDomConfig()
2896 {
2897 return domConfig;
2898 }
2900 /**
2901 *
2902 */
2903 void DocumentImpl::normalizeDocument()
2904 {
2905 //i assume that this means adjusting namespaces & prefixes
2906 if (documentElement)
2907 documentElement->normalizeNamespaces();
2908 }
2910 /**
2911 *
2912 */
2913 Node *DocumentImpl::renameNode(const Node *n,
2914 const DOMString &namespaceURI,
2915 const DOMString &qualifiedName)
2916 throw (DOMException)
2917 {
2918 Node *node = (Node *) n;
2919 NodeImpl *nodeImpl = dynamic_cast<NodeImpl *> (node);
2920 //nodeImpl->namespaceURI = stringCache(namespaceURI);
2921 nodeImpl->setNodeName(qualifiedName);
2922 return node;
2923 }
2927 //##################
2928 //# Non-API methods
2929 //##################
2931 /**
2932 *
2933 */
2934 DocumentImpl::DocumentImpl(const DOMImplementation *domImpl,
2935 const DOMString &theNamespaceURI,
2936 const DOMString &theQualifiedName,
2937 const DocumentType *theDoctype) : NodeImpl()
2938 {
2939 nodeType = DOCUMENT_NODE;
2940 nodeName = "#document";
2941 parent = (DOMImplementation *)domImpl;
2942 //documentURI = stringCache(theNamespaceURI);
2943 qualifiedName = theQualifiedName;
2944 if (theDoctype) //only assign if not null.
2945 doctype = (DocumentType *)theDoctype;
2946 else
2947 doctype = new DocumentTypeImpl("", "", "");
2948 documentElement = new ElementImpl(this, "root");
2949 namespaceIndex = 0;
2950 }
2953 /**
2954 *
2955 */
2956 DocumentImpl::~DocumentImpl()
2957 {
2958 delete documentElement;
2959 }
2972 } //namespace dom
2973 } //namespace w3c
2974 } //namespace org
2978 /*#########################################################################
2979 ## E N D O F F I L E
2980 #########################################################################*/