X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=jcr%2Forg.argeo.cms.jcr%2Fsrc%2Forg%2Fargeo%2Fcms%2Fjcr%2Facr%2FJcrContent.java;h=b32ae302085a059bf67c67ddfcca25c173bc9f4a;hb=eb4cc3db3bf141c229f0f7ff929daff108bee6d2;hp=9f78577b50b0095767c36cb44bd0557d570bc875;hpb=750a3e154c078d6e9fd72d8da950cb325b8ab012;p=lgpl%2Fargeo-commons.git diff --git a/jcr/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContent.java b/jcr/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContent.java index 9f78577b5..b32ae3020 100644 --- a/jcr/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContent.java +++ b/jcr/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContent.java @@ -28,8 +28,11 @@ import javax.xml.transform.stream.StreamSource; import org.argeo.api.acr.Content; 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; @@ -55,7 +58,9 @@ public class JcrContent extends AbstractContent { public QName getName() { String name = Jcr.getName(getJcrNode()); if (name.equals("")) {// root - name = Jcr.getWorkspaceName(getJcrNode()); + String mountPath = provider.getMountPath(); + name = ContentUtils.getParentPath(mountPath)[1]; + // name = Jcr.getWorkspaceName(getJcrNode()); } return NamespaceUtils.parsePrefixedName(provider, name); } @@ -256,29 +261,32 @@ public class JcrContent extends AbstractContent { return super.open(clss); } -// class JcrKeyIterator implements Iterator { -// 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); + } + } + }