Jackrabbit - 无法检索节点的属性

时间:2014-09-23 11:46:07

标签: java jackrabbit jcr

我使用超级用户创建了文件夹,并为应用程序用户提供了对文件夹的只读访问权限。

尝试查询所有可访问的文件夹(nt:文件夹)时,将属性列表设为空。

要复制的部分代码:

创建文件夹:

public Node createFolder(Session adminSession) { 
   try { 
     Node parentNode = adminSession.getNode("/MyCompany/CommonFolder”);

       if(!parentNode.hasNode("T1")){ 
           Node node = parentNode.addNode("T1", "nt:folder");                 
           node.addMixin("et:folderProperties"); 
           node.setProperty("et:folderName", "T1"); 
           node.addMixin("rep:AccessControllable");                               
           session.save(); return node;
       }else {
          System.out.println("Node already exists");
       }
    } catch (RepositoryException e) {
          e.printStackTrace();
   } 
  return null; 
 }

与用户共享(基于主体)

accessControlManager = (JackrabbitAccessControlManager) 
                               adminSession.getAccessControlManager();
accessControlPolicy = accessControlManager.getApplicablePolicies(userPrincipal); 
// for ex., principal is appuser1

if(accessControlPolicy != null && accessControlPolicy.length > 0) {
     accessControlList = (JackrabbitAccessControlList) accessControlPolicy[0];
}else {
      accessControlPolicy = accessControlManager.getPolicies(userPrincipal);
      accessControlList = (JackrabbitAccessControlList) accessControlPolicy[0];
 }

  ValueFactory valueFactory = adminSession.getValueFactory();

  //Tried all combinations, even providing with "JCR:ALL";
  Privilege[] readPrivilege = new javax.jcr.security.Privilege[] {                                        
                  accessControlManager.privilegeFromName(
                                 javax.jcr.security.Privilege.JCR_READ),
                  accessControlManager.privilegeFromName(
                                 javax.jcr.security.Privilege.JCR_NODE_TYPE_MANAGEMENT),
                  accessControlManager.privilegeFromName(
                                 javax.jcr.security.Privilege.JCR_READ_ACCESS_CONTROL)};

  Map<String, Value> restrictions = new HashMap<String, Value>();
  restrictions.put("rep:nodePath", valueFactory.createValue("/MyCompany/CommonFolder/T1",      
                                                                 PropertyType.PATH));
  restrictions.put("rep:glob",  valueFactory.createValue(""));

  accessControlList.addEntry(userPrincipal, privileges, true  , restrictions);
  accessControlManager.setPolicy(accessControlList.getPath(), accessControlList);
  adminSession.save();

打印所有适用于用户的文件夹

public void printAllFolders(Session userSession) {

   QueryManager queryManager;
   try {
        queryManager = userSession.getWorkspace().getQueryManager();

        String sql = "SELECT * FROM [nt:folder]";                       
        Query query= queryManager.createQuery(sql, Query.JCR_SQL2);

        QueryResult result = query.execute();
        NodeIterator nodeIterator = result.getNodes();

        System.out.println("Printing all applicable folders");      
        while(nodeIterator.hasNext()) {
            Node node = nodeIterator.nextNode();
            System.out.println("Folder Name:" + node.getName() + "; path: " + node.getPath());
            PropertyIterator pIterator =  node.getProperties();

            while (pIterator.hasNext()){  //Returning empty for path "/MyCompany/CommonFolder/T1"
                  Property property = pIterator.nextProperty();
                  if (property.getDefinition().isMultiple()) {
                      Value[] values = property.getValues();
                      for(Value v11: values) {
                            QValueValue value = (QValueValue)v11;                               
                            System.out.println(String.format("Multi-valued property for node:   
                                             '%s' - %s has values",node.getName(),  
                                              property.getName()   ,value.getString()));
                       }
                    } else {
                         QValueValue value = (QValueValue) property.getValue();
                         String strValue = value.getString();         
                         System.out.println(String.format("property for node: '%s' - %s has value   
                                                %s",node.getName(),property.getName(),strValue));
                       }
                }
         }                             

        }   catch (RepositoryException e) {
               e.printStackTrace();
         } 
   }

使用Jackrabbit(2.6.0版本)和JCR(2.0版本)。

1 个答案:

答案 0 :(得分:0)

            Node child = cl.addNode("ONE");

            child.setProperty("message", ("CL Child" + i));

            session.save();
            PropertyIterator iter = child.getProperties();
            System.out.println("Size" + iter.getSize());
            while (iter.hasNext()) {
                PropertyImpl key = (PropertyImpl) iter.next();
                String value = key.getString();
                System.out.println("------------->" + key);
                System.out.println("------------->" + value);

            }