return null;
}
// Find root folder
final App app = StructrApp.getInstance(securityContext);
Folder folder = null;
for (final Folder possibleRootFolder : app.nodeQuery(Folder.class).andName(parts[0])) {
if (possibleRootFolder.getProperty(Folder.parent) == null) {
folder = possibleRootFolder;
break;
}
}
if (folder == null) {
// Root folder doesn't exist, so create it and all child folders
folder = app.create(Folder.class, parts[0]);
logger.log(Level.INFO, "Created root folder {0}", new Object[]{parts[0]});
for (int i = 1; i < parts.length - 1; i++) {
Folder childFolder = app.create(Folder.class, parts[i]);
childFolder.setProperty(Folder.parent, folder);
logger.log(Level.INFO, "Created {0} {1} with path {2}", new Object[]{childFolder.getType(), childFolder, FileHelper.getFolderPath(childFolder)});
folder = childFolder;
}
return folder;
}
// Root folder exists, so walk over children and search for next path part
for (int i = 1; i < parts.length - 1; i++) {
Folder subFolder = null;
for (AbstractFile child : folder.getProperty(Folder.children)) {
if (child instanceof Folder && child.getName().equals(parts[i])) {
subFolder = (Folder) child;
break;
}
}
if (subFolder == null) {
// sub folder doesn't exist, so create it and all child folders
subFolder = app.create(Folder.class, parts[i]);
subFolder.setProperty(Folder.parent, folder);
logger.log(Level.INFO, "Created {0} {1} with path {2}", new Object[]{subFolder.getType(), subFolder, FileHelper.getFolderPath(subFolder)});
}
folder = subFolder;
}