if (session.itemExists(path) && session.getItem(path).isNode()) {
return true;
}
// check path walking it down
Node current = session.getRootNode();
final String[] names = path.split("/");
for (int i = 0; i < names.length; i++) {
if (names[i] == null || names[i].length() == 0) {
continue;
} else if (current.hasNode(names[i])) {
current = current.getNode(names[i]);
} else {
final Node parentNode = current;
try {
// adding the node could cause an exception
// for example if another thread tries to
// create the node "at the same time"
current = parentNode.addNode(names[i], NT_FOLDER);
session.save();
} catch (final RepositoryException re) {
// let's first refresh the session
// we don't catch an exception here, because if
// session refresh fails, we might have a serious problem!
session.refresh(false);
// let's check if the node is available now
if ( parentNode.hasNode(names[i]) ) {
current = parentNode.getNode(names[i]);
} else {
// we try it one more time to create the node - and fail otherwise
current = parentNode.addNode(names[i], NT_FOLDER);
session.save();
}
}
}
}