File indexing completed on 2024-04-28 15:22:58
0001 /** 0002 * This file is part of the DOM implementation for KDE. 0003 * 0004 * Copyright 1999 Lars Knoll (knoll@kde.org) 0005 * 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_text.h" 0024 #include "dom_exception.h" 0025 0026 #include <xml/dom_textimpl.h> 0027 0028 using namespace DOM; 0029 0030 CharacterData::CharacterData() : Node() 0031 { 0032 } 0033 0034 CharacterData::CharacterData(const CharacterData &other) : Node(other) 0035 { 0036 } 0037 0038 CharacterData &CharacterData::operator = (const Node &other) 0039 { 0040 NodeImpl *ohandle = other.handle(); 0041 if (impl != ohandle) { 0042 if (!ohandle || 0043 (ohandle->nodeType() != CDATA_SECTION_NODE && 0044 ohandle->nodeType() != TEXT_NODE && 0045 ohandle->nodeType() != COMMENT_NODE)) { 0046 if (impl) { 0047 impl->deref(); 0048 } 0049 impl = nullptr; 0050 } else { 0051 Node::operator =(other); 0052 } 0053 } 0054 return *this; 0055 } 0056 0057 CharacterData &CharacterData::operator = (const CharacterData &other) 0058 { 0059 Node::operator =(other); 0060 return *this; 0061 } 0062 0063 CharacterData::~CharacterData() 0064 { 0065 } 0066 0067 DOMString CharacterData::data() const 0068 { 0069 if (!impl) { 0070 return DOMString(); 0071 } 0072 return ((CharacterDataImpl *)impl)->data(); 0073 } 0074 0075 void CharacterData::setData(const DOMString &str) 0076 { 0077 if (!impl) { 0078 return; // ### enable throw DOMException(DOMException::NOT_FOUND_ERR); 0079 } 0080 0081 int exceptioncode = 0; 0082 ((CharacterDataImpl *)impl)->setData(str, exceptioncode); 0083 if (exceptioncode) { 0084 throw DOMException(exceptioncode); 0085 } 0086 return; 0087 } 0088 0089 unsigned long CharacterData::length() const 0090 { 0091 if (impl) { 0092 return ((CharacterDataImpl *)impl)->length(); 0093 } 0094 return 0; 0095 } 0096 0097 DOMString CharacterData::substringData(const unsigned long offset, const unsigned long count) 0098 { 0099 if (!impl) { 0100 return DOMString(); // ### enable throw DOMException(DOMException::NOT_FOUND_ERR); 0101 } 0102 0103 int exceptioncode = 0; 0104 DOMString str = ((CharacterDataImpl *)impl)->substringData(offset, count, exceptioncode); 0105 if (exceptioncode) { 0106 throw DOMException(exceptioncode); 0107 } 0108 return str; 0109 } 0110 0111 void CharacterData::appendData(const DOMString &arg) 0112 { 0113 if (!impl) { 0114 return; // ### enable throw DOMException(DOMException::NOT_FOUND_ERR); 0115 } 0116 0117 int exceptioncode = 0; 0118 ((CharacterDataImpl *)impl)->appendData(arg, exceptioncode); 0119 if (exceptioncode) { 0120 throw DOMException(exceptioncode); 0121 } 0122 } 0123 0124 void CharacterData::insertData(const unsigned long offset, const DOMString &arg) 0125 { 0126 if (!impl) { 0127 return; // ### enable throw DOMException(DOMException::NOT_FOUND_ERR); 0128 } 0129 0130 int exceptioncode = 0; 0131 ((CharacterDataImpl *)impl)->insertData(offset, arg, exceptioncode); 0132 if (exceptioncode) { 0133 throw DOMException(exceptioncode); 0134 } 0135 } 0136 0137 void CharacterData::deleteData(const unsigned long offset, const unsigned long count) 0138 { 0139 if (!impl) { 0140 return; // ### enable throw DOMException(DOMException::NOT_FOUND_ERR); 0141 } 0142 0143 int exceptioncode = 0; 0144 ((CharacterDataImpl *)impl)->deleteData(offset, count, exceptioncode); 0145 if (exceptioncode) { 0146 throw DOMException(exceptioncode); 0147 } 0148 } 0149 0150 void CharacterData::replaceData(const unsigned long offset, const unsigned long count, const DOMString &arg) 0151 { 0152 if (!impl) { 0153 return; // ### enable throw DOMException(DOMException::NOT_FOUND_ERR); 0154 } 0155 0156 int exceptioncode = 0; 0157 ((CharacterDataImpl *)impl)->replaceData(offset, count, arg, exceptioncode); 0158 if (exceptioncode) { 0159 throw DOMException(exceptioncode); 0160 } 0161 } 0162 0163 CharacterData::CharacterData(CharacterDataImpl *i) : Node(i) 0164 { 0165 } 0166 0167 // --------------------------------------------------------------------------- 0168 0169 Comment::Comment() : CharacterData() 0170 { 0171 } 0172 0173 Comment::Comment(const Comment &other) : CharacterData(other) 0174 { 0175 } 0176 0177 Comment &Comment::operator = (const Node &other) 0178 { 0179 NodeImpl *ohandle = other.handle(); 0180 if (impl != ohandle) { 0181 if (!ohandle || ohandle->nodeType() != COMMENT_NODE) { 0182 if (impl) { 0183 impl->deref(); 0184 } 0185 impl = nullptr; 0186 } else { 0187 Node::operator =(other); 0188 } 0189 } 0190 return *this; 0191 } 0192 0193 Comment &Comment::operator = (const Comment &other) 0194 { 0195 CharacterData::operator =(other); 0196 return *this; 0197 } 0198 0199 Comment::~Comment() 0200 { 0201 } 0202 0203 Comment::Comment(CommentImpl *i) : CharacterData(i) 0204 { 0205 } 0206 0207 // ---------------------------------------------------------------------------- 0208 0209 Text::Text() 0210 { 0211 } 0212 0213 Text::Text(const Text &other) : CharacterData(other) 0214 { 0215 } 0216 0217 Text &Text::operator = (const Node &other) 0218 { 0219 NodeImpl *ohandle = other.handle(); 0220 if (impl != ohandle) { 0221 if (!ohandle || 0222 (ohandle->nodeType() != TEXT_NODE && 0223 ohandle->nodeType() != CDATA_SECTION_NODE)) { 0224 if (impl) { 0225 impl->deref(); 0226 } 0227 impl = nullptr; 0228 } else { 0229 Node::operator =(other); 0230 } 0231 } 0232 return *this; 0233 } 0234 0235 Text &Text::operator = (const Text &other) 0236 { 0237 Node::operator =(other); 0238 return *this; 0239 } 0240 0241 Text::~Text() 0242 { 0243 } 0244 0245 Text Text::splitText(const unsigned long offset) 0246 { 0247 if (!impl) { 0248 return nullptr; // ### enable throw DOMException(DOMException::NOT_FOUND_ERR); 0249 } 0250 0251 int exceptioncode = 0; 0252 TextImpl *newText = static_cast<TextImpl *>(impl)->splitText(offset, exceptioncode); 0253 if (exceptioncode) { 0254 throw DOMException(exceptioncode); 0255 } 0256 return newText; 0257 } 0258 0259 Text::Text(TextImpl *i) : CharacterData(i) 0260 { 0261 }