Improve ACR / JCR integration.
[lgpl/argeo-commons.git] / jcr / org.argeo.cms.jcr / src / org / argeo / cms / jcr / acr / JcrContent.java
index 134f68162fcdfa5525d14bc0793c1dd9c4a2cc0c..dab41979498957a91a3906eb0402acfe4c85b57d 100644 (file)
@@ -31,6 +31,7 @@ import org.argeo.api.acr.ContentUtils;
 import org.argeo.api.acr.NamespaceUtils;
 import org.argeo.api.acr.spi.AbstractContent;
 import org.argeo.api.acr.spi.ProvidedSession;
+import org.argeo.api.cms.CmsConstants;
 import org.argeo.jcr.Jcr;
 import org.argeo.jcr.JcrException;
 import org.argeo.jcr.JcrUtils;
@@ -284,4 +285,22 @@ public class JcrContent extends AbstractContent {
 //             }
 //
 //     }
+       /*
+        * STATIC UTLITIES
+        */
+       public static Content nodeToContent(Node node) {
+               if (node == null)
+                       return null;
+               try {
+                       ProvidedSession contentSession = (ProvidedSession) node.getSession()
+                                       .getAttribute(ProvidedSession.class.getName());
+                       if (contentSession == null)
+                               throw new IllegalArgumentException(
+                                               "Cannot adapt " + node + " to content, because it was not loaded from a content session");
+                       return contentSession.get(CmsConstants.SYS_WORKSPACE + node.getPath());
+               } catch (RepositoryException e) {
+                       throw new JcrException("Cannot adapt " + node + " to a content", e);
+               }
+       }
+
 }