summaryrefslogtreecommitdiff
path: root/unoxml
diff options
context:
space:
mode:
authorHannah Meeks <hmeeks4135@gmail.com>2022-06-18 16:06:44 +0100
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-06-20 18:53:27 +0200
commita1c6d24aac530d7374cf0fdc5c62570d86e30996 (patch)
tree3b91c637dbf9cc840bd06277780a04f4510d55f7 /unoxml
parent6623d5196467c489585130725866e8993bc8dde2 (diff)
Simplify checks with functions.
Change-Id: I55fbab5d8184a743ace3cfec884b0364536ee6fa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136088 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'unoxml')
-rw-r--r--unoxml/inc/node.hxx6
-rw-r--r--unoxml/source/dom/node.cxx67
2 files changed, 41 insertions, 32 deletions
diff --git a/unoxml/inc/node.hxx b/unoxml/inc/node.hxx
index e6974271f83a..852bcd1ae972 100644
--- a/unoxml/inc/node.hxx
+++ b/unoxml/inc/node.hxx
@@ -113,6 +113,12 @@ namespace DOM
void dispatchSubtreeModified();
+ void checkNoParent(css::uno::Reference< css::xml::dom::XNode >const& xNode);
+
+ static void checkNoParent(const xmlNodePtr pNode);
+
+ void checkSameOwner(css::uno::Reference< css::xml::dom::XNode >const& xNode);
+
public:
virtual ~CNode() override;
diff --git a/unoxml/source/dom/node.cxx b/unoxml/source/dom/node.cxx
index 235af0bc5e0d..f5bd99aef475 100644
--- a/unoxml/source/dom/node.cxx
+++ b/unoxml/source/dom/node.cxx
@@ -268,6 +268,28 @@ namespace DOM
return false;
}
+ void CNode::checkNoParent(Reference<XNode>const& xNode){
+ if (xNode->getParentNode() != Reference<XNode>(this)){
+ DOMException e;
+ e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
+ throw e;
+ }
+ }
+ void CNode::checkNoParent(const xmlNodePtr pNode){
+ if (pNode->parent != nullptr){
+ DOMException e;
+ e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
+ throw e;
+ }
+ }
+ void CNode::checkSameOwner(Reference<XNode>const& xNode){
+ if (xNode->getOwnerDocument() != getOwnerDocument()) {
+ DOMException e;
+ e.Code = DOMExceptionType_WRONG_DOCUMENT_ERR;
+ throw e;
+ }
+ }
+
/**
Adds the node newChild to the end of the list of children of this node.
*/
@@ -296,11 +318,8 @@ namespace DOM
e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
throw e;
}
- if (cur->parent != nullptr) {
- DOMException e;
- e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
- throw e;
- }
+ checkNoParent(cur);
+
if (!IsChildTypeAllowed(pNewChild->m_aNodeType)) {
DOMException e;
e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
@@ -610,11 +629,8 @@ namespace DOM
{
if (!newChild.is() || !refChild.is()) { throw RuntimeException(); }
- if (newChild->getOwnerDocument() != getOwnerDocument()) {
- DOMException e;
- e.Code = DOMExceptionType_WRONG_DOCUMENT_ERR;
- throw e;
- }
+ checkSameOwner(newChild);
+
if (refChild->getParentNode() != Reference< XNode >(this)) {
DOMException e;
e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
@@ -636,12 +652,8 @@ namespace DOM
throw e;
}
// already has parent
- if (pNewChild->parent != nullptr)
- {
- DOMException e;
- e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
- throw e;
- }
+ checkNoParent(pNewChild);
+
if (!IsChildTypeAllowed(pNewNode->m_aNodeType)) {
DOMException e;
e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
@@ -714,11 +726,8 @@ namespace DOM
throw RuntimeException();
}
- if (xOldChild->getOwnerDocument() != getOwnerDocument()) {
- DOMException e;
- e.Code = DOMExceptionType_WRONG_DOCUMENT_ERR;
- throw e;
- }
+ checkSameOwner(xOldChild);
+
if (xOldChild->getParentNode() != Reference< XNode >(this)) {
DOMException e;
e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
@@ -784,16 +793,13 @@ namespace DOM
Reference< XNode > SAL_CALL CNode::replaceChild(
Reference< XNode > const& xNewChild,
Reference< XNode > const& xOldChild)
- {
+ {
if (!xOldChild.is() || !xNewChild.is()) {
throw RuntimeException();
}
- if (xNewChild->getOwnerDocument() != getOwnerDocument()) {
- DOMException e;
- e.Code = DOMExceptionType_WRONG_DOCUMENT_ERR;
- throw e;
- }
+ checkSameOwner(xNewChild);
+
if (xOldChild->getParentNode() != Reference< XNode >(this)) {
DOMException e;
e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
@@ -817,11 +823,8 @@ namespace DOM
throw e;
}
// already has parent
- if (pNew->parent != nullptr) {
- DOMException e;
- e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
- throw e;
- }
+ checkNoParent(pNew);
+
if (!IsChildTypeAllowed(pNewNode->m_aNodeType)) {
DOMException e;
e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;