Example #1
0
  @FixFor("MODE-1732")
  @Test
  public void shouldFollowReferenceFromRecentTagToCommit() throws Exception {
    Node git = gitNode();
    Node tag = git.getNode("tags/modeshape-3.0.0.Final");
    assertThat(tag.getProperty("git:objectId").getString(), is(notNullValue()));
    assertThat(tag.getProperty("git:tree").getString(), is(notNullValue()));
    assertThat(tag.getProperty("git:history").getString(), is(notNullValue()));
    Node tagTree = tag.getProperty("git:tree").getNode();
    assertThat(tagTree.getPath(), is(treePathFor(tag)));
    assertChildrenInclude(tagTree, expectedTopLevelFileAndFolderNames());

    // Load some of the child nodes ...
    Node pomFile = tagTree.getNode("pom.xml");
    assertThat(pomFile.getPrimaryNodeType().getName(), is("git:file"));
    assertNodeHasObjectIdProperty(pomFile);
    assertNodeHasCommittedProperties(pomFile);
    Node pomContent = pomFile.getNode("jcr:content");
    assertNodeHasCommittedProperties(pomContent);
    assertThat(pomContent.getProperty("jcr:data").getString(), is(notNullValue()));

    Node readmeFile = tagTree.getNode("README.md");
    assertThat(readmeFile.getPrimaryNodeType().getName(), is("git:file"));
    assertNodeHasObjectIdProperty(readmeFile);
    assertNodeHasCommittedProperties(readmeFile);
    Node readmeContent = readmeFile.getNode("jcr:content");
    assertNodeHasCommittedProperties(readmeContent);
    assertThat(readmeContent.getProperty("jcr:data").getString(), is(notNullValue()));

    Node parentModule = tagTree.getNode("modeshape-parent");
    assertThat(parentModule.getPrimaryNodeType().getName(), is("git:folder"));
    assertNodeHasObjectIdProperty(parentModule);
    assertNodeHasCommittedProperties(parentModule);
  }
