if (sentence != null) {
sentence = sentence.trim();
}
String command = req.getParameter("cmd");
String key = req.getParameter("key");
DiagramData data = DiagramStoreManager.get().getDiagram(key, email);
if ("add".equals(command)) {
if (sentence.length() > MAX_SENTENCE_LENGTH ||
data.getSentences().size() > MAX_DIAGRAM_LENGTH) {
return;
}
data.addSentence(sentence);
} else if ("delete".equals(command)) {
data.deleteSentence(sentence);
} else if ("moveup".equals(command)) {
data.moveUp(sentence);
} else if ("movedown".equals(command)) {
data.moveDown(sentence);
} else if ("changelayout".equals(command)) {
data.changeLayout();
} else if ("resize".equals(command)) {
int width = Integer.parseInt(req.getParameter("width"));
int height = Integer.parseInt(req.getParameter("height"));
data.setSize(new int[] { width, height });
} else if ("changepermission".equals(command)) {
data.setOwners(Arrays.asList(req.getParameter("owners").split(",")));
data.setViewPermission(DiagramData.Permission.valueOf(req
.getParameter("viewlevel")));
data.setEditPermission(DiagramData.Permission.valueOf(req
.getParameter("editlevel")));
}
if (command != null) {
DiagramStoreManager.get().updateDiagram(key, email, data);
}
try {
resp.getWriter().write(data.toJSON(true));
} catch (JSONException e) {
e.printStackTrace();
}
}