Skip to content
Snippets Groups Projects
Commit d88417c9 authored by Tinny Ng's avatar Tinny Ng
Browse files

DOM Fix: Misc Range related fixes

git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@174637 13f79535-47bb-0310-9956-ffa450edef68
parent c67e8415
No related branches found
No related tags found
No related merge requests found
...@@ -251,6 +251,18 @@ void DOMCharacterDataImpl::insertData(const DOMNode *node, XMLSize_t offset, con ...@@ -251,6 +251,18 @@ void DOMCharacterDataImpl::insertData(const DOMNode *node, XMLSize_t offset, con
if (newLen >= 3999) if (newLen >= 3999)
delete[] newString; delete[] newString;
if (node->getOwnerDocument() != 0) {
Ranges* ranges = ((DOMDocumentImpl *)node->getOwnerDocument())->getRanges();
if (ranges != 0) {
XMLSize_t sz = ranges->size();
if (sz != 0) {
for (XMLSize_t i =0; i<sz; i++) {
ranges->elementAt(i)->updateRangeForInsertedText( (DOMNode*)node, offset, datLen);
}
}
}
}
} }
...@@ -271,9 +283,7 @@ void DOMCharacterDataImpl::replaceData(const DOMNode *node, XMLSize_t offset, XM ...@@ -271,9 +283,7 @@ void DOMCharacterDataImpl::replaceData(const DOMNode *node, XMLSize_t offset, XM
void DOMCharacterDataImpl::setData(const DOMNode *node, const XMLCh *arg) void DOMCharacterDataImpl::setData(const DOMNode *node, const XMLCh *arg)
{ {
if (castToNodeImpl(node)->isReadOnly()) setNodeValue(node, arg);
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0);
fDataBuf->set(arg);
}; };
......
...@@ -60,8 +60,10 @@ ...@@ -60,8 +60,10 @@
#include "DOMCommentImpl.hpp" #include "DOMCommentImpl.hpp"
#include "DOMCharacterDataImpl.hpp" #include "DOMCharacterDataImpl.hpp"
#include "DOMStringPool.hpp"
#include "DOMCasts.hpp" #include "DOMCasts.hpp"
#include "DOMDocumentImpl.hpp" #include "DOMDocumentImpl.hpp"
#include "DOMRangeImpl.hpp"
#include <xercesc/dom/DOMNode.hpp> #include <xercesc/dom/DOMNode.hpp>
#include <xercesc/dom/DOMException.hpp> #include <xercesc/dom/DOMException.hpp>
#include <xercesc/util/XMLUniDefs.hpp> #include <xercesc/util/XMLUniDefs.hpp>
...@@ -127,6 +129,44 @@ void DOMCommentImpl::release() ...@@ -127,6 +129,44 @@ void DOMCommentImpl::release()
} }
// Non standard extension for the range to work
DOMComment *DOMCommentImpl::splitText(XMLSize_t offset)
{
if (fNode.isReadOnly())
{
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0);
}
XMLSize_t len = fCharacterData.fDataBuf->getLen();
if (offset > len || offset < 0)
throw DOMException(DOMException::INDEX_SIZE_ERR, 0);
DOMComment *newText =
getOwnerDocument()->createComment(
this->substringData(offset, len - offset));
DOMNode *parent = getParentNode();
if (parent != 0)
parent->insertBefore(newText, getNextSibling());
fCharacterData.fDataBuf->chop(offset);
if (this->getOwnerDocument() != 0) {
Ranges* ranges = ((DOMDocumentImpl *)this->getOwnerDocument())->getRanges();
if (ranges != 0) {
XMLSize_t sz = ranges->size();
if (sz != 0) {
for (XMLSize_t i =0; i<sz; i++) {
ranges->elementAt(i)->updateSplitInfo( this, newText, offset);
}
}
}
}
return newText;
};
DOMNode* DOMCommentImpl::appendChild(DOMNode *newChild) {return fNode.appendChild (newChild); }; DOMNode* DOMCommentImpl::appendChild(DOMNode *newChild) {return fNode.appendChild (newChild); };
DOMNamedNodeMap* DOMCommentImpl::getAttributes() const {return fNode.getAttributes (); }; DOMNamedNodeMap* DOMCommentImpl::getAttributes() const {return fNode.getAttributes (); };
DOMNodeList* DOMCommentImpl::getChildNodes() const {return fNode.getChildNodes (); }; DOMNodeList* DOMCommentImpl::getChildNodes() const {return fNode.getChildNodes (); };
......
...@@ -107,6 +107,9 @@ public: ...@@ -107,6 +107,9 @@ public:
virtual void setData(const XMLCh * arg); virtual void setData(const XMLCh * arg);
virtual const XMLCh * substringData(XMLSize_t offset, XMLSize_t count) const; virtual const XMLCh * substringData(XMLSize_t offset, XMLSize_t count) const;
// Non standard extension for the range to work
DOMComment* splitText(XMLSize_t offset);
}; };
XERCES_CPP_NAMESPACE_END XERCES_CPP_NAMESPACE_END
......
...@@ -61,6 +61,8 @@ ...@@ -61,6 +61,8 @@
#include "DOMProcessingInstructionImpl.hpp" #include "DOMProcessingInstructionImpl.hpp"
#include "DOMDocumentImpl.hpp" #include "DOMDocumentImpl.hpp"
#include "DOMNodeImpl.hpp" #include "DOMNodeImpl.hpp"
#include "DOMStringPool.hpp"
#include "DOMRangeImpl.hpp"
#include <xercesc/dom/DOMException.hpp> #include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMNode.hpp> #include <xercesc/dom/DOMNode.hpp>
...@@ -71,22 +73,20 @@ XERCES_CPP_NAMESPACE_BEGIN ...@@ -71,22 +73,20 @@ XERCES_CPP_NAMESPACE_BEGIN
DOMProcessingInstructionImpl::DOMProcessingInstructionImpl(DOMDocument *ownerDoc, DOMProcessingInstructionImpl::DOMProcessingInstructionImpl(DOMDocument *ownerDoc,
const XMLCh *targt, const XMLCh *targt,
const XMLCh *dat) const XMLCh *dat)
: fNode(ownerDoc), fBaseURI(0) : fNode(ownerDoc), fBaseURI(0), fCharacterData(ownerDoc, dat)
{ {
fNode.setIsLeafNode(true); fNode.setIsLeafNode(true);
this->fTarget = ((DOMDocumentImpl *)ownerDoc)->cloneString(targt); this->fTarget = ((DOMDocumentImpl *)ownerDoc)->cloneString(targt);
this->fData = ((DOMDocumentImpl *)ownerDoc)->cloneString(dat);
}; };
DOMProcessingInstructionImpl::DOMProcessingInstructionImpl( DOMProcessingInstructionImpl::DOMProcessingInstructionImpl(
const DOMProcessingInstructionImpl &other, const DOMProcessingInstructionImpl &other,
bool deep) bool deep)
: fNode(other.fNode), fChild(other.fChild) : fNode(other.fNode), fChild(other.fChild), fCharacterData(other.fCharacterData)
{ {
fNode.setIsLeafNode(true); fNode.setIsLeafNode(true);
fTarget = other.fTarget; fTarget = other.fTarget;
fData = other.fData;
fBaseURI = other.fBaseURI; fBaseURI = other.fBaseURI;
}; };
...@@ -115,26 +115,6 @@ short DOMProcessingInstructionImpl::getNodeType() const { ...@@ -115,26 +115,6 @@ short DOMProcessingInstructionImpl::getNodeType() const {
}; };
const XMLCh * DOMProcessingInstructionImpl::getNodeValue() const
{
return fData;
};
void DOMProcessingInstructionImpl::setNodeValue(const XMLCh *value)
{
if (fNode.isReadOnly())
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0);
fData = ((DOMDocumentImpl *)getOwnerDocument())->cloneString(value);
};
const XMLCh * DOMProcessingInstructionImpl::getData() const
{
return fData;
};
/** A PI's "target" states what processor channel the PI's data /** A PI's "target" states what processor channel the PI's data
should be directed to. It is defined differently in HTML and XML. should be directed to. It is defined differently in HTML and XML.
...@@ -151,20 +131,6 @@ const XMLCh * DOMProcessingInstructionImpl::getTarget() const ...@@ -151,20 +131,6 @@ const XMLCh * DOMProcessingInstructionImpl::getTarget() const
}; };
/**
* Change the data content of this PI.
* Note that setNodeValue is aliased to setData
* @see getData().
* @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if node is read-only.
*/
void DOMProcessingInstructionImpl::setData(const XMLCh *arg)
{
if (fNode.isReadOnly())
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR,
0);
fData = ((DOMDocumentImpl *)getOwnerDocument())->cloneString(arg);
};
void DOMProcessingInstructionImpl::release() void DOMProcessingInstructionImpl::release()
{ {
if (fNode.isOwned() && !fNode.isToBeReleased()) if (fNode.isOwned() && !fNode.isToBeReleased())
...@@ -173,6 +139,7 @@ void DOMProcessingInstructionImpl::release() ...@@ -173,6 +139,7 @@ void DOMProcessingInstructionImpl::release()
DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument(); DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
if (doc) { if (doc) {
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0); fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
fCharacterData.releaseBuffer();
doc->release(this, DOMDocumentImpl::PROCESSING_INSTRUCTION_OBJECT); doc->release(this, DOMDocumentImpl::PROCESSING_INSTRUCTION_OBJECT);
} }
else { else {
...@@ -190,6 +157,43 @@ const XMLCh* DOMProcessingInstructionImpl::getBaseURI() const ...@@ -190,6 +157,43 @@ const XMLCh* DOMProcessingInstructionImpl::getBaseURI() const
return fBaseURI? fBaseURI : fNode.fOwnerNode->getBaseURI(); return fBaseURI? fBaseURI : fNode.fOwnerNode->getBaseURI();
} }
// Non standard extension for the range to work
DOMProcessingInstruction *DOMProcessingInstructionImpl::splitText(XMLSize_t offset)
{
if (fNode.isReadOnly())
{
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0);
}
XMLSize_t len = fCharacterData.fDataBuf->getLen();
if (offset > len || offset < 0)
throw DOMException(DOMException::INDEX_SIZE_ERR, 0);
DOMProcessingInstruction *newText =
getOwnerDocument()->createProcessingInstruction(fTarget,
this->substringData(offset, len - offset));
DOMNode *parent = getParentNode();
if (parent != 0)
parent->insertBefore(newText, getNextSibling());
fCharacterData.fDataBuf->chop(offset);
if (this->getOwnerDocument() != 0) {
Ranges* ranges = ((DOMDocumentImpl *)this->getOwnerDocument())->getRanges();
if (ranges != 0) {
XMLSize_t sz = ranges->size();
if (sz != 0) {
for (XMLSize_t i =0; i<sz; i++) {
ranges->elementAt(i)->updateSplitInfo( this, newText, offset);
}
}
}
}
return newText;
};
// //
// Delegation stubs for inherited functions // Delegation stubs for inherited functions
// //
...@@ -201,6 +205,7 @@ const XMLCh* DOMProcessingInstructionImpl::getBaseURI() const ...@@ -201,6 +205,7 @@ const XMLCh* DOMProcessingInstructionImpl::getBaseURI() const
const XMLCh* DOMProcessingInstructionImpl::getLocalName() const {return fNode.getLocalName (); }; const XMLCh* DOMProcessingInstructionImpl::getLocalName() const {return fNode.getLocalName (); };
const XMLCh* DOMProcessingInstructionImpl::getNamespaceURI() const {return fNode.getNamespaceURI (); }; const XMLCh* DOMProcessingInstructionImpl::getNamespaceURI() const {return fNode.getNamespaceURI (); };
DOMNode* DOMProcessingInstructionImpl::getNextSibling() const {return fChild.getNextSibling (); }; DOMNode* DOMProcessingInstructionImpl::getNextSibling() const {return fChild.getNextSibling (); };
const XMLCh* DOMProcessingInstructionImpl::getNodeValue() const {return fCharacterData.getNodeValue (); };
DOMDocument* DOMProcessingInstructionImpl::getOwnerDocument() const {return fNode.getOwnerDocument (); }; DOMDocument* DOMProcessingInstructionImpl::getOwnerDocument() const {return fNode.getOwnerDocument (); };
const XMLCh* DOMProcessingInstructionImpl::getPrefix() const {return fNode.getPrefix (); }; const XMLCh* DOMProcessingInstructionImpl::getPrefix() const {return fNode.getPrefix (); };
DOMNode* DOMProcessingInstructionImpl::getParentNode() const {return fChild.getParentNode (this); }; DOMNode* DOMProcessingInstructionImpl::getParentNode() const {return fChild.getParentNode (this); };
...@@ -229,5 +234,19 @@ const XMLCh* DOMProcessingInstructionImpl::getBaseURI() const ...@@ -229,5 +234,19 @@ const XMLCh* DOMProcessingInstructionImpl::getBaseURI() const
const XMLCh* DOMProcessingInstructionImpl::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); }; const XMLCh* DOMProcessingInstructionImpl::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); };
DOMNode* DOMProcessingInstructionImpl::getInterface(const XMLCh* feature) {return fNode.getInterface(feature); }; DOMNode* DOMProcessingInstructionImpl::getInterface(const XMLCh* feature) {return fNode.getInterface(feature); };
//
// Delegation of CharacerData functions.
//
const XMLCh* DOMProcessingInstructionImpl::getData() const {return fCharacterData.getData();};
void DOMProcessingInstructionImpl::deleteData(XMLSize_t offset, XMLSize_t count)
{fCharacterData.deleteData(this, offset, count);};
const XMLCh* DOMProcessingInstructionImpl::substringData(XMLSize_t offset, XMLSize_t count) const
{return fCharacterData.substringData(this, offset, count);};
void DOMProcessingInstructionImpl::setData(const XMLCh *data) {fCharacterData.setData(this, data);};
void DOMProcessingInstructionImpl::setNodeValue(const XMLCh *nodeValue) {fCharacterData.setNodeValue (this, nodeValue); };
XERCES_CPP_NAMESPACE_END XERCES_CPP_NAMESPACE_END
...@@ -72,6 +72,7 @@ ...@@ -72,6 +72,7 @@
#include <xercesc/util/XercesDefs.hpp> #include <xercesc/util/XercesDefs.hpp>
#include <xercesc/dom/DOMProcessingInstruction.hpp> #include <xercesc/dom/DOMProcessingInstruction.hpp>
#include "DOMCharacterDataImpl.hpp"
#include "DOMNodeImpl.hpp" #include "DOMNodeImpl.hpp"
#include "DOMChildNode.hpp" #include "DOMChildNode.hpp"
...@@ -85,9 +86,10 @@ class CDOM_EXPORT DOMProcessingInstructionImpl: public DOMProcessingInstruction ...@@ -85,9 +86,10 @@ class CDOM_EXPORT DOMProcessingInstructionImpl: public DOMProcessingInstruction
private: private:
DOMNodeImpl fNode; DOMNodeImpl fNode;
DOMChildNode fChild; DOMChildNode fChild;
// use fCharacterData to store its data so that those character utitlites can be used
DOMCharacterDataImpl fCharacterData;
XMLCh *fTarget; XMLCh *fTarget;
XMLCh *fData;
const XMLCh *fBaseURI; const XMLCh *fBaseURI;
public: public:
...@@ -107,6 +109,11 @@ public: ...@@ -107,6 +109,11 @@ public:
// NON-DOM: set base uri // NON-DOM: set base uri
virtual void setBaseURI(const XMLCh* baseURI); virtual void setBaseURI(const XMLCh* baseURI);
// Non standard extension for the range to work
void deleteData(XMLSize_t offset, XMLSize_t count);
const XMLCh* substringData(XMLSize_t offset, XMLSize_t count) const;
DOMProcessingInstruction* splitText(XMLSize_t offset);
}; };
XERCES_CPP_NAMESPACE_END XERCES_CPP_NAMESPACE_END
......
This diff is collapsed.
...@@ -156,10 +156,11 @@ public: ...@@ -156,10 +156,11 @@ public:
DOMDocument* getDocument(); DOMDocument* getDocument();
// functions to inform all existing valid ranges about a change // functions to inform all existing valid ranges about a change
void updateSplitInfo(DOMText* oldNode, DOMText* startNode, XMLSize_t offset); void updateSplitInfo(DOMNode* oldNode, DOMNode* startNode, XMLSize_t offset);
void updateRangeForInsertedNode(DOMNode* node); void updateRangeForInsertedNode(DOMNode* node);
void receiveReplacedText(DOMNode* node); void receiveReplacedText(DOMNode* node);
void updateRangeForDeletedText(DOMNode* node, XMLSize_t offset, int count); void updateRangeForDeletedText(DOMNode* node, XMLSize_t offset, int count);
void updateRangeForInsertedText(DOMNode* node, XMLSize_t offset, int count);
void updateRangeForDeletedNode(DOMNode* node); void updateRangeForDeletedNode(DOMNode* node);
private: private:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment