1 23 24 package org.infoglue.cms.applications.managementtool.actions; 25 26 import java.util.Iterator ; 27 import java.util.List ; 28 29 import org.infoglue.cms.applications.common.VisualFormatter; 30 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction; 31 import org.infoglue.cms.controllers.kernel.impl.simple.GroupControllerProxy; 32 import org.infoglue.cms.controllers.kernel.impl.simple.RoleControllerProxy; 33 import org.infoglue.cms.controllers.kernel.impl.simple.UserControllerProxy; 34 import org.infoglue.cms.security.InfoGluePrincipal; 35 import org.infoglue.cms.util.CmsPropertyHandler; 36 import org.infoglue.cms.util.mail.MailServiceFactory; 37 38 public class CreateEmailAction extends InfoGlueAbstractAction 39 { 40 private static final long serialVersionUID = 1L; 41 42 private List users = null; 43 private List roles = null; 44 private List groups = null; 45 46 private String [] userNames; 47 private String [] roleNames; 48 private String [] groupNames; 49 50 private String usersAddresses = ""; 51 52 private String recipients; 53 private String from; 54 private String subject; 55 private String message; 56 57 private String errorMessage = ""; 58 59 public String doExecute() throws Exception  60 { 61 if(recipients != null && recipients.length() > 0 && subject != null && subject.length() > 0 && message != null && message.length() > 0) 62 { 63 if(from == null || from.length() == 0) 64 { 65 String systemEmailSender = CmsPropertyHandler.getSystemEmailSender(); 66 if(systemEmailSender == null || systemEmailSender.equalsIgnoreCase("")) 67 systemEmailSender = "InfoGlueCMS@" + CmsPropertyHandler.getMailSmtpHost(); 68 69 from = systemEmailSender; 70 } 71 72 String contentType = CmsPropertyHandler.getMailContentType(); 73 if(contentType == null || contentType.length() == 0) 74 contentType = "text/html"; 75 76 if(contentType.equalsIgnoreCase("text/html")) 77 { 78 VisualFormatter ui = new VisualFormatter(); 79 message = ui.escapeHTMLforXMLService(message); 80 message = "<div>" + message.replaceAll("\n", "<br/>\n") + "</div>"; 81 } 82 83 MailServiceFactory.getService().sendEmail(from, from, recipients, subject, message, "utf-8"); 84 } 85 else 86 { 87 errorMessage = "Must enter information in all fields below."; 88 return "inputCreateEmail"; 89 } 90 91 return "success"; 92 } 93 94 public String doInputChooseRecipients() throws Exception  95 { 96 users = UserControllerProxy.getController().getAllUsers(); 97 roles = RoleControllerProxy.getController().getAllRoles(); 98 groups = GroupControllerProxy.getController().getAllGroups(); 99 100 return "inputChooseRecipients"; 101 } 102 103 public String doInputCreateEmail() throws Exception  104 { 105 userNames = getRequest().getParameterValues("userName"); 106 roleNames = getRequest().getParameterValues("roleName"); 107 groupNames = getRequest().getParameterValues("groupName"); 108 109 if(userNames != null) 110 { 111 for(int i=0; i<userNames.length; i++) 112 { 113 String userName = userNames[i]; 114 InfoGluePrincipal principal = UserControllerProxy.getController().getUser(userName); 115 if(usersAddresses.indexOf(principal.getEmail()) == -1) 116 { 117 if(usersAddresses.length() > 0) 118 usersAddresses += ";"; 119 120 usersAddresses += principal.getEmail(); 121 } 122 } 123 } 124 125 if(roleNames != null) 126 { 127 for(int i=0; i<roleNames.length; i++) 128 { 129 String roleName = roleNames[i]; 130 131 List principals = RoleControllerProxy.getController().getInfoGluePrincipals(roleName); 132 Iterator principalsIterator = principals.iterator(); 133 while(principalsIterator.hasNext()) 134 { 135 InfoGluePrincipal principal = (InfoGluePrincipal)principalsIterator.next(); 136 if(usersAddresses.indexOf(principal.getEmail()) == -1) 137 { 138 if(usersAddresses.length() > 0) 139 usersAddresses += ";"; 140 141 usersAddresses += principal.getEmail(); 142 } 143 } 144 } 145 } 146 147 if(groupNames != null) 148 { 149 for(int i=0; i<groupNames.length; i++) 150 { 151 String groupName = groupNames[i]; 152 153 List principals = GroupControllerProxy.getController().getInfoGluePrincipals(groupName); 154 Iterator principalsIterator = principals.iterator(); 155 while(principalsIterator.hasNext()) 156 { 157 InfoGluePrincipal principal = (InfoGluePrincipal)principalsIterator.next(); 158 if(usersAddresses.indexOf(principal.getEmail()) == -1) 159 { 160 if(usersAddresses.length() > 0) 161 usersAddresses += ";"; 162 163 usersAddresses += principal.getEmail(); 164 } 165 } 166 } 167 } 168 169 return "inputCreateEmail"; 170 } 171 172 public List getGroups() 173 { 174 return groups; 175 } 176 177 public List getRoles() 178 { 179 return roles; 180 } 181 182 public List getUsers() 183 { 184 return users; 185 } 186 187 public String getUsersAddresses() 188 { 189 return usersAddresses; 190 } 191 192 public String getMessage() 193 { 194 return message; 195 } 196 197 public void setMessage(String message) 198 { 199 this.message = message; 200 } 201 202 public String getRecipients() 203 { 204 return recipients; 205 } 206 207 public void setRecipients(String recipients) 208 { 209 this.recipients = recipients; 210 } 211 212 public String getSubject() 213 { 214 return subject; 215 } 216 217 public void setSubject(String subject) 218 { 219 this.subject = subject; 220 } 221 222 public String getFrom() { 223 return from; 224 } 225 226 public void setFrom(String from) { 227 this.from = from; 228 } 229 230 public String getErrorMessage() { 231 return errorMessage; 232 } 233 } 234 | Popular Tags |