summaryrefslogtreecommitdiff
path: root/unoxml/source/dom/node.cxx
diff options
context:
space:
mode:
authorMichael Stahl <mst@openoffice.org>2011-01-19 20:27:28 +0100
committerMichael Stahl <mst@openoffice.org>2011-01-19 20:27:28 +0100
commitd76639d5d833a05a3181f7293e38a250dc6c1299 (patch)
treef868f4025d12b17c45c2b202c3879326d0d645c6 /unoxml/source/dom/node.cxx
parent76eac88260284d6c85c693f7186186a05e053c54 (diff)
xmlfix3: unoxml: eradicate the bizarre concept of "carrier nodes":
add namespace data member to CAttr. CAttr overrides getPrefix(), setPrefix(), getNamespaceURI(). CDocument::createAttributeNS() uses this new CAttr member instead of creating a dummy carrier element. CElement::setAttributeNode_Impl_Lock() and CNode::appendChild() do not free the no longer existing dummy carrier element. CNode::insertBefore() calls appendChild() for attributes instead of ignoring namespace. CNode::appendChild() does not invalidate attributes, because they are copied.
Diffstat (limited to 'unoxml/source/dom/node.cxx')
-rw-r--r--unoxml/source/dom/node.cxx82
1 files changed, 31 insertions, 51 deletions
diff --git a/unoxml/source/dom/node.cxx b/unoxml/source/dom/node.cxx
index 54645e35ad78..68ceb9bfa3e4 100644
--- a/unoxml/source/dom/node.cxx
+++ b/unoxml/source/dom/node.cxx
@@ -43,6 +43,7 @@
#include <com/sun/star/xml/sax/FastToken.hpp>
#include <document.hxx>
+#include <attr.hxx>
#include <childlist.hxx>
#include "../events/eventdispatcher.hxx"
@@ -317,67 +318,40 @@ namespace DOM
e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
throw e;
}
- // already has parent and is not attribute
- if (cur->parent != NULL && cur->type != XML_ATTRIBUTE_NODE) {
+ if (cur->parent != NULL) {
DOMException e;
e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
throw e;
}
- // check whether this is an attribute node so we remove it's
- // carrier node if it has one
+ // check whether this is an attribute node; it needs special handling
xmlNodePtr res = NULL;
if (cur->type == XML_ATTRIBUTE_NODE)
{
- if (cur->parent != NULL) {
- if (m_aNodePtr->type != XML_ELEMENT_NODE ||
- strcmp((char*)cur->parent->name, "__private") != 0)
- {
- DOMException e;
- e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
- throw e;
- }
-
- xmlNsPtr pAttrNs = cur->ns;
- xmlNsPtr pParentNs =
- xmlSearchNs(m_aNodePtr->doc, m_aNodePtr, pAttrNs->prefix);
- if (pParentNs == NULL ||
- strcmp((char*)pParentNs->href, (char*)pAttrNs->href) != 0)
- {
- pParentNs =
- xmlNewNs(m_aNodePtr, pAttrNs->href, pAttrNs->prefix);
- }
-
- if (cur->children != NULL) {
- res = (xmlNodePtr)xmlNewNsProp(m_aNodePtr,
- pParentNs, cur->name, cur->children->content);
- } else {
- res = (xmlNodePtr)xmlNewProp(m_aNodePtr,
- cur->name, (xmlChar*) "");
- }
-
- xmlFreeNode(cur->parent);
- cur->parent = NULL;
+ xmlChar const*const pChildren((cur->children)
+ ? cur->children->content
+ : reinterpret_cast<xmlChar const*>(""));
+ CAttr *const pCAttr(dynamic_cast<CAttr *>(pNewChild));
+ if (!pCAttr) { throw RuntimeException(); }
+ xmlNsPtr const pNs( pCAttr->GetNamespace(m_aNodePtr) );
+ if (pNs) {
+ res = reinterpret_cast<xmlNodePtr>(
+ xmlNewNsProp(m_aNodePtr, pNs, cur->name, pChildren));
} else {
- if (cur->children != NULL) {
- res = (xmlNodePtr)xmlNewProp(m_aNodePtr,
- cur->name, cur->children->content);
- } else {
- res = (xmlNodePtr)xmlNewProp(m_aNodePtr,
- cur->name, (xmlChar*) "");
- }
+ res = reinterpret_cast<xmlNodePtr>(
+ xmlNewProp(m_aNodePtr, cur->name, pChildren));
}
}
else
{
res = xmlAddChild(m_aNodePtr, cur);
- }
- // libxml can do optimizations, when appending nodes.
- // if res != cur, something was optimized and the newchild-wrapper
- // should be updated
- if (res && (cur != res)) {
- pNewChild->invalidate(); // cur has been freed
+ // libxml can do optimization when appending nodes.
+ // if res != cur, something was optimized and the newchild-wrapper
+ // should be updated
+ if (res && (cur != res)) {
+ pNewChild->invalidate(); // cur has been freed
+ }
}
if (!res) { return 0; }
@@ -696,7 +670,7 @@ namespace DOM
throw e;
}
- ::osl::MutexGuard const g(m_rMutex);
+ ::osl::ClearableMutexGuard guard(m_rMutex);
CNode *const pNewNode(CNode::GetImplementation(newChild));
CNode *const pRefNode(CNode::GetImplementation(refChild));
@@ -710,14 +684,20 @@ namespace DOM
e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
throw e;
}
- // already has parent and is not attribute
- if (pNewChild->parent != NULL && pNewChild->type != XML_ATTRIBUTE_NODE)
+ // already has parent
+ if (pNewChild->parent != NULL)
{
DOMException e;
e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
throw e;
}
+ // attributes are unordered anyway, so just do appendChild
+ if (XML_ATTRIBUTE_NODE == pNewChild->type) {
+ guard.clear();
+ return appendChild(newChild);
+ }
+
xmlNodePtr cur = m_aNodePtr->children;
//search child before which to insert
@@ -881,8 +861,8 @@ namespace DOM
e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
throw e;
}
- // already has parent and is not attribute
- if (pNew->parent != NULL && pNew->type != XML_ATTRIBUTE_NODE) {
+ // already has parent
+ if (pNew->parent != NULL) {
DOMException e;
e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
throw e;