public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException, CommunicationException, NamingException
{
String dataSource = Settings.getInstance().getSiteInfo(CVUtility.getHostName(super.getServlet().getServletContext())).getDataSource();
EmailSettingsHome emailSettingsHome = (EmailSettingsHome)CVUtility.getHomeObject("com.centraview.administration.emailsettings.EmailSettingsHome", "EmailSettings");
try {
EmailTemplateForm emailTemplateForm = (EmailTemplateForm) form;
ActionErrors allErrors = new ActionErrors();
boolean requiredToAddress = emailTemplateForm.getRequiredToAddress();
boolean requiredFromAddress = emailTemplateForm.getRequiredFromAddress();
boolean requiredSubject = emailTemplateForm.getRequiredSubject();
boolean requiredBody = emailTemplateForm.getRequiredBody();
String toAddress = emailTemplateForm.getToAddress();
String fromAddress = emailTemplateForm.getFromAddress();
String replyTo = emailTemplateForm.getReplyTo();
String subject = emailTemplateForm.getSubject();
String body = emailTemplateForm.getBody();
if (replyTo != null) {
if (replyTo.equals("")) {
emailTemplateForm.setReplyTo(null);
replyTo = null;
} else {
if (! CVUtility.isEmailAddressValid(replyTo)) {
allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.email.invalidAddress", "ReplyTo"));
}
}
}
if (requiredToAddress) {
if (toAddress == null || toAddress.length() <= 0) {
allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.general.requiredField", "To"));
}
if (toAddress != null) {
if (! CVUtility.isEmailAddressValid(toAddress)) {
allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.email.invalidAddress", "To"));
}
}
}
if (requiredFromAddress) {
if (fromAddress == null || fromAddress.length() <= 0) {
allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.general.requiredField", "From"));
}
if (fromAddress != null) {
if (! CVUtility.isEmailAddressValid(fromAddress)){
allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.email.invalidAddress", "From"));
}
}
}
if (requiredSubject) {
if (subject == null || subject.length() <= 0) {
allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.general.requiredField", "Subject"));
}
}
if (requiredBody) {
if (body == null || body.length() <= 0) {
allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.general.requiredField", "Body"));
}
}
if (! allErrors.isEmpty()) {
saveErrors(request, allErrors);
return(mapping.findForward(FORWARD_error));
}
EmailSettings emailSettingsRemote = (EmailSettings) emailSettingsHome.create();
emailSettingsRemote.setDataSource(dataSource);
emailSettingsRemote.updateEmailTemplate(emailTemplateForm);
FORWARD_final = FORWARD_save;
} catch (Exception e) {