1 | // |
---|
2 | // AttributesImpl.cpp |
---|
3 | // |
---|
4 | // $Id: //poco/1.3/XML/src/AttributesImpl.cpp#4 $ |
---|
5 | // |
---|
6 | // Library: XML |
---|
7 | // Package: SAX |
---|
8 | // Module: SAX |
---|
9 | // |
---|
10 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
---|
11 | // and Contributors. |
---|
12 | // |
---|
13 | // Permission is hereby granted, free of charge, to any person or organization |
---|
14 | // obtaining a copy of the software and accompanying documentation covered by |
---|
15 | // this license (the "Software") to use, reproduce, display, distribute, |
---|
16 | // execute, and transmit the Software, and to prepare derivative works of the |
---|
17 | // Software, and to permit third-parties to whom the Software is furnished to |
---|
18 | // do so, all subject to the following: |
---|
19 | // |
---|
20 | // The copyright notices in the Software and this entire statement, including |
---|
21 | // the above license grant, this restriction and the following disclaimer, |
---|
22 | // must be included in all copies of the Software, in whole or in part, and |
---|
23 | // all derivative works of the Software, unless such copies or derivative |
---|
24 | // works are solely in the form of machine-executable object code generated by |
---|
25 | // a source language processor. |
---|
26 | // |
---|
27 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
28 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
29 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
---|
30 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
---|
31 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
---|
32 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
33 | // DEALINGS IN THE SOFTWARE. |
---|
34 | // |
---|
35 | |
---|
36 | |
---|
37 | #include <Poco/SAX/AttributesImpl.h> |
---|
38 | |
---|
39 | |
---|
40 | namespace Poco { |
---|
41 | namespace XML { |
---|
42 | |
---|
43 | |
---|
44 | AttributesImpl::AttributesImpl() |
---|
45 | { |
---|
46 | _empty.specified = false; |
---|
47 | _empty.type = XML_LIT("CDATA"); |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | AttributesImpl::AttributesImpl(const Attributes& attributes) |
---|
52 | { |
---|
53 | _empty.specified = false; |
---|
54 | _empty.type = XML_LIT("CDATA"); |
---|
55 | setAttributes(attributes); |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | AttributesImpl::AttributesImpl(const AttributesImpl& attributes): |
---|
60 | _attributes(attributes._attributes), |
---|
61 | _empty(attributes._empty) |
---|
62 | { |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | AttributesImpl::~AttributesImpl() |
---|
67 | { |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | AttributesImpl& AttributesImpl::operator = (const AttributesImpl& attributes) |
---|
72 | { |
---|
73 | if (&attributes != this) |
---|
74 | { |
---|
75 | _attributes = attributes._attributes; |
---|
76 | } |
---|
77 | return *this; |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | int AttributesImpl::getIndex(const XMLString& qname) const |
---|
82 | { |
---|
83 | int i = 0; |
---|
84 | AttributeVec::const_iterator it; |
---|
85 | for (it = _attributes.begin(); it != _attributes.end(); ++it) |
---|
86 | { |
---|
87 | if (it->qname == qname) return i; |
---|
88 | ++i; |
---|
89 | } |
---|
90 | return -1; |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | int AttributesImpl::getIndex(const XMLString& namespaceURI, const XMLString& localName) const |
---|
95 | { |
---|
96 | int i = 0; |
---|
97 | AttributeVec::const_iterator it; |
---|
98 | for (it = _attributes.begin(); it != _attributes.end(); ++it) |
---|
99 | { |
---|
100 | if (it->namespaceURI == namespaceURI && it->localName == localName) return i; |
---|
101 | ++i; |
---|
102 | } |
---|
103 | return -1; |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | void AttributesImpl::setValue(int i, const XMLString& value) |
---|
108 | { |
---|
109 | poco_assert (0 <= i && i < static_cast<int>(_attributes.size())); |
---|
110 | _attributes[i].value = value; |
---|
111 | _attributes[i].specified = true; |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | void AttributesImpl::setValue(const XMLString& qname, const XMLString& value) |
---|
116 | { |
---|
117 | Attribute* pAttr = find(qname); |
---|
118 | if (pAttr) |
---|
119 | { |
---|
120 | pAttr->value = value; |
---|
121 | pAttr->specified = true; |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | void AttributesImpl::setValue(const XMLString& namespaceURI, const XMLString& localName, const XMLString& value) |
---|
127 | { |
---|
128 | Attribute* pAttr = find(namespaceURI, localName); |
---|
129 | if (pAttr) |
---|
130 | { |
---|
131 | pAttr->value = value; |
---|
132 | pAttr->specified = true; |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | void AttributesImpl::setAttributes(const Attributes& attributes) |
---|
138 | { |
---|
139 | if (&attributes != this) |
---|
140 | { |
---|
141 | int count = attributes.getLength(); |
---|
142 | _attributes.clear(); |
---|
143 | _attributes.reserve(count); |
---|
144 | for (int i = 0; i < count; i++) |
---|
145 | { |
---|
146 | addAttribute(attributes.getURI(i), attributes.getLocalName(i), attributes.getQName(i), attributes.getType(i), attributes.getValue(i)); |
---|
147 | } |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | |
---|
152 | void AttributesImpl::setAttribute(int i, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& type, const XMLString& value) |
---|
153 | { |
---|
154 | poco_assert (0 <= i && i < static_cast<int>(_attributes.size())); |
---|
155 | _attributes[i].namespaceURI = namespaceURI; |
---|
156 | _attributes[i].localName = localName; |
---|
157 | _attributes[i].qname = qname; |
---|
158 | _attributes[i].type = type; |
---|
159 | _attributes[i].value = value; |
---|
160 | _attributes[i].specified = true; |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | void AttributesImpl::addAttribute(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& type, const XMLString& value) |
---|
165 | { |
---|
166 | AttributeVec::iterator it = _attributes.insert(_attributes.end(), Attribute()); |
---|
167 | it->namespaceURI = namespaceURI; |
---|
168 | it->localName = localName; |
---|
169 | it->qname = qname; |
---|
170 | it->value = value; |
---|
171 | it->type = type; |
---|
172 | it->specified = true; |
---|
173 | } |
---|
174 | |
---|
175 | |
---|
176 | void AttributesImpl::addAttribute(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& type, const XMLString& value, bool specified) |
---|
177 | { |
---|
178 | AttributeVec::iterator it = _attributes.insert(_attributes.end(), Attribute()); |
---|
179 | it->namespaceURI = namespaceURI; |
---|
180 | it->localName = localName; |
---|
181 | it->qname = qname; |
---|
182 | it->value = value; |
---|
183 | it->type = type; |
---|
184 | it->specified = specified; |
---|
185 | } |
---|
186 | |
---|
187 | |
---|
188 | void AttributesImpl::addAttribute(const XMLChar* namespaceURI, const XMLChar* localName, const XMLChar* qname, const XMLChar* type, const XMLChar* value, bool specified) |
---|
189 | { |
---|
190 | AttributeVec::iterator it = _attributes.insert(_attributes.end(), Attribute()); |
---|
191 | it->namespaceURI = namespaceURI; |
---|
192 | it->localName = localName; |
---|
193 | it->qname = qname; |
---|
194 | it->value = value; |
---|
195 | it->type = type; |
---|
196 | it->specified = specified; |
---|
197 | } |
---|
198 | |
---|
199 | |
---|
200 | void AttributesImpl::removeAttribute(int i) |
---|
201 | { |
---|
202 | int cur = 0; |
---|
203 | for (AttributeVec::iterator it = _attributes.begin(); it != _attributes.end(); ++it, ++cur) |
---|
204 | { |
---|
205 | if (cur == i) |
---|
206 | { |
---|
207 | _attributes.erase(it); |
---|
208 | break; |
---|
209 | } |
---|
210 | } |
---|
211 | } |
---|
212 | |
---|
213 | |
---|
214 | void AttributesImpl::removeAttribute(const XMLString& qname) |
---|
215 | { |
---|
216 | for (AttributeVec::iterator it = _attributes.begin(); it != _attributes.end(); ++it) |
---|
217 | { |
---|
218 | if (it->qname == qname) |
---|
219 | { |
---|
220 | _attributes.erase(it); |
---|
221 | break; |
---|
222 | } |
---|
223 | } |
---|
224 | } |
---|
225 | |
---|
226 | |
---|
227 | void AttributesImpl::removeAttribute(const XMLString& namespaceURI, const XMLString& localName) |
---|
228 | { |
---|
229 | for (AttributeVec::iterator it = _attributes.begin(); it != _attributes.end(); ++it) |
---|
230 | { |
---|
231 | if (it->namespaceURI == namespaceURI && it->localName == localName) |
---|
232 | { |
---|
233 | _attributes.erase(it); |
---|
234 | break; |
---|
235 | } |
---|
236 | } |
---|
237 | } |
---|
238 | |
---|
239 | |
---|
240 | void AttributesImpl::clear() |
---|
241 | { |
---|
242 | _attributes.clear(); |
---|
243 | } |
---|
244 | |
---|
245 | |
---|
246 | void AttributesImpl::reserve(std::size_t capacity) |
---|
247 | { |
---|
248 | _attributes.reserve(capacity); |
---|
249 | } |
---|
250 | |
---|
251 | |
---|
252 | void AttributesImpl::setLocalName(int i, const XMLString& localName) |
---|
253 | { |
---|
254 | poco_assert (0 <= i && i < static_cast<int>(_attributes.size())); |
---|
255 | _attributes[i].localName = localName; |
---|
256 | } |
---|
257 | |
---|
258 | |
---|
259 | void AttributesImpl::setQName(int i, const XMLString& qname) |
---|
260 | { |
---|
261 | poco_assert (0 <= i && i < static_cast<int>(_attributes.size())); |
---|
262 | _attributes[i].qname = qname; |
---|
263 | } |
---|
264 | |
---|
265 | |
---|
266 | void AttributesImpl::setType(int i, const XMLString& type) |
---|
267 | { |
---|
268 | poco_assert (0 <= i && i < static_cast<int>(_attributes.size())); |
---|
269 | _attributes[i].type = type; |
---|
270 | } |
---|
271 | |
---|
272 | |
---|
273 | void AttributesImpl::setURI(int i, const XMLString& namespaceURI) |
---|
274 | { |
---|
275 | poco_assert (0 <= i && i < static_cast<int>(_attributes.size())); |
---|
276 | _attributes[i].namespaceURI = namespaceURI; |
---|
277 | } |
---|
278 | |
---|
279 | |
---|
280 | AttributesImpl::Attribute* AttributesImpl::find(const XMLString& qname) const |
---|
281 | { |
---|
282 | for (AttributeVec::const_iterator it = _attributes.begin(); it != _attributes.end(); ++it) |
---|
283 | { |
---|
284 | if (it->qname == qname) |
---|
285 | return const_cast<Attribute*>(&(*it)); |
---|
286 | } |
---|
287 | return 0; |
---|
288 | } |
---|
289 | |
---|
290 | |
---|
291 | AttributesImpl::Attribute* AttributesImpl::find(const XMLString& namespaceURI, const XMLString& localName) const |
---|
292 | { |
---|
293 | for (AttributeVec::const_iterator it = _attributes.begin(); it != _attributes.end(); ++it) |
---|
294 | { |
---|
295 | if (it->namespaceURI == namespaceURI && it->localName == localName) |
---|
296 | return const_cast<Attribute*>(&(*it)); |
---|
297 | } |
---|
298 | return 0; |
---|
299 | } |
---|
300 | |
---|
301 | |
---|
302 | } } // namespace Poco::XML |
---|