* <p>Create or update the user information.</p>
*/
public String save() {
State state = getState();
UserDatabase database = getUserDatabase();
String mode = state.getMode();
User user = state.getUser();
org.apache.struts.apps.mailreader.dao.Subscription subscription =
user.findSubscription(state.getHost());
if ("CREATE".equals(mode)) {
// Verify that the proposed hostname is not already taken
if (user.findSubscription(host) != null) {
// FIXME - localization
getFacesContext().addMessage("subscription:host",
new FacesMessage("That hostname is already defined"));
return null;
}
// Create a new subscription
subscription = user.createSubscription(host);
Registration registration = (Registration)getBean("registration");
user = getState().getUser();
registration.setFromAddress(user.getFromAddress());
registration.setFullName(user.getFullName());
registration.setPassword(user.getPassword());
registration.setPassword2(user.getPassword());
registration.setReplyToAddress(user.getReplyToAddress());
registration.setSubscriptions(user.getSubscriptions());
registration.setUsername(user.getUsername());
} else if ("DELETE".equals(mode)) {
user.removeSubscription(subscription);
try {
database.save();
} catch (Exception e) {
getFacesContext().addMessage(null,
new FacesMessage(e.getMessage()));
log.error("Database save exception", e);
return null;
}
state.setMode("EDIT");
return "registration";
} else /* if ("EDIT".equals(mode)) */ {
; // No special action required
}
// Copy the remaining properties
subscription.setUsername(username);
subscription.setPassword(password);
subscription.setType(type);
subscription.setAutoConnect(autoConnect);
// Save the updated information to the database
try {
database.save();
} catch (Exception e) {
getFacesContext().addMessage(null,
new FacesMessage(e.getMessage()));
log.error("Database save exception", e);
return null;