1 | // |
2 | // Attr.cpp |
3 | // |
4 | // Library: XML |
5 | // Package: DOM |
6 | // Module: DOM |
7 | // |
8 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | |
15 | #include "Poco/DOM/Attr.h" |
16 | #include "Poco/DOM/Document.h" |
17 | #include "Poco/XML/NamePool.h" |
18 | |
19 | |
20 | namespace Poco { |
21 | namespace XML { |
22 | |
23 | |
24 | Attr::Attr(Document* pOwnerDocument, Element* /*pOwnerElement*/, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& value, bool specified): |
25 | AbstractNode(pOwnerDocument), |
26 | _name(pOwnerDocument->namePool().insert(qname, namespaceURI, localName)), |
27 | _value(value), |
28 | _specified(specified) |
29 | { |
30 | } |
31 | |
32 | |
33 | Attr::Attr(Document* pOwnerDocument, const Attr& attr): |
34 | AbstractNode(pOwnerDocument, attr), |
35 | _name(pOwnerDocument->namePool().insert(attr._name)), |
36 | _value(attr._value), |
37 | _specified(attr._specified) |
38 | { |
39 | } |
40 | |
41 | |
42 | Attr::~Attr() |
43 | { |
44 | } |
45 | |
46 | |
47 | void Attr::setValue(const XMLString& value) |
48 | { |
49 | XMLString oldValue = _value; |
50 | _value = value; |
51 | _specified = true; |
52 | if (_pParent && !_pOwner->eventsSuspended()) |
53 | _pParent->dispatchAttrModified(this, MutationEvent::MODIFICATION, oldValue, value); |
54 | } |
55 | |
56 | |
57 | Node* Attr::parentNode() const |
58 | { |
59 | return 0; |
60 | } |
61 | |
62 | |
63 | Node* Attr::previousSibling() const |
64 | { |
65 | if (_pParent) |
66 | { |
67 | Attr* pSibling = static_cast<Element*>(_pParent)->_pFirstAttr; |
68 | while (pSibling) |
69 | { |
70 | if (pSibling->_pNext == const_cast<Attr*>(this)) return pSibling; |
71 | pSibling = static_cast<Attr*>(pSibling->_pNext); |
72 | } |
73 | return pSibling; |
74 | } |
75 | return 0; |
76 | } |
77 | |
78 | |
79 | const XMLString& Attr::nodeName() const |
80 | { |
81 | return _name.qname(); |
82 | } |
83 | |
84 | |
85 | const XMLString& Attr::getNodeValue() const |
86 | { |
87 | return _value; |
88 | } |
89 | |
90 | |
91 | void Attr::setNodeValue(const XMLString& value) |
92 | { |
93 | setValue(value); |
94 | } |
95 | |
96 | |
97 | unsigned short Attr::nodeType() const |
98 | { |
99 | return ATTRIBUTE_NODE; |
100 | } |
101 | |
102 | |
103 | const XMLString& Attr::namespaceURI() const |
104 | { |
105 | return _name.namespaceURI(); |
106 | } |
107 | |
108 | |
109 | XMLString Attr::prefix() const |
110 | { |
111 | return _name.prefix(); |
112 | } |
113 | |
114 | |
115 | const XMLString& Attr::localName() const |
116 | { |
117 | return _name.localName(); |
118 | } |
119 | |
120 | |
121 | XMLString Attr::innerText() const |
122 | { |
123 | return nodeValue(); |
124 | } |
125 | |
126 | |
127 | Node* Attr::copyNode(bool /*deep*/, Document* pOwnerDocument) const |
128 | { |
129 | return new Attr(pOwnerDocument, *this); |
130 | } |
131 | |
132 | |
133 | } } // namespace Poco::XML |
134 | |