dbertoni 00/04/11 07:30:47
Modified: c/src/DOMSupport DOMServices.cpp DOMServices.hpp
DOMSupport.hpp DOMSupportDefault.cpp
DOMSupportDefault.hpp DOMSupportException.cpp
DOMSupportException.hpp NamespaceResolver.cpp
NamespaceResolver.hpp NSInfo.hpp TreeWalker.cpp
TreeWalker.hpp
Log:
Changes for new Xalan DOM.
Revision Changes Path
1.5 +346 -85 xml-xalan/c/src/DOMSupport/DOMServices.cpp
Index: DOMServices.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/DOMSupport/DOMServices.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DOMServices.cpp 2000/02/17 20:26:37 1.4
+++ DOMServices.cpp 2000/04/11 14:30:44 1.5
@@ -62,15 +62,15 @@
-#include <dom/DOM_Attr.hpp>
-#include <dom/DOM_Document.hpp>
-#include <dom/DOM_Element.hpp>
-#include <dom/DOM_NamedNodeMap.hpp>
-#include <dom/DOM_Text.hpp>
+#include <XalanDOM/XalanAttr.hpp>
+#include <XalanDOM/XalanDocument.hpp>
+#include <XalanDOM/XalanElement.hpp>
+#include <XalanDOM/XalanNamedNodeMap.hpp>
+#include <XalanDOM/XalanText.hpp>
-#include <Include/DOMHelper.hpp>
+//#include <Include/DOMHelper.hpp>
#include <PlatformSupport/DOMStringHelper.hpp>
#include "DOMSupportException.hpp"
@@ -78,11 +78,11 @@
#if defined(XALAN_INLINE_INITIALIZATION)
-const DOMString DOMServices::s_XMLNamespaceURI;
+const XalanDOMString DOMServices::s_XMLNamespaceURI;
#else
-const DOMString
DOMServices::s_XMLNamespaceURI(XALAN_STATIC_UCODE_STRING("http://www.w3.org/XML/1998/namespace"));
+const XalanDOMString
DOMServices::s_XMLNamespaceURI(XALAN_STATIC_UCODE_STRING("http://www.w3.org/XML/1998/namespace"));
#endif
@@ -100,58 +100,89 @@
-DOMString
+DOMServices::WhitespaceSupportDefault::WhitespaceSupportDefault()
+{
+}
+
+
+
+DOMServices::WhitespaceSupportDefault::~WhitespaceSupportDefault()
+{
+}
+
+
+
+bool
+DOMServices::WhitespaceSupportDefault::isIgnorableWhitespace(const
XalanText& node) const
+{
+ const XalanDOMString theData(node.getData());
+
+ const unsigned int theLength = length(theData);
+
+ for (unsigned int i = 0; i < theLength; i++)
+ {
+ const XalanDOMChar theChar = charAt(theData, i);
+
+ if (!(theChar == 0x20 || theChar == 0xD || theChar == 0xA ||
theChar == 0x9))
+ {
+ break;
+ }
+ }
+
+ return i == theLength ? true : false;
+}
+
+
+
+XalanDOMString
DOMServices::getNodeData(
- const DOM_Node& node,
+ const XalanNode& node,
const WhitespaceSupport& theResolver)
{
- assert(node != 0);
+ XalanDOMString data;
- DOMString data;
-
switch(node.getNodeType())
{
- case DOM_Node::DOCUMENT_FRAGMENT_NODE:
- case DOM_Node::DOCUMENT_NODE:
- case DOM_Node::ELEMENT_NODE:
+ case XalanNode::DOCUMENT_FRAGMENT_NODE:
+ case XalanNode::DOCUMENT_NODE:
+ case XalanNode::ELEMENT_NODE:
{
- const DOM_NodeList children = node.getChildNodes();
-
- const unsigned int nNodes = children.getLength();
+ const XalanNode* child = node.getFirstChild();
- for(unsigned int i = 0; i < nNodes; i++)
+ while(child != 0)
{
- const DOMString nodeData =
- getNodeData(children.item(i),
+ const XalanDOMString nodeData =
+ getNodeData(*child,
theResolver);
if(0 < length(nodeData))
{
data += nodeData;
}
+
+ child = child->getNextSibling();
}
}
break;
- case DOM_Node::TEXT_NODE:
- case DOM_Node::CDATA_SECTION_NODE:
+ case XalanNode::TEXT_NODE:
+ case XalanNode::CDATA_SECTION_NODE:
{
- const DOM_Text& theTextNode =
+ const XalanText& theTextNode =
#if defined(XALAN_OLD_STYLE_CASTS)
- (const DOM_Text&)node;
+ (const XalanText&)node;
#else
- static_cast<const DOM_Text&>(node);
+ static_cast<const XalanText&>(node);
#endif
if(theResolver.isIgnorableWhitespace(theTextNode) ==
false)
{
- // data = fixWhiteSpace(theTextNode.getData(),
false, false, true);
data = theTextNode.getData();
}
}
break;
- case DOM_Node::ATTRIBUTE_NODE:
+ case XalanNode::ATTRIBUTE_NODE:
data = node.getNodeValue();
break;
@@ -165,14 +196,14 @@
-DOMString
-DOMServices::getLocalNameOfNode(const DOM_Node& n)
+XalanDOMString
+DOMServices::getLocalNameOfNode(const XalanNode& n)
{
- const DOMString qname = n.getNodeName();
+ const XalanDOMString qname = n.getNodeName();
- const int index = indexOf(qname, ':');
+ const unsigned int index = indexOf(qname, ':');
- return (index < 0) ? qname : substring(qname, index + 1);
+ return index == length(qname) ? qname : substring(qname, index + 1);
}
@@ -180,27 +211,30 @@
/**
* Support for getParentOfNode.
*/
-static DOM_Node
+static XalanNode*
locateAttrParent(
- const DOM_Element& elem,
- const DOM_Node& attr)
+ const XalanElement& elem,
+ const XalanNode& attr)
{
- DOM_Node parent;
+ XalanNode* parent = 0;
- // $$$ TODO: DOM_NamedNodeMap::item() should be const. When it does,
- // this can become const as well.
- DOM_NamedNodeMap attrs = elem.getAttributes();
+ const XalanNamedNodeMap* const attrs = elem.getAttributes();
+ assert(attrs != 0);
if(attrs != 0)
{
- const unsigned int nAttrs = attrs.getLength();
-
+ const unsigned int nAttrs = attrs->getLength();
+
for(unsigned int i = 0; i < nAttrs; i++)
{
- if(attrs.item(i) == attr)
+ if(attrs->item(i) == &attr)
{
- parent = elem;
+#if defined(XALAN_OLD_STYLE_CASTS)
+ parent = (XalanElement*)&elem;
+#else
+ parent = const_cast<XalanElement*>(&elem);
+#endif
break;
}
@@ -209,24 +243,29 @@
if(parent == 0)
{
- DOM_NodeList children = elem.getChildNodes();
+ bool fFound = false;
- const unsigned int nChildren = children.getLength();
+ const XalanNode* child = elem.getFirstChild();
- for(unsigned int i = 0; i < nChildren; i++)
+ while(child != 0 && fFound == false)
{
- DOM_Node node = children.item(i);
-
- if(node.getNodeType() == DOM_Node::ELEMENT_NODE)
+ if(child->getNodeType() == XalanNode::ELEMENT_NODE)
{
#if defined(XALAN_OLD_STYLE_CASTS)
- parent = locateAttrParent((const
DOM_Element&)node, attr);
+ parent = locateAttrParent((const
XalanElement&)*child, attr);
#else
- parent =
locateAttrParent(static_cast<DOM_Element&>(node), attr);
+ parent = locateAttrParent(static_cast<const
XalanElement&>(*child), attr);
#endif
if(parent != 0)
- break;
+ {
+ fFound = true;
+ }
+ }
+
+ if (fFound == false)
+ {
+ child = child->getNextSibling();
}
}
}
@@ -237,15 +276,16 @@
-DOM_Node
-DOMServices::getParentOfNode(const DOM_Node& node)
+XalanNode*
+DOMServices::getParentOfNode(const XalanNode& node)
{
- DOM_Node parent;
- const short nodeType = node.getNodeType();
+ XalanNode* parent = 0;
+
+ const XalanNode::NodeType nodeType = node.getNodeType();
- if(DOM_Node::ATTRIBUTE_NODE == nodeType)
+ if(XalanNode::ATTRIBUTE_NODE == nodeType)
{
- const DOM_Document doc = node.getOwnerDocument();
+ XalanDocument* const doc = node.getOwnerDocument();
if(doc == 0)
{
@@ -253,17 +293,17 @@
}
else
{
- const DOM_Element rootElem =
doc.getDocumentElement();
+ XalanElement* const rootElem =
doc->getDocumentElement();
assert(rootElem != 0);
- parent = locateAttrParent(rootElem, node);
+ parent = locateAttrParent(*rootElem, node);
}
}
else
{
parent = node.getParentNode();
-
- if(nodeType != DOM_Node::DOCUMENT_NODE && parent == 0)
+
+ if(nodeType != XalanNode::DOCUMENT_NODE && parent == 0)
{
throw DOMSupportException("Child does not have
parent!");
}
@@ -274,12 +314,12 @@
-DOMString
+XalanDOMString
DOMServices::getNamespaceForPrefix(
- const DOMString& prefix,
- const DOM_Element& namespaceContext)
+ const XalanDOMString& prefix,
+ const XalanElement& namespaceContext)
{
- DOMString theNamespace;
+ XalanDOMString theNamespace;
if(equals(prefix, "xml") == true)
{
@@ -287,25 +327,26 @@
}
else
{
- short type;
- DOM_Node parent = namespaceContext;
+ XalanNode::NodeType type;
+ const XalanNode* parent = &namespaceContext;
while (parent != 0 && length(theNamespace) == 0
- && ((type = parent.getNodeType()) ==
DOM_Node::ELEMENT_NODE
- || type == DOM_Node::ENTITY_REFERENCE_NODE))
+ && ((type = parent->getNodeType()) ==
XalanNode::ELEMENT_NODE
+ || type == XalanNode::ENTITY_REFERENCE_NODE))
{
- if (type == DOM_Node::ELEMENT_NODE)
+ if (type == XalanNode::ELEMENT_NODE)
{
- // $$$ TODO: DOM_NamedNodeMap::item() should be
const. When it does,
- // this can become const as well.
- DOM_NamedNodeMap nnm =
parent.getAttributes();
+ const XalanNamedNodeMap* const nnm =
parent->getAttributes();
+ assert(nnm != 0);
- const unsigned int theLength =
nnm.getLength();
+ const unsigned int
theLength = nnm->getLength();
for (unsigned int i = 0; i < theLength; i ++)
{
- DOM_Node attr = nnm.item(i);
- DOMString aname =
attr.getNodeName();
+ const XalanNode* const attr =
nnm->item(i);
+ assert(attr != 0);
+
+ const XalanDOMString aname =
attr->getNodeName();
const char* const theXMLNS =
"xmlns:";
@@ -317,17 +358,17 @@
if (equals(aname, "xmlns") || isPrefix)
{
- const int index =
indexOf(aname,
-
':');
+ const unsigned int index =
indexOf(aname,
+
':');
- const DOMString p =
+ const XalanDOMString p =
isPrefix ?
substring(aname,
index + 1,
-
length(aname)) : DOMString();
+
length(aname)) : XalanDOMString();
if (equals(p, prefix) == true)
{
- theNamespace =
attr.getNodeValue();
+ theNamespace =
attr->getNodeValue();
break;
}
@@ -335,9 +376,229 @@
}
}
- parent = getParentOfNode(parent);
+ parent = getParentOfNode(*parent);
}
}
return theNamespace;
}
+
+
+
+
+
+
+bool
+DOMServices::isNodeAfter(
+ const XalanNode& node1,
+ const XalanNode& node2)
+{
+ bool isNodeAfter = false;
+
+ const XalanNode* parent1 = getParentOfNode(node1);
+ assert(parent1 != 0);
+
+ const XalanNode* parent2 = getParentOfNode(node2);
+ assert(parent2 != 0);
+
+ // Optimize for most common case
+ if(parent1 == parent2) // then we know they are siblings
+ {
+ isNodeAfter = isNodeAfterSibling(*parent1,
+
node1,
+
node2);
+ }
+ else
+ {
+ // General strategy: Figure out the lengths of the two
+ // ancestor chains, and walk up them looking for the
+ // first common ancestor, at which point we can do a
+ // sibling compare. Edge condition where one is the
+ // ancestor of the other.
+
+ // Count parents, so we can see if one of the chains
+ // needs to be equalized.
+ int nParents1 = 2;
+ int nParents2 = 2; // count node & parent obtained above
+
+ while(parent1 != 0)
+ {
+ nParents1++;
+ parent1 = getParentOfNode(*parent1);
+ }
+
+ while(parent2 != 0)
+ {
+ nParents2++;
+ parent2 = getParentOfNode(*parent2);
+ }
+
+ // adjustable starting points
+ const XalanNode* startNode1 = &node1;
+ const XalanNode* startNode2 = &node2;
+
+ // Do I have to adjust the start point in one of
+ // the ancesor chains?
+ if(nParents1 < nParents2)
+ {
+ // adjust startNode2
+ const int adjust = nParents2 - nParents1;
+
+ for(int i = 0; i < adjust; i++)
+ {
+ startNode2 = getParentOfNode(*startNode2);
+ }
+ }
+ else if(nParents1 > nParents2)
+ {
+ // adjust startNode1
+ const int adjust = nParents1 - nParents2;
+
+ for(int i = 0; i < adjust; i++)
+ {
+ startNode1 = getParentOfNode(*startNode1);
+ }
+ }
+
+ // so we can "back up"
+ const XalanNode* prevChild1 = 0;
+ const XalanNode* prevChild2 = 0;
+
+ // Loop up the ancestor chain looking for common parent.
+ while(0 != startNode1)
+ {
+ if(startNode1 == startNode2) // common parent?
+ {
+ if(0 == prevChild1) // first time in loop?
+ {
+ // Edge condition: one is the ancestor
of the other.
+ isNodeAfter = (nParents1 < nParents2) ?
true : false;
+
+ break; // from while loop
+ }
+ else
+ {
+ isNodeAfter =
isNodeAfterSibling(*startNode1,
+
*prevChild1,
+
*prevChild2);
+
+ break; // from while loop
+ }
+ }
+
+ prevChild1 = startNode1;
+ assert(prevChild1 != 0);
+
+ startNode1 = getParentOfNode(*startNode1);
+ assert(startNode1 != 0);
+
+ prevChild2 = startNode2;
+ assert(prevChild2 != 0);
+
+ startNode2 = getParentOfNode(*startNode2);
+ assert(startNode2 != 0);
+ }
+ }
+
+ return isNodeAfter;
+}
+
+
+
+bool
+DOMServices::isNodeAfterSibling(
+ const XalanNode& parent,
+ const XalanNode& child1,
+ const XalanNode& child2)
+{
+ bool isNodeAfterSibling = false;
+
+ const XalanNode::NodeType child1type = child1.getNodeType();
+ const XalanNode::NodeType child2type = child2.getNodeType();
+
+ if(XalanNode::ATTRIBUTE_NODE != child1type &&
+ XalanNode::ATTRIBUTE_NODE == child2type)
+ {
+ // always sort attributes before non-attributes.
+ isNodeAfterSibling = false;
+ }
+ else if(XalanNode::ATTRIBUTE_NODE == child1type &&
+ XalanNode::ATTRIBUTE_NODE != child2type)
+ {
+ // always sort attributes before non-attributes.
+ isNodeAfterSibling = true;
+ }
+ else if(XalanNode::ATTRIBUTE_NODE == child1type)
+ {
+ const XalanNamedNodeMap* children =
parent.getAttributes();
+
+ const unsigned int nNodes = children->getLength();
+
+ bool found1 = false;
+ bool found2 = false;
+
+ for(unsigned int i = 0; i < nNodes; i++)
+ {
+ const XalanNode* child = children->item(i);
+
+ if(&child1 == child)
+ {
+ if(found2 == true)
+ {
+ isNodeAfterSibling = false;
+ break;
+ }
+
+ found1 = true;
+ }
+ else if(&child2 == child)
+ {
+ if(found1 == true)
+ {
+ isNodeAfterSibling = true;
+ break;
+ }
+
+ found2 = true;
+ }
+ }
+ }
+ else
+ {
+ const XalanNode* child = parent.getFirstChild();
+
+ bool found1 = false;
+ bool found2 = false;
+
+ while(child != 0)
+ {
+ if(&child1 == child)
+ {
+ if(found2 == true)
+ {
+ isNodeAfterSibling = false;
+ break;
+ }
+
+ found1 = true;
+ }
+ else if(&child2 == child)
+ {
+ if(found1 == true)
+ {
+ isNodeAfterSibling = true;
+ break;
+ }
+
+ found2 = true;
+ }
+
+ child = child->getNextSibling();
+ }
+
+ assert(found1 != found2);
+ }
+
+ return isNodeAfterSibling;
+}
+
1.7 +63 -16 xml-xalan/c/src/DOMSupport/DOMServices.hpp
Index: DOMServices.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/DOMSupport/DOMServices.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DOMServices.hpp 2000/03/06 17:17:51 1.6
+++ DOMServices.hpp 2000/04/11 14:30:44 1.7
@@ -64,8 +64,7 @@
-#include <dom/DOM_Node.hpp>
-#include <dom/DOMString.hpp>
+#include <XalanDOM/XalanDOMString.hpp>
@@ -75,8 +74,9 @@
-class DOM_Element;
-class DOM_Text;
+class XalanNode;
+class XalanElement;
+class XalanText;
@@ -86,11 +86,11 @@
#if defined(XALAN_INLINE_INITIALIZATION)
- static const DOMString
s_XMLNamespaceURI(XALAN_STATIC_UCODE_STRING("http://www.w3.org/XML/1998/namespace"));
+ static const XalanDOMString
s_XMLNamespaceURI(XALAN_STATIC_UCODE_STRING("http://www.w3.org/XML/1998/namespace"));
#else
- static const DOMString s_XMLNamespaceURI;
+ static const XalanDOMString s_XMLNamespaceURI;
#endif
@@ -111,9 +111,30 @@
* @return true if white space can be ignored
*/
virtual bool
- isIgnorableWhitespace(const DOM_Text& node) const = 0;
+ isIgnorableWhitespace(const XalanText& node) const = 0;
};
+ // A default implementation using the values from the XML spec.
+ class XALAN_DOMSUPPORT_EXPORT WhitespaceSupportDefault : public
WhitespaceSupport
+ {
+ public:
+
+ WhitespaceSupportDefault();
+
+ virtual
+ ~WhitespaceSupportDefault();
+
+ /**
+ * Tell if the node is ignorable whitespace. This should be in
the DOM.
+ * Return false if the parser doesn't handle this.
+ *
+ * @param node text node queried
+ * @return true if white space can be ignored
+ */
+ virtual bool
+ isIgnorableWhitespace(const XalanText& node) const;
+ };
+
/**
* Retrieves data for node
*
@@ -121,9 +142,9 @@
* @param theResolver prefix resolver to use
* @return a string representation of the node's data
*/
- static DOMString
+ static XalanDOMString
getNodeData(
- const DOM_Node& node,
+ const XalanNode& node,
const WhitespaceSupport& theResolver);
/**
@@ -132,8 +153,8 @@
* @param node DOM node whose name is returned
* @return name of node without namespace
*/
- static DOMString
- getLocalNameOfNode(const DOM_Node& n);
+ static XalanDOMString
+ getLocalNameOfNode(const XalanNode& n);
/**
* Retrieve the parent of a node. This function has to be implemented,
@@ -142,8 +163,8 @@
* @param node child node
* @return parent node
*/
- static DOM_Node
- getParentOfNode(const DOM_Node& node);
+ static XalanNode*
+ getParentOfNode(const XalanNode& node);
/**
* Retrieve the URI corresponding to a namespace prefix
@@ -152,10 +173,36 @@
* @param namespaceContext DOM element representing the context for
namespace
* @return URI corresponding to namespace
*/
- static DOMString
+ static XalanDOMString
getNamespaceForPrefix(
- const DOMString& prefix,
- const DOM_Element& namespaceContext);
+ const XalanDOMString& prefix,
+ const XalanElement& namespaceContext);
+
+ /**
+ * Determine if a node is after another node, in document order.
+ *
+ * @param node1 The first node
+ * @param node2 The second node
+ * @return true if node1 one is after node2, or false if it is not.
+ */
+ static bool
+ isNodeAfter(
+ const XalanNode& node1,
+ const XalanNode& node2);
+
+ /**
+ * Determine if a node is after another node in the sibling list.
+ *
+ * @param parent The parent of the nodes.
+ * @param node1 The first node
+ * @param node2 The second node
+ * @return true if node1 one is after node2, or false if it is not.
+ */
+ static bool
+ isNodeAfterSibling(
+ const XalanNode& parent,
+ const XalanNode& child1,
+ const XalanNode& child2);
}; // class DOMServices
1.3 +11 -11 xml-xalan/c/src/DOMSupport/DOMSupport.hpp
Index: DOMSupport.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/DOMSupport/DOMSupport.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DOMSupport.hpp 2000/02/23 20:23:09 1.2
+++ DOMSupport.hpp 2000/04/11 14:30:44 1.3
@@ -64,7 +64,7 @@
-#include <dom/DOMString.hpp>
+#include <XalanDOM/XalanDOMString.hpp>
@@ -72,10 +72,10 @@
-class DOM_Attr;
-class DOM_Element;
-class DOM_Node;
-class DOM_Text;
+class XalanAttr;
+class XalanElement;
+class XalanNode;
+class XalanText;
@@ -101,8 +101,8 @@
* @param theNode DOM node whose namespace is queried
* @return namespace corresponding to 'theNode'
*/
- virtual DOMString
- getNamespaceOfNode(const DOM_Node& theNode) const = 0;
+ virtual XalanDOMString
+ getNamespaceOfNode(const XalanNode& theNode) const = 0;
/**
* Retrieves expanded name of a DOM element, including namespace
@@ -110,8 +110,8 @@
* @param elem DOM element queried
* @return expanded name corresponding to 'elem'
*/
- virtual DOMString
- getExpandedElementName(const DOM_Element& elem) const = 0;
+ virtual XalanDOMString
+ getExpandedElementName(const XalanElement& elem) const = 0;
/**
* Retrieves expanded name of a DOM attribute, including namespace
@@ -119,8 +119,8 @@
* @param attr DOM attribute queried
* @return expanded name corresponding to 'attr'
*/
- virtual DOMString
- getExpandedAttributeName(const DOM_Attr& attr) const = 0;
+ virtual XalanDOMString
+ getExpandedAttributeName(const XalanAttr& attr) const = 0;
};
1.4 +14 -15 xml-xalan/c/src/DOMSupport/DOMSupportDefault.cpp
Index: DOMSupportDefault.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/DOMSupport/DOMSupportDefault.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DOMSupportDefault.cpp 2000/02/17 20:26:38 1.3
+++ DOMSupportDefault.cpp 2000/04/11 14:30:44 1.4
@@ -62,14 +62,13 @@
-#include <dom/DOM_Node.hpp>
-#include <dom/DOM_Attr.hpp>
-#include <dom/DOM_Document.hpp>
-#include <dom/DOM_Element.hpp>
+#include <XalanDOM/XalanNode.hpp>
+#include <XalanDOM/XalanAttr.hpp>
+#include <XalanDOM/XalanDocument.hpp>
+#include <XalanDOM/XalanElement.hpp>
-#include <Include/DOMHelper.hpp>
#include <PlatformSupport/DOMStringHelper.hpp>
#include "DOMServices.hpp"
#include "DOMSupportException.hpp"
@@ -98,30 +97,30 @@
-DOMString
-DOMSupportDefault::getNamespaceOfNode(const DOM_Node& theNode) const
+XalanDOMString
+DOMSupportDefault::getNamespaceOfNode(const XalanNode& theNode) const
{
return m_resolver.getNamespaceOfNode(theNode);
}
-DOMString
-DOMSupportDefault::getExpandedElementName(const DOM_Element& elem) const
+XalanDOMString
+DOMSupportDefault::getExpandedElementName(const XalanElement& elem)
const
{
- DOMString theNamespace = getNamespaceOfNode(elem);
+ const XalanDOMString theNamespace = getNamespaceOfNode(elem);
- return (0 != length(theNamespace)) ? theNamespace + ":" +
DOMServices::getLocalNameOfNode(elem)
+ return (0 != length(theNamespace)) ? theNamespace +
XALAN_STATIC_UCODE_STRING(":") + DOMServices::getLocalNameOfNode(elem)
:
DOMServices::getLocalNameOfNode(elem);
}
-DOMString
-DOMSupportDefault::getExpandedAttributeName(const DOM_Attr& attr)
const
+XalanDOMString
+DOMSupportDefault::getExpandedAttributeName(const XalanAttr& attr) const
{
- DOMString theNamespace = getNamespaceOfNode(attr);
+ const XalanDOMString theNamespace = getNamespaceOfNode(attr);
- return (0 != length(theNamespace)) ? theNamespace + ":" +
DOMServices::getLocalNameOfNode(attr)
+ return (0 != length(theNamespace)) ? theNamespace +
XALAN_STATIC_UCODE_STRING(":") + DOMServices::getLocalNameOfNode(attr)
: DOMServices::getLocalNameOfNode(attr);
}
1.3 +6 -11 xml-xalan/c/src/DOMSupport/DOMSupportDefault.hpp
Index: DOMSupportDefault.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/DOMSupport/DOMSupportDefault.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DOMSupportDefault.hpp 2000/02/17 20:26:38 1.2
+++ DOMSupportDefault.hpp 2000/04/11 14:30:44 1.3
@@ -64,11 +64,6 @@
-#include <dom/DOM_Node.hpp>
-#include <dom/DOMString.hpp>
-
-
-
#include <DOMSupport/DOMSupport.hpp>
#include <DOMSupport/NamespaceResolver.hpp>
@@ -89,14 +84,14 @@
reset();
// These interfaces are inherited from DOMSupport...
- virtual DOMString
- getNamespaceOfNode(const DOM_Node& theNode) const;
+ virtual XalanDOMString
+ getNamespaceOfNode(const XalanNode& theNode) const;
- virtual DOMString
- getExpandedElementName(const DOM_Element& elem) const;
+ virtual XalanDOMString
+ getExpandedElementName(const XalanElement& elem) const;
- virtual DOMString
- getExpandedAttributeName(const DOM_Attr& attr) const;
+ virtual XalanDOMString
+ getExpandedAttributeName(const XalanAttr& attr) const;
private:
1.2 +1 -1 xml-xalan/c/src/DOMSupport/DOMSupportException.cpp
Index: DOMSupportException.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/DOMSupport/DOMSupportException.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DOMSupportException.cpp 1999/12/18 19:47:47 1.1
+++ DOMSupportException.cpp 2000/04/11 14:30:44 1.2
@@ -60,7 +60,7 @@
-DOMSupportException::DOMSupportException(const DOMString& message) :
+DOMSupportException::DOMSupportException(const XalanDOMString&
message) :
XSLException(message)
{
}
1.3 +2 -3 xml-xalan/c/src/DOMSupport/DOMSupportException.hpp
Index: DOMSupportException.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/DOMSupport/DOMSupportException.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DOMSupportException.hpp 2000/02/23 20:23:09 1.2
+++ DOMSupportException.hpp 2000/04/11 14:30:44 1.3
@@ -64,7 +64,7 @@
-#include <dom/DOMString.hpp>
+#include <XalanDOM/XalanDOMString.hpp>
@@ -82,8 +82,7 @@
*
* @param message error message
*/
- explicit DOMSupportException(
- const DOMString& message = DOMString());
+ explicit DOMSupportException(const XalanDOMString& message =
XalanDOMString());
virtual
~DOMSupportException();
1.5 +46 -40 xml-xalan/c/src/DOMSupport/NamespaceResolver.cpp
Index: NamespaceResolver.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/DOMSupport/NamespaceResolver.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- NamespaceResolver.cpp 2000/02/17 20:26:38 1.4
+++ NamespaceResolver.cpp 2000/04/11 14:30:44 1.5
@@ -62,7 +62,11 @@
-#include <Include/DOMHelper.hpp>
+#include <XalanDOM/XalanNode.hpp>
+#include <XalanDOM/XalanNamedNodeMap.hpp>
+
+
+
#include "DOMServices.hpp"
@@ -97,15 +101,15 @@
-static DOMString theXMLString(XALAN_STATIC_UCODE_STRING("xml"));
-static DOMString theXMLNSString(XALAN_STATIC_UCODE_STRING("xmlns"));
-static DOMString
theXMLNSStringWithColon(XALAN_STATIC_UCODE_STRING("xmlns:"));
+static XalanDOMString theXMLString(XALAN_STATIC_UCODE_STRING("xml"));
+static XalanDOMString
theXMLNSString(XALAN_STATIC_UCODE_STRING("xmlns"));
+static XalanDOMString
theXMLNSStringWithColon(XALAN_STATIC_UCODE_STRING("xmlns:"));
void
NamespaceResolver::updateNamespace(
- const DOM_Node& theNode,
+ const XalanNode* theNode,
const NSInfo& theNamespace) const
{
#if defined(XALAN_NO_MUTABLE)
@@ -121,8 +125,8 @@
-DOMString
-NamespaceResolver::getNamespaceOfNode(const DOM_Node& theNode) const
+XalanDOMString
+NamespaceResolver::getNamespaceOfNode(const XalanNode& theNode) const
{
#if !defined(XALAN_NO_NAMESPACES)
using std::make_pair;
@@ -130,19 +134,19 @@
using std::vector;
#endif
- DOM_Node
theLocalNode(theNode);
+ const XalanNode* theLocalNode = &theNode;
bool hasProcessedNS;
NSInfo nsInfo;
- const int ntype =
theLocalNode.getNodeType();
+ const int ntype =
theLocalNode->getNodeType();
NSInfoMapType::const_iterator theIterator = m_NSInfos.end();
- // Find the node in the map of cached DOM_Nodes, if it's not an
+ // Find the node in the map of cached nodes, if it's not an
// attribute node.
- if(DOM_Node::ATTRIBUTE_NODE != ntype)
+ if(XalanNode::ATTRIBUTE_NODE != ntype)
{
theIterator = m_NSInfos.find(theLocalNode);
@@ -163,7 +167,7 @@
hasProcessedNS = false;
}
- DOMString namespaceOfPrefix;
+ XalanDOMString namespaceOfPrefix;
if(hasProcessedNS)
{
@@ -171,34 +175,34 @@
}
else
{
- DOMString nodeName = theLocalNode.getNodeName();
+ XalanDOMString nodeName = theLocalNode->getNodeName();
- int indexOfNSSep = indexOf(nodeName, ':');
+ unsigned int indexOfNSSep = indexOf(nodeName, ':');
- DOMString prefix;
+ XalanDOMString prefix;
// If we have an attribute node without a prefix, then
// we should use the prefix of the element parent.
- if(DOM_Node::ATTRIBUTE_NODE == ntype)
+ if(XalanNode::ATTRIBUTE_NODE == ntype)
{
- if(indexOfNSSep >= 0)
+ if(indexOfNSSep < length(nodeName))
{
prefix = substring(nodeName, 0, indexOfNSSep);
}
else
{
- theLocalNode =
DOMServices::getParentOfNode(theLocalNode);
+ theLocalNode =
DOMServices::getParentOfNode(*theLocalNode);
- nodeName = theLocalNode.getNodeName();
+ nodeName = theLocalNode->getNodeName();
indexOfNSSep = indexOf(nodeName, ':');
- prefix = (indexOfNSSep >= 0) ?
substring(nodeName, 0, indexOfNSSep) : DOMString();
+ prefix = indexOfNSSep < length(nodeName) ?
substring(nodeName, 0, indexOfNSSep) : XalanDOMString();
}
}
else
{
- prefix = (indexOfNSSep >= 0) ? substring(nodeName, 0,
indexOfNSSep) : DOMString();
+ prefix = indexOfNSSep < length(nodeName) ?
substring(nodeName, 0, indexOfNSSep) : XalanDOMString();
}
bool ancestorsHaveXMLNS = false;
@@ -210,10 +214,10 @@
}
else
{
- int parentType = 0;
- DOM_Node parent = theLocalNode;
+ XalanNode::NodeType parentType =
XalanNode::UNKNOWN_NODE;
+ const XalanNode* parent = theLocalNode;
- typedef pair<DOM_Node, NSInfo>
CandidateNoAncestorEntryType;
+ typedef pair<const XalanNode*, NSInfo>
CandidateNoAncestorEntryType;
typedef vector<CandidateNoAncestorEntryType>
CandidateNoAncestorVectorType;
CandidateNoAncestorVectorType
candidateNoAncestorXMLNS;
@@ -226,24 +230,26 @@
break;
}
- parentType = parent.getNodeType();
+ parentType = parent->getNodeType();
if(theIterator == m_NSInfos.end() ||
nsInfo.m_hasXMLNSAttrs == true)
{
bool elementHasXMLNS = false;
- if (parentType ==
DOM_Node::ELEMENT_NODE)
+ if (parentType ==
XalanNode::ELEMENT_NODE)
{
- // $$$ TODO:
DOM_NamedNodeMap::item() should be const. When it does,
- // this can become const as
well.
- DOM_NamedNodeMap nnm =
parent.getAttributes();
+ const XalanNamedNodeMap* const
nnm =
+ parent->getAttributes();
+ assert(nnm != 0);
+
+ const unsigned int
theLength = nnm->getLength();
- for (unsigned int i = 0; i <
nnm.getLength(); i ++)
+ for (unsigned int i = 0; i <
theLength; i ++)
{
- DOM_Node
attr = nnm.item(i);
+ const XalanNode*
attr = nnm->item(i);
- const DOMString
aname = attr.getNodeName();
+ const XalanDOMString
aname = attr->getNodeName();
if(charAt(aname, 0) ==
'x')
{
@@ -259,12 +265,12 @@
elementHasXMLNS = true;
ancestorsHaveXMLNS = true;
- const
DOMString p = isPrefix == true ?
-
substring(aname, length(theXMLNSStringWithColon)) : DOMString();
+ const
XalanDOMString p = isPrefix == true ?
+
substring(aname, length(theXMLNSStringWithColon)) : XalanDOMString();
if
(equals(p, prefix) == true)
{
-
namespaceOfPrefix = attr.getNodeValue();
+
namespaceOfPrefix = attr->getNodeValue();
break;
}
}
@@ -272,7 +278,7 @@
}
}
- if((DOM_Node::ATTRIBUTE_NODE !=
parentType) &&
+ if((XalanNode::ATTRIBUTE_NODE !=
parentType) &&
(theIterator ==
m_NSInfos.end()) &&
(theLocalNode != parent))
{
@@ -283,15 +289,15 @@
}
}
- if(DOM_Node::ATTRIBUTE_NODE == parentType)
+ if(XalanNode::ATTRIBUTE_NODE == parentType)
{
- parent =
DOMServices::getParentOfNode(parent);
+ parent =
DOMServices::getParentOfNode(*parent);
}
else
{
candidateNoAncestorXMLNS.push_back(make_pair(parent, nsInfo));
- parent = parent.getParentNode();
+ parent = parent->getParentNode();
}
if(0 != parent)
@@ -327,7 +333,7 @@
}
}
- if(DOM_Node::ATTRIBUTE_NODE != ntype)
+ if(XalanNode::ATTRIBUTE_NODE != ntype)
{
if(0 == length(namespaceOfPrefix))
{
1.5 +7 -23 xml-xalan/c/src/DOMSupport/NamespaceResolver.hpp
Index: NamespaceResolver.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/DOMSupport/NamespaceResolver.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- NamespaceResolver.hpp 2000/03/01 20:43:39 1.4
+++ NamespaceResolver.hpp 2000/04/11 14:30:44 1.5
@@ -73,8 +73,8 @@
-#include <dom/DOM_Node.hpp>
-#include <dom/DOMString.hpp>
+#include <XalanDOM/XalanNode.hpp>
+#include <XalanDOM/XalanDOMString.hpp>
@@ -104,36 +104,20 @@
* @param theNode DOM node
* @return namespace of 'theNode'
*/
- virtual DOMString
- getNamespaceOfNode(const DOM_Node& theNode) const;
+ virtual XalanDOMString
+ getNamespaceOfNode(const XalanNode& theNode) const;
protected:
#if defined(XALAN_NO_NAMESPACES)
-# define XALAN_STD
+ typedef map<const XalanNode*, NSInfo> NSInfoMapType;
#else
-# define XALAN_STD std::
+ typedef std::map<const XalanNode*, NSInfo> NSInfoMapType;
#endif
-#if defined(XALAN_HASH_CONTAINERS_AVAILABLE)
-#if defined(XALAN_NO_NAMESPACES)
- typedef hash_map<DOM_Node, NSInfo, DOM_NodeHashFunction>
NSInfoMapType;
-#else
- typedef XALAN_STD hash_map<DOM_Node, NSInfo, DOM_NodeHashFunction>
NSInfoMapType;
-#endif
-#else
-#if defined(XALAN_NO_NAMESPACES)
- typedef map<DOM_Node, NSInfo>
NSInfoMapType;
-#else
- typedef XALAN_STD map<DOM_Node, NSInfo>
NSInfoMapType;
-#endif
-#endif
-
-#undef XALAN_STD
-
void
updateNamespace(
- const DOM_Node& theNode,
+ const XalanNode* theNode,
const NSInfo& theNamespace) const;
// Cached namespace information...
1.3 +14 -9 xml-xalan/c/src/DOMSupport/NSInfo.hpp
Index: NSInfo.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/DOMSupport/NSInfo.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NSInfo.hpp 2000/02/23 20:23:09 1.2
+++ NSInfo.hpp 2000/04/11 14:30:44 1.3
@@ -64,7 +64,7 @@
-#include <dom/DOMString.hpp>
+#include <XalanDOM/XalanDOMString.hpp>
@@ -88,8 +88,9 @@
* @param hasProcessedNS $$$
* @param hasXMLNSAttrs $$$
*/
- explicit NSInfo(bool hasProcessedNS = false,
- bool hasXMLNSAttrs = false) :
+ explicit NSInfo(
+ bool hasProcessedNS = false,
+ bool hasXMLNSAttrs = false) :
m_hasProcessedNS(hasProcessedNS),
m_hasXMLNSAttrs(hasXMLNSAttrs),
m_namespace(),
@@ -105,9 +106,10 @@
* @param hasXMLNSAttrs $$$
* @param eHasXMLNSAttrs $$$
*/
- NSInfo(bool hasProcessedNS,
- bool hasXMLNSAttrs,
- eHasXMLNSAttrs ancestorHasXMLNSAttrs) :
+ NSInfo(
+ bool hasProcessedNS,
+ bool hasXMLNSAttrs,
+ eHasXMLNSAttrs ancestorHasXMLNSAttrs) :
m_hasProcessedNS(hasProcessedNS),
m_hasXMLNSAttrs(hasXMLNSAttrs),
m_ancestorHasXMLNSAttrs(ancestorHasXMLNSAttrs),
@@ -121,8 +123,9 @@
* @param theNamespace namespace
* @param hasXMLNSAttrs $$$
*/
- NSInfo(DOMString theNamespace,
- bool hasXMLNSAttrs) :
+ NSInfo(
+ const XalanDOMString& theNamespace,
+ bool hasXMLNSAttrs) :
m_hasProcessedNS(true),
m_hasXMLNSAttrs(hasXMLNSAttrs),
m_namespace(theNamespace),
@@ -143,9 +146,11 @@
equals(m_ancestorHasXMLNSAttrs,
theRHS.m_ancestorHasXMLNSAttrs);
}
- DOMString m_namespace;
+ XalanDOMString m_namespace;
+
bool m_hasXMLNSAttrs;
bool m_hasProcessedNS;
+
eHasXMLNSAttrs m_ancestorHasXMLNSAttrs;
};
1.2 +97 -15 xml-xalan/c/src/DOMSupport/TreeWalker.cpp
Index: TreeWalker.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/DOMSupport/TreeWalker.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TreeWalker.cpp 1999/12/18 19:47:47 1.1
+++ TreeWalker.cpp 2000/04/11 14:30:44 1.2
@@ -59,13 +59,11 @@
-// Xerces header files...
-#include <dom/DOM_Node.hpp>
+#include <cassert>
-// XSL4C header files.
-#include <Include/DOMHelper.hpp>
+#include <XalanDOM/XalanNode.hpp>
@@ -82,25 +80,65 @@
void
-TreeWalker::traverse(const DOM_Node& pos)
+TreeWalker::traverse(const XalanNode* pos)
{
- DOM_Node thePos(pos);
+ assert(pos != 0);
+ const XalanNode* thePos = pos;
+
+ while(0 != thePos)
+ {
+ startNode(thePos);
+
+ const XalanNode* nextNode = thePos->getFirstChild();
+
+ while(0 == nextNode)
+ {
+ endNode(thePos);
+
+ nextNode = thePos->getNextSibling();
+
+ if(0 == nextNode)
+ {
+ thePos = thePos->getParentNode();
+
+ if(0 == thePos)
+ {
+ nextNode = thePos;
+
+ break;
+ }
+ }
+ }
+
+ thePos = nextNode;
+ }
+}
+
+
+
+void
+TreeWalker::traverse(XalanNode* pos)
+{
+ assert(pos != 0);
+
+ XalanNode* thePos = pos;
+
while(0 != thePos)
{
startNode(thePos);
- DOM_Node nextNode = thePos.getFirstChild();
+ XalanNode* nextNode = thePos->getFirstChild();
while(0 == nextNode)
{
endNode(thePos);
- nextNode = pos.getNextSibling();
+ nextNode = thePos->getNextSibling();
if(0 == nextNode)
{
- thePos = thePos.getParentNode();
+ thePos = thePos->getParentNode();
if(0 == thePos)
{
@@ -119,26 +157,70 @@
void
TreeWalker::traverse(
- const DOM_Node& pos,
- const DOM_Node& parent)
+ const XalanNode* pos,
+ const XalanNode* parent)
{
- DOM_Node thePos(pos);
+ assert(pos != 0);
+ assert(parent != 0);
+
+ const XalanNode* thePos = pos;
+
+ while(parent != thePos)
+ {
+ startNode(thePos);
+
+ const XalanNode* nextNode = thePos->getFirstChild();
+
+ while(0 == nextNode)
+ {
+ endNode(thePos);
+
+ nextNode = thePos->getNextSibling();
+
+ if(0 == nextNode)
+ {
+ thePos = thePos->getParentNode();
+
+ if(parent == thePos)
+ {
+ nextNode = thePos;
+
+ break;
+ }
+ }
+ }
+
+ thePos = nextNode;
+ }
+}
+
+
+
+void
+TreeWalker::traverse(
+ XalanNode* pos,
+ XalanNode* parent)
+{
+ assert(pos != 0);
+ assert(parent != 0);
+
+ XalanNode* thePos = pos;
while(parent != thePos)
{
startNode(thePos);
- DOM_Node nextNode = thePos.getFirstChild();
+ XalanNode* nextNode = thePos->getFirstChild();
while(0 == nextNode)
{
endNode(thePos);
- nextNode = thePos.getNextSibling();
+ nextNode = thePos->getNextSibling();
if(0 == nextNode)
{
- thePos = thePos.getParentNode();
+ thePos = thePos->getParentNode();
if(parent == thePos)
{
1.3 +32 -6 xml-xalan/c/src/DOMSupport/TreeWalker.hpp
Index: TreeWalker.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/DOMSupport/TreeWalker.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TreeWalker.hpp 2000/02/23 20:23:09 1.2
+++ TreeWalker.hpp 2000/04/11 14:30:44 1.3
@@ -64,7 +64,7 @@
-class DOM_Node;
+class XalanNode;
@@ -87,26 +87,52 @@
*/
virtual void
- traverse(const DOM_Node& pos);
+ traverse(const XalanNode* pos);
/**
* Perform a pre-order traversal non-recursive style.
*
+ * @param pos starting node $$$
+ */
+
+ virtual void
+ traverse(XalanNode* pos);
+
+ /**
+ * Perform a pre-order traversal non-recursive style.
+ *
* @param pos starting node $$$
* @param parent parent node $$$
*/
virtual void
traverse(
- const DOM_Node& pos,
- const DOM_Node& parent);
+ const XalanNode* pos,
+ const XalanNode* parent);
+ /**
+ * Perform a pre-order traversal non-recursive style.
+ *
+ * @param pos starting node $$$
+ * @param parent parent node $$$
+ */
+ virtual void
+ traverse(
+ XalanNode* pos,
+ XalanNode* parent);
+
protected:
+ virtual void
+ startNode(const XalanNode* node) = 0;
+
+ virtual void
+ startNode(XalanNode* node) = 0;
+
virtual void
- startNode(const DOM_Node& node) = 0;
+ endNode(const XalanNode* node) = 0;
virtual void
- endNode(const DOM_Node& node) = 0;
+ endNode(XalanNode* node) = 0;
private:
};