Make JCR to ACR more flexible
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 26 Aug 2022 07:27:53 +0000 (09:27 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 26 Aug 2022 07:27:53 +0000 (09:27 +0200)
jcr/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContentUtils.java

index 702f4d6ba36fc91d6bbe6ea6a5252c5bbca79509..af2d782e8fc9592bd61ff1e5ae230bd140df82ea 100644 (file)
@@ -42,7 +42,7 @@ import org.xml.sax.SAXException;
 public class JcrContentUtils {
        private final static CmsLog log = CmsLog.getLog(JcrContentUtils.class);
 
-       public static void copyFiles(Node folder, Content collection) {
+       public static void copyFiles(Node folder, Content collection, String... additionalCollectionTypes) {
                try {
                        nodes: for (NodeIterator it = folder.getNodes(); it.hasNext();) {
                                Node node = it.nextNode();
@@ -54,8 +54,16 @@ public class JcrContentUtils {
                                        }
                                } else if (node.isNodeType(NodeType.NT_FOLDER)) {
                                        Content subCol = collection.add(name, CrName.collection.qName());
-                                       copyFiles(node, subCol);
+                                       copyFiles(node, subCol, additionalCollectionTypes);
                                } else {
+                                       for (String collectionType : additionalCollectionTypes) {
+                                               if (node.isNodeType(collectionType)) {
+                                                       Content subCol = collection.add(name, CrName.collection.qName());
+                                                       copyFiles(node, subCol, additionalCollectionTypes);
+                                                       continue nodes;
+                                               }
+                                       }
+
                                        QName qName = NamespaceUtils.parsePrefixedName(name);
                                        if (NamespaceUtils.hasNamespace(qName)) {
                                                if (node.getIndex() > 1) {
@@ -130,11 +138,11 @@ public class JcrContentUtils {
                                String namespaceUri = attr.getValue();
                                if (!namespaceUris.contains(namespaceUri)) {
                                        toRemove.add(attr);
-                                       //log.debug("Removing "+i+" " + namespaceUri);
+                                       // log.debug("Removing "+i+" " + namespaceUri);
                                }
                        }
                }
-               for(Attr attr:toRemove)
+               for (Attr attr : toRemove)
                        documentElement.removeAttributeNode(attr);
 
        }