*/
class FileTreeGetter implements Handler<Message<JsonObject>> {
@Override
public void handle(Message<JsonObject> message) {
GetDirectoryImpl request = GetDirectoryImpl.fromJsonString(Dto.get(message));
final GetDirectoryResponseImpl response = GetDirectoryResponseImpl.make();
synchronized (FileTree.this.lock) {
response.setRootId(Long.toString(currentTreeVersion));
PathUtils.walk(request.getPath(), "/", new PathVisitor() {
@Override
public void visit(String path, String name) {
// Special case root.
if ("/".equals(path)) {
response.setBaseDirectory(root);
response.setPath(path);
return;
}
// Search for the next directory.
DirInfo lastDir = response.getBaseDirectory();
if (lastDir != null) {
for (DirInfo dir : lastDir.getSubDirectories().asIterable()) {
if (dir.getName().equals(name)) {
response.setBaseDirectory((DirInfoImpl) dir);
response.setPath(path + '/');
return;
}
}
}
// Didn't find it.
response.setBaseDirectory(null);
}
});
}
message.reply(Dto.wrap(response));
}