This is an automated email from the ASF dual-hosted git repository.

ardovm pushed a commit to branch AOO42X
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 626e3ce77c6a68d6a46dc3b1f31d6b25a4ee98a7
Author: Arrigo Marchiori <ard...@yahoo.it>
AuthorDate: Sun Jan 19 22:16:04 2025 +0100

    File and URL history elements disappear when cleared
    
    Allow configuration elements to disappear by becoming "wiped"-type
    nodes.
    Intercept the removal of file and URL history elements and turn them into
    "wiped" nodes.
    
    (cherry picked from commit afd9e31976a562115f55d066936663bde22b7456)
---
 main/configmgr/Library_configmgr.mk               |  1 +
 main/configmgr/source/access.cxx                  | 24 ++++++++-
 main/configmgr/source/makefile.mk                 |  1 +
 main/configmgr/source/node.hxx                    | 43 ++++++++++++++-
 main/configmgr/source/wipednode.cxx               | 64 +++++++++++++++++++++++
 main/configmgr/source/{node.hxx => wipednode.hxx} | 63 ++++++++--------------
 main/configmgr/source/writemodfile.cxx            |  4 ++
 7 files changed, 155 insertions(+), 45 deletions(-)

diff --git a/main/configmgr/Library_configmgr.mk 
b/main/configmgr/Library_configmgr.mk
index 87c334dcbb..d53588fd03 100644
--- a/main/configmgr/Library_configmgr.mk
+++ b/main/configmgr/Library_configmgr.mk
@@ -74,6 +74,7 @@ $(eval $(call gb_Library_add_exception_objects,configmgr,\
        configmgr/source/type \
        configmgr/source/update \
        configmgr/source/valueparser \
+       configmgr/source/wipednode \
        configmgr/source/writemodfile \
        configmgr/source/xcdparser \
        configmgr/source/xcsparser \
diff --git a/main/configmgr/source/access.cxx b/main/configmgr/source/access.cxx
index f7ec65c897..b06c0d12ae 100644
--- a/main/configmgr/source/access.cxx
+++ b/main/configmgr/source/access.cxx
@@ -101,6 +101,7 @@
 #include "propertynode.hxx"
 #include "rootaccess.hxx"
 #include "setnode.hxx"
+#include "wipednode.hxx"
 #include "type.hxx"
 
 namespace configmgr {
@@ -480,7 +481,7 @@ void Access::initBroadcasterAndChanges(
          i != modifications.children.end(); ++i)
     {
         rtl::Reference< ChildAccess > child(getChild(i->first));
-        if (child.is()) {
+        if (child.is() && (child->getNode()->kind() != Node::KIND_WIPED)) {
             switch (child->getNode()->kind()) {
             case Node::KIND_LOCALIZED_PROPERTY:
                 if (!i->second.children.empty()) {
@@ -677,6 +678,8 @@ void Access::initBroadcasterAndChanges(
                         // listeners
                 }
                 break;
+            case Node::KIND_WIPED:
+                break; // Excluded above
             }
         } else {
             switch (getNode()->kind()) {
@@ -1906,12 +1909,29 @@ void Access::removeByName(rtl::OUString const & aName)
                     aName, static_cast< cppu::OWeakObject * >(this));
             }
         }
+        // Elements of file/URL histories must not be marked as
+        // "removed": they must disappear
+        bool mustWipe = false;
+        ::rtl::Reference< Access > parent = getParentAccess();
+        if (parent.is()) {
+            const ::rtl::OUString parentName = parent->getName();
+            mustWipe =
+                ((parentName == ::rtl::OUString::createFromAscii("PickList")) 
||
+                 (parentName == 
::rtl::OUString::createFromAscii("URLHistory"))) &&
+                (getName() == ::rtl::OUString::createFromAscii("ItemList"));
+        }
         Modifications localMods;
         localMods.add(child->getRelativePath());
         // unbind() modifies the parent chain that markChildAsModified() walks,
         // so order is important:
         markChildAsModified(child); //TODO: must not throw
-        child->unbind();
+        if (!mustWipe) {
+            // This will mark the element as "removed"
+            child->unbind();
+        } else {
+            // The element will disappear
+            child->setNode(new WipedNode(child->getNode()->getLayer()));
+        }
         getNotificationRoot()->initBroadcaster(localMods.getRoot(), &bc);
     }
     bc.send();
diff --git a/main/configmgr/source/makefile.mk 
b/main/configmgr/source/makefile.mk
index ca118eb3e8..7ebadd69e0 100644
--- a/main/configmgr/source/makefile.mk
+++ b/main/configmgr/source/makefile.mk
@@ -57,6 +57,7 @@ SLOFILES = \
     $(SLO)/type.obj \
     $(SLO)/update.obj \
     $(SLO)/valueparser.obj \
+    $(SLO)/wipednode.obj \
     $(SLO)/writemodfile.obj \
     $(SLO)/xcdparser.obj \
     $(SLO)/xcsparser.obj \
diff --git a/main/configmgr/source/node.hxx b/main/configmgr/source/node.hxx
index 32dc26d070..5a03d15f78 100644
--- a/main/configmgr/source/node.hxx
+++ b/main/configmgr/source/node.hxx
@@ -35,11 +35,50 @@ namespace rtl { class OUString; }
 
 namespace configmgr {
 
+/**
+ * Configuration element.
+ *
+ * This class represent either a "node" or a "property" in the words of the
+ * OpenOffice.org Registry Format (OOR).
+ */
 class Node: public salhelper::SimpleReferenceObject {
 public:
+    /// Identifies the type of configuration element.
     enum Kind {
-        KIND_PROPERTY, KIND_LOCALIZED_PROPERTY, KIND_LOCALIZED_VALUE,
-        KIND_GROUP, KIND_SET };
+        /** Property (&lt;prop&gt; element)
+         *
+         * Identifies instances of PropertyNode.
+         */
+        KIND_PROPERTY,
+        /** Localized property (&lt;prop&gt; element)
+         *
+         * Identifies instances of LocalizedPropertyNode.
+         */
+        KIND_LOCALIZED_PROPERTY,
+        /**
+         * Value of a property (&lt;value&gt; element)
+         *
+         * Identifies instances of LocalizedValueNode.
+         */
+        KIND_LOCALIZED_VALUE,
+        /** Group node (&lt;node&gt; element)
+         *
+         * Identifies instances of GroupNode.
+         */
+        KIND_GROUP,
+        /** Set node (&lt;node&gt; element)
+         *
+         * Identifies instances of SetNode.
+         */
+        KIND_SET,
+        /** Node to be deleted.
+         *
+         * This type of element is not present in the OOR. It is used as a
+         * placeholder for a node that is about to disappear.
+         *
+         * Identifies instances of WipedNode.
+         */
+        KIND_WIPED };
 
     virtual Kind kind() const = 0;
 
diff --git a/main/configmgr/source/wipednode.cxx 
b/main/configmgr/source/wipednode.cxx
new file mode 100644
index 0000000000..87c992f457
--- /dev/null
+++ b/main/configmgr/source/wipednode.cxx
@@ -0,0 +1,64 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+
+
+#include "precompiled_configmgr.hxx"
+#include "sal/config.h"
+
+#include "com/sun/star/beans/Optional.hpp"
+#include "com/sun/star/uno/Any.hxx"
+#include "osl/diagnose.h"
+#include "rtl/ref.hxx"
+#include "rtl/ustring.h"
+#include "rtl/ustring.hxx"
+
+#include "components.hxx"
+#include "node.hxx"
+#include "wipednode.hxx"
+
+namespace configmgr {
+
+namespace {
+
+namespace css = com::sun::star;
+
+}
+
+WipedNode::WipedNode(int layer):
+    Node(layer)
+{}
+
+rtl::Reference< Node > WipedNode::clone(bool) const {
+    return new WipedNode(*this);
+}
+
+WipedNode::WipedNode(WipedNode const & other):
+    Node(other)
+{}
+
+WipedNode::~WipedNode() {}
+
+Node::Kind WipedNode::kind() const {
+    return KIND_WIPED;
+}
+
+}
diff --git a/main/configmgr/source/node.hxx 
b/main/configmgr/source/wipednode.hxx
similarity index 55%
copy from main/configmgr/source/node.hxx
copy to main/configmgr/source/wipednode.hxx
index 32dc26d070..9386aec165 100644
--- a/main/configmgr/source/node.hxx
+++ b/main/configmgr/source/wipednode.hxx
@@ -1,5 +1,5 @@
 /**************************************************************
- * 
+ *
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -7,73 +7,54 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
- * 
+ *
  *************************************************************/
 
 
 
-#ifndef INCLUDED_CONFIGMGR_SOURCE_NODE_HXX
-#define INCLUDED_CONFIGMGR_SOURCE_NODE_HXX
+#ifndef INCLUDED_CONFIGMGR_SOURCE_WIPEDNODE_HXX
+#define INCLUDED_CONFIGMGR_SOURCE_WIPEDNODE_HXX
 
 #include "sal/config.h"
 
 #include "rtl/ref.hxx"
-#include "salhelper/simplereferenceobject.hxx"
 
-#include "nodemap.hxx"
+#include "node.hxx"
 
 namespace rtl { class OUString; }
 
 namespace configmgr {
 
-class Node: public salhelper::SimpleReferenceObject {
-public:
-    enum Kind {
-        KIND_PROPERTY, KIND_LOCALIZED_PROPERTY, KIND_LOCALIZED_VALUE,
-        KIND_GROUP, KIND_SET };
-
-    virtual Kind kind() const = 0;
-
-    virtual rtl::Reference< Node > clone(bool keepTemplateName) const = 0;
-
-    virtual NodeMap & getMembers();
-
-    virtual rtl::OUString getTemplateName() const;
-
-    virtual void setMandatory(int layer);
+class Components;
 
-    virtual int getMandatory() const;
-
-    void setLayer(int layer);
-
-    int getLayer() const;
-
-    void setFinalized(int layer);
-
-    int getFinalized() const;
-
-    rtl::Reference< Node > getMember(rtl::OUString const & name);
+/**
+ * A configuration element that is going to disappear.
+ *
+ * These objects are a placeholder for elements that are pending removal
+ * and must completely disappear from the configuration registry.
+ */
+class WipedNode: public Node {
+public:
+    WipedNode(int layer);
 
-protected:
-    explicit Node(int layer);
+    virtual rtl::Reference< Node > clone(bool keepTemplateName) const;
 
-    Node(const Node & other);
+private:
+    WipedNode(WipedNode const & other);
 
-    virtual ~Node();
+    virtual ~WipedNode();
 
-    virtual void clear();
+    virtual Kind kind() const;
 
-    int layer_;
-    int finalized_;
 };
 
 }
diff --git a/main/configmgr/source/writemodfile.cxx 
b/main/configmgr/source/writemodfile.cxx
index 113ac767b6..7bd8c64359 100644
--- a/main/configmgr/source/writemodfile.cxx
+++ b/main/configmgr/source/writemodfile.cxx
@@ -443,6 +443,8 @@ void writeNode(
         }
         writeData(handle, RTL_CONSTASCII_STRINGPARAM("</node>"));
         break;
+    case Node::KIND_WIPED:
+        break; // Nothing to write
     }
 }
 
@@ -494,6 +496,8 @@ void writeModifications(
                     handle,
                     RTL_CONSTASCII_STRINGPARAM("\" oor:op=\"remove\"/>"));
                 break;
+            case Node::KIND_WIPED:
+                break; // Our parent was wiped, we should not exist
             default:
                 OSL_ASSERT(false); // this cannot happen
                 break;

Reply via email to