dom_xmlimpl.cpp Source File (khtml Library)

| # khtml Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# dom_xmlimpl.cpp

    00001
    00022 #include "dom/dom_exception.h"
    00023
    00024 #include "xml/dom_xmlimpl.h"
    00025 #include "xml/dom_docimpl.h"
    00026 #include "xml/dom_stringimpl.h"
    00027 #include "css/css_stylesheetimpl.h"
    00028 #include "misc/loader.h"
    00029
    00030 using namespace DOM;
    00031
    00032 EntityImpl::EntityImpl(DocumentPtr *doc) : NodeBaseImpl(doc)
    00033 {
    00034     m_publicId = 0;
    00035     m_systemId = 0;
    00036     m_notationName = 0;
    00037     m_name = 0;
    00038 }
    00039
    00040 EntityImpl::EntityImpl(DocumentPtr *doc, DOMString _name) : NodeBaseImpl(doc)
    00041 {
    00042     m_publicId = 0;
    00043     m_systemId = 0;
    00044     m_notationName = 0;
    00045     m_name = _name.implementation();
    00046     if (m_name)
    00047         m_name->ref();
    00048 }
    00049
    00050 EntityImpl::EntityImpl(DocumentPtr *doc, DOMString _publicId, DOMString _systemId, DOMString _notationName) : NodeBaseImpl(doc)
    00051 {
    00052     m_publicId = _publicId.implementation();
    00053     if (m_publicId)
    00054         m_publicId->ref();
    00055     m_systemId = _systemId.implementation();
    00056     if (m_systemId)
    00057         m_systemId->ref();
    00058     m_notationName = _notationName.implementation();
    00059     if (m_notationName)
    00060         m_notationName->ref();
    00061     m_name = 0;
    00062 }
    00063
    00064
    00065 EntityImpl::~EntityImpl()
    00066 {
    00067     if (m_publicId)
    00068         m_publicId->deref();
    00069     if (m_systemId)
    00070         m_systemId->deref();
    00071     if (m_notationName)
    00072         m_notationName->deref();
    00073     if (m_name)
    00074         m_name->deref();
    00075 }
    00076
    00077 DOMString EntityImpl::publicId() const
    00078 {
    00079     return m_publicId;
    00080 }
    00081
    00082 DOMString EntityImpl::systemId() const
    00083 {
    00084     return m_systemId;
    00085 }
    00086
    00087 DOMString EntityImpl::notationName() const
    00088 {
    00089     return m_notationName;
    00090 }
    00091
    00092 DOMString EntityImpl::nodeName() const
    00093 {
    00094     return m_name;
    00095 }
    00096
    00097 unsigned short EntityImpl::nodeType() const
    00098 {
    00099     return Node::ENTITY_NODE;
    00100 }
    00101
    00102 NodeImpl *EntityImpl::cloneNode ( bool /*deep*/)
    00103 {
    00104     // Spec says cloning Document nodes is "implementation dependent"
    00105     // so we do not support it...
    00106     return 0;
    00107 }
    00108
    00109 // DOM Section 1.1.1
    00110 bool EntityImpl::childTypeAllowed( unsigned short type )
    00111 {
    00112     switch (type) {
    00113         case Node::ELEMENT_NODE:
    00114         case Node::PROCESSING_INSTRUCTION_NODE:
    00115         case Node::COMMENT_NODE:
    00116         case Node::TEXT_NODE:
    00117         case Node::CDATA_SECTION_NODE:
    00118         case Node::ENTITY_REFERENCE_NODE:
    00119             return true;
    00120             break;
    00121         default:
    00122             return false;
    00123     }
    00124 }
    00125
    00126 // -------------------------------------------------------------------------
    00127
    00128 EntityReferenceImpl::EntityReferenceImpl(DocumentPtr *doc) : NodeBaseImpl(doc)
    00129 {
    00130     m_entityName = 0;
    00131 }
    00132
    00133 EntityReferenceImpl::EntityReferenceImpl(DocumentPtr *doc, DOMStringImpl *_entityName) : NodeBaseImpl(doc)
    00134 {
    00135     m_entityName = _entityName;
    00136     if (m_entityName)
    00137         m_entityName->ref();
    00138 }
    00139
    00140 EntityReferenceImpl::~EntityReferenceImpl()
    00141 {
    00142     if (m_entityName)
    00143         m_entityName->deref();
    00144 }
    00145
    00146 DOMString EntityReferenceImpl::nodeName() const
    00147 {
    00148     return m_entityName;
    00149 }
    00150
    00151 unsigned short EntityReferenceImpl::nodeType() const
    00152 {
    00153     return Node::ENTITY_REFERENCE_NODE;
    00154 }
    00155
    00156 NodeImpl *EntityReferenceImpl::cloneNode ( bool deep )
    00157 {
    00158     EntityReferenceImpl *clone = new EntityReferenceImpl(docPtr(),m_entityName);
    00159     // ### make sure children are readonly
    00160     // ### since we are a reference, should we clone children anyway (even if not deep?)
    00161     if (deep)
    00162         cloneChildNodes(clone);
    00163     return clone;
    00164 }
    00165
    00166 // DOM Section 1.1.1
    00167 bool EntityReferenceImpl::childTypeAllowed( unsigned short type )
    00168 {
    00169     switch (type) {
    00170         case Node::ELEMENT_NODE:
    00171         case Node::PROCESSING_INSTRUCTION_NODE:
    00172         case Node::COMMENT_NODE:
    00173         case Node::TEXT_NODE:
    00174         case Node::CDATA_SECTION_NODE:
    00175         case Node::ENTITY_REFERENCE_NODE:
    00176             return true;
    00177             break;
    00178         default:
    00179             return false;
    00180     }
    00181 }
    00182
    00183 // -------------------------------------------------------------------------
    00184
    00185 NotationImpl::NotationImpl(DocumentPtr *doc) : NodeBaseImpl(doc)
    00186 {
    00187     m_publicId = 0;
    00188     m_systemId = 0;
    00189     m_name = 0;
    00190 }
    00191
    00192 NotationImpl::NotationImpl(DocumentPtr *doc, DOMString _name, DOMString _publicId, DOMString _systemId) : NodeBaseImpl(doc)
    00193 {
    00194     m_name = _name.implementation();
    00195     if (m_name)
    00196         m_name->ref();
    00197     m_publicId = _publicId.implementation();
    00198     if (m_publicId)
    00199         m_publicId->ref();
    00200     m_systemId = _systemId.implementation();
    00201     if (m_systemId)
    00202         m_systemId->ref();
    00203 }
    00204
    00205 NotationImpl::~NotationImpl()
    00206 {
    00207     if (m_name)
    00208         m_name->deref();
    00209     if (m_publicId)
    00210         m_publicId->deref();
    00211     if (m_systemId)
    00212         m_systemId->deref();
    00213 }
    00214
    00215 DOMString NotationImpl::publicId() const
    00216 {
    00217     return m_publicId;
    00218 }
    00219
    00220 DOMString NotationImpl::systemId() const
    00221 {
    00222     return m_systemId;
    00223 }
    00224
    00225 DOMString NotationImpl::nodeName() const
    00226 {
    00227     return m_name;
    00228 }
    00229
    00230 unsigned short NotationImpl::nodeType() const
    00231 {
    00232     return Node::NOTATION_NODE;
    00233 }
    00234
    00235 NodeImpl *NotationImpl::cloneNode ( bool /*deep*/)
    00236 {
    00237     // Spec says cloning Document nodes is "implementation dependent"
    00238     // so we do not support it...
    00239     return 0;
    00240 }
    00241
    00242 // DOM Section 1.1.1
    00243 bool NotationImpl::childTypeAllowed( unsigned short /*type*/ )
    00244 {
    00245     return false;
    00246 }
    00247
    00248 // -------------------------------------------------------------------------
    00249
    00250 // ### need a way of updating these properly whenever child nodes of the processing instruction
    00251 // change or are added/removed
    00252
    00253 ProcessingInstructionImpl::ProcessingInstructionImpl(DocumentPtr *doc) : NodeBaseImpl(doc)
    00254 {
    00255     m_target = 0;
    00256     m_data = 0;
    00257     m_localHref = 0;
    00258     m_sheet = 0;
    00259     m_cachedSheet = 0;
    00260 }
    00261
    00262 ProcessingInstructionImpl::ProcessingInstructionImpl(DocumentPtr *doc, DOMString _target, DOMString _data) : NodeBaseImpl(doc)
    00263 {
    00264     m_target = _target.implementation();
    00265     if (m_target)
    00266         m_target->ref();
    00267     m_data = _data.implementation();
    00268     if (m_data)
    00269         m_data->ref();
    00270     m_sheet = 0;
    00271     m_cachedSheet = 0;
    00272     m_localHref = 0;
    00273 }
    00274
    00275 ProcessingInstructionImpl::~ProcessingInstructionImpl()
    00276 {
    00277     if (m_target)
    00278         m_target->deref();
    00279     if (m_data)
    00280         m_data->deref();
    00281     if (m_cachedSheet)
    00282         m_cachedSheet->deref(this);
    00283     if (m_sheet)
    00284         m_sheet->deref();
    00285 }
    00286
    00287 DOMString ProcessingInstructionImpl::target() const
    00288 {
    00289     return m_target;
    00290 }
    00291
    00292 void ProcessingInstructionImpl::setData( const DOMString &_data, int &exceptioncode )
    00293 {
    00294     // NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
    00295     if (isReadOnly()) {
    00296         exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR;
    00297         return;
    00298     }
    00299
    00300     if (m_data)
    00301         m_data->deref();
    00302     m_data = _data.implementation();
    00303     if (m_data)
    00304         m_data->ref();
    00305 }
    00306
    00307 DOMString ProcessingInstructionImpl::nodeName() const
    00308 {
    00309     return m_target;
    00310 }
    00311
    00312 unsigned short ProcessingInstructionImpl::nodeType() const
    00313 {
    00314     return Node::PROCESSING_INSTRUCTION_NODE;
    00315 }
    00316
    00317 DOMString ProcessingInstructionImpl::nodeValue() const
    00318 {
    00319     return m_data;
    00320 }
    00321
    00322 void ProcessingInstructionImpl::setNodeValue( const DOMString &_nodeValue, int &exceptioncode )
    00323 {
    00324     // NO_MODIFICATION_ALLOWED_ERR: taken care of by setData()
    00325     setData(_nodeValue, exceptioncode);
    00326 }
    00327
    00328 NodeImpl *ProcessingInstructionImpl::cloneNode ( bool /*deep*/)
    00329 {
    00330     // ### copy m_localHref
    00331     return new ProcessingInstructionImpl(docPtr(),m_target,m_data);
    00332 }
    00333
    00334 DOMString ProcessingInstructionImpl::localHref() const
    00335 {
    00336     return m_localHref;
    00337 }
    00338
    00339 // DOM Section 1.1.1
    00340 bool ProcessingInstructionImpl::childTypeAllowed( unsigned short /*type*/ )
    00341 {
    00342     return false;
    00343 }
    00344
    00345 void ProcessingInstructionImpl::checkStyleSheet()
    00346 {
    00347     if (m_target && DOMString(m_target) == "xml-stylesheet") {
    00348         // see http://www.w3.org/TR/xml-stylesheet/
    00349         // ### check that this occurs only in the prolog
    00350         // ### support stylesheet included in a fragment of this (or another) document
    00351         // ### make sure this gets called when adding from javascript
    00352         XMLAttributeReader attrReader(DOMString(m_data).string());
    00353         bool attrsOk;
    00354         QXmlAttributes attrs = attrReader.readAttrs(attrsOk);
    00355         if (!attrsOk)
    00356             return;
    00357         if (attrs.value("type") != "text/css")
    00358             return;
    00359
    00360         DOMString href = attrs.value("href");
    00361
    00362         if (href.length()>1)
    00363         {
    00364             if (href[0]=='#')
    00365             {
    00366                 if (m_localHref)
    00367                     m_localHref->deref();
    00368                 m_localHref=href.implementation()->split(1);
    00369                 if (m_localHref)
    00370                     m_localHref->ref();
    00371             }
    00372             else
    00373             {
    00374                 // ### some validation on the URL?
    00375                 // ### FIXME charset
    00376                 if (m_cachedSheet) m_cachedSheet->deref(this);
    00377                 m_cachedSheet = getDocument()->docLoader()->requestStyleSheet(getDocument()->completeURL(href.string()), QString::null);
    00378                 if (m_cachedSheet)
    00379                     m_cachedSheet->ref( this );
    00380             }
    00381
    00382         }
    00383     }
    00384 }
    00385
    00386 StyleSheetImpl *ProcessingInstructionImpl::sheet() const
    00387 {
    00388     return m_sheet;
    00389 }
    00390
    00391 void ProcessingInstructionImpl::setStyleSheet(const DOM::DOMString &url, const DOM::DOMString &sheet)
    00392 {
    00393     if (m_sheet)
    00394         m_sheet->deref();
    00395     m_sheet = new CSSStyleSheetImpl(getDocument(), url);
    00396     m_sheet->ref();
    00397     m_sheet->parseString(sheet);
    00398     if (m_cachedSheet)
    00399         m_cachedSheet->deref(this);
    00400     m_cachedSheet = 0;
    00401
    00402     getDocument()->updateStyleSelector();
    00403 }
    00404
    00405 void ProcessingInstructionImpl::setStyleSheet(CSSStyleSheetImpl* sheet)
    00406 {
    00407     if (m_sheet)
    00408         m_sheet->deref();
    00409     m_sheet = sheet;
    00410     if (m_sheet)
    00411         m_sheet->ref();
    00412 }
    00413
    00414 // -------------------------------------------------------------------------
    00415
    00416 XMLAttributeReader::XMLAttributeReader(QString _attrString)
    00417 {
    00418     m_attrString = _attrString;
    00419 }
    00420
    00421 XMLAttributeReader::~XMLAttributeReader()
    00422 {
    00423 }
    00424
    00425 QXmlAttributes XMLAttributeReader::readAttrs(bool &ok)
    00426 {
    00427     // parse xml file
    00428     QXmlInputSource source;
    00429     source.setData("<?xml version=\"1.0\"?><attrs "+m_attrString+" />");
    00430     QXmlSimpleReader reader;
    00431     reader.setContentHandler( this );
    00432     ok = reader.parse( source );
    00433     return attrs;
    00434 }
    00435
    00436 bool XMLAttributeReader::startElement(const QString& /*namespaceURI*/, const QString& localName,
    00437                                       const QString& /*qName*/, const QXmlAttributes& atts)
    00438 {
    00439     if (localName == "attrs") {
    00440         attrs = atts;
    00441         return true;
    00442     }
    00443     else
    00444         return false; // we shouldn't have any other elements
    00445 }

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:33:49 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001