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()));