1 97 package com.ivata.groupware.business.mail.struts; 98 99 import java.util.Iterator ; 100 101 import javax.mail.MessagingException ; 102 import javax.servlet.http.HttpServletRequest ; 103 import javax.servlet.http.HttpSession ; 104 105 import org.apache.log4j.Logger; 106 import org.apache.struts.action.ActionMapping; 107 108 import com.ivata.groupware.admin.security.server.SecuritySession; 109 import com.ivata.groupware.business.drive.file.FileDO; 110 import com.ivata.groupware.business.mail.Mail; 111 import com.ivata.groupware.business.mail.message.MessageDO; 112 import com.ivata.mask.Mask; 113 import com.ivata.mask.util.CollectionHandling; 114 import com.ivata.mask.util.StringHandling; 115 import com.ivata.mask.util.SystemException; 116 import com.ivata.mask.validation.ValidationErrors; 117 import com.ivata.mask.web.struts.DialogForm; 118 119 120 129 public class ComposeForm extends DialogForm { 130 135 private String attach; 136 141 private Class baseClass; 142 145 private Logger log = Logger.getLogger(ComposeForm.class); 146 Mail mail; 147 152 private Mask mask; 153 154 158 private MessageDO message = new MessageDO(); 159 162 private MessagingException messagingException = null; 163 167 public ComposeForm(final Mail mail) { 168 this.mail = mail; 169 } 170 171 178 protected void clear() { 179 attach = null; 180 } 181 182 189 public final String getAttach() { 190 return attach; 191 } 192 193 200 public final boolean getAttachmentRemove(final String attachmentId) { 201 return false; 203 } 204 205 212 public final Class getBaseClass() { 213 return baseClass; 214 } 215 216 223 public final Mask getMask() { 224 return mask; 225 } 226 227 234 public MessageDO getMessage() { 235 return message; 236 } 237 238 241 public MessagingException getMessagingException() { 242 return messagingException; 243 } 244 245 253 public final String getRecipients() { 254 return CollectionHandling.convertToLines(message.getRecipients(), ';'); 255 } 256 257 269 public final String getRecipientsBCC() { 270 return CollectionHandling.convertToLines(message.getRecipientsBCC(), ';'); 271 } 272 273 285 public final String getRecipientsCC() { 286 return CollectionHandling.convertToLines(message.getRecipientsCC(), ';'); 287 } 288 289 297 public final String getSenders() { 298 return CollectionHandling.convertToLines(message.getSenders(), ';'); 299 } 300 301 309 public void reset(final ActionMapping mapping, 310 final HttpServletRequest request) { 311 super.reset(mapping, request); 313 attach = null; 314 } 315 316 323 public final void setAttach(final String attach) { 324 this.attach = attach; 325 } 326 327 333 public final void setAttachmentRemove(final String attachmentId, 334 final boolean remove) { 335 if (remove && (message.getAttachments() != null)) { 338 int attachmentIdHashCode = Integer.parseInt(attachmentId); 339 340 for (Iterator i = message.getAttachments().iterator(); i.hasNext();) { 341 FileDO currentDO = (FileDO) i.next(); 342 String currentId = currentDO.getName(); 343 344 if (currentId.hashCode() == attachmentIdHashCode) { 345 message.getAttachments().remove(currentDO); 346 347 break; 348 } 349 } 350 } 351 } 352 353 361 public final void setMessage(final MessageDO message) { 362 this.message = message; 363 } 364 367 public void setMessagingException(MessagingException messagingExceptionParam) { 368 if (log.isDebugEnabled()) { 369 log.debug("setMessagingException before: '" + messagingException 370 + "', after: '" + messagingExceptionParam + "'"); 371 } 372 373 messagingException = messagingExceptionParam; 374 } 375 376 384 public final void setRecipients(final String recipients) { 385 message.setRecipients(CollectionHandling.convertFromLines(recipients, 386 ";")); 387 } 388 389 400 public final void setRecipientsBCC(final String recipientsBCC) { 401 message.setRecipientsBCC(CollectionHandling.convertFromLines( 402 recipientsBCC, ";")); 403 } 404 405 416 public final void setRecipientsCC(final String recipientsCC) { 417 message.setRecipientsCC(CollectionHandling.convertFromLines( 418 recipientsCC, ";")); 419 } 420 421 429 public final void setSenders(final String senders) { 430 message.setSenders(CollectionHandling.convertFromLines(senders, ";")); 431 } 432 433 442 public ValidationErrors validate(final HttpServletRequest request, 443 final HttpSession session) { 444 if (StringHandling.isNullOrEmpty(getOk()) && 446 StringHandling.isNullOrEmpty(getApply())) { 447 return null; 448 } 449 450 if (mail == null) { 451 throw new NullPointerException ( 452 "ERROR in ComposeForm: mail remote instance is null."); 453 } 454 455 SecuritySession securitySession = (SecuritySession) 456 session.getAttribute("securitySession"); 457 ValidationErrors validationErrors; 458 try { 459 validationErrors = mail.validate(securitySession, 460 message); 461 } catch (SystemException e) { 462 throw new RuntimeException (e); 463 } 464 return validationErrors; 465 } 466 } 467 | Popular Tags |