You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by tn...@apache.org on 2002/02/04 22:50:17 UTC
cvs commit: xml-xerces/c/src/xercesc/idom IDAttrNSImpl.cpp IDDocumentImpl.cpp IDDocumentTypeImpl.cpp IDElementNSImpl.cpp IDNodeImpl.cpp IDNodeListImpl.cpp
tng 02/02/04 13:50:17
Modified: c/src/xercesc/idom IDAttrNSImpl.cpp IDDocumentImpl.cpp
IDDocumentTypeImpl.cpp IDElementNSImpl.cpp
IDNodeImpl.cpp IDNodeListImpl.cpp
Log:
Add DOM 2 Level missing functions:
1. NodeIterator::getRoot
2. TreeWalker::getRoot
3. Element::hasAttribute
4. Element::hasAttributeNS
5. Node::hasAttributes
6. Node::isSupported
Revision Changes Path
1.2 +4 -4 xml-xerces/c/src/xercesc/idom/IDAttrNSImpl.cpp
Index: IDAttrNSImpl.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/idom/IDAttrNSImpl.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- IDAttrNSImpl.cpp 1 Feb 2002 22:21:52 -0000 1.1
+++ IDAttrNSImpl.cpp 4 Feb 2002 21:50:17 -0000 1.2
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -55,7 +55,7 @@
*/
/*
- * $Id: IDAttrNSImpl.cpp,v 1.1 2002/02/01 22:21:52 peiyongz Exp $
+ * $Id: IDAttrNSImpl.cpp,v 1.2 2002/02/04 21:50:17 tng Exp $
*/
#include <xercesc/util/XMLUniDefs.hpp>
@@ -116,7 +116,7 @@
const XMLCh * URI = xmlnsAlone ?
xmlnsURI : IDNodeImpl::mapPrefix(fPrefix, namespaceURI, IDOM_Node::ATTRIBUTE_NODE);
- this -> fNamespaceURI = URI == 0 ? XMLUni::fgZeroLenString : ((IDDocumentImpl *)ownerDoc)->getPooledString(URI);
+ this -> fNamespaceURI = (URI == 0) ? 0 : ((IDDocumentImpl *)ownerDoc)->getPooledString(URI);
};
IDAttrNSImpl::IDAttrNSImpl(const IDAttrNSImpl &other, bool deep) :
@@ -157,7 +157,7 @@
if (fNode.isReadOnly())
throw IDOM_DOMException(IDOM_DOMException::NO_MODIFICATION_ALLOWED_ERR,
0);
- if (fNamespaceURI == 0 || XMLString::compareString(fLocalName, xmlns) == 0)
+ if (fNamespaceURI == 0 || fNamespaceURI[0] == chNull || XMLString::compareString(fLocalName, xmlns) == 0)
throw IDOM_DOMException(IDOM_DOMException::NAMESPACE_ERR, 0);
if (prefix != 0 && !IDDocumentImpl::isXMLName(prefix))
1.2 +39 -21 xml-xerces/c/src/xercesc/idom/IDDocumentImpl.cpp
Index: IDDocumentImpl.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/idom/IDDocumentImpl.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- IDDocumentImpl.cpp 1 Feb 2002 22:21:54 -0000 1.1
+++ IDDocumentImpl.cpp 4 Feb 2002 21:50:17 -0000 1.2
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -55,7 +55,7 @@
*/
/*
- * $Id: IDDocumentImpl.cpp,v 1.1 2002/02/01 22:21:54 peiyongz Exp $
+ * $Id: IDDocumentImpl.cpp,v 1.2 2002/02/04 21:50:17 tng Exp $
*/
#include <xercesc/util/XMLUniDefs.hpp>
@@ -150,10 +150,15 @@
fChanges(0),
fNodeListPool(0)
{
-
- fNamePool = new (this) IDStringPool(257, this);
- setDocumentType(doctype);
- appendChild(createElementNS(fNamespaceURI, qualifiedName)); //root element
+ fNamePool = new (this) IDStringPool(257, this);
+ try {
+ setDocumentType(doctype);
+ appendChild(createElementNS(fNamespaceURI, qualifiedName)); //root element
+ }
+ catch (...) {
+ this->deleteHeap();
+ throw;
+ }
}
void IDDocumentImpl::setDocumentType(IDOM_DocumentType *doctype)
@@ -181,6 +186,20 @@
IDDocumentImpl::~IDDocumentImpl()
{
+ // Clean up the fNodeListPool
+ if (fNodeListPool)
+ fNodeListPool->cleanup();
+
+ // Clean up the RefVector
+ if (fIterators)
+ fIterators->cleanup();
+
+ if (fTreeWalkers)
+ fTreeWalkers->cleanup();
+
+ if (fRanges)
+ fRanges->cleanup();
+
// Delete the heap for this document. This uncerimoniously yanks the storage
// out from under all of the nodes in the document. Destructors are NOT called.
this->deleteHeap();
@@ -665,23 +684,21 @@
//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".
+//Return 0 if there is no ':', or -1 if qName is malformed such as ":abcd" or "abcd:".
int IDDocumentImpl::indexofQualifiedName(const XMLCh * qName)
{
- //Check if s = prefix:localName, name or malformed
- int firstOccurence = XMLString::indexOf(qName, chColon);
- int lastOccurence = XMLString::lastIndexOf(qName, chColon);
-
- if (firstOccurence != lastOccurence || firstOccurence == 0) {
- // Error. More than two ':'s, or ':' is first char.
- return -1;
+ int qNameLen = XMLString::stringLen(qName);
+ int index = -1, count = 0;
+ for (int i = 0; i < qNameLen; ++i) {
+ if (qName[i] == chColon) {
+ index = i;
+ ++count; //number of ':' found
+ }
}
- if (firstOccurence == -1) {
- // No colons in the name
- firstOccurence = 0;
- }
- return firstOccurence;
+ if (qNameLen == 0 || count > 1 || index == 0 || index == qNameLen-1)
+ return -1;
+ return count == 0 ? 0 : index;
}
@@ -831,9 +848,10 @@
void IDDocumentImpl::normalize() {fNode.normalize (); };
IDOM_Node *IDDocumentImpl::replaceChild(IDOM_Node *newChild, IDOM_Node *oldChild)
{return fParent.replaceChild (newChild, oldChild); };
- bool IDDocumentImpl::supports(const XMLCh *feature, const XMLCh *version) const
- {return fNode.supports (feature, version); };
+ bool IDDocumentImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
+ {return fNode.isSupported (feature, version); };
void IDDocumentImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); };
+ bool IDDocumentImpl::hasAttributes() const {return fNode.hasAttributes(); };
//-----------------------------------------------------------------------
1.2 +33 -12 xml-xerces/c/src/xercesc/idom/IDDocumentTypeImpl.cpp
Index: IDDocumentTypeImpl.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/idom/IDDocumentTypeImpl.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- IDDocumentTypeImpl.cpp 1 Feb 2002 22:21:54 -0000 1.1
+++ IDDocumentTypeImpl.cpp 4 Feb 2002 21:50:17 -0000 1.2
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -55,7 +55,7 @@
*/
/*
- * $Id: IDDocumentTypeImpl.cpp,v 1.1 2002/02/01 22:21:54 peiyongz Exp $
+ * $Id: IDDocumentTypeImpl.cpp,v 1.2 2002/02/04 21:50:17 tng Exp $
*/
#include "IDDocumentTypeImpl.hpp"
@@ -87,6 +87,9 @@
}
else {
name = XMLString::replicate(dtName);
+ entities = new IDNamedNodeMapImpl(this);
+ notations= new IDNamedNodeMapImpl(this);
+ elements = new IDNamedNodeMapImpl(this);
}
};
@@ -123,6 +126,9 @@
publicId = XMLString::replicate(pubId);
systemId = XMLString::replicate(sysId);
name = XMLString::replicate(qualifiedName);
+ entities = new IDNamedNodeMapImpl(this);
+ notations= new IDNamedNodeMapImpl(this);
+ elements = new IDNamedNodeMapImpl(this);
}
};
@@ -144,10 +150,6 @@
name = other.name;
if (deep)
fParent.cloneChildren(&other);
- entities = ((IDNamedNodeMapImpl *)other.entities)->cloneMap(this);
- notations= ((IDNamedNodeMapImpl *)other.notations)->cloneMap(this);
- elements = ((IDNamedNodeMapImpl *)other.notations)->cloneMap(this);
-
//DOM Level 2
publicId = other.publicId;
systemId = other.systemId;
@@ -159,6 +161,11 @@
systemId = XMLString::replicate(other.systemId);
internalSubset = XMLString::replicate(other.internalSubset);
}
+
+ entities = ((IDNamedNodeMapImpl *)other.entities)->cloneMap(this);
+ notations= ((IDNamedNodeMapImpl *)other.notations)->cloneMap(this);
+ elements = ((IDNamedNodeMapImpl *)other.elements)->cloneMap(this);
+
}
@@ -176,6 +183,10 @@
temp = (XMLCh*) internalSubset;
delete [] temp;
+
+ delete entities;
+ delete notations;
+ delete elements;
}
}
@@ -217,12 +228,21 @@
name = docImpl->cloneString(name);
delete [] temp;
- entities = new (docImpl) IDNamedNodeMapImpl(this);
- notations= new (docImpl) IDNamedNodeMapImpl(this);
- elements = new (docImpl) IDNamedNodeMapImpl(this);
-
fNode.setOwnerDocument(doc);
fParent.setOwnerDocument(doc);
+
+ IDOM_NamedNodeMap* entitiesTemp = ((IDNamedNodeMapImpl *)entities)->cloneMap(this);
+ IDOM_NamedNodeMap* notationsTemp = ((IDNamedNodeMapImpl *)notations)->cloneMap(this);
+ IDOM_NamedNodeMap* elementsTemp = ((IDNamedNodeMapImpl *)elements)->cloneMap(this);
+
+ delete entities;
+ delete notations;
+ delete elements;
+
+ entities = entitiesTemp;
+ notations = notationsTemp;
+ elements = elementsTemp;
+
}
}
}
@@ -374,7 +394,8 @@
IDOM_Node *IDDocumentTypeImpl::removeChild(IDOM_Node *oldChild) {return fParent.removeChild (oldChild); };
IDOM_Node *IDDocumentTypeImpl::replaceChild(IDOM_Node *newChild, IDOM_Node *oldChild)
{return fParent.replaceChild (newChild, oldChild); };
- bool IDDocumentTypeImpl::supports(const XMLCh *feature, const XMLCh *version) const
- {return fNode.supports (feature, version); };
+ bool IDDocumentTypeImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
+ {return fNode.isSupported (feature, version); };
void IDDocumentTypeImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); };
+ bool IDDocumentTypeImpl::hasAttributes() const {return fNode.hasAttributes(); };
1.2 +4 -4 xml-xerces/c/src/xercesc/idom/IDElementNSImpl.cpp
Index: IDElementNSImpl.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/idom/IDElementNSImpl.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- IDElementNSImpl.cpp 1 Feb 2002 22:21:54 -0000 1.1
+++ IDElementNSImpl.cpp 4 Feb 2002 21:50:17 -0000 1.2
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -55,7 +55,7 @@
*/
/*
- * $Id: IDElementNSImpl.cpp,v 1.1 2002/02/01 22:21:54 peiyongz Exp $
+ * $Id: IDElementNSImpl.cpp,v 1.2 2002/02/04 21:50:17 tng Exp $
*/
#include <xercesc/util/XMLUniDefs.hpp>
@@ -104,7 +104,7 @@
}
const XMLCh * URI = IDNodeImpl::mapPrefix(fPrefix, namespaceURI, IDOM_Node::ELEMENT_NODE);
- this -> fNamespaceURI = URI == 0 ? XMLUni::fgZeroLenString : ((IDDocumentImpl *)ownerDoc)->getPooledString(URI);
+ this -> fNamespaceURI = (URI == 0) ? 0 : ((IDDocumentImpl *)ownerDoc)->getPooledString(URI);
};
IDElementNSImpl::IDElementNSImpl(const IDElementNSImpl &other, bool deep) :
@@ -146,7 +146,7 @@
if(prefix != 0 && !IDDocumentImpl::isXMLName(prefix))
throw IDOM_DOMException(IDOM_DOMException::INVALID_CHARACTER_ERR,0);
- if (fNamespaceURI == 0)
+ if (fNamespaceURI == 0 || fNamespaceURI[0] == chNull)
throw IDOM_DOMException(IDOM_DOMException::NAMESPACE_ERR, 0);
if (prefix == 0 || *prefix == 0) {
1.2 +38 -5 xml-xerces/c/src/xercesc/idom/IDNodeImpl.cpp
Index: IDNodeImpl.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/idom/IDNodeImpl.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- IDNodeImpl.cpp 1 Feb 2002 22:21:55 -0000 1.1
+++ IDNodeImpl.cpp 4 Feb 2002 21:50:17 -0000 1.2
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -55,7 +55,7 @@
*/
/*
- * $Id: IDNodeImpl.cpp,v 1.1 2002/02/01 22:21:55 peiyongz Exp $
+ * $Id: IDNodeImpl.cpp,v 1.2 2002/02/04 21:50:17 tng Exp $
*/
// This class doesn't support having any children, and implements the behavior
@@ -70,6 +70,8 @@
#include "IDDOMImplementation.hpp"
#include <xercesc/util/XMLUniDefs.hpp>
+#include <xercesc/util/XMLRegisterCleanup.hpp>
+#include <xercesc/util/PlatformUtils.hpp>
#include <stdio.h>
#include <assert.h>
@@ -86,7 +88,19 @@
const unsigned short IDNodeImpl::LEAFNODETYPE = 0x1<<10;
const unsigned short IDNodeImpl::CHILDNODE = 0x1<<11;
+// -----------------------------------------------------------------------
+// Reset the singleton gEmptyNodeList
+// -----------------------------------------------------------------------
+static IDNodeListImpl *gEmptyNodeList; // make a singleton empty node list
+static void reinitEmptyNodeList()
+{
+ delete gEmptyNodeList;
+ gEmptyNodeList = 0;
+}
+// -----------------------------------------------------------------------
+// IDNodeImpl Functions
+// -----------------------------------------------------------------------
IDNodeImpl::IDNodeImpl(IDOM_Node *ownerNode)
{
this->flags = 0;
@@ -133,9 +147,23 @@
};
-static IDOM_NodeList *gEmptyNodeList; // idom_revisit - make a singleton empty node list somewhere, shomehow.
IDOM_NodeList *IDNodeImpl::getChildNodes() const {
- return gEmptyNodeList; // overridden in ParentNode
+ static XMLRegisterCleanup emptyNodeListCleanup;
+
+ if (gEmptyNodeList == 0)
+ {
+ IDOM_NodeList *t = new IDNodeListImpl(0);
+ if (XMLPlatformUtils::compareAndSwap((void **)&gEmptyNodeList, t, 0) != 0)
+ {
+ delete t;
+ }
+ else
+ {
+ emptyNodeListCleanup.registerCleanup(reinitEmptyNodeList);
+ }
+
+ }
+ return (IDOM_NodeList *)gEmptyNodeList;
};
@@ -288,7 +316,7 @@
};
-bool IDNodeImpl::supports(const XMLCh *feature, const XMLCh *version) const
+bool IDNodeImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
{
return IDOM_DOMImplementation::getImplementation()->hasFeature(feature, version);
}
@@ -313,6 +341,11 @@
{
throw IDOM_DOMException(IDOM_DOMException::NAMESPACE_ERR, 0);
}
+
+
+bool IDNodeImpl::hasAttributes() const {
+ return 0; // overridden in ElementImpl
+};
1.2 +18 -10 xml-xerces/c/src/xercesc/idom/IDNodeListImpl.cpp
Index: IDNodeListImpl.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/idom/IDNodeListImpl.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- IDNodeListImpl.cpp 1 Feb 2002 22:21:55 -0000 1.1
+++ IDNodeListImpl.cpp 4 Feb 2002 21:50:17 -0000 1.2
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -56,8 +56,17 @@
/*
* $Log: IDNodeListImpl.cpp,v $
- * Revision 1.1 2002/02/01 22:21:55 peiyongz
- * Initial revision
+ * Revision 1.2 2002/02/04 21:50:17 tng
+ * Add DOM 2 Level missing functions:
+ * 1. NodeIterator::getRoot
+ * 2. TreeWalker::getRoot
+ * 3. Element::hasAttribute
+ * 4. Element::hasAttributeNS
+ * 5. Node::hasAttributes
+ * 6. Node::isSupported
+ *
+ * Revision 1.1.1.1 2002/02/01 22:21:55 peiyongz
+ * sane_include
*
* Revision 1.3 2001/06/04 14:55:34 tng
* IDOM: Add IRange and IDeepNodeList Support.
@@ -93,22 +102,27 @@
unsigned int IDNodeListImpl::getLength(){
unsigned int count = 0;
- IDOM_Node *node = castToParentImpl(fNode)->fFirstChild;
- while(node != 0)
- {
- ++count;
- node = castToChildImpl(node)->nextSibling;
+ if (fNode) {
+ IDOM_Node *node = castToParentImpl(fNode)->fFirstChild;
+ while(node != 0){
+ ++count;
+ node = castToChildImpl(node)->nextSibling;
+ }
}
+
return count;
};
IDOM_Node *IDNodeListImpl::item(unsigned int index){
- IDOM_Node *node = castToParentImpl(fNode)->fFirstChild;
- for(unsigned int i=0; i<index && node!=0; ++i)
- node = castToChildImpl(node)->nextSibling;
- return node;
+ if (fNode) {
+ IDOM_Node *node = castToParentImpl(fNode)->fFirstChild;
+ for(unsigned int i=0; i<index && node!=0; ++i)
+ node = castToChildImpl(node)->nextSibling;
+ return node;
+ }
+ return 0;
};
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org