diff --git a/src/xercesc/dom/DOMDocument.hpp b/src/xercesc/dom/DOMDocument.hpp index 0cd999dfd95a85b6157bfa4a0c8aa0302dd09844..eaefd189b62a005ef928a0992cf4e49212647704 100644 --- a/src/xercesc/dom/DOMDocument.hpp +++ b/src/xercesc/dom/DOMDocument.hpp @@ -281,6 +281,7 @@ public: virtual DOMNodeList *getElementsByTagName(const XMLCh *tagname) const = 0; //@} + /** @name Functions introduced in DOM Level 2. */ //@{ @@ -536,7 +537,121 @@ public: * @since DOM Level 2 */ virtual DOMElement * getElementById(const XMLCh *elementId) const = 0; + //@} + + /** @name Functions introduced in DOM Level 3. */ + //@{ + + /** + * An attribute specifying the actual encoding of this document. This is + * <code>null</code> otherwise. + * <br> This attribute represents the property [character encoding scheme] + * defined in. + * + * <p><b>"Experimental - subject to change"</b></p> + * + * @since DOM Level 3 + */ + virtual const XMLCh* getActualEncoding() const = 0; + + /** + * An attribute specifying the actual encoding of this document. This is + * <code>null</code> otherwise. + * <br> This attribute represents the property [character encoding scheme] + * defined in . + * + * <p><b>"Experimental - subject to change"</b></p> + * + * @since DOM Level 3 + */ + virtual void setActualEncoding(const XMLCh* actualEncoding) = 0; + + /** + * An attribute specifying, as part of the XML declaration, the encoding + * of this document. This is <code>null</code> when unspecified. + * + * <p><b>"Experimental - subject to change"</b></p> + * + * @since DOM Level 3 + */ + virtual const XMLCh* getEncoding() const = 0; + + /** + * An attribute specifying, as part of the XML declaration, the encoding + * of this document. This is <code>null</code> when unspecified. + * + * <p><b>"Experimental - subject to change"</b></p> + * + * @since DOM Level 3 + */ + virtual void setEncoding(const XMLCh* encoding) = 0; + + /** + * An attribute specifying, as part of the XML declaration, whether this + * document is standalone. + * <br> This attribute represents the property [standalone] defined in . + * + * <p><b>"Experimental - subject to change"</b></p> + * + * @since DOM Level 3 + */ + virtual bool getStandalone() const = 0; + + /** + * An attribute specifying, as part of the XML declaration, whether this + * document is standalone. + * <br> This attribute represents the property [standalone] defined in . + * + * <p><b>"Experimental - subject to change"</b></p> + * + * @since DOM Level 3 + */ + virtual void setStandalone(bool standalone) = 0; + + /** + * An attribute specifying, as part of the XML declaration, the version + * number of this document. This is <code>null</code> when unspecified. + * <br> This attribute represents the property [version] defined in . + * + * <p><b>"Experimental - subject to change"</b></p> + * + * @since DOM Level 3 + */ + virtual const XMLCh* getVersion() const = 0; + /** + * An attribute specifying, as part of the XML declaration, the version + * number of this document. This is <code>null</code> when unspecified. + * <br> This attribute represents the property [version] defined in . + * + * <p><b>"Experimental - subject to change"</b></p> + * + * @since DOM Level 3 + */ + virtual void setVersion(const XMLCh* version) = 0; + + /** + * The location of the document or <code>null</code> if undefined. + * <br>Beware that when the <code>DOMDocument</code> supports the feature + * "HTML" , the href attribute of the HTML BASE element takes precedence + * over this attribute. + * + * <p><b>"Experimental - subject to change"</b></p> + * + * @since DOM Level 3 + */ + virtual const XMLCh* getDocumentURI() const = 0; + /** + * The location of the document or <code>null</code> if undefined. + * <br>Beware that when the <code>DOMDocument</code> supports the feature + * "HTML" , the href attribute of the HTML BASE element takes precedence + * over this attribute. + * + * <p><b>"Experimental - subject to change"</b></p> + * + * @since DOM Level 3 + */ + virtual void setDocumentURI(const XMLCh* documentURI) = 0; //@} // ----------------------------------------------------------------------- diff --git a/src/xercesc/dom/DOMEntity.hpp b/src/xercesc/dom/DOMEntity.hpp index 08ae70fd66aadca38907f5ae9964368b414eb73b..2e9269a8229a2da16e07598a16fa51cab16b22e5 100644 --- a/src/xercesc/dom/DOMEntity.hpp +++ b/src/xercesc/dom/DOMEntity.hpp @@ -163,6 +163,73 @@ public: virtual const XMLCh * getNotationName() const = 0; //@} + /** @name Functions introduced in DOM Level 3. */ + //@{ + + /** + * An attribute specifying the actual encoding of this entity, when it is + * an external parsed entity. This is <code>null</code> otherwise. + * + * <p><b>"Experimental - subject to change"</b></p> + * + * @since DOM Level 3 + */ + virtual const XMLCh* getActualEncoding() const = 0; + + /** + * An attribute specifying the actual encoding of this entity, when it is + * an external parsed entity. This is <code>null</code> otherwise. + * + * <p><b>"Experimental - subject to change"</b></p> + * + * @since DOM Level 3 + */ + virtual void setActualEncoding(const XMLCh* actualEncoding) = 0; + + /** + * An attribute specifying, as part of the text declaration, the encoding + * of this entity, when it is an external parsed entity. This is + * <code>null</code> otherwise. + * + * <p><b>"Experimental - subject to change"</b></p> + * + * @since DOM Level 3 + */ + virtual const XMLCh* getEncoding() const = 0; + + /** + * An attribute specifying, as part of the text declaration, the encoding + * of this entity, when it is an external parsed entity. This is + * <code>null</code> otherwise. + * + * <p><b>"Experimental - subject to change"</b></p> + * + * @since DOM Level 3 + */ + virtual void setEncoding(const XMLCh* encoding) = 0; + + /** + * An attribute specifying, as part of the text declaration, the version + * number of this entity, when it is an external parsed entity. This is + * <code>null</code> otherwise. + * + * <p><b>"Experimental - subject to change"</b></p> + * + * @since DOM Level 3 + */ + virtual const XMLCh* getVersion() const = 0; + + /** + * An attribute specifying, as part of the text declaration, the version + * number of this entity, when it is an external parsed entity. This is + * <code>null</code> otherwise. + * + * <p><b>"Experimental - subject to change"</b></p> + * + * @since DOM Level 3 + */ + virtual void setVersion(const XMLCh* version) = 0; + //@} }; #endif diff --git a/src/xercesc/dom/impl/DOMDocumentImpl.cpp b/src/xercesc/dom/impl/DOMDocumentImpl.cpp index 7526ee4d3584d94022ee4f51c098bcf3603415d7..c44a952ce1a26bdf79c5265257e1c7513bab1da1 100644 --- a/src/xercesc/dom/impl/DOMDocumentImpl.cpp +++ b/src/xercesc/dom/impl/DOMDocumentImpl.cpp @@ -125,7 +125,12 @@ DOMDocumentImpl::DOMDocumentImpl() fUserData(0), fRanges(0), fChanges(0), - fNodeListPool(0) + fNodeListPool(0), + fActualEncoding(0), + fEncoding(0), + fVersion(0), + fStandalone(false), + fDocumentURI(0) { fNamePool = new (this) DOMStringPool(257, this); }; @@ -149,7 +154,12 @@ DOMDocumentImpl::DOMDocumentImpl(const XMLCh *fNamespaceURI, fUserData(0), fRanges(0), fChanges(0), - fNodeListPool(0) + fNodeListPool(0), + fActualEncoding(0), + fEncoding(0), + fVersion(0), + fStandalone(false), + fDocumentURI(0) { fNamePool = new (this) DOMStringPool(257, this); try { @@ -1016,3 +1026,45 @@ DOMNodeList *DOMDocumentImpl::getDeepNodeList(const DOMNode *rootNode, //DOM return retList; } + +//Introduced in DOM Level 3 +const XMLCh* DOMDocumentImpl::getActualEncoding() const { + return fActualEncoding; +} + +void DOMDocumentImpl::setActualEncoding(const XMLCh* actualEncoding){ + fActualEncoding = cloneString(actualEncoding); +} + +const XMLCh* DOMDocumentImpl::getEncoding() const { + return fEncoding; +} + +void DOMDocumentImpl::setEncoding(const XMLCh* encoding){ + fEncoding = cloneString(encoding); +} + +bool DOMDocumentImpl::getStandalone() const{ + return fStandalone; +} + +void DOMDocumentImpl::setStandalone(bool standalone){ + fStandalone = standalone; +} + +const XMLCh* DOMDocumentImpl::getVersion() const { + return fVersion; +} + +void DOMDocumentImpl::setVersion(const XMLCh* version){ + fVersion = cloneString(version); +} + +const XMLCh* DOMDocumentImpl::getDocumentURI() const { + return fDocumentURI; +} + +void DOMDocumentImpl::setDocumentURI(const XMLCh* documentURI){ + fDocumentURI = cloneString(documentURI); +} + diff --git a/src/xercesc/dom/impl/DOMDocumentImpl.hpp b/src/xercesc/dom/impl/DOMDocumentImpl.hpp index a276aa3c87af58d45bbac361ae11bb980d33361b..b64ed02ebae28734304dc5f89dc2e51bcb7e5c4a 100644 --- a/src/xercesc/dom/impl/DOMDocumentImpl.hpp +++ b/src/xercesc/dom/impl/DOMDocumentImpl.hpp @@ -134,6 +134,13 @@ public: bool errorChecking; // Bypass error checking. + // New data introduced in DOM Level 3 + XMLCh* fActualEncoding; + XMLCh* fEncoding; + bool fStandalone; + XMLCh* fVersion; + XMLCh* fDocumentURI; + // Per-Document heap Variables. // The heap consists of one or more biggish blocks which are @@ -180,6 +187,7 @@ public: // Add all functions that are pure virutal in DOMNODE DOMNODE_FUNCTIONS; + // Add all functions that are pure virutal in DOMDocument virtual DOMAttr *createAttribute(const XMLCh *name); virtual DOMCDATASection *createCDATASection(const XMLCh *data); virtual DOMComment *createComment(const XMLCh *data); @@ -270,6 +278,18 @@ public: const XMLCh *localName) const; virtual DOMElement *getElementById(const XMLCh *elementId) const; + //Introduced in DOM Level 3 + virtual const XMLCh* getActualEncoding() const; + virtual void setActualEncoding(const XMLCh* actualEncoding); + virtual const XMLCh* getEncoding() const; + virtual void setEncoding(const XMLCh* encoding); + virtual bool getStandalone() const; + virtual void setStandalone(bool standalone); + virtual const XMLCh* getVersion() const; + virtual void setVersion(const XMLCh* version); + virtual const XMLCh* getDocumentURI() const; + virtual void setDocumentURI(const XMLCh* documentURI); + //Return the index > 0 of ':' in the given qualified name qName="prefix:localName". //Return 0 if there is no ':', or -1 if qName is malformed such as ":abcd". diff --git a/src/xercesc/dom/impl/DOMEntityImpl.cpp b/src/xercesc/dom/impl/DOMEntityImpl.cpp index 46c2d4e5b4c77ed72e135d4df5203de2d2f3a8c1..ba6a1068bd4eafe41ace73e0b7be13400e794a53 100644 --- a/src/xercesc/dom/impl/DOMEntityImpl.cpp +++ b/src/xercesc/dom/impl/DOMEntityImpl.cpp @@ -66,7 +66,13 @@ DOMEntityImpl::DOMEntityImpl(DOMDocument *ownerDoc, const XMLCh *eName) - : fNode(ownerDoc), fParent(ownerDoc), fPublicId(0), fSystemId(0) + : fNode(ownerDoc), + fParent(ownerDoc), + fPublicId(0), + fSystemId(0), + fActualEncoding(0), + fEncoding(0), + fVersion(0) { fRefEntity = 0; fName = ((DOMDocumentImpl *)ownerDoc)->getPooledString(eName); @@ -75,7 +81,11 @@ DOMEntityImpl::DOMEntityImpl(DOMDocument *ownerDoc, const XMLCh *eName) DOMEntityImpl::DOMEntityImpl(const DOMEntityImpl &other, bool deep) - : fNode(other.fNode), fParent(other.fParent) + : fNode(other.fNode), + fParent(other.fParent), + fActualEncoding(other.fActualEncoding), + fEncoding(other.fEncoding), + fVersion(other.fVersion) { fName = other.fName; if (deep) @@ -232,3 +242,32 @@ bool DOMEntityImpl::hasChildNodes() const {return fNode.isSupported (feature, version); }; void DOMEntityImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); }; bool DOMEntityImpl::hasAttributes() const {return fNode.hasAttributes(); }; + +//Introduced in DOM Level 3 +const XMLCh* DOMEntityImpl::getActualEncoding() const { + return fActualEncoding; +} + +void DOMEntityImpl::setActualEncoding(const XMLCh* actualEncoding){ + DOMDocumentImpl *doc = (DOMDocumentImpl *)this->getOwnerDocument(); + fActualEncoding = doc->cloneString(actualEncoding); +} + +const XMLCh* DOMEntityImpl::getEncoding() const { + return fEncoding; +} + +void DOMEntityImpl::setEncoding(const XMLCh* encoding){ + DOMDocumentImpl *doc = (DOMDocumentImpl *)this->getOwnerDocument(); + fEncoding = doc->cloneString(encoding); +} + +const XMLCh* DOMEntityImpl::getVersion() const { + return fVersion; +} + +void DOMEntityImpl::setVersion(const XMLCh* version){ + DOMDocumentImpl *doc = (DOMDocumentImpl *)this->getOwnerDocument(); + fVersion = doc->cloneString(version); +} + diff --git a/src/xercesc/dom/impl/DOMEntityImpl.hpp b/src/xercesc/dom/impl/DOMEntityImpl.hpp index 333ab1711e83fd43adbebe8caa2c344c29e5b69f..99ee9ebafe9aae59f5a03c9e2ad4592e9d1dc897 100644 --- a/src/xercesc/dom/impl/DOMEntityImpl.hpp +++ b/src/xercesc/dom/impl/DOMEntityImpl.hpp @@ -87,9 +87,16 @@ private: const XMLCh * fSystemId; const XMLCh * fNotationName; DOMEntityReference* fRefEntity; - void cloneEntityRefTree() const; - friend class XercesDOMParser; + // New data introduced in DOM Level 3 + XMLCh* fActualEncoding; + XMLCh* fEncoding; + XMLCh* fVersion; + + // private helper function + void cloneEntityRefTree() const; + + friend class XercesDOMParser; public: DOMEntityImpl(DOMDocument *doc, const XMLCh *eName); @@ -107,9 +114,17 @@ public: virtual void setPublicId(const XMLCh *arg); virtual void setSystemId(const XMLCh *arg); - //DOM Level 2 additions. Non standard functions - virtual void setEntityRef(DOMEntityReference *); - virtual DOMEntityReference* getEntityRef() const; + //DOM Level 2 additions. Non standard functions + virtual void setEntityRef(DOMEntityReference *); + virtual DOMEntityReference* getEntityRef() const; + + //Introduced in DOM Level 3 + virtual const XMLCh* getActualEncoding() const; + virtual void setActualEncoding(const XMLCh* actualEncoding); + virtual const XMLCh* getEncoding() const; + virtual void setEncoding(const XMLCh* encoding); + virtual const XMLCh* getVersion() const; + virtual void setVersion(const XMLCh* version); }; #endif diff --git a/src/xercesc/parsers/AbstractDOMParser.cpp b/src/xercesc/parsers/AbstractDOMParser.cpp index ab7335fb2623da97be838debf0a76004fb75f7c6..41a4901af492de6f36ae22e8081f430a6d4d7ea0 100644 --- a/src/xercesc/parsers/AbstractDOMParser.cpp +++ b/src/xercesc/parsers/AbstractDOMParser.cpp @@ -108,6 +108,7 @@ AbstractDOMParser::AbstractDOMParser(XMLValidator* const valToAdopt) : , fScanner(0) , fCurrentParent(0) , fCurrentNode(0) +, fCurrentEntity(0) , fDocument(0) , fNodeStack(0) , fDocumentType(0) @@ -155,6 +156,7 @@ void AbstractDOMParser::reset() fCurrentParent = 0; fCurrentNode = 0; + fCurrentEntity = 0; fParseInProgress = false; fWithinElement = false; fNodeStack->removeAllElements(); @@ -577,6 +579,9 @@ void AbstractDOMParser::startDocument() fCurrentNode = fDocument; // set DOM error checking off fDocument->setErrorChecking(false); + + fDocument->setDocumentURI(fScanner->getLocator()->getSystemId()); + fDocument->setActualEncoding(fScanner->getReaderMgr()->getCurrentEncodingStr()); } @@ -695,9 +700,14 @@ void AbstractDOMParser::startElement(const XMLElementDecl& elemDecl void AbstractDOMParser::startEntityReference(const XMLEntityDecl& entDecl) { + const XMLCh * entName = entDecl.getName(); + DOMNamedNodeMap *entities = fDocumentType->getEntities(); + DOMEntityImpl* entity = (DOMEntityImpl*)entities->getNamedItem(entName); + entity->setActualEncoding(fScanner->getReaderMgr()->getCurrentEncodingStr()); + fCurrentEntity = entity; + if (fCreateEntityReferenceNodes == true) - { - const XMLCh * entName = entDecl.getName(); + { DOMEntityReference *er = fDocument->createEntityReference(entName); //set the readOnly flag to false before appending node, will be reset in endEntityReference @@ -713,10 +723,7 @@ void AbstractDOMParser::startEntityReference(const XMLEntityDecl& entDecl) // We'd decide later whether the entity nodes should be created by a // separated method in parser or not. For now just stick it in if // the ref nodes are created - DOMNamedNodeMap *entities = fDocumentType->getEntities(); - DOMEntityImpl* entity = (DOMEntityImpl*)entities->getNamedItem(entName); entity->setEntityRef(er); - } } @@ -726,7 +733,14 @@ void AbstractDOMParser::XMLDecl(const XMLCh* const version , const XMLCh* const standalone , const XMLCh* const actualEncStr) { - // placehold for DOM Level 3 + const XMLCh standalone_true[] = { + chLatin_t, chLatin_r, chLatin_u, chLatin_e, chNull + }; + fDocument->setStandalone(!XMLString::compareString(standalone_true, standalone)); + + fDocument->setVersion(version); + fDocument->setEncoding(encoding); + fDocument->setActualEncoding(actualEncStr); } // --------------------------------------------------------------------------- @@ -1197,4 +1211,8 @@ void AbstractDOMParser::TextDecl , const XMLCh* const encodingStr ) { + if (fCurrentEntity) { + fCurrentEntity->setVersion(versionStr); + fCurrentEntity->setEncoding(encodingStr); + } } diff --git a/src/xercesc/parsers/AbstractDOMParser.hpp b/src/xercesc/parsers/AbstractDOMParser.hpp index 00a0f05cacb3d3bb6709ce5e2b8b5a5080bf66dd..f30212f15e417af8b85a75e944f1f311c3bc77b6 100644 --- a/src/xercesc/parsers/AbstractDOMParser.hpp +++ b/src/xercesc/parsers/AbstractDOMParser.hpp @@ -1260,6 +1260,10 @@ private : // the tree must be built from a set of disjoint callbacks, we need // these to keep up with where we currently are. // + // fCurrentEntity + // Used to track the current entity decl. If a text decl is seen later on, + // it is used to update the encoding and version information. + // // fDocument // The root document object, filled with the document contents. // @@ -1301,6 +1305,7 @@ private : XMLScanner* fScanner; DOMNode* fCurrentParent; DOMNode* fCurrentNode; + DOMEntity* fCurrentEntity; DOMDocumentImpl* fDocument; ValueStackOf<DOMNode*>* fNodeStack; DOMDocumentTypeImpl* fDocumentType;