diff options
author | Michael Stahl <mst@openoffice.org> | 2011-02-10 16:45:04 +0100 |
---|---|---|
committer | Michael Stahl <mst@openoffice.org> | 2011-02-10 16:45:04 +0100 |
commit | baea7fb003baf92129decc6a778659767edd7427 (patch) | |
tree | b58191f209f0b50fed775ed4a52801b7e6762e58 /unoxml/source | |
parent | 141773454451569127d388a1f3fd1fdc65f5554a (diff) |
xmlfix3: unoxml: refactor CAttributesMap::removeNamedItem*: forward to CElement
also fix CElement::removeAttributeNode* to save the prefix.
Diffstat (limited to 'unoxml/source')
-rw-r--r-- | unoxml/source/dom/attributesmap.cxx | 71 | ||||
-rw-r--r-- | unoxml/source/dom/element.cxx | 9 |
2 files changed, 29 insertions, 51 deletions
diff --git a/unoxml/source/dom/attributesmap.cxx b/unoxml/source/dom/attributesmap.cxx index b1542bacebdf..3cec81767d9e 100644 --- a/unoxml/source/dom/attributesmap.cxx +++ b/unoxml/source/dom/attributesmap.cxx @@ -167,29 +167,17 @@ namespace DOM CAttributesMap::removeNamedItem(OUString const& name) throw (RuntimeException) { - ::osl::MutexGuard const g(m_rMutex); - - xmlNodePtr const pNode = m_pElement->GetNodePtr(); - if (pNode != NULL) - { - OString o1 = OUStringToOString(name, RTL_TEXTENCODING_UTF8); - xmlChar* xName = (xmlChar*)o1.getStr(); - xmlAttrPtr cur = pNode->properties; - while (cur != NULL) - { - if (strcmp((char*)xName, (char*)cur->name) == 0) { - ::rtl::Reference<CNode> const pCNode = - m_pElement->GetOwnerDocument().GetCNode( - reinterpret_cast<xmlNodePtr>(cur)).get(); - // this seems to be legal... - xmlUnlinkNode(reinterpret_cast<xmlNodePtr>(cur)); - pCNode->m_bUnlinked = true; - return Reference< XNode >(pCNode.get()); - } - cur = cur->next; - } + // no MutexGuard needed: m_pElement is const + Reference< XAttr > const xAttr(m_pElement->getAttributeNode(name)); + if (!xAttr.is()) { + throw DOMException(OUString(RTL_CONSTASCII_USTRINGPARAM( + "CAttributesMap::removeNamedItem: no such attribute")), + static_cast<OWeakObject*>(this), + DOMExceptionType_NOT_FOUND_ERR); } - return 0; + Reference< XNode > const xRet( + m_pElement->removeAttributeNode(xAttr), UNO_QUERY); + return xRet; } /** @@ -200,35 +188,18 @@ namespace DOM OUString const& namespaceURI, OUString const& localName) throw (RuntimeException) { - ::osl::MutexGuard const g(m_rMutex); - - xmlNodePtr const pNode = m_pElement->GetNodePtr(); - if (pNode != NULL) - { - OString o1 = OUStringToOString(localName, RTL_TEXTENCODING_UTF8); - xmlChar* xName = (xmlChar*)o1.getStr(); - OString o2 = OUStringToOString(namespaceURI, RTL_TEXTENCODING_UTF8); - xmlChar const*const xNs = - reinterpret_cast<xmlChar const*>(o2.getStr()); - xmlNsPtr const pNs = xmlSearchNsByHref(pNode->doc, pNode, xNs); - xmlAttrPtr cur = pNode->properties; - while (cur != NULL && pNs != NULL) - { - if (strcmp((char*)xName, (char*)cur->name) == 0 && - cur->ns == pNs) - { - ::rtl::Reference<CNode> const pCNode = - m_pElement->GetOwnerDocument().GetCNode( - reinterpret_cast<xmlNodePtr>(cur)).get(); - // this seems to be legal... - xmlUnlinkNode(reinterpret_cast<xmlNodePtr>(cur)); - pCNode->m_bUnlinked = true; - return Reference< XNode >(pCNode.get()); - } - cur = cur->next; - } + // no MutexGuard needed: m_pElement is const + Reference< XAttr > const xAttr( + m_pElement->getAttributeNodeNS(namespaceURI, localName)); + if (!xAttr.is()) { + throw DOMException(OUString(RTL_CONSTASCII_USTRINGPARAM( + "CAttributesMap::removeNamedItemNS: no such attribute")), + static_cast<OWeakObject*>(this), + DOMExceptionType_NOT_FOUND_ERR); } - return 0; + Reference< XNode > const xRet( + m_pElement->removeAttributeNode(xAttr), UNO_QUERY); + return xRet; } /** diff --git a/unoxml/source/dom/element.cxx b/unoxml/source/dom/element.cxx index 8fee8d63d63f..c034ca1257d2 100644 --- a/unoxml/source/dom/element.cxx +++ b/unoxml/source/dom/element.cxx @@ -31,6 +31,8 @@ #include <boost/shared_ptr.hpp> +#include <rtl/ustrbuf.hxx> + #include <com/sun/star/xml/sax/FastToken.hdl> #include <comphelper/attributelist.hxx> @@ -508,8 +510,13 @@ namespace DOM Reference< XAttr > aAttr; if (oldAttr->getNamespaceURI().getLength() > 0) { + ::rtl::OUStringBuffer qname(oldAttr->getPrefix()); + if (0 != qname.getLength()) { + qname.append(sal_Unicode(':')); + } + qname.append(oldAttr->getName()); aAttr = GetOwnerDocument().createAttributeNS( - oldAttr->getNamespaceURI(), oldAttr->getName()); + oldAttr->getNamespaceURI(), qname.makeStringAndClear()); } else { aAttr = GetOwnerDocument().createAttribute(oldAttr->getName()); } |