Improve content edition and validation
[lgpl/argeo-commons.git] / jcr / org.argeo.cms.jcr / src / org / argeo / cms / jcr / acr / JcrContentUtils.java
index af2d782e8fc9592bd61ff1e5ae230bd140df82ea..c85e3644190bb50d73d4e4b704cda3084a0d0af4 100644 (file)
@@ -44,6 +44,7 @@ public class JcrContentUtils {
 
        public static void copyFiles(Node folder, Content collection, String... additionalCollectionTypes) {
                try {
+                       log.debug("Copy collection " + collection);
                        nodes: for (NodeIterator it = folder.getNodes(); it.hasNext();) {
                                Node node = it.nextNode();
                                String name = node.getName();
@@ -65,25 +66,23 @@ public class JcrContentUtils {
                                        }
 
                                        QName qName = NamespaceUtils.parsePrefixedName(name);
-                                       if (NamespaceUtils.hasNamespace(qName)) {
-                                               if (node.getIndex() > 1) {
-                                                       log.warn("Same name siblings not supported, skipping " + node);
-                                                       continue nodes;
-                                               }
-                                               Content content = collection.add(qName, qName);
-                                               Source source = toSource(node);
-                                               ((ProvidedContent) content).getSession().edit((s) -> {
-                                                       ((ProvidedSession) s).notifyModification((ProvidedContent) content);
-                                                       content.write(Source.class).complete(source);
-//                                                     ContentUtils.traverse(content,
-//                                                                     (c, depth) -> ContentUtils.print(c, System.out, depth, false));
-                                               }).toCompletableFuture().join();
-
-                                       } else {
-                                               // ignore
-                                               log.debug(() -> "Ignored " + node);
+//                                     if (NamespaceUtils.hasNamespace(qName)) {
+                                       if (node.getIndex() > 1) {
+                                               log.warn("Same name siblings not supported, skipping " + node);
                                                continue nodes;
                                        }
+                                       Content content = collection.add(qName, qName);
+                                       Source source = toSource(node);
+                                       ((ProvidedContent) content).getSession().edit((s) -> {
+                                               ((ProvidedSession) s).notifyModification((ProvidedContent) content);
+                                               content.write(Source.class).complete(source);
+                                       }).toCompletableFuture().join();
+
+//                                     } else {
+//                                             // ignore
+//                                             log.debug(() -> "Ignored " + node);
+//                                             continue nodes;
+//                                     }
                                }
                        }
                } catch (RepositoryException e) {
@@ -93,7 +92,21 @@ public class JcrContentUtils {
                }
        }
 
-       private static Source toSource(Node node) {
+       private static Source toSource(Node node) throws RepositoryException {
+
+//             try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+//                     node.getSession().exportDocumentView(node.getPath(), out, true, false);
+//                     DocumentBuilder documentBuilder = DocumentBuilderFactory.newNSInstance().newDocumentBuilder();
+//                     Document document;
+//                     try (ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray())) {
+//                             document = documentBuilder.parse(in);
+//                     }
+//                     cleanJcrDom(document);
+//                     return new DOMSource(document);
+//             } catch (IOException | SAXException | ParserConfigurationException e) {
+//                     throw new RuntimeException(e);
+//             }
+
                try (PipedInputStream in = new PipedInputStream();) {
 
                        CompletableFuture<Document> toDo = CompletableFuture.supplyAsync(() -> {