getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("XML parse error: "+ex.getMessage());
}
try {
User user = fetch();
if (user!=null) {
Element top = doc.getDocumentElement();
String alias = top.getAttributeValue("alias");
Element name = top.getFirstElementNamed(XML.NAME_NAME);
Element email = top.getFirstElementNamed(XML.EMAIL_NAME);
if (alias!=null && !User.isAlias(alias)) {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("The alias '"+alias+"' is not a valid alias.");
}
if (alias!=null && !alias.equals(user.getAlias())) {
// rename
try {
if (!user.changeAlias(alias)) {
getResponse().setStatus(Status.CLIENT_ERROR_CONFLICT);
return new StringRepresentation("The alias '"+alias+"' is not available.");
}
} catch (SQLException ex) {
getContext().getLogger().log(Level.SEVERE,"Database error during while changing alias: "+ex.getMessage(),ex);
getResponse().setStatus(Status.CLIENT_ERROR_CONFLICT);
return new StringRepresentation("The alias '"+alias+"' is not available.");
}
}
if (name!=null) {
String value = name.getText();
if (!value.equals(user.getName())) {
// set name
user.setName(value);
}
} else {
if (user.getName()!=null) {
user.setName(null);
}
}
if (email!=null) {
String value = email.getText();
if (!value.equals(user.getEmail())) {
// set email
user.setEmail(value);
}
} else {
if (user.getEmail()!=null) {
user.setEmail(null);
}
}
getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
return null;
} else {