IPath path = getPath(req);
if (path.segmentCount() < 2) {
handleNotFound(req, resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED);
return;
}
MetadataInfo info = getNode(path, req, resp);
if (info == null) {
handleNotFound(req, resp, HttpServletResponse.SC_NOT_FOUND);
return;
}
String key = req.getParameter("key"); //$NON-NLS-1$
String prefix = getPrefix(path);
try {
boolean changed = false;
if (key != null) {
prefix = prefix + '/' + key;
String newValue = req.getParameter("value"); //$NON-NLS-1$
String oldValue = info.setProperty(prefix.toString(), newValue);
changed = !newValue.equals(oldValue);
} else {
JSONObject newNode = new JSONObject(new JSONTokener(req.getReader()));
//can't overwrite base user settings via preference servlet
if (prefix.startsWith("User")) {
resp.setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
}
//operations should not be removed by PUT
if (!prefix.equals("operations")) {
//clear existing values matching prefix
changed |= removeMatchingProperties(info, prefix.toString());
}
for (Iterator<String> it = newNode.keys(); it.hasNext();) {
key = it.next();
String newValue = newNode.getString(key);
String qualifiedKey = prefix + '/' + key;
String oldValue = info.setProperty(qualifiedKey, newValue);
changed |= !newValue.equals(oldValue);
}
}
if (changed)
save(info);