00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "dom/dom_exception.h"
00024 #include "dom/dom_xml.h"
00025 #include "dom/dom2_range.h"
00026 #include "dom/dom2_events.h"
00027 #include "dom/dom2_views.h"
00028 #include "dom/dom2_traversal.h"
00029 #include "dom/html_document.h"
00030 #include "html/html_documentimpl.h"
00031
00032 #include "xml/dom_docimpl.h"
00033 #include "xml/dom_elementimpl.h"
00034
00035 #include <kdebug.h>
00036
00037 namespace DOM {
00038
00039 DOMImplementation::DOMImplementation()
00040 {
00041 impl = 0;
00042 }
00043
00044 DOMImplementation::DOMImplementation(const DOMImplementation &other)
00045 {
00046 impl = other.impl;
00047 if (impl) impl->ref();
00048 }
00049
00050 DOMImplementation::DOMImplementation(DOMImplementationImpl *i)
00051 {
00052 impl = i;
00053 if (impl) impl->ref();
00054 }
00055
00056 DOMImplementation &DOMImplementation::operator = (const DOMImplementation &other)
00057 {
00058 if ( impl != other.impl ) {
00059 if (impl) impl->deref();
00060 impl = other.impl;
00061 if (impl) impl->ref();
00062 }
00063 return *this;
00064 }
00065
00066 DOMImplementation::~DOMImplementation()
00067 {
00068 if (impl) impl->deref();
00069 }
00070
00071 bool DOMImplementation::hasFeature( const DOMString &feature, const DOMString &version )
00072 {
00073 if (!impl)
00074 return false;
00075
00076 return impl->hasFeature(feature,version);
00077 }
00078
00079 DocumentType DOMImplementation::createDocumentType ( const DOMString &qualifiedName,
00080 const DOMString &publicId,
00081 const DOMString &systemId )
00082 {
00083 if (!impl)
00084 throw DOMException(DOMException::NOT_FOUND_ERR);
00085
00086 int exceptioncode = 0;
00087 DocumentTypeImpl *r = impl->createDocumentType(qualifiedName, publicId, systemId, exceptioncode);
00088 if ( exceptioncode )
00089 throw DOMException( exceptioncode );
00090 return r;
00091 }
00092
00093 Document DOMImplementation::createDocument ( const DOMString &namespaceURI,
00094 const DOMString &qualifiedName,
00095 const DocumentType &doctype )
00096 {
00097 if (!impl)
00098 throw DOMException(DOMException::NOT_FOUND_ERR);
00099
00100 int exceptioncode = 0;
00101 DocumentImpl *r = impl->createDocument(namespaceURI, qualifiedName,
00102 (DocumentTypeImpl*)doctype.handle(), exceptioncode );
00103 if ( exceptioncode )
00104 throw DOMException( exceptioncode );
00105 return r;
00106 }
00107
00108 HTMLDocument DOMImplementation::createHTMLDocument( const DOMString& title )
00109 {
00110 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00111 return static_cast<DOMImplementationImpl*>(impl)->createHTMLDocument(title);
00112 }
00113
00114 DOMImplementation DOMImplementation::getInterface(const DOMString &feature) const
00115 {
00116 if (!impl)
00117 throw DOMException(DOMException::NOT_FOUND_ERR);
00118
00119 return impl->getInterface(feature);
00120 }
00121
00122 CSSStyleSheet DOMImplementation::createCSSStyleSheet(const DOMString &title, const DOMString &media)
00123 {
00124 if (!impl)
00125 throw DOMException(DOMException::NOT_FOUND_ERR);
00126
00127 int exceptioncode = 0;
00128 CSSStyleSheetImpl *r = impl->createCSSStyleSheet(title.implementation(), media.implementation(),
00129 exceptioncode);
00130 if ( exceptioncode )
00131 throw DOMException( exceptioncode );
00132 return r;
00133 }
00134
00135 DOMImplementationImpl *DOMImplementation::handle() const
00136 {
00137 return impl;
00138 }
00139
00140 bool DOMImplementation::isNull() const
00141 {
00142 return (impl == 0);
00143 }
00144
00145
00146
00147 Document::Document()
00148 : Node()
00149 {
00150
00151 impl = DOMImplementationImpl::instance()->createDocument();
00152 impl->ref();
00153 }
00154
00155 Document::Document(bool create)
00156 : Node()
00157 {
00158 if(create)
00159 {
00160 impl = DOMImplementationImpl::instance()->createDocument();
00161 impl->ref();
00162 }
00163 else
00164 impl = 0;
00165
00166 }
00167
00168 Document::Document(const Document &other) : Node(other)
00169 {
00170
00171 }
00172
00173 Document::Document(DocumentImpl *i) : Node(i)
00174 {
00175
00176 }
00177
00178 Document &Document::operator = (const Node &other)
00179 {
00180 NodeImpl* ohandle = other.handle();
00181 if ( impl != ohandle ) {
00182 if (!ohandle || ohandle->nodeType() != DOCUMENT_NODE) {
00183 if ( impl ) impl->deref();
00184 impl = 0;
00185 } else {
00186 Node::operator =(other);
00187 }
00188 }
00189 return *this;
00190 }
00191
00192 Document &Document::operator = (const Document &other)
00193 {
00194 Node::operator =(other);
00195 return *this;
00196 }
00197
00198 Document::~Document()
00199 {
00200
00201 }
00202
00203 DocumentType Document::doctype() const
00204 {
00205 if (impl) return ((DocumentImpl *)impl)->doctype();
00206 return 0;
00207 }
00208
00209 DOMImplementation Document::implementation() const
00210 {
00211 if (impl) return ((DocumentImpl *)impl)->implementation();
00212 return 0;
00213 }
00214
00215 Element Document::documentElement() const
00216 {
00217 if (impl) return ((DocumentImpl *)impl)->documentElement();
00218 return 0;
00219 }
00220
00221 Element Document::createElement( const DOMString &tagName )
00222 {
00223 if (!impl)
00224 throw DOMException(DOMException::NOT_FOUND_ERR);
00225
00226 int exceptioncode = 0;
00227 ElementImpl* r = ((DocumentImpl *)impl)->createElement(tagName, &exceptioncode);
00228 if ( exceptioncode )
00229 throw DOMException( exceptioncode );
00230 return r;
00231 }
00232
00233 Element Document::createElementNS( const DOMString &namespaceURI, const DOMString &qualifiedName )
00234 {
00235 if (!impl)
00236 throw DOMException(DOMException::NOT_FOUND_ERR);
00237
00238 int exceptioncode = 0;
00239 ElementImpl* r = ((DocumentImpl *)impl)->createElementNS(namespaceURI,qualifiedName, &exceptioncode);
00240 if ( exceptioncode )
00241 throw DOMException( exceptioncode );
00242 return r;
00243 }
00244
00245 DocumentFragment Document::createDocumentFragment( )
00246 {
00247 if (impl) return ((DocumentImpl *)impl)->createDocumentFragment();
00248 return 0;
00249 }
00250
00251 Text Document::createTextNode( const DOMString &data )
00252 {
00253 if (impl) return ((DocumentImpl *)impl)->createTextNode( data.implementation() );
00254 return 0;
00255 }
00256
00257 Comment Document::createComment( const DOMString &data )
00258 {
00259 if (impl) return ((DocumentImpl *)impl)->createComment( data.implementation() );
00260 return 0;
00261 }
00262
00263 CDATASection Document::createCDATASection( const DOMString &data )
00264 {
00265
00266 if (impl) return ((DocumentImpl *)impl)->createCDATASection( data.implementation() );
00267 return 0;
00268 }
00269
00270 ProcessingInstruction Document::createProcessingInstruction( const DOMString &target, const DOMString &data )
00271 {
00272 if (impl) return ((DocumentImpl *)impl)->createProcessingInstruction( target, data.implementation() );
00273 return 0;
00274 }
00275
00276 Attr Document::createAttribute( const DOMString &name )
00277 {
00278 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00279 if (name.isNull()) throw DOMException(DOMException::NOT_FOUND_ERR);
00280 int exceptioncode = 0;
00281 AttrImpl* a = impl->getDocument()->createAttribute(name, &exceptioncode);
00282 if ( exceptioncode )
00283 throw DOMException( exceptioncode );
00284 return a;
00285 }
00286
00287 Attr Document::createAttributeNS( const DOMString &namespaceURI, const DOMString &qualifiedName )
00288 {
00289 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00290 if (qualifiedName.isNull()) throw DOMException(DOMException::NAMESPACE_ERR);
00291 int exceptioncode = 0;
00292 AttrImpl* a = impl->getDocument()->createAttributeNS(namespaceURI, qualifiedName, &exceptioncode);
00293 if ( exceptioncode )
00294 throw DOMException( exceptioncode );
00295 return a;
00296 }
00297
00298 EntityReference Document::createEntityReference( const DOMString &name )
00299 {
00300 if (impl) return ((DocumentImpl *)impl)->createEntityReference( name );
00301 return 0;
00302 }
00303
00304 Element Document::getElementById( const DOMString &elementId ) const
00305 {
00306 if(impl) return ((DocumentImpl *)impl)->getElementById( elementId );
00307 return 0;
00308 }
00309
00310 NodeList Document::getElementsByTagName( const DOMString &tagName )
00311 {
00312 if (!impl) return 0;
00313 return impl->getElementsByTagName( tagName );
00314 }
00315
00316 NodeList Document::getElementsByTagNameNS( const DOMString &namespaceURI, const DOMString &localName )
00317 {
00318 if (!impl) return 0;
00319 return impl->getElementsByTagNameNS( namespaceURI, localName );
00320 }
00321
00322 Node Document::importNode( const Node & importedNode, bool deep )
00323 {
00324 if (!impl)
00325 throw DOMException(DOMException::INVALID_STATE_ERR);
00326
00327 int exceptioncode = 0;
00328 NodeImpl *r = static_cast<DocumentImpl*>(impl)->importNode(importedNode.handle(), deep, exceptioncode);
00329 if (exceptioncode)
00330 throw DOMException(exceptioncode);
00331 return r;
00332 }
00333
00334 bool Document::isHTMLDocument() const
00335 {
00336 if (impl) return ((DocumentImpl *)impl)->isHTMLDocument();
00337 return 0;
00338 }
00339
00340 Range Document::createRange()
00341 {
00342 if (impl) return ((DocumentImpl *)impl)->createRange();
00343 return 0;
00344 }
00345
00346 NodeIterator Document::createNodeIterator(Node root, unsigned long whatToShow,
00347 NodeFilter filter, bool entityReferenceExpansion)
00348 {
00349 if (!impl)
00350 throw DOMException(DOMException::INVALID_STATE_ERR);
00351
00352 int exceptioncode = 0;
00353 NodeIteratorImpl *r = static_cast<DocumentImpl*>(impl)->createNodeIterator(root.handle(),
00354 whatToShow,filter.handle(),entityReferenceExpansion,exceptioncode);
00355 if (exceptioncode)
00356 throw DOMException(exceptioncode);
00357 return r;
00358 }
00359
00360 TreeWalker Document::createTreeWalker(Node root, unsigned long whatToShow, NodeFilter filter,
00361 bool entityReferenceExpansion)
00362 {
00363 if (!impl)
00364 throw DOMException(DOMException::INVALID_STATE_ERR);
00365
00366 int exceptioncode = 0;
00367
00368 TreeWalkerImpl *tw = static_cast<DocumentImpl *>(impl)->createTreeWalker(
00369 root.handle(), whatToShow, filter.handle(), entityReferenceExpansion, exceptioncode);
00370 if (exceptioncode)
00371 throw DOMException(exceptioncode);
00372
00373 return tw;
00374 }
00375
00376 Event Document::createEvent(const DOMString &eventType)
00377 {
00378 if (!impl)
00379 throw DOMException(DOMException::INVALID_STATE_ERR);
00380
00381 int exceptioncode = 0;
00382 EventImpl *r = ((DocumentImpl *)impl)->createEvent(eventType,exceptioncode);
00383 if (exceptioncode)
00384 throw DOMException(exceptioncode);
00385 return r;
00386 }
00387
00388 AbstractView Document::defaultView() const
00389 {
00390 if (!impl)
00391 throw DOMException(DOMException::INVALID_STATE_ERR);
00392
00393 return static_cast<DocumentImpl*>(impl)->defaultView();
00394 }
00395
00396 StyleSheetList Document::styleSheets() const
00397 {
00398 if (!impl)
00399 throw DOMException(DOMException::INVALID_STATE_ERR);
00400
00401 return static_cast<DocumentImpl*>(impl)->styleSheets();
00402 }
00403
00404 DOMString Document::preferredStylesheetSet()
00405 {
00406 if (!impl)
00407 throw DOMException(DOMException::INVALID_STATE_ERR);
00408
00409 return static_cast<DocumentImpl*>(impl)->preferredStylesheetSet();
00410 }
00411
00412 DOMString Document::selectedStylesheetSet()
00413 {
00414 if (!impl)
00415 throw DOMException(DOMException::INVALID_STATE_ERR);
00416
00417 return static_cast<DocumentImpl*>(impl)->selectedStylesheetSet();
00418 }
00419
00420 void Document::setSelectedStylesheetSet(const DOMString& s)
00421 {
00422 if (!impl)
00423 throw DOMException(DOMException::INVALID_STATE_ERR);
00424
00425 static_cast<DocumentImpl*>(impl)->setSelectedStylesheetSet(s);
00426 }
00427
00428
00429 KHTMLView *Document::view() const
00430 {
00431 if (!impl) return 0;
00432
00433 return static_cast<DocumentImpl*>(impl)->view();
00434 }
00435
00436 CSSStyleDeclaration Document::getOverrideStyle(const Element &elt, const DOMString &pseudoElt)
00437 {
00438 if (!impl)
00439 throw DOMException(DOMException::INVALID_STATE_ERR);
00440
00441 CSSStyleDeclarationImpl *r = ((DocumentImpl *)impl)->getOverrideStyle(static_cast<ElementImpl*>(elt.handle()),pseudoElt.implementation());
00442 return r;
00443 }
00444
00445 bool Document::async() const
00446 {
00447 if (!impl)
00448 throw DOMException(DOMException::INVALID_STATE_ERR);
00449
00450 return static_cast<DocumentImpl*>( impl )->async( );
00451 }
00452
00453 void Document::setAsync( bool b )
00454 {
00455 if (!impl)
00456 throw DOMException(DOMException::INVALID_STATE_ERR);
00457
00458 static_cast<DocumentImpl*>( impl )->setAsync( b );
00459 }
00460
00461 void Document::abort()
00462 {
00463 if (!impl)
00464 throw DOMException(DOMException::INVALID_STATE_ERR);
00465
00466
00467 static_cast<DocumentImpl*>( impl )->abort( );
00468 }
00469
00470 void Document::load( const DOMString &uri )
00471 {
00472 if (!impl)
00473 throw DOMException(DOMException::INVALID_STATE_ERR);
00474
00475 static_cast<DocumentImpl*>( impl )->load( uri );
00476 }
00477
00478 void Document::loadXML( const DOMString &source )
00479 {
00480 if (!impl)
00481 throw DOMException(DOMException::INVALID_STATE_ERR);
00482
00483
00484 static_cast<DocumentImpl*>( impl )->loadXML( source );
00485 }
00486
00487 bool Document::designMode() const {
00488 if (!impl)
00489 throw DOMException(DOMException::INVALID_STATE_ERR);
00490
00491 return static_cast<DocumentImpl*>( impl )->designMode();
00492 }
00493
00494 void Document::setDesignMode(bool enable) {
00495 if (!impl)
00496 throw DOMException(DOMException::INVALID_STATE_ERR);
00497
00498 static_cast<DocumentImpl*>( impl )->setDesignMode( enable );
00499 }
00500
00501 DOMString Document::completeURL(const DOMString& url)
00502 {
00503 if ( !impl ) return url;
00504 return static_cast<DocumentImpl*>( impl )->completeURL( url.string() );
00505 }
00506
00507 DOMString Document::toString() const
00508 {
00509 if (!impl)
00510 throw DOMException(DOMException::NOT_FOUND_ERR);
00511
00512 return static_cast<DocumentImpl*>(impl)->toString();
00513 }
00514
00515 void Document::updateRendering()
00516 {
00517 if ( !impl ) return;
00518 static_cast<DocumentImpl*>( impl )->updateRendering( );
00519 }
00520
00521 void Document::addStyleSheet(const StyleSheet &sheet)
00522 {
00523 if (!impl || sheet.isNull())
00524 throw DOMException(DOMException::INVALID_STATE_ERR);
00525
00526 int exceptioncode;
00527 static_cast<DocumentImpl*>( impl )->addStyleSheet( sheet.handle(), &exceptioncode );
00528 if (exceptioncode)
00529 throw DOMException(exceptioncode);
00530 }
00531
00532 void Document::removeStyleSheet(const StyleSheet &sheet)
00533 {
00534 if (!impl || sheet.isNull())
00535 throw DOMException(DOMException::INVALID_STATE_ERR);
00536
00537 int exceptioncode;
00538 static_cast<DocumentImpl*>( impl )->removeStyleSheet( sheet.handle(), &exceptioncode );
00539 if (exceptioncode)
00540 throw DOMException(exceptioncode);
00541 }
00542
00543
00544
00545 DocumentFragment::DocumentFragment() : Node()
00546 {
00547 }
00548
00549 DocumentFragment::DocumentFragment(const DocumentFragment &other) : Node(other)
00550 {
00551 }
00552
00553 DocumentFragment &DocumentFragment::operator = (const Node &other)
00554 {
00555 NodeImpl* ohandle = other.handle();
00556 if ( impl != ohandle ) {
00557 if (!ohandle || ohandle->nodeType() != DOCUMENT_FRAGMENT_NODE) {
00558 if ( impl ) impl->deref();
00559 impl = 0;
00560 } else {
00561 Node::operator =(other);
00562 }
00563 }
00564 return *this;
00565 }
00566
00567 DocumentFragment &DocumentFragment::operator = (const DocumentFragment &other)
00568 {
00569 Node::operator =(other);
00570 return *this;
00571 }
00572
00573 DocumentFragment::~DocumentFragment()
00574 {
00575 }
00576
00577 DocumentFragment::DocumentFragment(DocumentFragmentImpl *i) : Node(i)
00578 {
00579 }
00580
00581
00582
00583 DocumentType::DocumentType()
00584 : Node()
00585 {
00586 }
00587
00588 DocumentType::DocumentType(const DocumentType &other)
00589 : Node(other)
00590 {
00591 }
00592
00593 DocumentType::DocumentType(DocumentTypeImpl *impl) : Node(impl)
00594 {
00595 }
00596
00597 DocumentType &DocumentType::operator = (const Node &other)
00598 {
00599 NodeImpl* ohandle = other.handle();
00600 if ( impl != ohandle ) {
00601 if (!ohandle || ohandle->nodeType() != DOCUMENT_TYPE_NODE) {
00602 if ( impl ) impl->deref();
00603 impl = 0;
00604 } else {
00605 Node::operator =(other);
00606 }
00607 }
00608 return *this;
00609 }
00610
00611 DocumentType &DocumentType::operator = (const DocumentType &other)
00612 {
00613 Node::operator =(other);
00614 return *this;
00615 }
00616
00617 DocumentType::~DocumentType()
00618 {
00619 }
00620
00621 DOMString DocumentType::name() const
00622 {
00623 if (!impl)
00624 return DOMString();
00625
00626 return static_cast<DocumentTypeImpl*>(impl)->name();
00627 }
00628
00629 NamedNodeMap DocumentType::entities() const
00630 {
00631 if (!impl)
00632 return 0;
00633
00634 return static_cast<DocumentTypeImpl*>(impl)->entities();
00635 }
00636
00637 NamedNodeMap DocumentType::notations() const
00638 {
00639 if (!impl)
00640 return 0;
00641
00642 return static_cast<DocumentTypeImpl*>(impl)->notations();
00643 }
00644
00645 DOMString DocumentType::publicId() const
00646 {
00647 if (!impl)
00648 throw DOMException(DOMException::NOT_FOUND_ERR);
00649
00650 return static_cast<DocumentTypeImpl*>(impl)->publicId();
00651 }
00652
00653 DOMString DocumentType::systemId() const
00654 {
00655 if (!impl)
00656 throw DOMException(DOMException::NOT_FOUND_ERR);
00657
00658 return static_cast<DocumentTypeImpl*>(impl)->systemId();
00659 }
00660
00661 DOMString DocumentType::internalSubset() const
00662 {
00663 if (!impl)
00664 throw DOMException(DOMException::NOT_FOUND_ERR);
00665
00666 return static_cast<DocumentTypeImpl*>(impl)->internalSubset();
00667 }
00668
00669 }