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(),
00103 0, exceptioncode );
00104 if ( exceptioncode )
00105 throw DOMException( exceptioncode );
00106 return r;
00107 }
00108
00109 HTMLDocument DOMImplementation::createHTMLDocument( const DOMString& title )
00110 {
00111 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00112 return static_cast<DOMImplementationImpl*>(impl)->createHTMLDocument(title);
00113 }
00114
00115 DOMImplementation DOMImplementation::getInterface(const DOMString &feature) const
00116 {
00117 if (!impl)
00118 throw DOMException(DOMException::NOT_FOUND_ERR);
00119
00120 return impl->getInterface(feature);
00121 }
00122
00123 CSSStyleSheet DOMImplementation::createCSSStyleSheet(const DOMString &title, const DOMString &media)
00124 {
00125 if (!impl)
00126 throw DOMException(DOMException::NOT_FOUND_ERR);
00127
00128 int exceptioncode = 0;
00129 CSSStyleSheetImpl *r = impl->createCSSStyleSheet(title.implementation(), media.implementation(),
00130 exceptioncode);
00131 if ( exceptioncode )
00132 throw DOMException( exceptioncode );
00133 return r;
00134 }
00135
00136 DOMImplementationImpl *DOMImplementation::handle() const
00137 {
00138 return impl;
00139 }
00140
00141 bool DOMImplementation::isNull() const
00142 {
00143 return (impl == 0);
00144 }
00145
00146
00147
00148 Document::Document()
00149 : Node()
00150 {
00151
00152 impl = DOMImplementationImpl::instance()->createDocument();
00153 impl->ref();
00154 }
00155
00156 Document::Document(bool create)
00157 : Node()
00158 {
00159 if(create)
00160 {
00161 impl = DOMImplementationImpl::instance()->createDocument();
00162 impl->ref();
00163 }
00164 else
00165 impl = 0;
00166
00167 }
00168
00169 Document::Document(const Document &other) : Node(other)
00170 {
00171
00172 }
00173
00174 Document::Document(DocumentImpl *i) : Node(i)
00175 {
00176
00177 }
00178
00179 Document &Document::operator = (const Node &other)
00180 {
00181 NodeImpl* ohandle = other.handle();
00182 if ( impl != ohandle ) {
00183 if (!ohandle || ohandle->nodeType() != DOCUMENT_NODE) {
00184 if ( impl ) impl->deref();
00185 impl = 0;
00186 } else {
00187 Node::operator =(other);
00188 }
00189 }
00190 return *this;
00191 }
00192
00193 Document &Document::operator = (const Document &other)
00194 {
00195 Node::operator =(other);
00196 return *this;
00197 }
00198
00199 Document::~Document()
00200 {
00201
00202 }
00203
00204 DocumentType Document::doctype() const
00205 {
00206 if (impl) return ((DocumentImpl *)impl)->doctype();
00207 return 0;
00208 }
00209
00210 DOMImplementation Document::implementation() const
00211 {
00212 if (impl) return ((DocumentImpl *)impl)->implementation();
00213 return 0;
00214 }
00215
00216 Element Document::documentElement() const
00217 {
00218 if (impl) return ((DocumentImpl *)impl)->documentElement();
00219 return 0;
00220 }
00221
00222 Element Document::createElement( const DOMString &tagName )
00223 {
00224 if (!impl)
00225 throw DOMException(DOMException::NOT_FOUND_ERR);
00226
00227 int exceptioncode = 0;
00228 ElementImpl* r = ((DocumentImpl *)impl)->createElement(tagName, &exceptioncode);
00229 if ( exceptioncode )
00230 throw DOMException( exceptioncode );
00231 return r;
00232 }
00233
00234 Element Document::createElementNS( const DOMString &namespaceURI, const DOMString &qualifiedName )
00235 {
00236 if (!impl)
00237 throw DOMException(DOMException::NOT_FOUND_ERR);
00238
00239 int exceptioncode = 0;
00240 ElementImpl* r = ((DocumentImpl *)impl)->createElementNS(namespaceURI,qualifiedName, &exceptioncode);
00241 if ( exceptioncode )
00242 throw DOMException( exceptioncode );
00243 return r;
00244 }
00245
00246 DocumentFragment Document::createDocumentFragment( )
00247 {
00248 if (impl) return ((DocumentImpl *)impl)->createDocumentFragment();
00249 return 0;
00250 }
00251
00252 Text Document::createTextNode( const DOMString &data )
00253 {
00254 if (impl) return ((DocumentImpl *)impl)->createTextNode( data.implementation() );
00255 return 0;
00256 }
00257
00258 Comment Document::createComment( const DOMString &data )
00259 {
00260 if (impl) return ((DocumentImpl *)impl)->createComment( data.implementation() );
00261 return 0;
00262 }
00263
00264 CDATASection Document::createCDATASection( const DOMString &data )
00265 {
00266
00267 if (impl) return ((DocumentImpl *)impl)->createCDATASection( data.implementation() );
00268 return 0;
00269 }
00270
00271 ProcessingInstruction Document::createProcessingInstruction( const DOMString &target, const DOMString &data )
00272 {
00273 if (impl) return ((DocumentImpl *)impl)->createProcessingInstruction( target, data.implementation() );
00274 return 0;
00275 }
00276
00277 Attr Document::createAttribute( const DOMString &name )
00278 {
00279 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00280 if (name.isNull()) throw DOMException(DOMException::NOT_FOUND_ERR);
00281 int exceptioncode = 0;
00282 AttrImpl* a = impl->document()->createAttribute(name, &exceptioncode);
00283 if ( exceptioncode )
00284 throw DOMException( exceptioncode );
00285 return a;
00286 }
00287
00288 Attr Document::createAttributeNS( const DOMString &namespaceURI, const DOMString &qualifiedName )
00289 {
00290 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00291 if (qualifiedName.isNull()) throw DOMException(DOMException::NAMESPACE_ERR);
00292 int exceptioncode = 0;
00293 AttrImpl* a = impl->document()->createAttributeNS(namespaceURI, qualifiedName, &exceptioncode);
00294 if ( exceptioncode )
00295 throw DOMException( exceptioncode );
00296 return a;
00297 }
00298
00299 EntityReference Document::createEntityReference( const DOMString &name )
00300 {
00301 if (impl) return ((DocumentImpl *)impl)->createEntityReference( name );
00302 return 0;
00303 }
00304
00305 Element Document::getElementById( const DOMString &elementId ) const
00306 {
00307 if(impl) return ((DocumentImpl *)impl)->getElementById( elementId );
00308 return 0;
00309 }
00310
00311 NodeList Document::getElementsByTagName( const DOMString &tagName )
00312 {
00313 if (!impl) return 0;
00314 return impl->getElementsByTagName( tagName );
00315 }
00316
00317 NodeList Document::getElementsByTagNameNS( const DOMString &namespaceURI, const DOMString &localName )
00318 {
00319 if (!impl) return 0;
00320 return impl->getElementsByTagNameNS( namespaceURI, localName );
00321 }
00322
00323 NodeList Document::getElementsByClassName( const DOMString& className )
00324 {
00325 if (!impl) return 0;
00326 return impl->getElementsByClassName( className );
00327 }
00328
00329 Node Document::importNode( const Node & importedNode, bool deep )
00330 {
00331 if (!impl)
00332 throw DOMException(DOMException::INVALID_STATE_ERR);
00333
00334 int exceptioncode = 0;
00335 NodeImpl *r = static_cast<DocumentImpl*>(impl)->importNode(importedNode.handle(), deep, exceptioncode);
00336 if (exceptioncode)
00337 throw DOMException(exceptioncode);
00338 return r;
00339 }
00340
00341 bool Document::isHTMLDocument() const
00342 {
00343 if (impl) return ((DocumentImpl *)impl)->isHTMLDocument();
00344 return 0;
00345 }
00346
00347 Range Document::createRange()
00348 {
00349 if (impl) return ((DocumentImpl *)impl)->createRange();
00350 return 0;
00351 }
00352
00353 NodeIterator Document::createNodeIterator(Node root, unsigned long whatToShow,
00354 NodeFilter filter, bool entityReferenceExpansion)
00355 {
00356 if (!impl)
00357 throw DOMException(DOMException::INVALID_STATE_ERR);
00358
00359 int exceptioncode = 0;
00360 NodeIteratorImpl *r = static_cast<DocumentImpl*>(impl)->createNodeIterator(root.handle(),
00361 whatToShow,filter.handle(),entityReferenceExpansion,exceptioncode);
00362 if (exceptioncode)
00363 throw DOMException(exceptioncode);
00364 return r;
00365 }
00366
00367 TreeWalker Document::createTreeWalker(Node root, unsigned long whatToShow, NodeFilter filter,
00368 bool entityReferenceExpansion)
00369 {
00370 if (!impl)
00371 throw DOMException(DOMException::INVALID_STATE_ERR);
00372
00373 int exceptioncode = 0;
00374
00375 TreeWalkerImpl *tw = static_cast<DocumentImpl *>(impl)->createTreeWalker(
00376 root.handle(), whatToShow, filter.handle(), entityReferenceExpansion, exceptioncode);
00377 if (exceptioncode)
00378 throw DOMException(exceptioncode);
00379
00380 return tw;
00381 }
00382
00383 Event Document::createEvent(const DOMString &eventType)
00384 {
00385 if (!impl)
00386 throw DOMException(DOMException::INVALID_STATE_ERR);
00387
00388 int exceptioncode = 0;
00389 EventImpl *r = ((DocumentImpl *)impl)->createEvent(eventType,exceptioncode);
00390 if (exceptioncode)
00391 throw DOMException(exceptioncode);
00392 return r;
00393 }
00394
00395 AbstractView Document::defaultView() const
00396 {
00397 if (!impl)
00398 throw DOMException(DOMException::INVALID_STATE_ERR);
00399
00400 return static_cast<DocumentImpl*>(impl)->defaultView();
00401 }
00402
00403 StyleSheetList Document::styleSheets() const
00404 {
00405 if (!impl)
00406 throw DOMException(DOMException::INVALID_STATE_ERR);
00407
00408 return static_cast<DocumentImpl*>(impl)->styleSheets();
00409 }
00410
00411 DOMString Document::preferredStylesheetSet()
00412 {
00413 if (!impl)
00414 throw DOMException(DOMException::INVALID_STATE_ERR);
00415
00416 return static_cast<DocumentImpl*>(impl)->preferredStylesheetSet();
00417 }
00418
00419 DOMString Document::selectedStylesheetSet()
00420 {
00421 if (!impl)
00422 throw DOMException(DOMException::INVALID_STATE_ERR);
00423
00424 return static_cast<DocumentImpl*>(impl)->selectedStylesheetSet();
00425 }
00426
00427 void Document::setSelectedStylesheetSet(const DOMString& s)
00428 {
00429 if (!impl)
00430 throw DOMException(DOMException::INVALID_STATE_ERR);
00431
00432 static_cast<DocumentImpl*>(impl)->setSelectedStylesheetSet(s);
00433 }
00434
00435
00436 KHTMLView *Document::view() const
00437 {
00438 if (!impl) return 0;
00439
00440 return static_cast<DocumentImpl*>(impl)->view();
00441 }
00442
00443 CSSStyleDeclaration Document::getOverrideStyle(const Element &elt, const DOMString &pseudoElt)
00444 {
00445 if (!impl)
00446 throw DOMException(DOMException::INVALID_STATE_ERR);
00447
00448 CSSStyleDeclarationImpl *r = ((DocumentImpl *)impl)->getOverrideStyle(static_cast<ElementImpl*>(elt.handle()),pseudoElt.implementation());
00449 return r;
00450 }
00451
00452 bool Document::execCommand(const DOMString &command, bool userInterface, const DOMString &value)
00453 {
00454 if (!impl)
00455 throw DOMException(DOMException::NOT_FOUND_ERR);
00456
00457 return static_cast<DocumentImpl*>(impl)->execCommand(command, userInterface, value);
00458 }
00459
00460 bool Document::queryCommandEnabled(const DOMString &command)
00461 {
00462 if (!impl)
00463 throw DOMException(DOMException::NOT_FOUND_ERR);
00464
00465 return static_cast<DocumentImpl*>(impl)->queryCommandEnabled(command);
00466 }
00467
00468 bool Document::queryCommandIndeterm(const DOMString &command)
00469 {
00470 if (!impl)
00471 throw DOMException(DOMException::NOT_FOUND_ERR);
00472
00473 return static_cast<DocumentImpl*>(impl)->queryCommandIndeterm(command);
00474 }
00475
00476 bool Document::queryCommandState(const DOMString &command)
00477 {
00478 if (!impl)
00479 throw DOMException(DOMException::NOT_FOUND_ERR);
00480
00481 return static_cast<DocumentImpl*>(impl)->queryCommandState(command);
00482 }
00483
00484 bool Document::queryCommandSupported(const DOMString &command)
00485 {
00486 if (!impl)
00487 throw DOMException(DOMException::NOT_FOUND_ERR);
00488
00489 return static_cast<DocumentImpl*>(impl)->queryCommandSupported(command);
00490 }
00491
00492 DOMString Document::queryCommandValue(const DOMString &command)
00493 {
00494 if (!impl)
00495 throw DOMException(DOMException::NOT_FOUND_ERR);
00496
00497 return static_cast<DocumentImpl*>(impl)->queryCommandValue(command);
00498 }
00499
00500 bool Document::async() const
00501 {
00502 if (!impl)
00503 throw DOMException(DOMException::INVALID_STATE_ERR);
00504
00505 return static_cast<DocumentImpl*>( impl )->async( );
00506 }
00507
00508 void Document::setAsync( bool b )
00509 {
00510 if (!impl)
00511 throw DOMException(DOMException::INVALID_STATE_ERR);
00512
00513 static_cast<DocumentImpl*>( impl )->setAsync( b );
00514 }
00515
00516 void Document::abort()
00517 {
00518 if (!impl)
00519 throw DOMException(DOMException::INVALID_STATE_ERR);
00520
00521
00522 static_cast<DocumentImpl*>( impl )->abort( );
00523 }
00524
00525 void Document::load( const DOMString &uri )
00526 {
00527 if (!impl)
00528 throw DOMException(DOMException::INVALID_STATE_ERR);
00529
00530 static_cast<DocumentImpl*>( impl )->load( uri );
00531 }
00532
00533 void Document::loadXML( const DOMString &source )
00534 {
00535 if (!impl)
00536 throw DOMException(DOMException::INVALID_STATE_ERR);
00537
00538
00539 static_cast<DocumentImpl*>( impl )->loadXML( source );
00540 }
00541
00542 bool Document::designMode() const {
00543 if (!impl)
00544 throw DOMException(DOMException::INVALID_STATE_ERR);
00545
00546 return static_cast<DocumentImpl*>( impl )->designMode();
00547 }
00548
00549 void Document::setDesignMode(bool enable) {
00550 if (!impl)
00551 throw DOMException(DOMException::INVALID_STATE_ERR);
00552
00553 static_cast<DocumentImpl*>( impl )->setDesignMode( enable );
00554 }
00555
00556 DOMString Document::completeURL(const DOMString& url)
00557 {
00558 if ( !impl ) return url;
00559 return static_cast<DocumentImpl*>( impl )->completeURL( url.string() );
00560 }
00561
00562 DOMString Document::toString() const
00563 {
00564 if (!impl)
00565 throw DOMException(DOMException::NOT_FOUND_ERR);
00566
00567 return static_cast<DocumentImpl*>(impl)->toString();
00568 }
00569
00570 void Document::updateRendering()
00571 {
00572 if ( !impl ) return;
00573 static_cast<DocumentImpl*>( impl )->updateRendering( );
00574 }
00575
00576 void Document::addStyleSheet(const StyleSheet &sheet)
00577 {
00578 if (!impl || sheet.isNull())
00579 throw DOMException(DOMException::INVALID_STATE_ERR);
00580
00581 int exceptioncode;
00582 static_cast<DocumentImpl*>( impl )->addStyleSheet( sheet.handle(), &exceptioncode );
00583 if (exceptioncode)
00584 throw DOMException(exceptioncode);
00585 }
00586
00587 void Document::removeStyleSheet(const StyleSheet &sheet)
00588 {
00589 if (!impl || sheet.isNull())
00590 throw DOMException(DOMException::INVALID_STATE_ERR);
00591
00592 int exceptioncode;
00593 static_cast<DocumentImpl*>( impl )->removeStyleSheet( sheet.handle(), &exceptioncode );
00594 if (exceptioncode)
00595 throw DOMException(exceptioncode);
00596 }
00597
00598
00599
00600 DocumentFragment::DocumentFragment() : Node()
00601 {
00602 }
00603
00604 DocumentFragment::DocumentFragment(const DocumentFragment &other) : Node(other)
00605 {
00606 }
00607
00608 DocumentFragment &DocumentFragment::operator = (const Node &other)
00609 {
00610 NodeImpl* ohandle = other.handle();
00611 if ( impl != ohandle ) {
00612 if (!ohandle || ohandle->nodeType() != DOCUMENT_FRAGMENT_NODE) {
00613 if ( impl ) impl->deref();
00614 impl = 0;
00615 } else {
00616 Node::operator =(other);
00617 }
00618 }
00619 return *this;
00620 }
00621
00622 DocumentFragment &DocumentFragment::operator = (const DocumentFragment &other)
00623 {
00624 Node::operator =(other);
00625 return *this;
00626 }
00627
00628 DocumentFragment::~DocumentFragment()
00629 {
00630 }
00631
00632 DocumentFragment::DocumentFragment(DocumentFragmentImpl *i) : Node(i)
00633 {
00634 }
00635
00636
00637
00638 DocumentType::DocumentType()
00639 : Node()
00640 {
00641 }
00642
00643 DocumentType::DocumentType(const DocumentType &other)
00644 : Node(other)
00645 {
00646 }
00647
00648 DocumentType::DocumentType(DocumentTypeImpl *impl) : Node(impl)
00649 {
00650 }
00651
00652 DocumentType &DocumentType::operator = (const Node &other)
00653 {
00654 NodeImpl* ohandle = other.handle();
00655 if ( impl != ohandle ) {
00656 if (!ohandle || ohandle->nodeType() != DOCUMENT_TYPE_NODE) {
00657 if ( impl ) impl->deref();
00658 impl = 0;
00659 } else {
00660 Node::operator =(other);
00661 }
00662 }
00663 return *this;
00664 }
00665
00666 DocumentType &DocumentType::operator = (const DocumentType &other)
00667 {
00668 Node::operator =(other);
00669 return *this;
00670 }
00671
00672 DocumentType::~DocumentType()
00673 {
00674 }
00675
00676 DOMString DocumentType::name() const
00677 {
00678 if (!impl)
00679 return DOMString();
00680
00681 return static_cast<DocumentTypeImpl*>(impl)->name();
00682 }
00683
00684 NamedNodeMap DocumentType::entities() const
00685 {
00686 if (!impl)
00687 return 0;
00688
00689 return static_cast<DocumentTypeImpl*>(impl)->entities();
00690 }
00691
00692 NamedNodeMap DocumentType::notations() const
00693 {
00694 if (!impl)
00695 return 0;
00696
00697 return static_cast<DocumentTypeImpl*>(impl)->notations();
00698 }
00699
00700 DOMString DocumentType::publicId() const
00701 {
00702 if (!impl)
00703 throw DOMException(DOMException::NOT_FOUND_ERR);
00704
00705 return static_cast<DocumentTypeImpl*>(impl)->publicId();
00706 }
00707
00708 DOMString DocumentType::systemId() const
00709 {
00710 if (!impl)
00711 throw DOMException(DOMException::NOT_FOUND_ERR);
00712
00713 return static_cast<DocumentTypeImpl*>(impl)->systemId();
00714 }
00715
00716 DOMString DocumentType::internalSubset() const
00717 {
00718 if (!impl)
00719 throw DOMException(DOMException::NOT_FOUND_ERR);
00720
00721 return static_cast<DocumentTypeImpl*>(impl)->internalSubset();
00722 }
00723
00724 }