Example #2
0
  public String[] getFileNames(long companyId, long repositoryId) throws SystemException {

    List<String> fileNames = new ArrayList<String>();

    Session session = null;

    try {
      session = JCRFactoryUtil.createSession();

      Node rootNode = getRootNode(session, companyId);

      Node repositoryNode = getFolderNode(rootNode, repositoryId);

      NodeIterator itr = repositoryNode.getNodes();

      while (itr.hasNext()) {
        Node node = (Node) itr.next();

        NodeType primaryNodeType = node.getPrimaryNodeType();

        String primaryNodeTypeName = primaryNodeType.getName();

        if (primaryNodeTypeName.equals(JCRConstants.NT_FILE)) {
          fileNames.add(node.getName());
        }
      }
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      JCRFactoryUtil.closeSession(session);
    }

    return fileNames.toArray(new String[0]);
  }
  @Override
  public List<JcrNode> childNodes(String path) throws RemoteException {
    List<JcrNode> children = null;
    if (path == null || path.trim().length() == 0) {
      return Collections.emptyList();
    }
    try {
      Node node = (Node) session().getItem(path);
      NodeIterator it = node.getNodes();
      children = new ArrayList<JcrNode>((int) it.getSize());

      while (it.hasNext()) {
        Node n = it.nextNode();
        JcrNode childNode = new JcrNode(n.getName(), n.getPath(), n.getPrimaryNodeType().getName());
        childNode.setProperties(getProperties(n));
        childNode.setAcessControlList(getAccessList(session().getAccessControlManager(), node));
        childNode.setMixins(mixins(n));
        childNode.setPropertyDefs(propertyDefs(n));
        children.add(childNode);
      }

    } catch (PathNotFoundException e) {
      log.log(Level.FINER, e.getLocalizedMessage());
    } catch (RepositoryException e) {
      log.log(Level.SEVERE, "Unexpected error", e);
      throw new RemoteException(e.getMessage());
    }

    return children;
  }
  /**
   * Gets the list of properties available to the given node.
   *
   * @param node the node instance.
   * @return list of property names.
   * @throws RepositoryException
   */
  private String[] propertyDefs(Node node) throws RepositoryException {
    ArrayList<String> list = new ArrayList();

    NodeType primaryType = node.getPrimaryNodeType();
    PropertyDefinition[] defs = primaryType.getPropertyDefinitions();

    for (PropertyDefinition def : defs) {
      if (!def.isProtected()) {
        list.add(def.getName());
      }
    }

    NodeType[] mixinType = node.getMixinNodeTypes();
    for (NodeType type : mixinType) {
      defs = type.getPropertyDefinitions();
      for (PropertyDefinition def : defs) {
        if (!def.isProtected()) {
          list.add(def.getName());
        }
      }
    }

    String[] res = new String[list.size()];
    list.toArray(res);
    return res;
  }
  @Before
  public void setUp() throws RepositoryException {
    initMocks(this);
    final String relPath = "/" + testPid;
    final NodeType[] types = new NodeType[0];
    try {
      when(mockObjNode.getName()).thenReturn(testPid);
      when(mockObjNode.getSession()).thenReturn(mockSession);
      when(mockObjNode.getMixinNodeTypes()).thenReturn(types);
      NodeType mockNodeType = mock(NodeType.class);
      when(mockNodeType.getName()).thenReturn("nt:folder");
      when(mockObjNode.getPrimaryNodeType()).thenReturn(mockNodeType);
      when(mockSession.getRootNode()).thenReturn(mockRootNode);
      when(mockRootNode.getNode(relPath)).thenReturn(mockObjNode);
      when(mockSession.getUserID()).thenReturn(mockUser);
      testFedoraObject = new FedoraObject(mockObjNode);

      mockNodetypes = new NodeType[2];
      mockNodetypes[0] = mock(NodeType.class);
      mockNodetypes[1] = mock(NodeType.class);

      when(mockObjNode.getMixinNodeTypes()).thenReturn(mockNodetypes);

      when(mockPredicate.apply(mockObjNode)).thenReturn(true);

    } catch (final RepositoryException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
Example #6
0
  /** A LockException is thrown if a lock prevents the copy. */
  public void testMoveNodesLocked() throws RepositoryException {
    // we assume repository supports locking
    String dstAbsPath = node2.getPath() + "/" + node1.getName();

    // get other session
    Session otherSession = helper.getReadWriteSession();

    try {
      // get lock target node in destination wsp through other session
      Node lockTarget = (Node) otherSession.getItem(node2.getPath());

      // add mixin "lockable" to be able to lock the node
      if (!lockTarget.getPrimaryNodeType().isNodeType(mixLockable)) {
        lockTarget.addMixin(mixLockable);
        lockTarget.getParent().save();
      }

      // lock dst parent node using other session
      lockTarget.lock(true, true);

      try {
        workspace.move(node1.getPath(), dstAbsPath);
        fail("LockException was expected.");
      } catch (LockException e) {
        // successful
      } finally {
        lockTarget.unlock();
      }
    } finally {
      otherSession.logout();
    }
  }
 private String getType(Node node) throws Exception {
   if (node.isNodeType("exo:taxonomy")) {
     return "category";
   } else if (documentTypes.contains(node.getPrimaryNodeType().getName())) {
     return "article";
   }
   return "";
 }
Example #8
0
 @Override
 public boolean matchesSafely(Node item) {
   try {
     return item != null && item.getPrimaryNodeType().getName().equals(primaryType);
   } catch (RepositoryException e) {
     return false;
   }
 }
Example #9
0
 @Test
 public void shouldContainTagsAndBranchNamesAndCommitsUnderTreeNode() throws Exception {
   Node git = gitNode();
   Node tree = git.getNode("tree");
   assertThat(tree.getPrimaryNodeType().getName(), is("git:trees"));
   assertChildrenInclude(tree, expectedBranchNames());
   assertChildrenInclude("Make sure you run <git fetch --tags>", tree, expectedTagNames());
 }
Example #10
0
  /**
   * Create a link to a file. There is no need to call a session.save, the change is persistent.
   *
   * @param fileNode The node that represents the file. This node has to be retrieved via the normal
   *     user his {@link Session session}. If the userID equals {@link UserConstants.ANON_USERID} an
   *     AccessDeniedException will be thrown.
   * @param linkPath The absolute path in JCR where the link should be placed.
   * @param slingRepository The {@link SlingRepository} to use to login as an administrative.
   * @return The newly created node.
   * @throws AccessDeniedException When the user is anonymous.
   * @throws RepositoryException Something else went wrong.
   */
  public static boolean createLink(Node fileNode, String linkPath, SlingRepository slingRepository)
      throws AccessDeniedException, RepositoryException {
    Session session = fileNode.getSession();
    String userId = session.getUserID();
    if (UserConstants.ANON_USERID.equals(userId)) {
      throw new AccessDeniedException();
    }

    boolean hasMixin =
        JcrUtils.hasMixin(fileNode, REQUIRED_MIXIN) && fileNode.canAddMixin(REQUIRED_MIXIN);
    // If the fileNode doesn't have the required referenceable mixin, we need to set it.
    if (!hasMixin) {
      // The required mixin is not on the node.
      // Set it.
      Session adminSession = null;
      try {
        adminSession = slingRepository.loginAdministrative(null);

        // Grab the node via the adminSession
        String path = fileNode.getPath();
        Node adminFileNode = (Node) adminSession.getItem(path);
        if (!hasMixin) {
          adminFileNode.addMixin(REQUIRED_MIXIN);
        }

        if (adminSession.hasPendingChanges()) {
          adminSession.save();
        }
      } finally {
        if (adminSession != null) {
          adminSession.logout();
        }
      }
    }

    // Now that the file is referenceable, it has a uuid.
    // Use it for the link.
    // Grab the (updated) node via the user's session id.
    fileNode = (Node) session.getItem(fileNode.getPath());

    // Create the link
    Node linkNode = JcrUtils.deepGetOrCreateNode(session, linkPath);
    if (!"sling:Folder".equals(linkNode.getPrimaryNodeType().getName())) {
      // sling folder allows single and multiple properties, no need for the mixin.
      if (linkNode.canAddMixin(REQUIRED_MIXIN)) {
        linkNode.addMixin(REQUIRED_MIXIN);
      }
    }
    linkNode.setProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, RT_SAKAI_LINK);
    linkNode.setProperty(SAKAI_LINK, fileNode.getIdentifier());

    // Save link.
    if (session.hasPendingChanges()) {
      session.save();
    }

    return true;
  }
Example #11
0
  @Override
  protected void describeMismatchSafely(Node item, Description mismatchDescription) {

    try {
      mismatchDescription
          .appendText("was node with primary type ")
          .appendValue(item.getPrimaryNodeType().getName());
    } catch (RepositoryException e) {
      super.describeMismatchSafely(item, mismatchDescription);
    }
  }
 private boolean getIsOrderable(Resource resource) {
   Node node = resource.adaptTo(Node.class);
   if (node != null) {
     try {
       return node.getPrimaryNodeType().hasOrderableChildNodes();
     } catch (RepositoryException re) {
       // Ignored
     }
   }
   return false;
 }
Example #13
0
 /** @throws RepositoryException */
 public void testFrozenNodeNodeType() throws RepositoryException {
   VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
   String path = versionableNode.getPath();
   Version v = versionManager.checkin(path);
   Node n = v.getFrozenNode();
   String puuid = n.getProperty(jcrPrimaryType).getValue().getString();
   String nuuid = n.getPrimaryNodeType().getName();
   assertEquals(
       "jcr:primaryType needs to be equal to the getPrimaryNodeType() return value.",
       nuuid,
       puuid);
 }
Example #14
0
 private String getTypeFromPath(String workspace, String path, SessionProvider sessionProvider)
     throws Exception {
   ManageableRepository manageableRepository = repositoryService.getCurrentRepository();
   Session session = sessionProvider.getSession(workspace, manageableRepository);
   Node currentFolder = null;
   try {
     Node node = (Node) session.getItem(path);
     return node.getPrimaryNodeType().getName();
   } catch (PathNotFoundException pne) {
     return null;
   }
 }
Example #15
0
 /**
  * Get the MimeType
  *
  * @param node the node
  * @return the MimeType
  */
 public static String getMimeType(Node node) {
   try {
     if (node.getPrimaryNodeType().getName().equals(NodetypeConstant.NT_FILE)) {
       if (node.hasNode(NodetypeConstant.JCR_CONTENT))
         return node.getNode(NodetypeConstant.JCR_CONTENT)
             .getProperty(NodetypeConstant.JCR_MIME_TYPE)
             .getString();
     }
   } catch (RepositoryException e) {
     LOG.error(e.getMessage(), e);
   }
   return "";
 }
Example #16
0
 /**
  * This method will get all node types of node.
  *
  * @param node
  * @return
  * @throws Exception
  */
 private List<String> getDocumentNodeTypes(Node node) throws Exception {
   List<String> nodeTypeNameList = new ArrayList<String>();
   NodeType primaryType = node.getPrimaryNodeType();
   if (templateService_.isManagedNodeType(primaryType.getName())) {
     nodeTypeNameList.add(primaryType.getName());
   }
   for (NodeType nodeType : node.getMixinNodeTypes()) {
     if (templateService_.isManagedNodeType(nodeType.getName())) {
       nodeTypeNameList.add(nodeType.getName());
     }
   }
   return nodeTypeNameList;
 }
Example #17
0
 /** @throws RepositoryException */
 public void testFrozenChildNodeType() throws RepositoryException {
   Node n1 = versionableNode.addNode("child");
   versionableNode.getSession().save();
   VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
   String path = versionableNode.getPath();
   Version v = versionManager.checkin(path);
   Node n = v.getFrozenNode().getNode("child");
   String fuuid = n.getProperty("jcr:frozenPrimaryType").getValue().getString();
   String ruuid = n1.getPrimaryNodeType().getName();
   assertEquals(
       "jcr:frozenPrimaryType needs to be equal to the getPrimaryNodeType() return value.",
       ruuid,
       fuuid);
 }
Example #18
0
  /**
   * Pull a node-type specific transform out of JCR
   *
   * @param node
   * @param key
   * @return node-type specific transform
   * @throws RepositoryException
   */
  public static LDPathTransform getNodeTypeTransform(final Node node, final String key)
      throws RepositoryException {

    final Node programNode = node.getSession().getNode(CONFIGURATION_FOLDER + key);

    LOGGER.debug("Found program node: {}", programNode.getPath());

    final NodeType primaryNodeType = node.getPrimaryNodeType();

    final Set<NodeType> supertypes =
        orderedBy(nodeTypeComp).add(primaryNodeType.getSupertypes()).build();
    final Set<NodeType> mixinTypes = orderedBy(nodeTypeComp).add(node.getMixinNodeTypes()).build();

    // start with mixins, primary type, and supertypes of primary type
    final ImmutableList.Builder<NodeType> nodeTypesB =
        new ImmutableList.Builder<NodeType>()
            .addAll(mixinTypes)
            .add(primaryNodeType)
            .addAll(supertypes);

    // add supertypes of mixins
    for (final NodeType mixin : mixinTypes) {
      nodeTypesB.addAll(orderedBy(nodeTypeComp).add(mixin.getDeclaredSupertypes()).build());
    }

    final List<NodeType> nodeTypes = nodeTypesB.build();

    LOGGER.debug("Discovered node types: {}", nodeTypes);

    for (final NodeType nodeType : nodeTypes) {
      if (programNode.hasNode(nodeType.toString())) {
        return new LDPathTransform(
            programNode
                .getNode(nodeType.toString())
                .getNode(JCR_CONTENT)
                .getProperty(JCR_DATA)
                .getBinary()
                .getStream());
      }
    }

    throw new WebApplicationException(
        new Exception(
            "Couldn't find transformation for "
                + node.getPath()
                + " and transformation key "
                + key),
        SC_BAD_REQUEST);
  }
Example #19
0
 public static List<String> getListAllowedFileType(
     Node currentNode, TemplateService templateService) throws Exception {
   List<String> nodeTypes = new ArrayList<String>();
   NodeTypeManager ntManager = currentNode.getSession().getWorkspace().getNodeTypeManager();
   NodeType currentNodeType = currentNode.getPrimaryNodeType();
   NodeDefinition[] childDefs = currentNodeType.getChildNodeDefinitions();
   List<String> templates = templateService.getDocumentTemplates();
   try {
     for (int i = 0; i < templates.size(); i++) {
       String nodeTypeName = templates.get(i).toString();
       NodeType nodeType = ntManager.getNodeType(nodeTypeName);
       NodeType[] superTypes = nodeType.getSupertypes();
       boolean isCanCreateDocument = false;
       for (NodeDefinition childDef : childDefs) {
         NodeType[] requiredChilds = childDef.getRequiredPrimaryTypes();
         for (NodeType requiredChild : requiredChilds) {
           if (nodeTypeName.equals(requiredChild.getName())) {
             isCanCreateDocument = true;
             break;
           }
         }
         if (nodeTypeName.equals(childDef.getName()) || isCanCreateDocument) {
           if (!nodeTypes.contains(nodeTypeName)) nodeTypes.add(nodeTypeName);
           isCanCreateDocument = true;
         }
       }
       if (!isCanCreateDocument) {
         for (NodeType superType : superTypes) {
           for (NodeDefinition childDef : childDefs) {
             for (NodeType requiredType : childDef.getRequiredPrimaryTypes()) {
               if (superType.getName().equals(requiredType.getName())) {
                 if (!nodeTypes.contains(nodeTypeName)) nodeTypes.add(nodeTypeName);
                 isCanCreateDocument = true;
                 break;
               }
             }
             if (isCanCreateDocument) break;
           }
           if (isCanCreateDocument) break;
         }
       }
     }
   } catch (Exception e) {
     if (LOG.isErrorEnabled()) {
       LOG.error("Unexpected error", e);
     }
   }
   return nodeTypes;
 }
Example #20
0
 /**
  * Get node nt:file if node support multi-language
  *
  * @param currentNode Current Node
  * @return Node which has type nt:file
  * @throws Exception
  */
 public static Node getFileLangNode(Node currentNode) throws Exception {
   if (currentNode.isNodeType(NT_UNSTRUCTURED)) {
     if (currentNode.getNodes().getSize() > 0) {
       NodeIterator nodeIter = currentNode.getNodes();
       while (nodeIter.hasNext()) {
         Node ntFile = nodeIter.nextNode();
         if (ntFile.getPrimaryNodeType().getName().equals(NT_FILE)) {
           return ntFile;
         }
       }
       return currentNode;
     }
   }
   return currentNode;
 }
Example #21
0
  @Override
  public JcrNode getRootNode() throws RemoteException {
    try {
      // take root node
      Node root = session().getRootNode();

      // convert into value object
      JcrNode node = new JcrNode("root", root.getPath(), root.getPrimaryNodeType().getName());
      node.setProperties(getProperties(root));
      node.setAcessControlList(getAccessList(session().getAccessControlManager(), root));

      return node;
    } catch (RepositoryException e) {
      throw new RemoteException(e.getMessage());
    }
  }
Example #22
0
 @Before
 public void setUp() throws Exception {
   initMocks(this);
   testObj = new FedoraVersions();
   mockSession = mockSession(testObj);
   setField(testObj, "nodeService", mockNodes);
   setField(testObj, "uriInfo", getUriInfoImpl());
   setField(testObj, "session", mockSession);
   setField(testObj, "versionService", mockVersions);
   setField(testObj, "sessionFactory", mockSessionFactory);
   when(mockSessionFactory.getInternalSession()).thenReturn(mockSession);
   when(mockNode.getPath()).thenReturn("/test/path");
   when(mockResource.getNode()).thenReturn(mockNode);
   when(mockNodeType.getName()).thenReturn("nt:folder");
   when(mockNode.getPrimaryNodeType()).thenReturn(mockNodeType);
 }
Example #23
0
 public String getContentType() {
   String ct = "application/octet-stream";
   try {
     if (node.getPrimaryNodeType().getName().equals(JcrConstants.NT_FILE)) {
       Node contentNode = node.getNode(JcrConstants.JCR_CONTENT);
       ct = contentNode.getProperty(JcrConstants.JCR_MIMETYPE).getString();
     } else {
       if (node.hasProperty(MessageConstants.PROP_SAKAI_CONTENT_TYPE)) {
         ct = node.getProperty(MessageConstants.PROP_SAKAI_CONTENT_TYPE).getString();
       }
     }
   } catch (RepositoryException re) {
     LOGGER.error(re.getMessage(), re);
   }
   return ct;
 }
 private boolean isPrimaryType(final Resource resource, final String primaryType) {
   Node node = resource.adaptTo(Node.class);
   if (node != null) {
     // JCR-based resource resolver
     try {
       return StringUtils.equals(node.getPrimaryNodeType().getName(), primaryType);
     } catch (RepositoryException ex) {
       // ignore
       return false;
     }
   } else {
     // sling resource resolver mock
     ValueMap props = resource.getValueMap();
     return StringUtils.equals(props.get(JcrConstants.JCR_PRIMARYTYPE, String.class), primaryType);
   }
 }
Example #25
0
  private static void updateMainActivity(
      ActivityManager activityManager, Node contentNode, ExoSocialActivity activity) {
    Map<String, String> activityParams = activity.getTemplateParams();
    String state;
    String nodeTitle;
    String nodeType = null;
    String nodeIconName = null;
    String documentTypeLabel;
    String currentVersion = null;
    TemplateService templateService = WCMCoreUtils.getService(TemplateService.class);
    try {
      nodeType = contentNode.getPrimaryNodeType().getName();
      documentTypeLabel = templateService.getTemplateLabel(nodeType);
    } catch (Exception e) {
      documentTypeLabel = "";
    }
    try {
      nodeTitle = org.exoplatform.ecm.webui.utils.Utils.getTitle(contentNode);
    } catch (Exception e1) {
      nodeTitle = "";
    }
    try {
      state =
          contentNode.hasProperty(CURRENT_STATE_PROP)
              ? contentNode.getProperty(CURRENT_STATE_PROP).getValue().getString()
              : "";
    } catch (Exception e) {
      state = "";
    }
    try {
      currentVersion = contentNode.getBaseVersion().getName();

      // TODO Must improve this hardcode later, need specification
      if (currentVersion.contains("jcr:rootVersion")) currentVersion = "0";
    } catch (Exception e) {
      currentVersion = "";
    }
    activityParams.put(ContentUIActivity.STATE, state);
    activityParams.put(ContentUIActivity.DOCUMENT_TYPE_LABEL, documentTypeLabel);
    activityParams.put(ContentUIActivity.DOCUMENT_TITLE, nodeTitle);
    activityParams.put(ContentUIActivity.DOCUMENT_VERSION, currentVersion);
    String summary = getSummary(contentNode);
    summary = getFirstSummaryLines(summary, MAX_SUMMARY_LINES_COUNT);
    activityParams.put(ContentUIActivity.DOCUMENT_SUMMARY, summary);
    activity.setTemplateParams(activityParams);
    activityManager.updateActivity(activity);
  }
Example #26
0
  /**
   * Get allowed folder types in current path.
   *
   * @param currentNode
   * @param currentDrive
   * @return List<String> of node types
   * @throws Exception
   */
  public static List<String> getAllowedFolderTypesInCurrentPath(
      Node currentNode, DriveData currentDrive) throws Exception {
    List<String> allowedTypes = new ArrayList<String>();
    NodeTypeImpl currentNodeType = (NodeTypeImpl) currentNode.getPrimaryNodeType();
    String[] arrFoldertypes = currentDrive.getAllowCreateFolders().split(",");
    NodeTypeManager ntManager = currentNode.getSession().getWorkspace().getNodeTypeManager();

    for (String strFolderType : arrFoldertypes) {
      if (strFolderType.isEmpty()) continue;
      NodeType folderType = ntManager.getNodeType(strFolderType);
      if ((currentNodeType)
          .isChildNodePrimaryTypeAllowed(
              Constants.JCR_ANY_NAME, ((NodeTypeImpl) folderType).getQName())) {
        allowedTypes.add(strFolderType);
      }
    }

    return allowedTypes;
  }
Example #27
0
 protected Node getNodeToCheckState(Node node) throws Exception {
   Node displayNode = node;
   if (displayNode.isNodeType("nt:resource")) {
     displayNode = node.getParent();
   }
   // return exo:webContent when exo:htmlFile found
   if (displayNode.isNodeType("exo:htmlFile")) {
     Node parent = displayNode.getParent();
     if (parent.isNodeType("exo:webContent")) return parent;
     return displayNode;
   }
   //
   String[] contentTypes = queryCriteria.getContentTypes();
   if (contentTypes != null && contentTypes.length > 0) {
     String primaryNodeType = displayNode.getPrimaryNodeType().getName();
     if (!ArrayUtils.contains(contentTypes, primaryNodeType)) return null;
   }
   return displayNode;
 }
Example #28
0
 public InputStream getInputStream() throws IOException {
   InputStream is = null;
   try {
     if (node.getPrimaryNodeType().getName().equals(JcrConstants.NT_FILE)) {
       Node contentNode = node.getNode(JcrConstants.JCR_CONTENT);
       is = contentNode.getProperty(JcrConstants.JCR_DATA).getBinary().getStream();
     } else {
       is =
           node.getProperty(MessageConstants.PROP_SAKAI_ATTACHMENT_CONTENT)
               .getBinary()
               .getStream();
     }
   } catch (RepositoryException e) {
     LOGGER.error(e.getMessage(), e);
     // in Java 1.6 this would be "throw new IOException(e)" the following is a 1.5 hack
     // to get the same result
     throw (IOException) new IOException(e.getMessage()).initCause(e);
   }
   return is;
 }
 private boolean isChildNodePrimaryTypeAllowed(Node parent, String childNodeTypeName)
     throws Exception {
   NodeType childNodeType =
       parent.getSession().getWorkspace().getNodeTypeManager().getNodeType(childNodeTypeName);
   // In some cases, the child node is mixins type of a nt:file example
   if (childNodeType.isMixin()) return true;
   List<NodeType> allNodeTypes = new ArrayList<NodeType>();
   allNodeTypes.add(parent.getPrimaryNodeType());
   for (NodeType mixin : parent.getMixinNodeTypes()) {
     allNodeTypes.add(mixin);
   }
   for (NodeType nodetype : allNodeTypes) {
     if (((NodeTypeImpl) nodetype)
         .isChildNodePrimaryTypeAllowed(
             Constants.JCR_ANY_NAME, ((NodeTypeImpl) childNodeType).getQName())) {
       return true;
     }
   }
   return false;
 }
Example #30
0
  private int type(Node node, String propertyName) throws RepositoryException {
    PropertyDefinition[] defs = node.getPrimaryNodeType().getPropertyDefinitions();
    for (PropertyDefinition def : defs) {
      if (def.getName().equals(propertyName)) {
        return def.getRequiredType();
      }
    }

    NodeType[] mixins = node.getMixinNodeTypes();
    for (NodeType type : mixins) {
      defs = type.getPropertyDefinitions();
      for (PropertyDefinition def : defs) {
        if (def.getName().equals(propertyName)) {
          return def.getRequiredType();
        }
      }
    }

    return -1;
  }