]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - jcr/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContent.java
ACR compatible with Android.
[lgpl/argeo-commons.git] / jcr / org.argeo.cms.jcr / src / org / argeo / cms / jcr / acr / JcrContent.java
index 134f68162fcdfa5525d14bc0793c1dd9c4a2cc0c..b32ae302085a059bf67c67ddfcca25c173bc9f4a 100644 (file)
@@ -27,10 +27,12 @@ import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
 
 import org.argeo.api.acr.Content;
-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.ContentProvider;
 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.jcr.Jcr;
 import org.argeo.jcr.JcrException;
 import org.argeo.jcr.JcrUtils;
@@ -259,29 +261,32 @@ public class JcrContent extends AbstractContent {
                return super.open(clss);
        }
 
-//     class JcrKeyIterator implements Iterator<QName> {
-//             private final PropertyIterator propertyIterator;
-//
-//             protected JcrKeyIterator(PropertyIterator propertyIterator) {
-//                     this.propertyIterator = propertyIterator;
-//             }
-//
-//             @Override
-//             public boolean hasNext() {
-//                     return propertyIterator.hasNext();
-//             }
-//
-//             @Override
-//             public QName next() {
-//                     Property property = null;
-//                     try {
-//                             property = propertyIterator.nextProperty();
-//                             // TODO map standard property names
-//                             return NamespaceUtils.parsePrefixedName(provider, property.getName());
-//                     } catch (RepositoryException e) {
-//                             throw new JcrException("Cannot retrieve property " + property, null);
-//                     }
-//             }
-//
-//     }
+       @Override
+       public ProvidedSession getSession() {
+               return session;
+       }
+
+       @Override
+       public ContentProvider getProvider() {
+               return provider;
+       }
+
+       /*
+        * 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);
+               }
+       }
+
 }