public void unzip(List<String> paths, boolean removeArchive, JCRSessionWrapper currentUserSession) throws GWTJahiaServiceException {
List<String> missedPaths = new ArrayList<String>();
List<JCRNodeWrapper> nodesToUnzip = new ArrayList<JCRNodeWrapper>();
for (String path : paths) {
JCRNodeWrapper nodeToUnzip;
try {
nodeToUnzip = currentUserSession.getNode(JCRContentUtils.escapeNodePath(path));
} catch (RepositoryException e) {
logger.error(e.toString(), e);
missedPaths.add(new StringBuilder(path).append(" could not be accessed : ").append(e.toString()).toString());
continue;
}
nodesToUnzip.add(nodeToUnzip);
}
if (nodesToUnzip.size() > 0) {
String firstPath = nodesToUnzip.get(0).getPath();
int index = firstPath.lastIndexOf("/");
String parentPath;
if (index > 0) {
parentPath = firstPath.substring(0, index);
} else {
parentPath = "/";
}
JCRNodeWrapper parent;
try {
parent = currentUserSession.getNode(parentPath);
} catch (RepositoryException e) {
logger.error(e.toString(), e);
throw new GWTJahiaServiceException(new StringBuilder(parentPath).append(" could not be accessed :\n").append(e.toString()).toString());
}
if (parent.hasPermission("jcr:addChildNodes") && !parent.isLocked()) {
for (JCRNodeWrapper nodeToUnzip : nodesToUnzip) {
try {
if (!unzipFile(nodeToUnzip, parent, currentUserSession)) {
missedPaths.add(nodeToUnzip.getName());
} else if (removeArchive) {
try {
nodeToUnzip.remove();
} catch (RepositoryException e) {
logger.error("Issue when trying to delete original archive " + nodeToUnzip.getPath(), e);
}
}
} catch (RepositoryException e) {
missedPaths.add(nodeToUnzip.getName());
logger.error(e.getMessage(), e);
}
}
} else {
throw new GWTJahiaServiceException("Directory " + parent.getPath() + " is not writable.");
}
try {
parent.saveSession();
} catch (RepositoryException e) {
logger.error("Could not save changes in " + parent.getPath(), e);
}
}
if (missedPaths.size() > 0) {
StringBuilder errors = new StringBuilder("The following files could not be unzipped:");
for (String err : missedPaths) {