]> git.argeo.org Git - gpl/argeo-jcr.git/blobdiff - org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContent.java
Adapt to changes in Argeo Commons
[gpl/argeo-jcr.git] / org.argeo.cms.jcr / src / org / argeo / cms / jcr / acr / JcrContent.java
index 32366a4fb810df15f5bb777b7a07ade013d15abc..6a0cccb84fb8e9d0ae976a163e6f983c12e566bb 100644 (file)
@@ -46,7 +46,7 @@ import org.argeo.api.acr.NamespaceUtils;
 import org.argeo.api.acr.spi.ProvidedSession;
 import org.argeo.api.cms.CmsConstants;
 import org.argeo.cms.acr.AbstractContent;
-import org.argeo.cms.acr.ContentUtils;
+import org.argeo.cms.acr.CmsContent;
 import org.argeo.cms.util.AsyncPipedOutputStream;
 import org.argeo.jcr.Jcr;
 import org.argeo.jcr.JcrException;
@@ -78,7 +78,7 @@ public class JcrContent extends AbstractContent {
                this.jcrWorkspace = jcrWorkspace;
                this.jcrPath = jcrPath;
 
-               this.isMountBase = ContentUtils.SLASH_STRING.equals(jcrPath);
+               this.isMountBase = "/".equals(jcrPath);
        }
 
        /*
@@ -90,7 +90,7 @@ public class JcrContent extends AbstractContent {
                String name = Jcr.getName(getJcrNode());
                if (name.equals("")) {// root
                        String mountPath = provider.getMountPath();
-                       name = ContentUtils.getParentPath(mountPath)[1];
+                       name = CmsContent.getParentPath(mountPath)[1];
                        // name = Jcr.getWorkspaceName(getJcrNode());
                }
                return NamespaceUtils.parsePrefixedName(provider, name);
@@ -251,7 +251,7 @@ public class JcrContent extends AbstractContent {
                        String mountPath = provider.getMountPath();
                        if (mountPath == null || mountPath.equals("/"))
                                return null;
-                       String[] parent = ContentUtils.getParentPath(mountPath);
+                       String[] parent = CmsContent.getParentPath(mountPath);
                        return getSession().get(parent[0]);
                }
 //             if (Jcr.isRoot(getJcrNode())) // root
@@ -290,6 +290,7 @@ public class JcrContent extends AbstractContent {
        @Override
        public Content add(QName name, QName... classes) {
                try {
+                       Node node = openForEdit();
                        Node child;
                        if (classes.length > 0) {
                                classes: for (int i = 0; i < classes.length; i++) {
@@ -302,7 +303,6 @@ public class JcrContent extends AbstractContent {
                                        }
                                }
                                QName primaryType = classes[0];
-                               Node node = openForEdit();
                                child = Jcr.addNode(node, name.toString(), primaryType.toString());
 
                                for (int i = 1; i < classes.length; i++)
@@ -311,18 +311,11 @@ public class JcrContent extends AbstractContent {
                                if (NtType.file.qName().equals(primaryType)) {
                                        // TODO optimise when we have a proper save mechanism
                                        child.addNode(Node.JCR_CONTENT, NodeType.NT_UNSTRUCTURED);
-//                                     Binary binary;
-//                                     try (InputStream in = new ByteArrayInputStream(new byte[0])) {
-//                                             binary = content.getSession().getValueFactory().createBinary(in);
-//                                             content.setProperty(Property.JCR_DATA, binary);
-//                                     } catch (IOException e) {
-//                                             throw new UncheckedIOException(e);
-//                                     }
-                                       child.getSession().save();
                                }
                        } else {
-                               child = Jcr.addNode(getJcrNode(), name.toString(), NodeType.NT_UNSTRUCTURED);
+                               child = Jcr.addNode(node, name.toString(), NodeType.NT_UNSTRUCTURED);
                        }
+                       saveEditedNode(node);
                        return new JcrContent(getSession(), provider, jcrWorkspace, child.getPath());
                } catch (RepositoryException e) {
                        throw new JcrException("Cannot add child to " + jcrPath + " in " + jcrWorkspace, e);
@@ -462,9 +455,9 @@ public class JcrContent extends AbstractContent {
 
        @Override
        public boolean isParentAccessible() {
-               String jcrParentPath = ContentUtils.getParentPath(jcrPath)[0];
+               String jcrParentPath = CmsContent.getParentPath(jcrPath)[0];
                if ("".equals(jcrParentPath)) // JCR root node
-                       jcrParentPath = ContentUtils.SLASH_STRING;
+                       jcrParentPath = "/";
                try {
                        return getJcrSession().hasPermission(jcrParentPath, Session.ACTION_READ);
                } catch (RepositoryException e) {