try {
Node node = toNode(path);
if (node == null) {
- Node parentNode = toNode(path.getParent());
- if (parentNode == null)
+ Node parent = toNode(path.getParent());
+ if (parent == null)
throw new JcrFsException("No parent directory for " + path);
- if (!(parentNode.getPath().equals("/") || parentNode.isNodeType(NodeType.NT_FOLDER)))
- throw new JcrFsException("Parent of " + path + " is not a directory");
+ if (parent.getPrimaryNodeType().isNodeType(NodeType.NT_FILE)
+ || parent.getPrimaryNodeType().isNodeType(NodeType.NT_LINKED_FILE))
+ throw new JcrFsException(path + " parent is a file");
- node = parentNode.addNode(path.getFileName().toString(), NodeType.NT_FILE);
+ String fileName = path.getFileName().toString();
+ fileName = Text.escapeIllegalJcrChars(fileName);
+ node = parent.addNode(fileName, NodeType.NT_FILE);
node.addMixin(NodeType.MIX_CREATED);
node.addMixin(NodeType.MIX_LAST_MODIFIED);
}
Node parent = toNode(dir.getParent());
if (parent == null)
throw new IOException("Parent of " + dir + " does not exist");
- if (!(parent.getPath().equals("/") || parent.getPrimaryNodeType().isNodeType(NodeType.NT_FOLDER)))
- throw new JcrFsException(dir + " parent is not a directory");
- node = parent.addNode(dir.getFileName().toString(), NodeType.NT_FOLDER);
+ if (parent.getPrimaryNodeType().isNodeType(NodeType.NT_FILE)
+ || parent.getPrimaryNodeType().isNodeType(NodeType.NT_LINKED_FILE))
+ throw new JcrFsException(dir + " parent is a file");
+ String fileName = dir.getFileName().toString();
+ fileName = Text.escapeIllegalJcrChars(fileName);
+ node = parent.addNode(fileName, NodeType.NT_FOLDER);
node.addMixin(NodeType.MIX_CREATED);
node.addMixin(NodeType.MIX_LAST_MODIFIED);
node.getSession().save();
try {
// TODO check if assignable
Node node = toNode(path);
+ if(node==null) {
+ throw new JcrFsException("JCR node not found for "+path);
+ }
return (A) new JcrBasicfileAttributes(node);
} catch (RepositoryException e) {
throw new JcrFsException("Cannot read basic attributes of " + path, e);
return ((JcrPath) path).getNode();
}
+ /**
+ * To be overriden in order to support the ~ path, with an implementation
+ * specific concept of user home.
+ *
+ * @return null by default
+ */
+ public Node getUserHome(Session session) {
+ return null;
+ }
}