File indexing completed on 2024-04-28 15:22:55
0001 /** 0002 * This file is part of the DOM implementation for KDE. 0003 * 0004 * Copyright 1999 Lars Knoll (knoll@kde.org) 0005 * Copyright 2000 Frederik Holljen (frederik.holljen@hig.no) 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Library General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Library General Public License 0017 * along with this library; see the file COPYING.LIB. If not, write to 0018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 * 0021 */ 0022 0023 #include "dom/dom_exception.h" 0024 #include "dom/dom_string.h" 0025 #include "xml/dom_nodeimpl.h" 0026 #include "xml/dom2_traversalimpl.h" 0027 0028 using namespace DOM; 0029 0030 NodeIterator::NodeIterator() 0031 { 0032 impl = nullptr; 0033 } 0034 0035 NodeIterator::NodeIterator(const NodeIterator &other) 0036 { 0037 impl = other.impl; 0038 if (impl) { 0039 impl->ref(); 0040 } 0041 } 0042 0043 NodeIterator::NodeIterator(NodeIteratorImpl *i) 0044 { 0045 impl = i; 0046 if (impl) { 0047 impl->ref(); 0048 } 0049 } 0050 0051 NodeIterator &NodeIterator::operator = (const NodeIterator &other) 0052 { 0053 if (impl != other.impl) { 0054 if (impl) { 0055 impl->deref(); 0056 } 0057 impl = other.impl; 0058 if (impl) { 0059 impl->ref(); 0060 } 0061 } 0062 return *this; 0063 } 0064 0065 NodeIterator::~NodeIterator() 0066 { 0067 if (impl) { 0068 impl->deref(); 0069 } 0070 } 0071 0072 Node NodeIterator::root() 0073 { 0074 if (impl) { 0075 return impl->root(); 0076 } 0077 return nullptr; 0078 } 0079 0080 unsigned long NodeIterator::whatToShow() 0081 { 0082 if (impl) { 0083 return impl->whatToShow(); 0084 } 0085 return 0; 0086 } 0087 0088 NodeFilter NodeIterator::filter() 0089 { 0090 if (impl) { 0091 return impl->filter(); 0092 } 0093 return nullptr; 0094 } 0095 0096 bool NodeIterator::expandEntityReferences() 0097 { 0098 if (impl) { 0099 return impl->expandEntityReferences(); 0100 } 0101 return 0; 0102 } 0103 0104 Node NodeIterator::nextNode() 0105 { 0106 void *dummy; 0107 if (!impl) { 0108 throw DOMException(DOMException::INVALID_STATE_ERR); 0109 } 0110 0111 int exceptioncode = 0; 0112 SharedPtr<NodeImpl> r = impl->nextNode(exceptioncode, dummy); 0113 if (exceptioncode) { 0114 throw DOMException(exceptioncode); 0115 } 0116 return r.get(); 0117 } 0118 0119 Node NodeIterator::previousNode() 0120 { 0121 void *dummy; // ### rely on C++ exception propagation --- might not be safe 0122 // we could probably proxy the DOM exceptions at the very least 0123 if (!impl) { 0124 throw DOMException(DOMException::INVALID_STATE_ERR); 0125 } 0126 0127 int exceptioncode = 0; 0128 SharedPtr<NodeImpl> r = impl->previousNode(exceptioncode, dummy); 0129 if (exceptioncode) { 0130 throw DOMException(exceptioncode); 0131 } 0132 return r.get(); 0133 } 0134 0135 void NodeIterator::detach() 0136 { 0137 if (!impl) { 0138 throw DOMException(DOMException::INVALID_STATE_ERR); 0139 } 0140 0141 int exceptioncode = 0; 0142 impl->detach(exceptioncode); 0143 if (exceptioncode) { 0144 throw DOMException(exceptioncode); 0145 } 0146 } 0147 0148 NodeIteratorImpl *NodeIterator::handle() const 0149 { 0150 return impl; 0151 } 0152 0153 bool NodeIterator::isNull() const 0154 { 0155 return (impl == nullptr); 0156 } 0157 0158 // ----------------------------------------------------------- 0159 0160 NodeFilter::NodeFilter() 0161 { 0162 impl = nullptr; 0163 } 0164 0165 NodeFilter::NodeFilter(const NodeFilter &other) 0166 { 0167 impl = other.impl; 0168 if (impl) { 0169 impl->ref(); 0170 } 0171 } 0172 0173 NodeFilter::NodeFilter(NodeFilterImpl *i) 0174 { 0175 impl = i; 0176 if (impl) { 0177 impl->ref(); 0178 } 0179 } 0180 0181 NodeFilter &NodeFilter::operator = (const NodeFilter &other) 0182 { 0183 if (impl != other.impl) { 0184 if (impl) { 0185 impl->deref(); 0186 } 0187 impl = other.impl; 0188 if (impl) { 0189 impl->ref(); 0190 } 0191 } 0192 return *this; 0193 } 0194 0195 NodeFilter::~NodeFilter() 0196 { 0197 if (impl) { 0198 impl->deref(); 0199 } 0200 } 0201 0202 short NodeFilter::acceptNode(const Node &n) 0203 { 0204 void *dummy; 0205 if (impl) { 0206 return impl->acceptNode(n, dummy); 0207 } 0208 return 0; 0209 } 0210 0211 void NodeFilter::setCustomNodeFilter(CustomNodeFilter *custom) 0212 { 0213 if (impl) { 0214 impl->setCustomNodeFilter(custom); 0215 } 0216 } 0217 0218 CustomNodeFilter *NodeFilter::customNodeFilter() 0219 { 0220 if (impl) { 0221 return impl->customNodeFilter(); 0222 } 0223 return nullptr; 0224 } 0225 0226 NodeFilterImpl *NodeFilter::handle() const 0227 { 0228 return impl; 0229 } 0230 0231 bool NodeFilter::isNull() const 0232 { 0233 return (impl == nullptr); 0234 } 0235 0236 NodeFilter NodeFilter::createCustom(CustomNodeFilter *custom) 0237 { 0238 NodeFilterImpl *i = new NodeFilterImpl(); 0239 i->setCustomNodeFilter(custom); 0240 return i; 0241 } 0242 0243 // -------------------------------------------------------------- 0244 CustomNodeFilter::CustomNodeFilter() 0245 { 0246 impl = nullptr; 0247 } 0248 0249 CustomNodeFilter::~CustomNodeFilter() 0250 { 0251 } 0252 0253 short CustomNodeFilter::acceptNode(const Node &/*n*/) 0254 { 0255 return NodeFilter::FILTER_ACCEPT; 0256 } 0257 0258 bool CustomNodeFilter::isNull() 0259 { 0260 return false; 0261 } 0262 0263 DOMString CustomNodeFilter::customNodeFilterType() 0264 { 0265 return ""; 0266 } 0267 0268 // -------------------------------------------------------------- 0269 0270 TreeWalker::TreeWalker() 0271 { 0272 impl = nullptr; 0273 } 0274 0275 TreeWalker::TreeWalker(const TreeWalker &other) 0276 { 0277 impl = other.impl; 0278 if (impl) { 0279 impl->ref(); 0280 } 0281 } 0282 0283 TreeWalker::TreeWalker(TreeWalkerImpl *i) 0284 { 0285 impl = i; 0286 if (impl) { 0287 impl->ref(); 0288 } 0289 } 0290 0291 TreeWalker &TreeWalker::operator = (const TreeWalker &other) 0292 { 0293 if (impl != other.impl) { 0294 if (impl) { 0295 impl->deref(); 0296 } 0297 impl = other.impl; 0298 if (impl) { 0299 impl->ref(); 0300 } 0301 } 0302 0303 return *this; 0304 } 0305 0306 TreeWalker::~TreeWalker() 0307 { 0308 if (impl) { 0309 impl->deref(); 0310 } 0311 } 0312 0313 Node TreeWalker::root() 0314 { 0315 if (impl) { 0316 return impl->getRoot(); 0317 } 0318 return nullptr; 0319 } 0320 0321 unsigned long TreeWalker::whatToShow() 0322 { 0323 if (impl) { 0324 return impl->getWhatToShow(); 0325 } 0326 return 0; 0327 } 0328 0329 NodeFilter TreeWalker::filter() 0330 { 0331 if (impl) { 0332 return impl->getFilter(); 0333 } 0334 return nullptr; 0335 } 0336 0337 bool TreeWalker::expandEntityReferences() 0338 { 0339 if (impl) { 0340 return impl->getExpandEntityReferences(); 0341 } 0342 return false; 0343 } 0344 0345 Node TreeWalker::currentNode() 0346 { 0347 if (impl) { 0348 return impl->getCurrentNode(); 0349 } 0350 return nullptr; 0351 } 0352 0353 void TreeWalker::setCurrentNode(const Node &_currentNode) 0354 { 0355 int exceptionCode = 0; 0356 if (impl) { 0357 impl->setCurrentNode(_currentNode.handle(), exceptionCode); 0358 } 0359 if (exceptionCode) { 0360 throw DOMException(exceptionCode); 0361 } 0362 } 0363 0364 Node TreeWalker::parentNode() 0365 { 0366 void *dummy; 0367 if (impl) { 0368 return impl->parentNode(dummy); 0369 } 0370 return nullptr; 0371 } 0372 0373 Node TreeWalker::firstChild() 0374 { 0375 void *dummy; 0376 if (impl) { 0377 return impl->firstChild(dummy); 0378 } 0379 return nullptr; 0380 } 0381 0382 Node TreeWalker::lastChild() 0383 { 0384 void *dummy; 0385 if (impl) { 0386 return impl->lastChild(dummy); 0387 } 0388 return nullptr; 0389 } 0390 0391 Node TreeWalker::previousSibling() 0392 { 0393 void *dummy; 0394 if (impl) { 0395 return impl->previousSibling(dummy); 0396 } 0397 return nullptr; 0398 } 0399 0400 Node TreeWalker::nextSibling() 0401 { 0402 void *dummy; 0403 if (impl) { 0404 return impl->nextSibling(dummy); 0405 } 0406 return nullptr; 0407 } 0408 0409 Node TreeWalker::previousNode() 0410 { 0411 void *dummy; 0412 if (impl) { 0413 return impl->previousNode(dummy); 0414 } 0415 return nullptr; 0416 } 0417 0418 Node TreeWalker::nextNode() 0419 { 0420 void *dummy; 0421 if (impl) { 0422 return impl->nextNode(dummy); 0423 } 0424 return nullptr; 0425 } 0426 0427 TreeWalkerImpl *TreeWalker::handle() const 0428 { 0429 return impl; 0430 } 0431 0432 bool TreeWalker::isNull() const 0433 { 0434 return (impl == nullptr); 0435 } 0436