targetParent = (JCRNodeWrapper) targetNode.getParent();
} else {
targetParent = targetNode;
}
} catch (RepositoryException e) {
throw new GWTJahiaServiceException(e.getMessage());
}
try {
for (String aNode : pathsToCopy) {
JCRNodeWrapper node = currentUserSession.getNode(aNode);
String name = newName != null ? newName : node.getName();
try {
name = findAvailableName(targetParent, name);
if (targetParent.hasPermission("jcr:addChildNodes") && !targetParent.isLocked()) {
final JCRNodeWrapper copy = doPaste(targetParent, node, name, cut, reference);
if (moveOnTop && targetParent.getPrimaryNodeType().hasOrderableChildNodes()) {
targetParent.orderBefore(name, targetNode.getName());
}
currentUserSession.save();
res.add(navigation.getGWTJahiaNode(copy));
} else {
missedPaths
.add(new StringBuilder("File ").append(name).append(" could not be referenced in ")
.append(targetParent.getPath()).toString());
}
} catch (RepositoryException e) {
logger.error("Exception", e);
missedPaths.add(new StringBuilder("File ").append(name).append(" could not be referenced in ")
.append(targetParent.getPath()).toString());
} catch (JahiaException e) {
logger.error("Exception", e);
missedPaths.add(new StringBuilder("File ").append(name).append(" could not be referenced in ")
.append(targetParent.getPath()).toString());
}
}
} catch (RepositoryException e) {
throw new GWTJahiaServiceException(e.getMessage());
}
if (missedPaths.size() > 0) {
StringBuilder errors = new StringBuilder("The following files could not have their reference pasted:");
for (String err : missedPaths) {
errors.append("\n").append(err);
}
throw new GWTJahiaServiceException(errors.toString());
}
return res;
}