1 #ifndef __DOM_H__
2 #define __DOM_H__
3 /**
4 * Phoebe DOM Implementation.
5 *
6 * This is a C++ approximation of the W3C DOM model, which follows
7 * fairly closely the specifications in the various .idl files, copies of
8 * which are provided for reference. Most important is this one:
9 *
10 * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
11 *
12 * More thorough explanations of the various classes and their algorithms
13 * can be found there.
14 *
15 *
16 * Authors:
17 * Bob Jamison
18 *
19 * Copyright (C) 2006-2008 Bob Jamison
20 *
21 * This library is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU Lesser General Public
23 * License as published by the Free Software Foundation; either
24 * version 2.1 of the License, or (at your option) any later version.
25 *
26 * This library is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * Lesser General Public License for more details.
30 *
31 * You should have received a copy of the GNU Lesser General Public
32 * License along with this library; if not, write to the Free Software
33 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 *
35 * =======================================================================
36 * NOTES:
37 *
38 * Notice that many of the classes defined here are pure virtual. In other
39 * words, they are purely unimplemented interfaces. For the implementations
40 * of them, look in domimpl.h and domimpl.cpp.
41 *
42 * Also, note that there is a domptr.cpp file that has a couple of necessary
43 * functions which cannot be in a .h file.
44 *
45 * Some of the comments below are quoted from the W3C spec:
46 * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html
47 *
48 */
50 #include <vector>
52 #include "domptr.h"
55 /**
56 * What type of string do we want? Pick one of the following
57 * Then below, select one of the corresponding typedefs.
58 */
60 #include <glibmm.h>
61 //#include <string>
63 //# Unfortunate hack for a name collision
64 #ifdef SEVERITY_ERROR
65 #undef SEVERITY_ERROR
66 #endif
68 #define XMLNSNAME "http://www.w3.org/2000/xmlns/"
70 namespace org
71 {
72 namespace w3c
73 {
74 namespace dom
75 {
78 /**
79 * This is the org::w3c::dom::DOMString definition.
80 * Which type do we want?
81 */
82 typedef Glib::ustring DOMString;
83 typedef gunichar XMLCh;
85 //typedef std::string DOMString;
86 //typedef unsigned short XMLCh;
89 /**
90 * At least 64 bit time stamp value.
91 */
92 typedef unsigned long long DOMTimeStamp;
94 /**
95 * This is used for storing refs to user-supplied data.
96 */
97 typedef void DOMUserData;
101 /**
102 * This is used for opaque references to arbitrary objects from
103 * the DOM tree.
104 */
105 typedef void DOMObject;
108 /**
109 * Forward references. These are needed because of extensive
110 * inter-referencing within the DOM tree.
111 */
112 class NodeList;
113 class NamedNodeMap;
114 class DOMException;
115 class DOMStringList;
116 class NameList;
117 class DOMImplementationList;
118 class DOMImplementationSource;
119 class DOMImplementation;
120 class TypeInfo;
121 class UserDataHandler;
122 class DOMError;
123 class DOMErrorHandler;
124 class DOMLocator;
125 class DOMConfiguration;
127 /**
128 * Smart pointer definitions. Most methods that return references to
129 * Nodes of various types, will return one of these smart pointers instead,
130 * to allow refcounting and GC.
131 */
132 class Node;
133 typedef Ptr<Node> NodePtr;
134 class CharacterData;
135 typedef Ptr<CharacterData> CharacterDataPtr;
136 class Attr;
137 typedef Ptr<Attr> AttrPtr;
138 class Element;
139 typedef Ptr<Element> ElementPtr;
140 class Text;
141 typedef Ptr<Text> TextPtr;
142 class Comment;
143 typedef Ptr<Comment> CommentPtr;
144 class DocumentType;
145 typedef Ptr<DocumentType> DocumentTypePtr;
146 class CDATASection;
147 typedef Ptr<CDATASection> CDATASectionPtr;
148 class Notation;
149 typedef Ptr<Notation> NotationPtr;
150 class Entity;
151 typedef Ptr<Entity> EntityPtr;
152 class EntityReference;
153 typedef Ptr<EntityReference> EntityReferencePtr;
154 class ProcessingInstruction;
155 typedef Ptr<ProcessingInstruction> ProcessingInstructionPtr;
156 class DocumentFragment;
157 typedef Ptr<DocumentFragment> DocumentFragmentPtr;
158 class Document;
159 typedef Ptr<Document> DocumentPtr;
164 /**
165 * NOTE: We were originally intending to split ALL specifications into
166 * interface and implementation. After consideration, though, it behooves
167 * us to simplify things by implementing the base exception and
168 * container classes directly:
169 *
170 * DOMException
171 * DOMStringList
172 * NameList
173 * DOMImplementationList
174 * DOMImplementationSource
175 * DOMImplementation
176 * NodeList
177 * NamedNodeMap
178 */
181 /*#########################################################################
182 ## DOMException
183 #########################################################################*/
185 /**
186 * An Exception class. Not an interface, since this is something that
187 * all implementations must support.
188 */
189 class DOMException
190 {
192 public:
194 /**
195 * ExceptionCode
196 */
197 typedef enum
198 {
199 INDEX_SIZE_ERR = 1,
200 DOMSTRING_SIZE_ERR = 2,
201 HIERARCHY_REQUEST_ERR = 3,
202 WRONG_DOCUMENT_ERR = 4,
203 INVALID_CHARACTER_ERR = 5,
204 NO_DATA_ALLOWED_ERR = 6,
205 NO_MODIFICATION_ALLOWED_ERR = 7,
206 NOT_FOUND_ERR = 8,
207 NOT_SUPPORTED_ERR = 9,
208 INUSE_ATTRIBUTE_ERR = 10,
209 INVALID_STATE_ERR = 11,
210 SYNTAX_ERR = 12,
211 INVALID_MODIFICATION_ERR = 13,
212 NAMESPACE_ERR = 14,
213 INVALID_ACCESS_ERR = 15,
214 VALIDATION_ERR = 16,
215 TYPE_MISMATCH_ERR = 17
216 } ExceptionCode;
220 DOMException(const DOMString &reasonMsg)
221 { msg = reasonMsg; }
223 DOMException(short theCode)
224 {
225 code = theCode;
226 }
228 virtual ~DOMException() throw()
229 {}
231 /**
232 * What type of exception? One of the ExceptionCodes above.
233 */
234 unsigned short code;
236 /**
237 * Some text describing the context that generated this exception.
238 */
239 DOMString msg;
241 /**
242 * Get a string, translated from the code.
243 * Like std::exception. Not in spec.
244 */
245 const char *what()
246 { return (const char *)msg.c_str(); }
250 };
257 /*#########################################################################
258 ## DOMStringList
259 #########################################################################*/
261 /**
262 * This holds a list of DOMStrings. This is likely the response to a query,
263 * or the value of an attribute.
264 */
265 class DOMStringList
266 {
267 public:
269 /**
270 * Get the nth string of the list
271 */
272 virtual DOMString item(unsigned long index)
273 {
274 if (index>=strings.size())
275 return "";
276 return strings[index];
277 }
279 /**
280 * How many strings in this list?
281 */
282 virtual unsigned long getLength()
283 {
284 return (unsigned long) strings.size();
285 }
287 /**
288 * Is the argument string present in this list? Lexically, not identically.
289 */
290 virtual bool contains(const DOMString &str)
291 {
292 for (unsigned int i=0; i<strings.size() ; i++)
293 {
294 if (strings[i] == str)
295 return true;
296 }
297 return false;
298 }
301 //##################
302 //# Non-API methods
303 //##################
305 /**
306 *
307 */
308 DOMStringList() {}
311 /**
312 *
313 */
314 DOMStringList(const DOMStringList &other)
315 {
316 strings = other.strings;
317 }
319 /**
320 *
321 */
322 DOMStringList &operator=(const DOMStringList &other)
323 {
324 strings = other.strings;
325 return *this;
326 }
328 /**
329 *
330 */
331 virtual ~DOMStringList() {}
334 protected:
336 /**
337 *
338 */
339 virtual void add(const DOMString &str)
340 {
341 strings.push_back(str);
342 }
344 std::vector<DOMString>strings;
346 };
350 /*#########################################################################
351 ## NameList
352 #########################################################################*/
355 /**
356 * Constains a list of namespaced names.
357 */
358 class NameList
359 {
360 private:
362 class NamePair
363 {
364 public:
365 NamePair(const DOMString &theNamespaceURI, const DOMString &theName)
366 {
367 namespaceURI = theNamespaceURI;
368 name = theName;
369 }
370 NamePair(const NamePair &other)
371 {
372 namespaceURI = other.namespaceURI;
373 name = other.name;
374 }
375 NamePair &operator=(const NamePair &other)
376 {
377 namespaceURI = other.namespaceURI;
378 name = other.name;
379 return *this;
380 }
381 virtual ~NamePair() {}
383 DOMString namespaceURI;
384 DOMString name;
385 };
387 public:
389 /**
390 * Returns a name at the given index. If out of range, return -1.
391 */
392 virtual DOMString getName(unsigned long index)
393 {
394 if (index>=namePairs.size())
395 return "";
396 return namePairs[index].name;
397 }
399 /**
400 * Returns a namespace at the given index. If out of range, return -1.
401 */
402 virtual DOMString getNamespaceURI(unsigned long index)
403 {
404 if (index>=namePairs.size())
405 return "";
406 return namePairs[index].namespaceURI;
407 }
409 /**
410 * Return the number of entries in this list.
411 */
412 virtual unsigned long getLength()
413 {
414 return (unsigned long)namePairs.size();
415 }
417 /**
418 * Return whether the name argument is present in the list.
419 * This is done lexically, not identically.
420 */
421 virtual bool contains(const DOMString &name)
422 {
423 for (unsigned int i=0; i<namePairs.size() ; i++)
424 {
425 if (namePairs[i].name == name )
426 return true;
427 }
428 return false;
429 }
431 /**
432 * Return whether the namespaced name argument is present in the list.
433 * This is done lexically, not identically.
434 */
435 virtual bool containsNS(const DOMString namespaceURI,const DOMString &name)
436 {
437 for (unsigned int i=0; i<namePairs.size() ; i++)
438 {
439 if (namePairs[i].namespaceURI == namespaceURI ||
440 namePairs[i].name == name )
441 return true;
442 }
443 return false;
444 }
447 //##################
448 //# Non-API methods
449 //##################
451 /**
452 *
453 */
454 NameList() {}
456 /**
457 *
458 */
459 NameList(const NameList &other)
460 {
461 namePairs = other.namePairs;
462 }
464 /**
465 *
466 */
467 NameList &operator=(const NameList &other)
468 {
469 namePairs = other.namePairs;
470 return *this;
471 }
473 /**
474 *
475 */
476 virtual ~NameList() {}
479 protected:
481 std::vector<NamePair> namePairs;
483 };
485 /*#########################################################################
486 ## DOMImplementationList
487 #########################################################################*/
489 /**
490 * Contains a list of DOMImplementations, with accessors.
491 */
492 class DOMImplementationList
493 {
494 public:
496 /**
497 * Return a DOMImplementation at the given index. If
498 * out of range, return NULL.
499 */
500 virtual DOMImplementation *item(unsigned long index)
501 {
502 if (index >implementations.size())
503 return NULL;
504 return implementations[index];
505 }
507 /**
508 * Return the number of DOMImplementations in this list.
509 */
510 virtual unsigned long getLength()
511 {
512 return (unsigned long) implementations.size();
513 }
516 //##################
517 //# Non-API methods
518 //##################
520 /**
521 *
522 */
523 DOMImplementationList() {}
526 /**
527 *
528 */
529 DOMImplementationList(const DOMImplementationList &other)
530 {
531 implementations = other.implementations;
532 }
534 /**
535 *
536 */
537 DOMImplementationList &operator=(const DOMImplementationList &other)
538 {
539 implementations = other.implementations;
540 return *this;
541 }
543 /**
544 *
545 */
546 virtual ~DOMImplementationList() {}
548 protected:
550 std::vector<DOMImplementation *>implementations;
552 };
555 /*#########################################################################
556 ## DOMImplementationSource
557 #########################################################################*/
559 /**
560 * This is usually the first item to be called when creating a Document.
561 * You will either find one DOMImplementation with a given set of features,
562 * or return a list that match. Using "" will get any implementation
563 * available.
564 */
565 class DOMImplementationSource
566 {
567 public:
569 /**
570 * Return the first DOMImplementation with the given set of features.
571 * Use "" to fetch any implementation.
572 */
573 virtual DOMImplementation *getDOMImplementation(const DOMString &features) = 0;
575 /**
576 * Return a list of DOMImplementations with the given set of features.
577 * Use "" to fetch any implementation.
578 */
579 virtual DOMImplementationList getDOMImplementationList(const DOMString &features) = 0;
581 //##################
582 //# Non-API methods
583 //##################
585 /**
586 *
587 */
588 virtual ~DOMImplementationSource() {}
590 };
596 /*#########################################################################
597 ## DOMImplementation
598 #########################################################################*/
600 /**
601 * This is the class that actually creates a Document.
602 */
603 class DOMImplementation
604 {
605 public:
607 /**
608 * Determine if this implementation has the given feature and version.
609 */
610 virtual bool hasFeature(const DOMString& feature, const DOMString& version) = 0;
613 /**
614 * Create a document type to be used in creating documents.
615 */
616 virtual DocumentTypePtr createDocumentType(
617 const DOMString& qualifiedName,
618 const DOMString& publicId,
619 const DOMString& systemId)
620 throw(DOMException) = 0;
622 /**
623 * Create a DOM document.
624 */
625 virtual DocumentPtr createDocument(const DOMString& namespaceURI,
626 const DOMString& qualifiedName,
627 DocumentTypePtr doctype)
628 throw(DOMException) = 0;
629 /**
630 * Return the thing which is the feature of this implementation. Since
631 * this is a "one size fits all" call, you will need to typecast the
632 * result to the expected type.
633 */
634 virtual DOMObject *getFeature(const DOMString& feature,
635 const DOMString& version) = 0;
638 //##################
639 //# Non-API methods
640 //##################
642 /**
643 *
644 */
645 virtual ~DOMImplementation() {}
647 };
653 /*#########################################################################
654 ## Node
655 #########################################################################*/
657 /**
658 * The basic Node class, which is the root of most other
659 * classes in DOM. Thus it is by far the most important, and the one
660 * whose implementation we must perform correctly.
661 */
662 class Node
663 {
664 public:
666 /**
667 * Which of the DOM Core node types is this node?
668 */
669 typedef enum
670 {
671 ELEMENT_NODE = 1,
672 ATTRIBUTE_NODE = 2,
673 TEXT_NODE = 3,
674 CDATA_SECTION_NODE = 4,
675 ENTITY_REFERENCE_NODE = 5,
676 ENTITY_NODE = 6,
677 PROCESSING_INSTRUCTION_NODE = 7,
678 COMMENT_NODE = 8,
679 DOCUMENT_NODE = 9,
680 DOCUMENT_TYPE_NODE = 10,
681 DOCUMENT_FRAGMENT_NODE = 11,
682 NOTATION_NODE = 12
683 } NodeType;
685 /**
686 * Return the name of this node.
687 */
688 virtual DOMString getNodeName() = 0;
690 /**
691 * Return the value of this node. The interpretation of the
692 * value is type-specific.
693 */
694 virtual DOMString getNodeValue() throw (DOMException) = 0;
696 /**
697 * Set the value of this node. The interpretation of the
698 * value is type-specific.
699 */
700 virtual void setNodeValue(const DOMString& val) throw (DOMException) = 0;
702 /**
703 * Return the type of this Node. One of the NodeType values above.
704 */
705 virtual unsigned short getNodeType() = 0;
707 /**
708 * Return the parent which references this node as a child in the DOM
709 * tree. Return NULL if there is none.
710 */
711 virtual NodePtr getParentNode() = 0;
713 /**
714 * Return a list of the children of this Node.
715 * NOTE: the spec expects this to be a "live" list that always
716 * reflects an accurate list of what the Node current possesses, not
717 * a snapshot. How do we do this?
718 */
719 virtual NodeList getChildNodes() = 0;
721 /**
722 * Return the first sibling of the chidren of this node. Return
723 * null if there is none.
724 */
725 virtual NodePtr getFirstChild() = 0;
727 /**
728 * Return the last sibling of the children of this node. Return
729 * null if there is none.
730 */
731 virtual NodePtr getLastChild() = 0;
733 /**
734 * Return the node that is previous to this one in the parent's
735 * list of children. Return null if there is none.
736 */
737 virtual NodePtr getPreviousSibling() = 0;
739 /**
740 * Return the node that is after this one in the parent's list
741 * of children. Return null if there is none.
742 */
743 virtual NodePtr getNextSibling() = 0;
745 /**
746 * Get the list of all attributes of this node.
747 */
748 virtual NamedNodeMap &getAttributes() = 0;
751 /**
752 * Return the document that created or inherited this node.
753 */
754 virtual DocumentPtr getOwnerDocument() = 0;
756 /**
757 * Insert a node as a new child. Place it before the referenced child.
758 * Place it at the end if the referenced child does not exist.
759 */
760 virtual NodePtr insertBefore(const NodePtr newChild,
761 const NodePtr refChild)
762 throw(DOMException) = 0;
764 /**
765 * Insert a node as a new child. Replace the referenced child with it.
766 * Place it at the end if the referenced child does not exist.
767 */
768 virtual NodePtr replaceChild(const NodePtr newChild,
769 const NodePtr oldChild)
770 throw(DOMException) = 0;
772 /**
773 * Remove a node from the list of children. Do nothing if the
774 * node is not a member of the child list.
775 */
776 virtual NodePtr removeChild(const NodePtr oldChild)
777 throw(DOMException) = 0;
779 /**
780 * Add the node to the end of this node's child list.
781 */
782 virtual NodePtr appendChild(const NodePtr newChild)
783 throw(DOMException) = 0;
785 /**
786 * Return true if this node has one or more children, else return false.
787 */
788 virtual bool hasChildNodes() = 0;
790 /**
791 * Return a new node which has the name, type, value, attributes, and
792 * child list as this one.
793 * If 'deep' is true, continue cloning recursively with this node's children,
794 * so that the child list also contains clones of their respective nodes.
795 */
796 virtual NodePtr cloneNode(bool deep) = 0;
798 /**
799 * Adjust this node and its children to have its namespaces and
800 * prefixes in "canonical" order.
801 */
802 virtual void normalize() = 0;
804 /**
805 * Return true if the named feature is supported by this node,
806 * else false.
807 */
808 virtual bool isSupported(const DOMString& feature,
809 const DOMString& version) = 0;
811 /**
812 * Return the namespace of this node. This would be whether the
813 * namespace were declared explicitly on this node, it has a namespace
814 * prefix, or it is inherits the namespace from an ancestor node.
815 */
816 virtual DOMString getNamespaceURI() = 0;
818 /**
819 * Return the namespace prefix of this node, if any. For example, if
820 * the tag were <svg:image> then the prefix would be "svg"
821 */
822 virtual DOMString getPrefix() = 0;
824 /**
825 * Sets the namespace prefix of this node to the given value. This
826 * does not change the namespaceURI value.
827 */
828 virtual void setPrefix(const DOMString& val) throw(DOMException) = 0;
830 /**
831 * Return the local name of this node. This is merely the name without
832 * any namespace or prefix.
833 */
834 virtual DOMString getLocalName() = 0;
836 /**
837 * Return true if this node has one or more attributes, else false.
838 */
839 virtual bool hasAttributes() = 0;
841 /**
842 * Return the base URI of this node. This is basically the "location" of this
843 * node, and is used in resolving the relative locations of other URIs.
844 */
845 virtual DOMString getBaseURI() = 0;
847 /**
848 * DocumentPosition.
849 * This is used to describe the position of one node relative
850 * to another in a document
851 */
852 typedef enum
853 {
854 DOCUMENT_POSITION_DISCONNECTED = 0x01,
855 DOCUMENT_POSITION_PRECEDING = 0x02,
856 DOCUMENT_POSITION_FOLLOWING = 0x04,
857 DOCUMENT_POSITION_CONTAINS = 0x08,
858 DOCUMENT_POSITION_CONTAINED_BY = 0x10,
859 DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20
860 } DocumentPosition;
863 /**
864 * Get the position of this node relative to the node argument.
865 */
866 virtual unsigned short compareDocumentPosition(
867 const NodePtr other) = 0;
869 /**
870 * This is a DOM L3 method. Return the text value of this node and its
871 * children. This is done by concatenating all of the TEXT_NODE and
872 * CDATA_SECTION nodes of this node and its children, in order, together.
873 * Very handy.
874 */
875 virtual DOMString getTextContent() throw(DOMException) = 0;
878 /**
879 * This is a DOM L3 method. Remember, this is a destructive call. This
880 * will replace all of the child nodes of this node with a single TEXT_NODE
881 * with the given text value.
882 */
883 virtual void setTextContent(const DOMString &val) throw(DOMException) = 0;
886 /**
887 * This will search the tree from this node up, for a prefix that
888 * has been assigned to the namespace argument. Return "" if not found.
889 */
890 virtual DOMString lookupPrefix(const DOMString &namespaceURI) =0;
893 /**
894 * Return true if this node is in the namespace of the argument, without
895 * requiring an explicit namespace declaration or a suffix.
896 */
897 virtual bool isDefaultNamespace(const DOMString &namespaceURI) =0;
900 /**
901 * This will search the tree from this node up, for a namespace that
902 * has been assigned the suffix in the argument. Return "" if not found.
903 */
904 virtual DOMString lookupNamespaceURI(const DOMString &prefix) =0;
907 /**
908 * Return true if the argument node is equal to this one. Use W3C rules
909 * for equality.
910 */
911 virtual bool isEqualNode(const NodePtr node) =0;
915 /**
916 * Return an opaque reference to the named feature. Return null if
917 * not supported. Using other than "" for the version will look for
918 * a feature with the given version.
919 */
920 virtual DOMObject *getFeature(const DOMString &feature,
921 const DOMString &version) =0;
923 /**
924 * Store a user data reference in this node, using the given key.
925 * A handler is an optional function object that will be called during
926 * future settings of this value. See UserDataHandler for more info.
927 */
928 virtual DOMUserData *setUserData(const DOMString &key,
929 const DOMUserData *data,
930 const UserDataHandler *handler) =0;
933 /**
934 * Return a reference to the named user data object. Return null
935 * if it does not exist.
936 */
937 virtual DOMUserData *getUserData(const DOMString &key) =0;
939 //##################
940 //# Non-API methods
941 //##################
943 /**
944 *
945 */
946 Node() : _refCnt(0)
947 {}
949 /**
950 *
951 */
952 virtual ~Node() {}
954 protected:
956 friend void incrementRefCount(Node *p);
957 friend void decrementRefCount(Node *p);
959 /**
960 * For the Ptr smart pointer
961 */
962 int _refCnt;
964 };
969 /*#########################################################################
970 ## NodeList
971 #########################################################################*/
973 /**
974 * Contains a list of Nodes. This is the standard API container for Nodes,
975 * and is used in lieu of other lists, arrays, etc, in order to provide
976 * a consistent API and algorithm.
977 */
978 class NodeList
979 {
980 public:
982 /**
983 * Retrieve the Node at the given index. Return NULL
984 * if out of range.
985 */
986 virtual NodePtr item(unsigned long index)
987 {
988 if (index>=nodes.size())
989 return NULL;
990 return nodes[index];
991 }
993 /**
994 * Get the number of nodes in this list
995 */
996 virtual unsigned long getLength()
997 {
998 return (unsigned long) nodes.size();
999 }
1001 //##################
1002 //# Non-API methods
1003 //##################
1006 /**
1007 *
1008 */
1009 NodeList() {}
1011 /**
1012 *
1013 */
1014 NodeList(const NodeList &other)
1015 {
1016 nodes = other.nodes;
1017 }
1019 /**
1020 *
1021 */
1022 NodeList &operator=(const NodeList &other)
1023 {
1024 nodes = other.nodes;
1025 return *this;
1026 }
1028 /**
1029 *
1030 */
1031 virtual ~NodeList() {}
1033 /**
1034 *
1035 */
1036 virtual void clear()
1037 {
1038 nodes.clear();
1039 }
1041 protected:
1043 friend class NodeImpl;
1044 friend class ElementImpl;
1046 /*
1047 *
1048 */
1049 virtual void add(const NodePtr node)
1050 {
1051 nodes.push_back(node);
1052 }
1054 protected:
1056 std::vector<NodePtr> nodes;
1058 };
1063 /*#########################################################################
1064 ## NamedNodeMap
1065 #########################################################################*/
1067 /**
1068 * Contains a mapping from name->NodePtr. Used for various purposes. For
1069 * example, a list of Attributes is a NamedNodeMap.
1070 */
1071 class NamedNodeMap
1072 {
1073 private:
1075 /**
1076 * table entry. Not an API item
1077 */
1078 class NamedNodeMapEntry
1079 {
1080 public:
1081 NamedNodeMapEntry(const DOMString &theNamespaceURI,
1082 const DOMString &theName,
1083 const NodePtr theNode)
1084 {
1085 namespaceURI = theNamespaceURI;
1086 name = theName;
1087 node = theNode;
1088 }
1089 NamedNodeMapEntry(const NamedNodeMapEntry &other)
1090 {
1091 assign(other);
1092 }
1093 NamedNodeMapEntry &operator=(const NamedNodeMapEntry &other)
1094 {
1095 assign(other);
1096 return *this;
1097 }
1098 virtual ~NamedNodeMapEntry()
1099 {
1100 }
1101 void assign(const NamedNodeMapEntry &other)
1102 {
1103 namespaceURI = other.namespaceURI;
1104 name = other.name;
1105 node = other.node;
1106 }
1107 DOMString namespaceURI;
1108 DOMString name;
1109 NodePtr node;
1110 };
1113 public:
1115 /**
1116 * Return the named node. Return nullptr if not found.
1117 */
1118 virtual NodePtr getNamedItem(const DOMString& name)
1119 {
1120 std::vector<NamedNodeMapEntry>::iterator iter;
1121 for (iter = entries.begin() ; iter!=entries.end() ; iter++)
1122 {
1123 if (iter->name == name)
1124 {
1125 NodePtr node = iter->node;
1126 return node;
1127 }
1128 }
1129 return NULL;
1130 }
1132 /**
1133 *
1134 */
1135 virtual NodePtr setNamedItem(NodePtr arg) throw(DOMException)
1136 {
1137 if (!arg)
1138 return NULL;
1139 DOMString namespaceURI = arg->getNamespaceURI();
1140 DOMString name = arg->getNodeName();
1141 std::vector<NamedNodeMapEntry>::iterator iter;
1142 for (iter = entries.begin() ; iter!=entries.end() ; iter++)
1143 {
1144 if (iter->name == name)
1145 {
1146 NodePtr node = iter->node;
1147 iter->node = arg;
1148 return node;
1149 }
1150 }
1151 NamedNodeMapEntry entry(namespaceURI, name, arg);
1152 entries.push_back(entry);
1153 return arg;
1154 }
1157 /**
1158 *
1159 */
1160 virtual NodePtr removeNamedItem(const DOMString& name) throw(DOMException)
1161 {
1162 std::vector<NamedNodeMapEntry>::iterator iter;
1163 for (iter = entries.begin() ; iter!=entries.end() ; iter++)
1164 {
1165 if (iter->name == name)
1166 {
1167 NodePtr node = iter->node;
1168 entries.erase(iter);
1169 return node;
1170 }
1171 }
1172 return NULL;
1173 }
1175 /**
1176 *
1177 */
1178 virtual NodePtr item(unsigned long index)
1179 {
1180 if (index>=entries.size())
1181 return NULL;
1182 return entries[index].node;
1183 }
1185 /**
1186 *
1187 */
1188 virtual unsigned long getLength()
1189 {
1190 return (unsigned long)entries.size();
1191 }
1193 /**
1194 *
1195 */
1196 virtual NodePtr getNamedItemNS(const DOMString& namespaceURI,
1197 const DOMString& localName)
1198 {
1199 std::vector<NamedNodeMapEntry>::iterator iter;
1200 for (iter = entries.begin() ; iter!=entries.end() ; iter++)
1201 {
1202 if (iter->namespaceURI == namespaceURI && iter->name == localName)
1203 {
1204 NodePtr node = iter->node;
1205 return node;
1206 }
1207 }
1208 return NULL;
1209 }
1211 /**
1212 *
1213 */
1214 virtual NodePtr setNamedItemNS(NodePtr arg) throw(DOMException)
1215 {
1216 if (!arg)
1217 return NULL;
1218 DOMString namespaceURI = arg->getNamespaceURI();
1219 DOMString name = arg->getNodeName();
1220 std::vector<NamedNodeMapEntry>::iterator iter;
1221 for (iter = entries.begin() ; iter!=entries.end() ; iter++)
1222 {
1223 if (iter->namespaceURI == namespaceURI && iter->name == name)
1224 {
1225 NodePtr node = iter->node;
1226 iter->node = arg;
1227 return node;
1228 }
1229 }
1230 NamedNodeMapEntry entry(namespaceURI, name, arg);
1231 entries.push_back(entry);
1232 return arg;
1233 }
1235 /**
1236 *
1237 */
1238 virtual NodePtr removeNamedItemNS(const DOMString& namespaceURI,
1239 const DOMString& localName)
1240 throw(DOMException)
1241 {
1242 std::vector<NamedNodeMapEntry>::iterator iter;
1243 for (iter = entries.begin() ; iter!=entries.end() ; iter++)
1244 {
1245 if (iter->namespaceURI == namespaceURI && iter->name == localName)
1246 {
1247 NodePtr node = iter->node;
1248 entries.erase(iter);
1249 return node;
1250 }
1251 }
1252 return NULL;
1253 }
1255 //##################
1256 //# Non-API methods
1257 //##################
1259 /**
1260 *
1261 */
1262 NamedNodeMap() {}
1265 /**
1266 *
1267 */
1268 NamedNodeMap(const NamedNodeMap &other)
1269 {
1270 entries = other.entries;
1271 }
1273 /**
1274 *
1275 */
1276 NamedNodeMap &operator=(const NamedNodeMap &other)
1277 {
1278 entries = other.entries;
1279 return *this;
1280 }
1283 /**
1284 *
1285 */
1286 virtual ~NamedNodeMap() {}
1288 protected:
1290 std::vector<NamedNodeMapEntry> entries;
1292 };
1297 /*#########################################################################
1298 ## CharacterData
1299 #########################################################################*/
1301 /**
1302 * This is the base class for other text-oriented Nodes, such as TEXT_NODE
1303 * or CDATA_SECTION_NODE. No DOM objects correspond directly to CharacterData.
1304 */
1305 class CharacterData : virtual public Node
1306 {
1307 public:
1309 /**
1310 * This is an alias for getNodeValue()
1311 */
1312 virtual DOMString getData() throw(DOMException) = 0;
1314 /**
1315 * This is an alias for setNodeValue()
1316 */
1317 virtual void setData(const DOMString& val) throw(DOMException) = 0;
1319 /**
1320 * Return the number of characters contained in this node's data
1321 */
1322 virtual unsigned long getLength() = 0;
1324 /**
1325 * Return a substring of this node's data, starting at offset, and
1326 * continuing for 'count' characters. Throw an exception if this goes
1327 * out of range.
1328 */
1329 virtual DOMString substringData(unsigned long offset,
1330 unsigned long count)
1331 throw(DOMException) = 0;
1333 /**
1334 * Append the argument string to the end of the node's current data.
1335 */
1336 virtual void appendData(const DOMString& arg) throw(DOMException) = 0;
1338 /**
1339 * Insert the argument string at the offset position into the node's
1340 * current data. If the position is out of range, throw an Exception.
1341 */
1342 virtual void insertData(unsigned long offset,
1343 const DOMString& arg)
1344 throw(DOMException) = 0;
1346 /**
1347 * Delete 'count' characters from the node's data starting from the
1348 * offset position. If this goes out of range, throw an Exception.
1349 */
1350 virtual void deleteData(unsigned long offset,
1351 unsigned long count)
1352 throw(DOMException) = 0;
1354 /**
1355 * Replace the 'count' characters at the offset position with the given
1356 * argument string. If this goes out of range, throw an Exception.
1357 */
1358 virtual void replaceData(unsigned long offset,
1359 unsigned long count,
1360 const DOMString& arg)
1361 throw(DOMException) = 0;
1364 //##################
1365 //# Non-API methods
1366 //##################
1369 /**
1370 *
1371 */
1372 virtual ~CharacterData() {}
1374 };
1379 /*#########################################################################
1380 ## Attr
1381 #########################################################################*/
1383 /**
1384 * The Attr interface represents an attribute in an Element object.
1385 * Typically the allowable values for the attribute are defined in a
1386 * schema associated with the document.
1387 * Since Attrs are not considered to be part of the DOM tree, parent,
1388 * previousSibling, and nextSibling are null.
1389 */
1390 class Attr : virtual public Node
1391 {
1392 public:
1394 /**
1395 *
1396 */
1397 virtual DOMString getName() = 0;
1399 /**
1400 *
1401 */
1402 virtual bool getSpecified() = 0;
1404 /**
1405 *
1406 */
1407 virtual DOMString getValue() = 0;
1409 /**
1410 *
1411 */
1412 virtual void setValue(const DOMString& val) throw(DOMException) = 0;
1414 /**
1415 *
1416 */
1417 virtual ElementPtr getOwnerElement() = 0;
1420 /**
1421 *
1422 */
1423 virtual TypeInfo &getSchemaTypeInfo() = 0;
1426 /**
1427 *
1428 */
1429 virtual bool getIsId() = 0;
1431 //##################
1432 //# Non-API methods
1433 //##################
1436 /**
1437 *
1438 */
1439 virtual ~Attr() {}
1441 };
1447 /*#########################################################################
1448 ## Element
1449 #########################################################################*/
1451 /**
1452 * The Element interface represents an element in an XML document.
1453 * Elements may have attributes associated with them; since the Element interface
1454 * inherits from Node, the generic Node interface attribute attributes may be
1455 * used to retrieve the set of all attributes for an element. There are methods
1456 * on the Element interface to retrieve either an Attr object by name or an
1457 * attribute value by name. In XML, where an attribute value may contain entity
1458 * references, an Attr object should be retrieved to examine the possibly fairly
1459 * complex sub-tree representing the attribute value. On the other hand, in HTML,
1460 * where all attributes have simple string values, methods to directly access an
1461 * attribute value can safely be used as a convenience.
1462 */
1463 class Element : virtual public Node
1464 {
1465 public:
1468 /**
1469 *
1470 */
1471 virtual DOMString getTagName() = 0;
1473 /**
1474 *
1475 */
1476 virtual DOMString getAttribute(const DOMString& name) = 0;
1478 /**
1479 *
1480 */
1481 virtual void setAttribute(const DOMString& name,
1482 const DOMString& value)
1483 throw(DOMException) = 0;
1485 /**
1486 *
1487 */
1488 virtual void removeAttribute(const DOMString& name)
1489 throw(DOMException) = 0;
1491 /**
1492 *
1493 */
1494 virtual AttrPtr getAttributeNode(const DOMString& name) = 0;
1496 /**
1497 *
1498 */
1499 virtual AttrPtr setAttributeNode(AttrPtr newAttr)
1500 throw(DOMException) = 0;
1502 /**
1503 *
1504 */
1505 virtual AttrPtr removeAttributeNode(AttrPtr oldAttr)
1506 throw(DOMException) = 0;
1508 /**
1509 *
1510 */
1511 virtual NodeList getElementsByTagName(const DOMString& name) = 0;
1513 /**
1514 *
1515 */
1516 virtual DOMString getAttributeNS(const DOMString& namespaceURI,
1517 const DOMString& localName) = 0;
1519 /**
1520 *
1521 */
1522 virtual void setAttributeNS(const DOMString& namespaceURI,
1523 const DOMString& qualifiedName,
1524 const DOMString& value)
1525 throw(DOMException) = 0;
1527 /**
1528 *
1529 */
1530 virtual void removeAttributeNS(const DOMString& namespaceURI,
1531 const DOMString& localName)
1532 throw(DOMException) = 0;
1534 /**
1535 *
1536 */
1537 virtual AttrPtr getAttributeNodeNS(const DOMString& namespaceURI,
1538 const DOMString& localName) = 0;
1540 /**
1541 *
1542 */
1543 virtual AttrPtr setAttributeNodeNS(AttrPtr newAttr)
1544 throw(DOMException) = 0;
1546 /**
1547 *
1548 */
1549 virtual NodeList getElementsByTagNameNS(const DOMString& namespaceURI,
1550 const DOMString& localName) = 0;
1552 /**
1553 *
1554 */
1555 virtual bool hasAttribute(const DOMString& name) = 0;
1557 /**
1558 *
1559 */
1560 virtual bool hasAttributeNS(const DOMString& namespaceURI,
1561 const DOMString& localName) = 0;
1563 /**
1564 *
1565 */
1566 virtual TypeInfo &getSchemaTypeInfo() = 0;
1569 /**
1570 *
1571 */
1572 virtual void setIdAttribute(const DOMString &name,
1573 bool isId) throw (DOMException) = 0;
1575 /**
1576 *
1577 */
1578 virtual void setIdAttributeNS(const DOMString &namespaceURI,
1579 const DOMString &localName,
1580 bool isId) throw (DOMException) = 0;
1582 /**
1583 *
1584 */
1585 virtual void setIdAttributeNode(const AttrPtr idAttr,
1586 bool isId) throw (DOMException) = 0;
1588 //##################
1589 //# Non-API methods
1590 //##################
1592 /**
1593 *
1594 */
1595 virtual ~Element() {}
1597 };
1603 /*#########################################################################
1604 ## Text
1605 #########################################################################*/
1607 /**
1608 * The Text interface inherits from CharacterData and represents the textual
1609 * content (termed character data in XML) of an Element or Attr. If there is no
1610 * markup inside an element's content, the text is contained in a single object
1611 * implementing the Text interface that is the only child of the element. If
1612 * there is markup, it is parsed into the information items (elements, comments,
1613 * etc.) and Text nodes that form the list of children of the element.
1614 */
1615 class Text : virtual public CharacterData
1616 {
1617 public:
1619 /**
1620 *
1621 */
1622 virtual TextPtr splitText(unsigned long offset)
1623 throw(DOMException) = 0;
1625 /**
1626 *
1627 */
1628 virtual bool getIsElementContentWhitespace()= 0;
1630 /**
1631 *
1632 */
1633 virtual DOMString getWholeText() = 0;
1636 /**
1637 *
1638 */
1639 virtual TextPtr replaceWholeText(const DOMString &content)
1640 throw(DOMException) = 0;
1642 //##################
1643 //# Non-API methods
1644 //##################
1647 /**
1648 *
1649 */
1650 virtual ~Text() {}
1652 };
1656 /*#########################################################################
1657 ## Comment
1658 #########################################################################*/
1660 /**
1661 * This interface inherits from CharacterData and represents the content of a
1662 * comment, i.e., all the characters between the starting '<!--' and ending '-->'.
1663 * Note that this is the definition of a comment in XML, and, in practice,
1664 * HTML, although some HTML tools may implement the full SGML comment structure.
1665 */
1666 class Comment : virtual public CharacterData
1667 {
1668 public:
1670 //##################
1671 //# Non-API methods
1672 //##################
1675 /**
1676 *
1677 */
1678 virtual ~Comment() {}
1681 };
1685 /*#########################################################################
1686 ## TypeInfo
1687 #########################################################################*/
1689 /**
1690 * The TypeInfo interface represents a type referenced from Element or Attr nodes,
1691 * specified in the schemas associated with the document. The type is a pair of
1692 * a namespace URI and name properties, and depends on the document's schema.
1693 */
1694 class TypeInfo
1695 {
1696 public:
1698 /**
1699 *
1700 */
1701 virtual DOMString getTypeName()
1702 { return typeName; }
1704 /**
1705 *
1706 */
1707 virtual DOMString getTypeNamespace()
1708 { return typeNameSpace; }
1710 /**
1711 *
1712 */
1713 typedef enum
1714 {
1715 DERIVATION_RESTRICTION = 0x00000001,
1716 DERIVATION_EXTENSION = 0x00000002,
1717 DERIVATION_UNION = 0x00000004,
1718 DERIVATION_LIST = 0x00000008
1719 } DerivationMethod;
1722 /**
1723 *
1724 */
1725 virtual bool isDerivedFrom(const DOMString &typeNamespaceArg,
1726 const DOMString &typeNameArg,
1727 DerivationMethod derivationMethod)
1728 { (void)typeNamespaceArg; (void)typeNameArg; (void)derivationMethod; return false; }
1730 //##################
1731 //# Non-API methods
1732 //##################
1735 /**
1736 *
1737 */
1738 TypeInfo()
1739 {}
1741 /**
1742 *
1743 */
1744 TypeInfo(const TypeInfo &other)
1745 { assign(other); }
1747 /**
1748 *
1749 */
1750 TypeInfo &operator=(const TypeInfo &other)
1751 { assign(other); return *this; }
1753 /**
1754 *
1755 */
1756 virtual ~TypeInfo() {}
1758 private:
1760 void assign(const TypeInfo &other)
1761 {
1762 typeName = other.typeName;
1763 typeNameSpace = other.typeNameSpace;
1764 }
1766 DOMString typeName;
1767 DOMString typeNameSpace;
1768 };
1773 /*#########################################################################
1774 ## UserDataHandler
1775 #########################################################################*/
1777 /**
1778 * When associating an object to a key on a node using Node.setUserData() the
1779 * application can provide a handler that gets called when the node the object is
1780 * associated to is being cloned, imported, or renamed. This can be used by the
1781 * application to implement various behaviors regarding the data it associates to
1782 * the DOM nodes. This interface defines that handler.
1783 */
1784 class UserDataHandler
1785 {
1786 public:
1788 typedef enum
1789 {
1790 NODE_CLONED = 1,
1791 NODE_IMPORTED = 2,
1792 NODE_DELETED = 3,
1793 NODE_RENAMED = 4,
1794 NODE_ADOPTED = 5
1795 } OperationType;
1798 /**
1799 *
1800 */
1801 virtual void handle(unsigned short operation,
1802 const DOMString &key,
1803 const DOMUserData *data,
1804 const NodePtr src,
1805 const NodePtr dst) =0;
1807 //##################
1808 //# Non-API methods
1809 //##################
1812 /**
1813 *
1814 */
1815 virtual ~UserDataHandler() {}
1817 };
1820 /*#########################################################################
1821 ## DOMError
1822 #########################################################################*/
1824 /**
1825 * DOMError is an interface that describes an error.
1826 */
1827 class DOMError
1828 {
1829 public:
1831 typedef enum
1832 {
1833 SEVERITY_WARNING = 1,
1834 SEVERITY_ERROR = 2,
1835 SEVERITY_FATAL_ERROR = 3
1836 } ErrorSeverity;
1839 /**
1840 *
1841 */
1842 virtual unsigned short getSeverity() =0;
1844 /**
1845 *
1846 */
1847 virtual DOMString getMessage() =0;
1849 /**
1850 *
1851 */
1852 virtual DOMString getType() =0;
1854 /**
1855 *
1856 */
1857 virtual DOMObject *getRelatedException() =0;
1859 /**
1860 *
1861 */
1862 virtual DOMObject *getRelatedData() =0;
1864 /**
1865 *
1866 */
1867 virtual DOMLocator *getLocation() =0;
1870 //##################
1871 //# Non-API methods
1872 //##################
1875 /**
1876 *
1877 */
1878 virtual ~DOMError() {}
1880 };
1883 /*#########################################################################
1884 ## DOMErrorHandler
1885 #########################################################################*/
1887 /**
1888 * DOMErrorHandler is a callback interface that the DOM implementation can call
1889 * when reporting errors that happens while processing XML data, or when doing
1890 * some other processing (e.g. validating a document). A DOMErrorHandler object
1891 * can be attached to a Document using the "error-handler" on the
1892 * DOMConfiguration interface. If more than one error needs to be reported during
1893 * an operation, the sequence and numbers of the errors passed to the error
1894 * handler are implementation dependent.
1895 */
1896 class DOMErrorHandler
1897 {
1898 public:
1899 /**
1900 *
1901 */
1902 virtual bool handleError(const DOMError *error) =0;
1904 //##################
1905 //# Non-API methods
1906 //##################
1909 /**
1910 *
1911 */
1912 virtual ~DOMErrorHandler() {}
1914 };
1918 /*#########################################################################
1919 ## DOMLocator
1920 #########################################################################*/
1922 /**
1923 * DOMLocator is an interface that describes a location (e.g. where an error occurred).
1924 */
1925 class DOMLocator
1926 {
1927 public:
1929 /**
1930 *
1931 */
1932 virtual long getLineNumber() =0;
1934 /**
1935 *
1936 */
1937 virtual long getColumnNumber() =0;
1939 /**
1940 *
1941 */
1942 virtual long getByteOffset() =0;
1944 /**
1945 *
1946 */
1947 virtual long getUtf16Offset() =0;
1950 /**
1951 *
1952 */
1953 virtual NodePtr getRelatedNode() =0;
1956 /**
1957 *
1958 */
1959 virtual DOMString getUri() =0;
1961 //##################
1962 //# Non-API methods
1963 //##################
1965 /**
1966 *
1967 */
1968 virtual ~DOMLocator() {}
1969 };
1972 /*#########################################################################
1973 ## DOMConfiguration
1974 #########################################################################*/
1976 /**
1977 * The DOMConfiguration interface represents the configuration of a document and
1978 * maintains a table of recognized parameters. Using the configuration, it is
1979 * possible to change Document.normalizeDocument() behavior, such as replacing
1980 * the CDATASection nodes with Text nodes or specifying the type of the schema
1981 * that must be used when the validation of the Document is requested.
1982 * DOMConfiguration objects are also used in [DOM Level 3 Load and Save] in the
1983 * DOMParser and DOMSerializer interfaces.
1984 */
1985 class DOMConfiguration
1986 {
1987 public:
1989 /**
1990 *
1991 */
1992 virtual void setParameter(const DOMString &name,
1993 const DOMUserData *value)
1994 throw (DOMException) =0;
1996 /**
1997 *
1998 */
1999 virtual DOMUserData *getParameter(const DOMString &name)
2000 throw (DOMException) =0;
2002 /**
2003 *
2004 */
2005 virtual bool canSetParameter(const DOMString &name,
2006 const DOMUserData *data) =0;
2008 /**
2009 *
2010 */
2011 virtual DOMStringList *getParameterNames() =0;
2013 //##################
2014 //# Non-API methods
2015 //##################
2018 /**
2019 *
2020 */
2021 virtual ~DOMConfiguration() {}
2023 };
2030 /*#########################################################################
2031 ## CDATASection
2032 #########################################################################*/
2034 /**
2035 * CDATA sections are used to escape blocks of text containing characters that
2036 * would otherwise be regarded as markup. The only delimiter that is recognized
2037 * in a CDATA section is the "]]>" string that ends the CDATA section. CDATA
2038 * sections cannot be nested. Their primary purpose is for including material
2039 * such as XML fragments, without needing to escape all the delimiters.
2040 */
2041 class CDATASection : virtual public Text
2042 {
2043 public:
2045 //##################
2046 //# Non-API methods
2047 //##################
2050 /**
2051 *
2052 */
2053 virtual ~CDATASection() {}
2055 };
2060 /*#########################################################################
2061 ## DocumentType
2062 #########################################################################*/
2064 /**
2065 * Each Document has a doctype attribute whose value is either null or a
2066 * DocumentType object. The DocumentType interface in the DOM Core provides an
2067 * interface to the list of entities that are defined for the document, and
2068 * little else because the effect of namespaces and the various XML schema
2069 * efforts on DTD representation are not clearly understood as of this writing.
2070 */
2071 class DocumentType : virtual public Node
2072 {
2073 public:
2075 /**
2076 *
2077 */
2078 virtual DOMString getName() = 0;
2080 /**
2081 *
2082 */
2083 virtual NamedNodeMap getEntities() = 0;
2085 /**
2086 *
2087 */
2088 virtual NamedNodeMap getNotations() = 0;
2090 /**
2091 *
2092 */
2093 virtual DOMString getPublicId() = 0;
2095 /**
2096 *
2097 */
2098 virtual DOMString getSystemId() = 0;
2100 /**
2101 *
2102 */
2103 virtual DOMString getInternalSubset() = 0;
2105 //##################
2106 //# Non-API methods
2107 //##################
2109 /**
2110 *
2111 */
2112 virtual ~DocumentType() {}
2114 };
2120 /*#########################################################################
2121 ## Notation
2122 #########################################################################*/
2124 /**
2125 * This interface represents a notation declared in the DTD. A notation either
2126 * declares, by name, the format of an unparsed entity (see section 4.7 of the
2127 * XML 1.0 specification [XML 1.0]), or is used for formal declaration of
2128 * processing instruction targets (see section 2.6 of the XML 1.0 specification
2129 * [XML 1.0]). The nodeName attribute inherited from Node is set to the declared
2130 * name of the notation.
2131 */
2132 class Notation : virtual public Node
2133 {
2134 public:
2136 /**
2137 *
2138 */
2139 virtual DOMString getPublicId() = 0;
2141 /**
2142 *
2143 */
2144 virtual DOMString getSystemId() = 0;
2146 //##################
2147 //# Non-API methods
2148 //##################
2151 /**
2152 *
2153 */
2154 virtual ~Notation() {}
2155 };
2162 /*#########################################################################
2163 ## Entity
2164 #########################################################################*/
2166 /**
2167 * This interface represents a known entity, either parsed or unparsed, in an XML
2168 * document. Note that this models the entity itself not the entity declaration.
2169 */
2170 class Entity : virtual public Node
2171 {
2172 public:
2174 /**
2175 *
2176 */
2177 virtual DOMString getPublicId() = 0;
2179 /**
2180 *
2181 */
2182 virtual DOMString getSystemId() = 0;
2184 /**
2185 *
2186 */
2187 virtual DOMString getNotationName() = 0;
2189 /**
2190 *
2191 */
2192 virtual DOMString getInputEncoding() = 0;
2194 /**
2195 *
2196 */
2197 virtual DOMString getXmlEncoding() = 0;
2199 /**
2200 *
2201 */
2202 virtual DOMString getXmlVersion() = 0;
2204 //##################
2205 //# Non-API methods
2206 //##################
2209 /**
2210 *
2211 */
2212 virtual ~Entity() {}
2213 };
2219 /*#########################################################################
2220 ## EntityReference
2221 #########################################################################*/
2223 /**
2224 * EntityReference nodes may be used to represent an entity reference in the tree.
2225 */
2226 class EntityReference : virtual public Node
2227 {
2228 public:
2231 //##################
2232 //# Non-API methods
2233 //##################
2235 /**
2236 *
2237 */
2238 virtual ~EntityReference() {}
2239 };
2245 /*#########################################################################
2246 ## ProcessingInstruction
2247 #########################################################################*/
2249 /**
2250 * The ProcessingInstruction interface represents a "processing instruction",
2251 * used in XML as a way to keep processor-specific information in the text of the
2252 * document.
2253 */
2254 class ProcessingInstruction : virtual public Node
2255 {
2256 public:
2258 /**
2259 *
2260 */
2261 virtual DOMString getTarget() = 0;
2263 /**
2264 *
2265 */
2266 virtual DOMString getData() = 0;
2268 /**
2269 *
2270 */
2271 virtual void setData(const DOMString& val) throw(DOMException) = 0;
2273 //##################
2274 //# Non-API methods
2275 //##################
2278 /**
2279 *
2280 */
2281 virtual ~ProcessingInstruction() {}
2283 };
2289 /*#########################################################################
2290 ## DocumentFragment
2291 #########################################################################*/
2293 /**
2294 * DocumentFragment is a "lightweight" or "minimal" Document object. It is very
2295 * common to want to be able to extract a portion of a document's tree or to
2296 * create a new fragment of a document. Imagine implementing a user command like
2297 * cut or rearranging a document by moving fragments around. It is desirable to
2298 * have an object which can hold such fragments and it is quite natural to use a
2299 * Node for this purpose. While it is true that a Document object could fulfill
2300 * this role, a Document object can potentially be a heavyweight object,
2301 * depending on the underlying implementation. What is really needed for this is
2302 * a very lightweight object. DocumentFragment is such an object.
2303 */
2304 class DocumentFragment : virtual public Node
2305 {
2306 public:
2308 //##################
2309 //# Non-API methods
2310 //##################
2313 /**
2314 *
2315 */
2316 virtual ~DocumentFragment() {}
2317 };
2324 /*#########################################################################
2325 ## Document
2326 #########################################################################*/
2328 /**
2329 * From the spec:
2330 *
2331 * The Document interface represents the entire HTML or XML document.
2332 * Conceptually, it is the root of the document tree, and provides the primary
2333 * access to the document's data.
2334 *
2335 * Since elements, text nodes, comments, processing instructions, etc. cannot
2336 * exist outside the context of a Document, the Document interface also contains
2337 * the factory methods needed to create these objects. The Node objects created
2338 * have a ownerDocument attribute which associates them with the Document within
2339 * whose context they were created.
2340 *
2341 */
2342 class Document : virtual public Node
2343 {
2344 public:
2346 /**
2347 * The Document Type Declaration (see DocumentType) associated with this document.
2348 */
2349 virtual DocumentTypePtr getDoctype() = 0;
2351 /**
2352 * The DOMImplementation object that handles this document. A DOM application
2353 * may use objects from multiple implementations.
2354 */
2355 virtual DOMImplementation *getImplementation() = 0;
2357 /**
2358 * This is a convenience attribute that allows direct access to the child
2359 * node that is the document element of the document.
2360 */
2361 virtual ElementPtr getDocumentElement() = 0;
2363 /**
2364 * Creates an element of the type specified.
2365 */
2366 virtual ElementPtr createElement(const DOMString& tagName)
2367 throw(DOMException) = 0;
2369 /**
2370 *
2371 */
2372 virtual DocumentFragmentPtr createDocumentFragment() = 0;
2374 /**
2375 * Creates an TextNode with the text data specified.
2376 */
2377 virtual TextPtr createTextNode(const DOMString& data) = 0;
2379 /**
2380 *
2381 */
2382 virtual CommentPtr createComment(const DOMString& data) = 0;
2384 /**
2385 *
2386 */
2387 virtual CDATASectionPtr createCDATASection(const DOMString& data)
2388 throw(DOMException) = 0;
2390 /**
2391 *
2392 */
2393 virtual ProcessingInstructionPtr
2394 createProcessingInstruction(const DOMString& target,
2395 const DOMString& data)
2396 throw(DOMException) = 0;
2398 /**
2399 *
2400 */
2401 virtual AttrPtr createAttribute(const DOMString& name)
2402 throw(DOMException) = 0;
2404 /**
2405 *
2406 */
2407 virtual EntityReferencePtr createEntityReference(const DOMString& name)
2408 throw(DOMException) = 0;
2410 /**
2411 *
2412 */
2413 virtual NodeList getElementsByTagName(const DOMString& tagname) = 0;
2416 /**
2417 *
2418 */
2419 virtual NodePtr importNode(const NodePtr importedNode,
2420 bool deep)
2421 throw(DOMException) = 0;
2423 /**
2424 *
2425 */
2426 virtual ElementPtr createElementNS(const DOMString& namespaceURI,
2427 const DOMString& qualifiedName)
2428 throw(DOMException) = 0;
2430 /**
2431 *
2432 */
2433 virtual AttrPtr createAttributeNS(const DOMString& namespaceURI,
2434 const DOMString& qualifiedName)
2435 throw(DOMException) = 0;
2437 /**
2438 *
2439 */
2440 virtual NodeList getElementsByTagNameNS(const DOMString& namespaceURI,
2441 const DOMString& localName) = 0;
2443 /**
2444 *
2445 */
2446 virtual ElementPtr getElementById(const DOMString& elementId) = 0;
2449 /**
2450 *
2451 */
2452 virtual DOMString getInputEncoding() = 0;
2455 /**
2456 *
2457 */
2458 virtual DOMString getXmlEncoding() = 0;
2460 /**
2461 *
2462 */
2463 virtual bool getXmlStandalone() = 0;
2465 /**
2466 *
2467 */
2468 virtual void setXmlStandalone(bool val) throw (DOMException) = 0;
2470 /**
2471 * Gets the version (1.0, 1.1, etc) of this document.
2472 */
2473 virtual DOMString getXmlVersion() = 0;
2475 /**
2476 * Sets the XML version of this document.
2477 */
2478 virtual void setXmlVersion(const DOMString &version)
2479 throw (DOMException) = 0;
2481 /**
2482 * An attribute specifying whether error checking is enforced or not. When set to
2483 * false, the implementation is free to not test every possible error case
2484 * normally defined on DOM operations, and not raise any DOMException on DOM
2485 * operations or report errors while using Document.normalizeDocument(). In case
2486 * of error, the behavior is undefined. This attribute is true by default.
2487 */
2488 virtual bool getStrictErrorChecking() = 0;
2490 /**
2491 * Sets the value described above.
2492 */
2493 virtual void setStrictErrorChecking(bool val) = 0;
2496 /**
2497 * Gets the document URI (the base location) of this Document.
2498 */
2499 virtual DOMString getDocumentURI() = 0;
2501 /**
2502 * Sets the document URI (the base location) of this Document to the
2503 * argument uri.
2504 */
2505 virtual void setDocumentURI(const DOMString &uri) = 0;
2507 /**
2508 * Attempts to adopt a node from another document to this document. If supported,
2509 * it changes the ownerDocument of the source node, its children, as well as the
2510 * attached attribute nodes if there are any. If the source node has a parent it
2511 * is first removed from the child list of its parent. This effectively allows
2512 * moving a subtree from one document to another (unlike importNode() which
2513 * create a copy of the source node instead of moving it). When it fails,
2514 * applications should use Document.importNode() instead. Note that if the
2515 * adopted node is already part of this document (i.e. the source and target
2516 * document are the same), this method still has the effect of removing the
2517 * source node from the child list of its parent, if any.
2518 */
2519 virtual NodePtr adoptNode(const NodePtr source) throw (DOMException) = 0;
2521 /**
2522 * Get the configuration item associated with this Document
2523 */
2524 virtual DOMConfiguration *getDomConfig() = 0;
2526 /**
2527 * This method acts as if the document was going through a save and load cycle,
2528 * putting the document in a "normal" form. As a consequence, this method updates
2529 * the replacement tree of EntityReference nodes and normalizes Text nodes, as
2530 * defined in the method Node.normalize(). Otherwise, the actual result depends
2531 * on the features being set on the Document.domConfig object and governing what
2532 * operations actually take place. Noticeably this method could also make the
2533 * document namespace well-formed according to the algorithm described in
2534 * Namespace Normalization, check the character normalization, remove the
2535 * CDATASection nodes, etc. See DOMConfiguration for details.
2536 */
2537 virtual void normalizeDocument() = 0;
2539 /**
2540 *
2541 * Rename an existing node of type ELEMENT_NODE or ATTRIBUTE_NODE. When possible
2542 * this simply changes the name of the given node, otherwise this creates a new
2543 * node with the specified name and replaces the existing node with the new node
2544 * as described below. If simply changing the name of the given node is not
2545 * possible, the following operations are performed: a new node is created, any
2546 * registered event listener is registered on the new node, any user data
2547 * attached to the old node is removed from that node, the old node is removed
2548 * from its parent if it has one, the children are moved to the new node, if the
2549 * renamed node is an Element its attributes are moved to the new node, the new
2550 * node is inserted at the position the old node used to have in its parent's
2551 * child nodes list if it has one, the user data that was attached to the old
2552 * node is attached to the new node. When the node being renamed is an Element
2553 * only the specified attributes are moved, default attributes originated from
2554 * the DTD are updated according to the new element name. In addition, the
2555 * implementation may update default attributes from other schemas. Applications
2556 * should use Document.normalizeDocument() to guarantee these attributes are
2557 * up-to-date. When the node being renamed is an Attr that is attached to an
2558 * Element, the node is first removed from the Element attributes map. Then, once
2559 * renamed, either by modifying the existing node or creating a new one as
2560 * described above, it is put back.
2561 *
2562 * In addition,
2563 * a user data event NODE_RENAMED is fired,
2564 * when the implementation supports the feature "MutationNameEvents",
2565 * each mutation operation involved in this method fires the appropriate
2566 * event, and in the end the event {http://www.w3.org/2001/xml-events,
2567 * DOMElementNameChanged} or {http://www.w3.org/2001/xml-events,
2568 * DOMAttributeNameChanged} is fired.
2569 *
2570 */
2571 virtual NodePtr renameNode(const NodePtr n,
2572 const DOMString &namespaceURI,
2573 const DOMString &qualifiedName)
2574 throw (DOMException) = 0;
2577 //##################
2578 //# Non-API methods
2579 //##################
2581 /**
2582 *
2583 */
2584 virtual ~Document() {}
2586 };
2595 } //namespace dom
2596 } //namespace w3c
2597 } //namespace org
2600 #endif // __DOM_H__
2603 /*#########################################################################
2604 ## E N D O F F I L E
2605 #########################################################################*/