Clarify ACR API
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / acr / xml / DomContent.java
index 1520bc2cf7cf48b49b40caf88d92dbcbb6e4becd..1d751149101caaabad4e17b697b4bb699de94e9e 100644 (file)
@@ -29,11 +29,12 @@ import javax.xml.transform.stream.StreamResult;
 
 import org.argeo.api.acr.Content;
 import org.argeo.api.acr.ContentName;
+import org.argeo.api.acr.CrAttributeType;
 import org.argeo.api.acr.CrName;
 import org.argeo.api.acr.spi.ProvidedContent;
 import org.argeo.api.acr.spi.ProvidedSession;
 import org.argeo.cms.acr.AbstractContent;
-import org.argeo.cms.acr.ContentUtils;
+import org.argeo.cms.acr.CmsContent;
 import org.w3c.dom.Attr;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Document;
@@ -68,7 +69,7 @@ public class DomContent extends AbstractContent implements ProvidedContent {
                if (isLocalRoot()) {// root
                        String mountPath = provider.getMountPath();
                        if (mountPath != null) {
-                               if (ContentUtils.ROOT_SLASH.equals(mountPath)) {
+                               if (Content.ROOT_PATH.equals(mountPath)) {
                                        return CrName.root.qName();
                                }
                                Content mountPoint = getSession().getMountPoint(mountPath);
@@ -137,17 +138,16 @@ public class DomContent extends AbstractContent implements ProvidedContent {
                return result;
        }
 
-       @SuppressWarnings("unchecked")
+//     @SuppressWarnings("unchecked")
        @Override
        public <A> Optional<A> get(QName key, Class<A> clss) {
                String namespaceUriOrNull = XMLConstants.NULL_NS_URI.equals(key.getNamespaceURI()) ? null
                                : key.getNamespaceURI();
                if (element.hasAttributeNS(namespaceUriOrNull, key.getLocalPart())) {
                        String value = element.getAttributeNS(namespaceUriOrNull, key.getLocalPart());
-                       if (clss.isAssignableFrom(String.class))
-                               return Optional.of((A) value);
-                       else
-                               return Optional.empty();
+//                     if (isDefaultAttrTypeRequested(clss))
+//                             return Optional.of((A) CrAttributeType.parse(value));
+                       return CrAttributeType.cast(clss, value);
                } else
                        return Optional.empty();
        }
@@ -236,11 +236,11 @@ public class DomContent extends AbstractContent implements ProvidedContent {
                        String mountPath = provider.getMountPath();
                        if (mountPath == null)
                                return null;
-                       if (ContentUtils.ROOT_SLASH.equals(mountPath)) {
+                       if (Content.ROOT_PATH.equals(mountPath)) {
                                return null;
                        }
-                       String[] parent = ContentUtils.getParentPath(mountPath);
-                       if (ContentUtils.EMPTY.equals(parent[0]))
+                       String[] parent = CmsContent.getParentPath(mountPath);
+                       if ("".equals(parent[0]))
                                return null;
                        return getSession().get(parent[0]);
                }
@@ -386,7 +386,7 @@ public class DomContent extends AbstractContent implements ProvidedContent {
                List<QName> res = new ArrayList<>();
                if (isLocalRoot()) {
                        String mountPath = provider.getMountPath();
-                       if (ContentUtils.SLASH_STRING.equals(mountPath)) {// repository root
+                       if (Content.ROOT_PATH.equals(mountPath)) {// repository root
                                res.add(CrName.root.qName());
                        } else {
                                Content mountPoint = getSession().getMountPoint(mountPath);
@@ -402,7 +402,7 @@ public class DomContent extends AbstractContent implements ProvidedContent {
        public void addContentClasses(QName... contentClass) {
                if (isLocalRoot()) {
                        String mountPath = provider.getMountPath();
-                       if (ContentUtils.SLASH_STRING.equals(mountPath)) {// repository root
+                       if (Content.ROOT_PATH.equals(mountPath)) {// repository root
                                throw new IllegalArgumentException("Cannot add content classes to repository root");
                        } else {
                                Content mountPoint = getSession().getMountPoint(mountPath);