@Override
public void move(Path source, Path target, CopyOption... options) throws IOException {
- Node sourceNode = toNode(source);
+ JcrFileSystem sourceFileSystem = (JcrFileSystem) source.getFileSystem();
+ WorkspaceFileStore sourceStore = sourceFileSystem.getFileStore(source.toString());
+ WorkspaceFileStore targetStore = sourceFileSystem.getFileStore(target.toString());
try {
- Session session = sourceNode.getSession();
- synchronized (session) {
- session.move(sourceNode.getPath(), target.toString());
- save(session);
+ if (sourceStore.equals(targetStore)) {
+ sourceStore.getWorkspace().move(sourceStore.toJcrPath(source.toString()),
+ targetStore.toJcrPath(target.toString()));
+ } else {
+ // TODO implement it
+ throw new UnsupportedOperationException("Can only move paths within the same workspace.");
}
} catch (RepositoryException e) {
- discardChanges(sourceNode);
throw new IOException("Cannot move from " + source + " to " + target, e);
}
+
+// Node sourceNode = toNode(source);
+// try {
+// Session session = sourceNode.getSession();
+// synchronized (session) {
+// session.move(sourceNode.getPath(), target.toString());
+// save(session);
+// }
+// } catch (RepositoryException e) {
+// discardChanges(sourceNode);
+// throw new IOException("Cannot move from " + source + " to " + target, e);
+// }
}
@Override
public class WorkspaceFileStore extends FileStore {
private final String mountPath;
private final Workspace workspace;
+ private final String workspaceName;
private final int mountDepth;
public WorkspaceFileStore(String mountPath, Workspace workspace) {
mountDepth = mountPath.split(JcrPath.separator).length - 1;
}
this.workspace = workspace;
+ this.workspaceName = workspace.getName();
}
public void close() {
return node;
}
+ String toJcrPath(String fsPath) {
+ if (fsPath.length() == 1)
+ return toJcrPath((String[]) null);// root
+ String[] arr = fsPath.substring(1).split("/");
+// if (arr.length == 0 || (arr.length == 1 && arr[0].equals("")))
+// return toJcrPath((String[]) null);// root
+// else
+ return toJcrPath(arr);
+ }
+
private String toJcrPath(String[] path) {
if (path == null)
return "/";
return sb.toString();
}
+ public String getMountPath() {
+ return mountPath;
+ }
+
+ public String getWorkspaceName() {
+ return workspaceName;
+ }
+
+ public int getMountDepth() {
+ return mountDepth;
+ }
+
+ @Override
+ public int hashCode() {
+ return workspaceName.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof WorkspaceFileStore))
+ return false;
+ WorkspaceFileStore other = (WorkspaceFileStore) obj;
+ return workspaceName.equals(other.workspaceName);
+ }
+
+ @Override
+ public String toString() {
+ return "WorkspaceFileStore " + workspaceName;
+ }
+
}