| 1 16 package org.outerj.daisy.emailnotifier.serverimpl.formatters; 17 18 import org.outerj.daisy.emailnotifier.serverimpl.MailTemplateFactory; 19 import org.outerj.daisy.emailnotifier.serverimpl.MailTemplate; 20 import org.outerj.daisy.emailnotifier.serverimpl.DocumentURLProvider; 21 import org.outerj.daisy.repository.Repository; 22 import org.outerj.daisy.repository.Document; 23 import org.outerj.daisy.repository.variant.VariantManager; 24 import org.apache.xmlbeans.XmlObject; 25 import org.outerx.daisy.x10.CommentDocument; 26 import org.outerx.daisy.x10.CommentDeletedDocument; 27 28 import java.util.*; 29 import java.text.DateFormat ; 30 31 public class CommentDeletedTemplateFactory implements MailTemplateFactory { 32 public MailTemplate createMailTemplate(XmlObject eventDescription, Repository repository, DocumentURLProvider urlProvider) throws Exception { 33 CommentDeletedDocument commentDeletedDocument = (CommentDeletedDocument)eventDescription; 34 CommentDocument.Comment commentXml = commentDeletedDocument.getCommentDeleted().getDeletedComment().getComment(); 35 36 Document document = repository.getDocument(commentXml.getDocumentId(), commentXml.getBranchId(), commentXml.getLanguageId(), false); 37 VariantManager variantManager = repository.getVariantManager(); 38 39 CommentDeletedMailTemplate template = new CommentDeletedMailTemplate(); 40 template.docName = document.getName(); 41 template.docId = String.valueOf(document.getId()); 42 template.branch = TemplateUtil.getBranchName(commentXml.getBranchId(), variantManager); 43 template.language = TemplateUtil.getLanguageName(commentXml.getLanguageId(), variantManager); 44 template.url = urlProvider.getURL(document); 45 template.deleter = repository.getUserManager().getUserDisplayName(commentDeletedDocument.getCommentDeleted().getDeleterId()); 46 template.deletedOn = commentDeletedDocument.getCommentDeleted().getDeletedTime().getTime(); 47 template.commentText = commentXml.getContent(); 48 49 return template; 50 } 51 52 static class CommentDeletedMailTemplate implements MailTemplate { 53 private Map cachedByLocale = new HashMap(); 54 private String docName; 55 private String docId; 56 private String branch; 57 private String language; 58 private String commentText; 59 private String deleter; 60 private Date deletedOn; 61 private String url; 62 63 private ResourceBundle getBundle(Locale locale) { 64 return ResourceBundle.getBundle("org/outerj/daisy/emailnotifier/serverimpl/formatters/messages", locale); 65 } 66 67 public String getSubject(Locale locale) { 68 ResourceBundle bundle = getBundle(locale); 69 return bundle.getString("commentdeleted.subject") + " " + docName; 70 } 71 72 public String getMessage(Locale locale) { 73 String message = (String )cachedByLocale.get(locale); 74 if (message == null) { 75 ResourceBundle bundle = getBundle(locale); 76 DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale); 77 78 StringBuffer buffer = new StringBuffer (); 79 buffer.append(bundle.getString("commentdeleted.intro")); 80 buffer.append("\n"); 81 if (url != null) { 82 buffer.append('\n').append(url).append('\n'); 83 } 84 buffer.append('\n').append(bundle.getString("common.id")).append(": ").append(docId); 85 buffer.append('\n').append(bundle.getString("common.name")).append(": ").append(docName); 86 buffer.append('\n').append(bundle.getString("common.branch")).append(": ").append(branch); 87 buffer.append('\n').append(bundle.getString("common.language")).append(": ").append(language); 88 buffer.append("\n\n").append(bundle.getString("commentdeleted.deleter")).append(": ").append(deleter); 89 buffer.append("\n").append(bundle.getString("commentdeleted.deletedon")).append(": ").append(dateFormat.format(deletedOn)); 90 buffer.append("\n\n"); 91 buffer.append(commentText); 92 93 message = buffer.toString(); 94 cachedByLocale.put(locale, message); 95 } 96 return message; 97 } 98 } 99 } | Popular Tags |