public String pasteNode(String pathOrigin, String pathSelected, int pasteType, int action)
      throws ExchangeException, RepositoryException {
    boolean move = false;
    if (action == Tree.ACTION_MOVE) {
      move = true;
    }
    String label = StringUtils.substringAfterLast(pathOrigin, "/"); // $NON-NLS-1$
    String slash = "/"; // $NON-NLS-1$
    if (pathSelected.equals("/")) { // $NON-NLS-1$
      slash = StringUtils.EMPTY;
    }
    String destination = pathSelected + slash + label;
    if (pasteType == Tree.PASTETYPE_SUB
        && action != Tree.ACTION_COPY
        && destination.equals(pathOrigin)) {
      // drag node to parent node: move to last position
      pasteType = Tree.PASTETYPE_LAST;
    }
    if (pasteType == Tree.PASTETYPE_SUB) {
      destination = pathSelected + slash + label;
      Content touchedContent = this.copyMoveNode(pathOrigin, destination, move);
      if (touchedContent == null) {
        return StringUtils.EMPTY;
      }
      return touchedContent.getHandle();

    } else if (pasteType == Tree.PASTETYPE_LAST) {
      // LAST only available for sorting inside the same directory
      try {
        Content touchedContent = getHierarchyManager().getContent(pathOrigin);
        return touchedContent.getHandle();
      } catch (RepositoryException re) {
        return StringUtils.EMPTY;
      }
    } else {
      try {
        // PASTETYPE_ABOVE | PASTETYPE_BELOW
        String nameSelected = StringUtils.substringAfterLast(pathSelected, "/"); // $NON-NLS-1$
        String nameOrigin = StringUtils.substringAfterLast(pathOrigin, "/"); // $NON-NLS-1$
        Content tomove = getHierarchyManager().getContent(pathOrigin);
        Content selected = getHierarchyManager().getContent(pathSelected);
        if (tomove.getParent().getUUID().equals(selected.getParent().getUUID())) {
          tomove.getParent().orderBefore(nameOrigin, nameSelected);
          tomove.getParent().save();
        } else {
          String newOrigin = selected.getParent().getHandle() + "/" + nameOrigin;
          getHierarchyManager().moveTo(pathOrigin, newOrigin);
          Content newNode = getHierarchyManager().getContent(newOrigin);
          if (pasteType == Tree.PASTETYPE_ABOVE) {
            newNode.getParent().orderBefore(nameOrigin, nameSelected);
          }
        }
        return tomove.getHandle();
      } catch (RepositoryException re) {
        re.printStackTrace();
        log.error("Problem when pasting node", re);
        return StringUtils.EMPTY;
      }
    }
  }
  public String renameNode(String newLabel)
      throws AccessDeniedException, ExchangeException, PathNotFoundException, RepositoryException {
    String returnValue;
    String parentPath = StringUtils.substringBeforeLast(this.getPath(), "/"); // $NON-NLS-1$
    newLabel = Path.getValidatedLabel(newLabel);

    // don't rename if it uses the same name as the current
    if (this.getPath().endsWith("/" + newLabel)) {
      return newLabel;
    }

    String dest = parentPath + "/" + newLabel; // $NON-NLS-1$
    if (getHierarchyManager().isExist(dest)) {
      newLabel = Path.getUniqueLabel(getHierarchyManager(), parentPath, newLabel);
      dest = parentPath + "/" + newLabel; // $NON-NLS-1$
    }
    this.deActivateNode(this.getPath());

    if (log.isInfoEnabled()) {
      log.info("Moving node from " + this.getPath() + " to " + dest); // $NON-NLS-1$ //$NON-NLS-2$
    }
    if (getHierarchyManager().isNodeData(this.getPath())) {
      Content parentPage = getHierarchyManager().getContent(parentPath);
      NodeData newNodeData = parentPage.createNodeData(newLabel);
      NodeData existingNodeData = getHierarchyManager().getNodeData(this.getPath());
      newNodeData.setValue(existingNodeData.getString());
      existingNodeData.delete();
      dest = parentPath;
    } else {
      // we can't rename a node. we must move
      // we must place the node at the same position
      Content current = getHierarchyManager().getContent(this.getPath());
      Content parent = current.getParent();
      String placedBefore = null;
      for (Iterator iter = parent.getChildren(current.getNodeTypeName()).iterator();
          iter.hasNext(); ) {
        Content child = (Content) iter.next();
        if (child.getHandle().equals(this.getPath())) {
          if (iter.hasNext()) {
            child = (Content) iter.next();
            placedBefore = child.getName();
          }
        }
      }

      getHierarchyManager().moveTo(this.getPath(), dest);

      // now set at the same place as before
      if (placedBefore != null) {
        parent.orderBefore(newLabel, placedBefore);
      }
    }

    Content newPage = getHierarchyManager().getContent(dest);
    returnValue = newLabel;
    newPage.updateMetaData();
    newPage.save();

    return returnValue;
  }