khtml Library API Documentation

dom_doc.cpp

00001 
00024 #include "dom/dom_exception.h"
00025 #include "dom/dom_xml.h"
00026 #include "dom/dom2_range.h"
00027 #include "dom/dom2_events.h"
00028 #include "dom/dom2_views.h"
00029 #include "dom/dom2_traversal.h"
00030 #include "dom/html_document.h"
00031 #include "html/html_documentimpl.h"
00032 
00033 #include "xml/dom_docimpl.h"
00034 #include "xml/dom_elementimpl.h"
00035 
00036 #include <kdebug.h>
00037 
00038 using namespace DOM;
00039 
00040 DOMImplementation::DOMImplementation()
00041 {
00042     impl = 0;
00043 }
00044 
00045 DOMImplementation::DOMImplementation(const DOMImplementation &other)
00046 {
00047     impl = other.impl;
00048     if (impl) impl->ref();
00049 }
00050 
00051 DOMImplementation::DOMImplementation(DOMImplementationImpl *i)
00052 {
00053     impl = i;
00054     if (impl) impl->ref();
00055 }
00056 
00057 DOMImplementation &DOMImplementation::operator = (const DOMImplementation &other)
00058 {
00059     if ( impl != other.impl ) {
00060         if (impl) impl->deref();
00061         impl = other.impl;
00062         if (impl) impl->ref();
00063     }
00064     return *this;
00065 }
00066 
00067 DOMImplementation::~DOMImplementation()
00068 {
00069     if (impl) impl->deref();
00070 }
00071 
00072 bool DOMImplementation::hasFeature( const DOMString &feature, const DOMString &version )
00073 {
00074     if (!impl)
00075     return false; // ### enable throw DOMException(DOMException::NOT_FOUND_ERR);
00076 
00077     return impl->hasFeature(feature,version);
00078 }
00079 
00080 DocumentType DOMImplementation::createDocumentType ( const DOMString &qualifiedName,
00081                                                      const DOMString &publicId,
00082                                                      const DOMString &systemId )
00083 {
00084     if (!impl)
00085     throw DOMException(DOMException::NOT_FOUND_ERR);
00086 
00087     int exceptioncode = 0;
00088     DocumentTypeImpl *r = impl->createDocumentType(qualifiedName, publicId, systemId, exceptioncode);
00089     if ( exceptioncode )
00090         throw DOMException( exceptioncode );
00091     return r;
00092 }
00093 
00094 Document DOMImplementation::createDocument ( const DOMString &namespaceURI,
00095                                              const DOMString &qualifiedName,
00096                                              const DocumentType &doctype )
00097 {
00098     if (!impl)
00099     throw DOMException(DOMException::NOT_FOUND_ERR);
00100 
00101     int exceptioncode = 0;
00102     DocumentImpl *r = impl->createDocument(namespaceURI, qualifiedName, doctype, 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 
00112     HTMLDocumentImpl* r = impl->createHTMLDocument( 0 /* ### create a view otherwise it doesn't work */);
00113 
00114     r->open();
00115 
00116     r->write(QString::fromLatin1("<HTML><HEAD><TITLE>") + title.string() +
00117              QString::fromLatin1("</TITLE></HEAD>"));
00118 
00119     return r;
00120 }
00121 
00122 DOMImplementation DOMImplementation::getInterface(const DOMString &feature) const
00123 {
00124     if (!impl)
00125         throw DOMException(DOMException::NOT_FOUND_ERR);
00126 
00127     return impl->getInterface(feature);
00128 }
00129 
00130 CSSStyleSheet DOMImplementation::createCSSStyleSheet(const DOMString &title, const DOMString &media)
00131 {
00132     if (!impl)
00133         throw DOMException(DOMException::NOT_FOUND_ERR);
00134 
00135     int exceptioncode = 0;
00136     CSSStyleSheetImpl *r = impl->createCSSStyleSheet(title.implementation(), media.implementation(),
00137                                                      exceptioncode);
00138     if ( exceptioncode )
00139         throw DOMException( exceptioncode );
00140     return r;
00141 }
00142 
00143 DOMImplementationImpl *DOMImplementation::handle() const
00144 {
00145     return impl;
00146 }
00147 
00148 bool DOMImplementation::isNull() const
00149 {
00150     return (impl == 0);
00151 }
00152 
00153 // ----------------------------------------------------------------------------
00154 
00155 Document::Document()
00156     : Node()
00157 {
00158     // we always want an implementation
00159     impl = DOMImplementationImpl::instance()->createDocument();
00160     impl->ref();
00161 }
00162 
00163 Document::Document(bool create)
00164     : Node()
00165 {
00166     if(create)
00167     {
00168     impl = DOMImplementationImpl::instance()->createDocument();
00169     impl->ref();
00170     }
00171     else
00172     impl = 0;
00173 //    kdDebug(6090) << "Document::Document(bool)" << endl;
00174 }
00175 
00176 Document::Document(const Document &other) : Node(other)
00177 {
00178 //    kdDebug(6090) << "Document::Document(Document &)" << endl;
00179 }
00180 
00181 Document::Document(DocumentImpl *i) : Node(i)
00182 {
00183 //    kdDebug(6090) << "Document::Document(DocumentImpl)" << endl;
00184 }
00185 
00186 Document &Document::operator = (const Node &other)
00187 {
00188     NodeImpl* ohandle = other.handle();
00189     if ( impl != ohandle ) {
00190         if (!ohandle || ohandle->nodeType() != DOCUMENT_NODE) {
00191         if ( impl ) impl->deref();
00192             impl = 0;
00193     } else {
00194             Node::operator =(other);
00195     }
00196     }
00197     return *this;
00198 }
00199 
00200 Document &Document::operator = (const Document &other)
00201 {
00202     Node::operator =(other);
00203     return *this;
00204 }
00205 
00206 Document::~Document()
00207 {
00208 //    kdDebug(6090) << "Document::~Document\n" << endl;
00209 }
00210 
00211 DocumentType Document::doctype() const
00212 {
00213     if (impl) return ((DocumentImpl *)impl)->doctype();
00214     return 0;
00215 }
00216 
00217 DOMImplementation Document::implementation() const
00218 {
00219     if (impl) return ((DocumentImpl *)impl)->implementation();
00220     return 0;
00221 }
00222 
00223 Element Document::documentElement() const
00224 {
00225     if (impl) return ((DocumentImpl *)impl)->documentElement();
00226     return 0;
00227 }
00228 
00229 Element Document::createElement( const DOMString &tagName )
00230 {
00231     if (impl) return ((DocumentImpl *)impl)->createElement(tagName);
00232     return 0;
00233 }
00234 
00235 Element Document::createElementNS( const DOMString &namespaceURI, const DOMString &qualifiedName )
00236 {
00237     if (impl) return ((DocumentImpl *)impl)->createElementNS(namespaceURI,qualifiedName);
00238     return 0;
00239 }
00240 
00241 DocumentFragment Document::createDocumentFragment(  )
00242 {
00243     if (impl) return ((DocumentImpl *)impl)->createDocumentFragment();
00244     return 0;
00245 }
00246 
00247 Text Document::createTextNode( const DOMString &data )
00248 {
00249     if (impl) return ((DocumentImpl *)impl)->createTextNode( data.implementation() );
00250     return 0;
00251 }
00252 
00253 Comment Document::createComment( const DOMString &data )
00254 {
00255     if (impl) return ((DocumentImpl *)impl)->createComment( data.implementation() );
00256     return 0;
00257 }
00258 
00259 CDATASection Document::createCDATASection( const DOMString &data )
00260 {
00261     // ### DOM1 spec says raise exception if html documents - what about XHTML documents?
00262     if (impl) return ((DocumentImpl *)impl)->createCDATASection( data.implementation() );
00263     return 0;
00264 }
00265 
00266 ProcessingInstruction Document::createProcessingInstruction( const DOMString &target, const DOMString &data )
00267 {
00268     if (impl) return ((DocumentImpl *)impl)->createProcessingInstruction( target, data.implementation() );
00269     return 0;
00270 }
00271 
00272 Attr Document::createAttribute( const DOMString &name )
00273 {
00274     return createAttributeNS(DOMString(), name);
00275 }
00276 
00277 Attr Document::createAttributeNS( const DOMString &namespaceURI, const DOMString &qualifiedName )
00278 {
00279     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00280     if (qualifiedName.isNull()) throw DOMException(DOMException::NAMESPACE_ERR);
00281 
00282     DOMString localName(qualifiedName.copy());
00283     DOMString prefix;
00284     int colonpos;
00285     if ((colonpos = qualifiedName.find(':')) >= 0) {
00286         prefix = qualifiedName.copy();
00287         prefix.truncate(colonpos);
00288         localName.remove(0, colonpos+1);
00289     }
00290 
00291     // ### check correctness of parameters
00292 
00293     NodeImpl::Id id = static_cast<DocumentImpl*>(impl)->attrId(namespaceURI.implementation(), localName.implementation(), false /* allocate */);
00294     Attr r = static_cast<DocumentImpl*>(impl)->createAttribute(id);
00295     int exceptioncode = 0;
00296     if (r.handle() && prefix.implementation())
00297         r.handle()->setPrefix(prefix.implementation(), exceptioncode);
00298     if (exceptioncode)
00299         throw DOMException(exceptioncode);
00300     return r;
00301 }
00302 
00303 EntityReference Document::createEntityReference( const DOMString &name )
00304 {
00305     if (impl) return ((DocumentImpl *)impl)->createEntityReference( name );
00306     return 0;
00307 }
00308 
00309 Element Document::getElementById( const DOMString &elementId ) const
00310 {
00311     if(impl) return ((DocumentImpl *)impl)->getElementById( elementId );
00312     return 0;
00313 }
00314 
00315 NodeList Document::getElementsByTagName( const DOMString &tagName )
00316 {
00317     if (!impl) return 0;
00318     return static_cast<DocumentImpl*>(impl)->
00319         getElementsByTagNameNS(0, tagName.implementation());
00320 }
00321 
00322 NodeList Document::getElementsByTagNameNS( const DOMString &namespaceURI, const DOMString &localName )
00323 {
00324     if (!impl) return 0;
00325     return static_cast<DocumentImpl*>(impl)->
00326         getElementsByTagNameNS(namespaceURI.implementation(), localName.implementation());
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,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) return ((DocumentImpl *)impl)->createTreeWalker(root,whatToShow,filter,entityReferenceExpansion);
00371     return 0;
00372 }
00373 
00374 Event Document::createEvent(const DOMString &eventType)
00375 {
00376     if (!impl)
00377     throw DOMException(DOMException::INVALID_STATE_ERR);
00378 
00379     int exceptioncode = 0;
00380     EventImpl *r = ((DocumentImpl *)impl)->createEvent(eventType,exceptioncode);
00381     if (exceptioncode)
00382     throw DOMException(exceptioncode);
00383     return r;
00384 }
00385 
00386 AbstractView Document::defaultView() const
00387 {
00388     if (!impl)
00389     throw DOMException(DOMException::INVALID_STATE_ERR);
00390 
00391     return ((DocumentImpl *)impl)->defaultView();
00392 }
00393 
00394 StyleSheetList Document::styleSheets() const
00395 {
00396     if (!impl)
00397     throw DOMException(DOMException::INVALID_STATE_ERR);
00398 
00399     return ((DocumentImpl *)impl)->styleSheets();
00400 }
00401 
00402 
00403 KHTMLView *Document::view() const
00404 {
00405     if (!impl) return 0;
00406 
00407     return static_cast<DocumentImpl*>(impl)->view();
00408 }
00409 
00410 DOMString Document::completeURL(const DOMString& url)
00411 {
00412     if ( !impl ) return url;
00413     return static_cast<DocumentImpl*>( impl )->completeURL( url.string() );
00414 }
00415 
00416 CSSStyleDeclaration Document::getOverrideStyle(const Element &elt, const DOMString &pseudoElt)
00417 {
00418     if (!impl)
00419     throw DOMException(DOMException::INVALID_STATE_ERR);
00420 
00421     int exceptioncode = 0;
00422     CSSStyleDeclarationImpl *r = ((DocumentImpl *)impl)->getOverrideStyle(static_cast<ElementImpl*>(elt.handle()),pseudoElt.implementation());
00423     if (exceptioncode)
00424     throw DOMException(exceptioncode);
00425     return r;
00426 }
00427 
00428 // ----------------------------------------------------------------------------
00429 
00430 DocumentFragment::DocumentFragment() : Node()
00431 {
00432 }
00433 
00434 DocumentFragment::DocumentFragment(const DocumentFragment &other) : Node(other)
00435 {
00436 }
00437 
00438 DocumentFragment &DocumentFragment::operator = (const Node &other)
00439 {
00440     NodeImpl* ohandle = other.handle();
00441     if ( impl != ohandle ) {
00442         if (!ohandle || ohandle->nodeType() != DOCUMENT_FRAGMENT_NODE) {
00443             if ( impl ) impl->deref();
00444             impl = 0;
00445         } else {
00446             Node::operator =(other);
00447         }
00448     }
00449     return *this;
00450 }
00451 
00452 DocumentFragment &DocumentFragment::operator = (const DocumentFragment &other)
00453 {
00454     Node::operator =(other);
00455     return *this;
00456 }
00457 
00458 DocumentFragment::~DocumentFragment()
00459 {
00460 }
00461 
00462 DocumentFragment::DocumentFragment(DocumentFragmentImpl *i) : Node(i)
00463 {
00464 }
00465 
00466 // ----------------------------------------------------------------------------
00467 
00468 DocumentType::DocumentType()
00469     : Node()
00470 {
00471 }
00472 
00473 DocumentType::DocumentType(const DocumentType &other)
00474     : Node(other)
00475 {
00476 }
00477 
00478 DocumentType::DocumentType(DocumentTypeImpl *impl) : Node(impl)
00479 {
00480 }
00481 
00482 DocumentType &DocumentType::operator = (const Node &other)
00483 {
00484     NodeImpl* ohandle = other.handle();
00485     if ( impl != ohandle ) {
00486         if (!ohandle || ohandle->nodeType() != DOCUMENT_TYPE_NODE) {
00487         if ( impl ) impl->deref();
00488             impl = 0;
00489     } else {
00490             Node::operator =(other);
00491     }
00492     }
00493     return *this;
00494 }
00495 
00496 DocumentType &DocumentType::operator = (const DocumentType &other)
00497 {
00498     Node::operator =(other);
00499     return *this;
00500 }
00501 
00502 DocumentType::~DocumentType()
00503 {
00504 }
00505 
00506 DOMString DocumentType::name() const
00507 {
00508     if (!impl)
00509     return DOMString(); // ### enable throw DOMException(DOMException::NOT_FOUND_ERR);
00510 
00511     return static_cast<DocumentTypeImpl*>(impl)->name();
00512 }
00513 
00514 NamedNodeMap DocumentType::entities() const
00515 {
00516     if (!impl)
00517     return 0; // ### enable throw DOMException(DOMException::NOT_FOUND_ERR);
00518 
00519     return static_cast<DocumentTypeImpl*>(impl)->entities();
00520 }
00521 
00522 NamedNodeMap DocumentType::notations() const
00523 {
00524     if (!impl)
00525     return 0; // ### enable throw DOMException(DOMException::NOT_FOUND_ERR);
00526 
00527     return static_cast<DocumentTypeImpl*>(impl)->notations();
00528 }
00529 
00530 DOMString DocumentType::publicId() const
00531 {
00532     if (!impl)
00533     throw DOMException(DOMException::NOT_FOUND_ERR);
00534 
00535     return static_cast<DocumentTypeImpl*>(impl)->publicId();
00536 }
00537 
00538 DOMString DocumentType::systemId() const
00539 {
00540     if (!impl)
00541     throw DOMException(DOMException::NOT_FOUND_ERR);
00542 
00543     return static_cast<DocumentTypeImpl*>(impl)->systemId();
00544 }
00545 
00546 DOMString DocumentType::internalSubset() const
00547 {
00548     if (!impl)
00549     throw DOMException(DOMException::NOT_FOUND_ERR);
00550 
00551     return static_cast<DocumentTypeImpl*>(impl)->internalSubset();
00552 }
00553 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:22:35 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001