| 1 | // |
| 2 | // AbstractNode.h |
| 3 | // |
| 4 | // Library: XML |
| 5 | // Package: DOM |
| 6 | // Module: DOM |
| 7 | // |
| 8 | // Definition of the AbstractNode class. |
| 9 | // |
| 10 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
| 11 | // and Contributors. |
| 12 | // |
| 13 | // SPDX-License-Identifier: BSL-1.0 |
| 14 | // |
| 15 | |
| 16 | |
| 17 | #ifndef DOM_AbstractNode_INCLUDED |
| 18 | #define DOM_AbstractNode_INCLUDED |
| 19 | |
| 20 | |
| 21 | #include "Poco/XML/XML.h" |
| 22 | #include "Poco/DOM/Node.h" |
| 23 | #include "Poco/DOM/MutationEvent.h" |
| 24 | #include "Poco/XML/XMLString.h" |
| 25 | |
| 26 | |
| 27 | namespace Poco { |
| 28 | namespace XML { |
| 29 | |
| 30 | |
| 31 | class AbstractContainerNode; |
| 32 | class Attr; |
| 33 | class EventDispatcher; |
| 34 | |
| 35 | |
| 36 | class XML_API AbstractNode: public Node |
| 37 | /// AbstractNode provides a basic implementation |
| 38 | /// of the Node interface for all types of nodes |
| 39 | /// that do not contain other nodes. |
| 40 | { |
| 41 | public: |
| 42 | // Node |
| 43 | const XMLString& nodeName() const; |
| 44 | const XMLString& getNodeValue() const; |
| 45 | void setNodeValue(const XMLString& value); |
| 46 | Node* parentNode() const; |
| 47 | NodeList* childNodes() const; |
| 48 | Node* firstChild() const; |
| 49 | Node* lastChild() const; |
| 50 | Node* previousSibling() const; |
| 51 | Node* nextSibling() const; |
| 52 | NamedNodeMap* attributes() const; |
| 53 | Document* ownerDocument() const; |
| 54 | Node* insertBefore(Node* newChild, Node* refChild); |
| 55 | Node* replaceChild(Node* newChild, Node* oldChild); |
| 56 | Node* removeChild(Node* oldChild); |
| 57 | Node* appendChild(Node* newChild); |
| 58 | bool hasChildNodes() const; |
| 59 | Node* cloneNode(bool deep) const; |
| 60 | void normalize(); |
| 61 | bool isSupported(const XMLString& feature, const XMLString& version) const; |
| 62 | const XMLString& namespaceURI() const; |
| 63 | XMLString prefix() const; |
| 64 | const XMLString& localName() const; |
| 65 | bool hasAttributes() const; |
| 66 | |
| 67 | // EventTarget |
| 68 | void addEventListener(const XMLString& type, EventListener* listener, bool useCapture); |
| 69 | void removeEventListener(const XMLString& type, EventListener* listener, bool useCapture); |
| 70 | bool dispatchEvent(Event* evt); |
| 71 | |
| 72 | // Extensions |
| 73 | XMLString innerText() const; |
| 74 | Node* getNodeByPath(const XMLString& path) const; |
| 75 | Node* getNodeByPathNS(const XMLString& path, const NSMap& nsMap) const; |
| 76 | |
| 77 | virtual void autoRelease(); |
| 78 | |
| 79 | protected: |
| 80 | AbstractNode(Document* pOwnerDocument); |
| 81 | AbstractNode(Document* pOwnerDocument, const AbstractNode& node); |
| 82 | ~AbstractNode(); |
| 83 | |
| 84 | virtual Node* copyNode(bool deep, Document* pOwnerDocument) const = 0; |
| 85 | |
| 86 | virtual bool events() const; |
| 87 | virtual bool eventsSuspended() const; |
| 88 | void captureEvent(Event* evt); |
| 89 | void bubbleEvent(Event* evt); |
| 90 | void dispatchSubtreeModified(); |
| 91 | void dispatchNodeInserted(); |
| 92 | void dispatchNodeRemoved(); |
| 93 | virtual void dispatchNodeRemovedFromDocument(); |
| 94 | virtual void dispatchNodeInsertedIntoDocument(); |
| 95 | void dispatchAttrModified(Attr* pAttr, MutationEvent::AttrChangeType changeType, const XMLString& prevValue, const XMLString& newValue); |
| 96 | void dispatchCharacterDataModified(const XMLString& prevValue, const XMLString& newValue); |
| 97 | void setOwnerDocument(Document* pOwnerDocument); |
| 98 | |
| 99 | static const XMLString EMPTY_STRING; |
| 100 | |
| 101 | private: |
| 102 | AbstractNode(); |
| 103 | |
| 104 | AbstractContainerNode* _pParent; |
| 105 | AbstractNode* _pNext; |
| 106 | Document* _pOwner; |
| 107 | EventDispatcher* _pEventDispatcher; |
| 108 | |
| 109 | static const XMLString NODE_NAME; |
| 110 | |
| 111 | friend class AbstractContainerNode; |
| 112 | friend class Document; |
| 113 | friend class DocumentFragment; |
| 114 | friend class Element; |
| 115 | friend class Attr; |
| 116 | friend class CharacterData; |
| 117 | friend class DOMBuilder; |
| 118 | friend class NodeAppender; |
| 119 | }; |
| 120 | |
| 121 | |
| 122 | } } // namespace Poco::XML |
| 123 | |
| 124 | |
| 125 | #endif // DOM_AbstractNode_INCLUDED |
| 126 | |