You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by kw...@apache.org on 2023/04/27 11:38:11 UTC

[jackrabbit-filevault] branch master updated: JCRVLT-705 export special properties which are not protected (#292)

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

kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git


The following commit(s) were added to refs/heads/master by this push:
     new a23193e2 JCRVLT-705 export special properties which are not protected (#292)
a23193e2 is described below

commit a23193e2a82e6fd43a8f40135d41aadf9a666e33
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Thu Apr 27 13:38:05 2023 +0200

    JCRVLT-705 export special properties which are not protected (#292)
    
    Properties with special names should only be excluded from the export in
    case they are really protected.
    In some cases "jcr:created" properties are unprotected.
---
 .../vault/fs/impl/io/DocViewSAXFormatter.java      |  8 ++---
 .../vault/fs/impl/io/DocViewSaxFormatterIT.java    | 38 ++++++++++++++++++++--
 2 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXFormatter.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXFormatter.java
index 166f8766..16ca0068 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXFormatter.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXFormatter.java
@@ -107,9 +107,9 @@ public class DocViewSAXFormatter implements AggregateWalkListener {
     private final boolean useBinaryReferences;
 
     /**
-     * Names of properties which should never be contained in the doc view serialization.
+     * Names of properties which should not be contained in the doc view serialization in case they are protected (in the underlying node definition).
      */
-    private static final Set<String> IGNORED_PROTECTED_PROPERTIES;
+    private static final Set<String> IGNORED_POTENTIALLY_PROTECTED_PROPERTIES;
     static {
         Set<String> props = new HashSet<>();
         props.add(JcrConstants.JCR_CREATED);
@@ -117,7 +117,7 @@ public class DocViewSAXFormatter implements AggregateWalkListener {
         props.add(JcrConstants.JCR_BASEVERSION);
         props.add(JcrConstants.JCR_VERSIONHISTORY);
         props.add(JcrConstants.JCR_PREDECESSORS);
-        IGNORED_PROTECTED_PROPERTIES = Collections.unmodifiableSet(props);
+        IGNORED_POTENTIALLY_PROTECTED_PROPERTIES = Collections.unmodifiableSet(props);
     }
 
     protected DocViewSAXFormatter(Aggregate aggregate, XMLStreamWriter writer)
@@ -222,7 +222,7 @@ public class DocViewSAXFormatter implements AggregateWalkListener {
      */
     @Override
     public void onProperty(Property prop, int level) throws RepositoryException {
-        if (IGNORED_PROTECTED_PROPERTIES.contains(prop.getName())) {
+        if (IGNORED_POTENTIALLY_PROTECTED_PROPERTIES.contains(prop.getName()) && prop.getDefinition().isProtected()) {
             return;
         }
 
diff --git a/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSaxFormatterIT.java b/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSaxFormatterIT.java
index 39b195d3..081bd6fd 100644
--- a/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSaxFormatterIT.java
+++ b/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSaxFormatterIT.java
@@ -17,11 +17,18 @@
 
 package org.apache.jackrabbit.vault.fs.impl.io;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.net.URISyntaxException;
+import java.time.ZoneOffset;
+import java.util.Calendar;
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
+import java.util.TimeZone;
 
 import javax.jcr.GuestCredentials;
 import javax.jcr.ItemExistsException;
@@ -43,6 +50,7 @@ import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
 import org.apache.jackrabbit.commons.JcrUtils;
 import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
 import org.apache.jackrabbit.core.security.principal.EveryonePrincipal;
+import org.apache.jackrabbit.util.ISO8601;
 import org.apache.jackrabbit.vault.fs.Mounter;
 import org.apache.jackrabbit.vault.fs.api.Aggregate;
 import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
@@ -54,8 +62,6 @@ import org.apache.jackrabbit.vault.util.JcrConstants;
 import org.junit.Assume;
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
-
 public class DocViewSaxFormatterIT extends IntegrationTestBase {
 
     static String getSerializedAggregate(Session session, String rootNodePath) throws URISyntaxException, RepositoryException, IOException {
@@ -226,4 +232,32 @@ public class DocViewSaxFormatterIT extends IntegrationTestBase {
                 "    jcr:primaryType=\"nt:unstructured\"\n" +
                 "    customMv=\"[value2,value3,value1]\"/>\n", serialization); // don't sort other mv-properties
     }
+
+    @Test
+    public void testUnprotectedAndProtectedProperties() throws RepositoryException, URISyntaxException, IOException {
+        Node node = JcrUtils.getOrCreateByPath("/testroot", NodeType.NT_UNSTRUCTURED, admin);
+        node.addMixin(JcrConstants.MIX_LOCKABLE);
+        node.addMixin(JcrConstants.MIX_LAST_MODIFIED); // adds protected, auto-created properties jcr:lastModified (DATE) and jcr:lastModifiedBy (String)
+        node.addMixin(JcrConstants.MIX_VERSIONABLE);
+        Calendar date = Calendar.getInstance(TimeZone.getTimeZone(ZoneOffset.UTC), Locale.ROOT);
+        node.setProperty("jcr:created", date);
+        admin.save();
+
+        String serialization = getSerializedAggregate(admin, "/testroot");
+
+        assertTrue(node.hasProperty(JcrConstants.JCR_BASEVERSION));
+        // export should contain both protected and unprotected properties
+        // only the ones which have a special name and(!) are protected are excluded (like jcr:baseVersion)
+        assertEquals("valid xml",
+                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+                "<jcr:root xmlns:jcr=\"http://www.jcp.org/jcr/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\"\n" +
+                "    jcr:created=\"{Date}"+ ISO8601.format(date) + "\"\n" +
+                "    jcr:isCheckedOut=\"{Boolean}true\"\n" +
+                "    jcr:lastModified=\"{Date}" + ISO8601.format(node.getProperty("jcr:lastModified").getDate()) + "\"\n" +
+                "    jcr:lastModifiedBy=\"admin\"\n" +
+                "    jcr:mixinTypes=\"[mix:lastModified,mix:lockable,mix:versionable]\"\n" +
+                "    jcr:primaryType=\"nt:unstructured\"\n" +
+                "    jcr:uuid=\"" + node.getIdentifier() + "\"/>\n"
+                , serialization); 
+    }
 }