1 4 package com.openedit.blog; 5 6 import java.util.HashSet ; 7 import java.util.Iterator ; 8 import java.util.Set ; 9 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 13 import com.openedit.OpenEditException; 14 import com.openedit.WebPageRequest; 15 import com.openedit.modules.email.TemplateWebEmail; 16 import com.openedit.page.Page; 17 import com.openedit.page.manage.PageManager; 18 import com.openedit.users.User; 19 import com.openedit.users.UserManager; 20 import com.openedit.modules.email.PostMail; 21 public class BlogCommentNotification 22 { 23 protected PageManager fieldPageManager; 24 protected UserManager fieldUserManager; 25 private static final Log log = LogFactory.getLog(BlogCommentNotification.class); 26 private PostMail postMail; 27 public PostMail getPostMail() { 28 return postMail; 29 } 30 31 public void setPostMail(PostMail postMail) { 32 this.postMail = postMail; 33 } 34 35 public void commentAdded( WebPageRequest inReq, Blog inBlog, BlogEntry inEntry, Comment inComment) throws OpenEditException 36 { 37 if( !inBlog.isUseNotification() ) 38 { 39 return; 40 } 41 42 Set notify = new HashSet (); 48 49 if( inEntry.getUser() != null) 50 { 51 String email = inEntry.getUser().getEmail(); 52 if( email != null) 53 { 54 notify.add(email); 55 } 56 } 57 58 for (Iterator iterator = inEntry.getComments().iterator(); iterator.hasNext();) 59 { 60 Comment lastcomment = (Comment)iterator.next(); 61 User user = lastcomment.getUser(); 62 if( user != null) { 64 String email = user.getEmail(); 65 if( email != null) 66 { 67 notify.add(email); 68 } 69 } 70 } 71 if( inReq.getUser().getEmail() != null) 72 { 73 notify.remove(inReq.getUser().getEmail()); } 75 76 if( notify.size() > 0 ) 77 { 78 inReq.putPageValue("comment", inComment); 80 inReq.putPageValue("entry", inEntry); 81 inReq.putPageValue("blog", inBlog); 82 83 try 84 { 85 Page page = getPageManager().getPage( inBlog.getBlogHome() + "/layout/commentemail.html"); 86 TemplateWebEmail template = postMail.getTemplateWebEmail(); 87 template.setMailTemplatePage(page); 88 template.setWebPageContext(inReq); 89 template.loadSettings(page); 90 String sub = template.getSubject(); 91 sub = "[" + inBlog.getHostName() + "] " + sub; 92 template.setSubject(sub); 93 for (Iterator iterator = notify.iterator(); iterator.hasNext();) 94 { 95 String email = (String ) iterator.next(); 96 template.setTo(email); 97 template.send(); 98 } 99 } 101 catch ( Exception ex) 102 { 103 log.error(ex); 104 } 105 } 106 } 107 108 public PageManager getPageManager() 109 { 110 return fieldPageManager; 111 } 112 113 public void setPageManager(PageManager inPageManager) 114 { 115 fieldPageManager = inPageManager; 116 } 117 118 public UserManager getUserManager() 119 { 120 return fieldUserManager; 121 } 122 123 public void setUserManager(UserManager inUserManager) 124 { 125 fieldUserManager = inUserManager; 126 } 127 } 128 | Popular Tags |