]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.cms/src/org/argeo/cms/acr/ContentUtils.java
Directory as a hierarchy unit.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / acr / ContentUtils.java
index 272a5c5a148d3f51b3315fad79918e4837aed3c9..5ea79662a387341f5d902c58f0fdc5c95de74f3b 100644 (file)
@@ -3,11 +3,16 @@ package org.argeo.cms.acr;
 import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.StringJoiner;
 import java.util.function.BiConsumer;
 
 import javax.xml.namespace.QName;
 
 import org.argeo.api.acr.Content;
+import org.argeo.api.acr.ContentSession;
+import org.argeo.cms.CmsUserManager;
+import org.argeo.osgi.useradmin.UserDirectory;
+import org.osgi.service.useradmin.Role;
 
 /** Utilities and routines around {@link Content}. */
 public class ContentUtils {
@@ -78,6 +83,13 @@ public class ContentUtils {
                                path.substring(parentIndex + 1) };
        }
 
+       public static String toPath(List<String> segments) {
+               // TODO checks
+               StringJoiner sj = new StringJoiner("/");
+               segments.forEach((s) -> sj.add(s));
+               return sj.toString();
+       }
+
        public static List<String> toPathSegments(String path) {
                List<String> res = new ArrayList<>();
                if ("".equals(path) || ROOT_SLASH.equals(path))
@@ -106,4 +118,12 @@ public class ContentUtils {
 
        }
 
+       public static Content roleToContent(CmsUserManager userManager, ContentSession contentSession, Role role) {
+               UserDirectory userDirectory = userManager.getDirectory(role);
+               String path = CmsContentRepository.DIRECTORY_BASE + SLASH + userDirectory.getName() + SLASH
+                               + userDirectory.getRolePath(role);
+               Content content = contentSession.get(path);
+               return content;
+       }
+
 }