コード例 #1
0
  @Override
  public void renameFile(SrvSession sess, TreeConnection tree, String oldPath, String newPath)
      throws IOException {
    ContentContext tctx = (ContentContext) tree.getContext();
    NodeRef rootNode = tctx.getRootNode();

    if (logger.isDebugEnabled()) {
      logger.debug("renameFile oldPath:" + oldPath + ", newPath:" + newPath);
    }

    DriverState driverState = getDriverState(sess);

    // Is this a rename within the same folder or a move between folders?

    String[] paths = FileName.splitPath(oldPath);
    String oldFolder = paths[0];
    String oldFile = paths[1];

    paths = FileName.splitPath(newPath);
    String newFolder = paths[0];
    String newFile = paths[1];

    try {
      if (oldFolder.equalsIgnoreCase(newFolder)) {
        logger.debug("renameFileCommand - is a rename within the same folder");

        EvaluatorContext ctx = getEvaluatorContext(driverState, oldFolder);

        Operation o = new RenameFileOperation(oldFile, newFile, oldPath, newPath, rootNode);
        Command c = ruleEvaluator.evaluate(ctx, o);
        commandExecutor.execute(sess, tree, c);

        ruleEvaluator.notifyRename(ctx, o, c);

        releaseEvaluatorContextIfEmpty(driverState, ctx, oldFolder);

      } else {
        logger.debug("moveFileCommand - move between folders");

        Operation o = new MoveFileOperation(oldFile, newFile, oldPath, newPath, rootNode);

        /*
         * Note: At the moment we only have move scenarios for the destination folder - so
         * we only need to evaluate against a single (destination) context/folder.
         * This will require re-design as and when we need to have scenarios for the source/folder
         */

        // EvaluatorContext ctx1 = getEvaluatorContext(driverState, oldFolder);
        EvaluatorContext ctx2 = getEvaluatorContext(driverState, newFolder);

        Command c = ruleEvaluator.evaluate(ctx2, o);

        commandExecutor.execute(sess, tree, c);

        releaseEvaluatorContextIfEmpty(driverState, ctx2, newFolder);

        //  diskInterface.renameFile(sess, tree, oldPath, newPath);

      }
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ade) {
      throw new AccessDeniedException("Unable to rename file file " + oldPath, ade);
    }
  }