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