Clarify ACR API
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / acr / MountManager.java
index 8cb90893637b91ebd63dbb2b8db441c389384d46..39b2038fb02676bbf09677e0b46b34a966d6184d 100644 (file)
@@ -28,7 +28,7 @@ class MountManager {
                partitions.put(mountPath, contentProvider);
                if ("/".equals(mountPath))// root
                        return;
-               String[] parentPath = ContentUtils.getParentPath(mountPath);
+               String[] parentPath = CmsContent.getParentPath(mountPath);
                Content parent = systemSession.get(parentPath[0]);
                Content mount = parent.add(parentPath[1]);
                mount.put(CrName.mount.qName(), "true");
@@ -47,20 +47,43 @@ class MountManager {
                return partitions.get(mountPath);
        }
 
+       /** The content provider for this path. */
        synchronized ContentProvider findContentProvider(String path) {
-               Map.Entry<String, ContentProvider> entry = partitions.floorEntry(path);
-               if (entry == null)
-                       throw new IllegalArgumentException("No entry provider found for " + path);
-               String mountPath = entry.getKey();
+//             if (ContentUtils.EMPTY.equals(path))
+//                     return partitions.firstEntry().getValue();
+               Map.Entry<String, ContentProvider> floorEntry = partitions.floorEntry(path);
+               if (floorEntry == null)
+                       throw new IllegalArgumentException("No floor entry provider found for path '" + path + "'");
+               String mountPath = floorEntry.getKey();
                if (!path.startsWith(mountPath)) {
                        // FIXME make it more robust and find when there is no content provider
-                       String[] parent = ContentUtils.getParentPath(path);
+                       String[] parent = CmsContent.getParentPath(path);
                        return findContentProvider(parent[0]);
                        // throw new IllegalArgumentException("Path " + path + " doesn't have a content
                        // provider");
                }
-               ContentProvider contentProvider = entry.getValue();
+               ContentProvider contentProvider = floorEntry.getValue();
                assert mountPath.equals(contentProvider.getMountPath());
                return contentProvider;
        }
+
+       /** All content providers under this path. */
+       synchronized NavigableMap<String, ContentProvider> findContentProviders(String path) {
+               Map.Entry<String, ContentProvider> floorEntry = partitions.floorEntry(path);
+               if (floorEntry == null)
+                       throw new IllegalArgumentException("No floor entry provider found for path '" + path + "'");
+               // we first find the parent provider
+               String parentProviderPath = floorEntry.getKey();
+               // then gather all sub-providers
+               NavigableMap<String, ContentProvider> res = new TreeMap<>();
+               res.put(floorEntry.getKey(), floorEntry.getValue());
+               tail: for (Map.Entry<String, ContentProvider> provider : partitions.tailMap(parentProviderPath).entrySet()) {
+                       if (!provider.getKey().startsWith(path))
+                               break tail;
+                       res.put(provider.getKey(), provider.getValue());
+               }
+               return res;
+
+       }
+
 }