+ /**
+ * Create sub nodes relative to a parent node
+ *
+ * @param nodeType
+ * the type of the leaf node
+ */
+ public static Node mkdirs(Node parentNode, String relativePath,
+ String nodeType) {
+ return mkdirs(parentNode, relativePath, nodeType, null);
+ }
+
+ /**
+ * Create sub nodes relative to a parent node
+ *
+ * @param nodeType
+ * the type of the leaf node
+ */
+ public static Node mkdirs(Node parentNode, String relativePath,
+ String nodeType, String intermediaryNodeType) {
+ List<String> tokens = tokenize(relativePath);
+ Node currParent = parentNode;
+ try {
+ for (int i = 0; i < tokens.size(); i++) {
+ String name = tokens.get(i);
+ if (parentNode.hasNode(name)) {
+ currParent = currParent.getNode(name);
+ } else {
+ if (i != (tokens.size() - 1)) {// intermediary
+ currParent = currParent.addNode(name,
+ intermediaryNodeType);
+ } else {// leaf
+ currParent = currParent.addNode(name, nodeType);
+ }
+ }
+ }
+ return currParent;
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot mkdirs relative path "
+ + relativePath + " from " + parentNode, e);
+ }
+ }
+