Clarify ACR API
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / acr / CmsContentSession.java
index daefe9835e371c4210bf6487ce108ac04700e05d..04a6fea6cdf15ad231127f66b79c7153981289d1 100644 (file)
@@ -74,7 +74,7 @@ class CmsContentSession implements ProvidedSession, UuidIdentified {
                        throw new IllegalArgumentException(path + " is not an absolute path");
                ContentProvider contentProvider = contentRepository.getMountManager().findContentProvider(path);
                String mountPath = contentProvider.getMountPath();
-               String relativePath = ContentUtils.relativize(mountPath, path);
+               String relativePath = CmsContent.relativize(mountPath, path);
                ProvidedContent content = contentProvider.get(CmsContentSession.this, relativePath);
                return content;
        }
@@ -85,7 +85,7 @@ class CmsContentSession implements ProvidedSession, UuidIdentified {
                        throw new IllegalArgumentException(path + " is not an absolute path");
                ContentProvider contentProvider = contentRepository.getMountManager().findContentProvider(path);
                String mountPath = contentProvider.getMountPath();
-               String relativePath = ContentUtils.relativize(mountPath, path);
+               String relativePath = CmsContent.relativize(mountPath, path);
                return contentProvider.exists(this, relativePath);
        }
 
@@ -113,7 +113,7 @@ class CmsContentSession implements ProvidedSession, UuidIdentified {
         */
        @Override
        public Content getMountPoint(String path) {
-               String[] parent = ContentUtils.getParentPath(path);
+               String[] parent = CmsContent.getParentPath(path);
                ProvidedContent mountParent = (ProvidedContent) get(parent[0]);
 //                     Content mountPoint = mountParent.getProvider().get(CmsContentSession.this, null, path);
                return mountParent.getMountPoint(parent[1]);
@@ -206,10 +206,12 @@ class CmsContentSession implements ProvidedSession, UuidIdentified {
                        NavigableMap<String, ContentProvider> contentProviders = contentRepository.getMountManager()
                                        .findContentProviders(scopePath);
                        for (Map.Entry<String, ContentProvider> contentProvider : contentProviders.entrySet()) {
+                               assert scopePath.startsWith(contentProvider.getKey())
+                                               : "scopePath=" + scopePath + ", contentProvider path=" + contentProvider.getKey();
                                // TODO deal with depth
                                String relPath;
-                               if (scopePath.startsWith(contentProvider.getKey())) {
-                                       relPath = scopePath.substring(contentProvider.getKey().length());
+                               if (!scopePath.equals(contentProvider.getKey())) {
+                                       relPath = scopePath.substring(contentProvider.getKey().length() + 1, scopePath.length());
                                } else {
                                        relPath = null;
                                }
@@ -217,6 +219,8 @@ class CmsContentSession implements ProvidedSession, UuidIdentified {
                                searchPartitions.put(contentProvider.getKey(), searchPartition);
                        }
                }
+               if (searchPartitions.isEmpty())
+                       return Stream.empty();
                return StreamSupport.stream(new SearchPartitionsSpliterator(searchPartitions), true);
        }