public void get() throws IOException {
getCtx().popParam(); // get rid of the /at/
java.io.File requestedFile = getFilesystem().getFileHandle(getUser(), getPath());
EditMode editMode = EditMode.ReadWrite;
SessionTracker tracker = getSessionTracker();
synchronized (tracker) {
List<EditSession> editSessions = tracker.getSessions(requestedFile);
// cover our error conditions
if (editMode == EditMode.ReadWrite) {
// check for other editors
for (EditSession session : editSessions) {
if (!session.getUser().equals(getUser())) {
if (session.getEditMode() == EditMode.ReadWrite) {
getCtx().getResp().sendError(409, "User \"" + session.getUser().username + "\" is already editing the requested file");
return;
}
}
}
} else if (editMode == EditMode.Read) {
// check for an existing read/write session from this user
for (EditSession session : editSessions) {
if (session.getUser().equals(getUser())) {
getCtx().getResp().sendError(400, "File already opened by this user in read/write mode; cannot open in read-only mode");
return;
}
}
}
boolean openSession = true;
// check for an existing edit session from the current user
EditSession session = tracker.getSession(requestedFile, getUser());
if (session != null) {
if (session.getEditMode() == editMode) openSession = false;
if ((session.getEditMode() == EditMode.Read) && (editMode == EditMode.ReadWrite)) {
tracker.closeSession(requestedFile, getUser());
}
}
if (openSession) {
tracker.openSession(requestedFile, getUser(), editMode);
}
try {
String contents = getFilesystem().read(getUser(), getPath());
print(contents);