001: /**
002: * @author garethc
003: * 22/10/2002 11:52:37
004: */package vqwiki;
005:
006: import java.util.Collection;
007: import java.util.Iterator;
008: import java.util.Locale;
009: import java.util.ResourceBundle;
010:
011: import org.apache.log4j.Logger;
012:
013: import vqwiki.utils.Utilities;
014: import vqwiki.utils.JSPUtils;
015:
016: public abstract class AbstractNotify implements Notify {
017:
018: private static final Logger logger = Logger
019: .getLogger(AbstractNotify.class);
020: protected String topicName;
021: protected String virtualWiki;
022:
023: /**
024: *
025: */
026: public abstract void addMember(String userName) throws Exception;
027:
028: /**
029: *
030: */
031: public abstract void removeMember(String userName) throws Exception;
032:
033: /**
034: *
035: */
036: public abstract boolean isMember(String userName) throws Exception;
037:
038: /**
039: *
040: */
041: public abstract Collection getMembers() throws Exception;
042:
043: /**
044: *
045: */
046: public boolean sendNotifications(String rootPath, Locale locale)
047: throws Exception {
048: logger.debug("sending notifications for path " + rootPath);
049: ResourceBundle messages = ResourceBundle.getBundle(
050: "ApplicationResources", locale);
051: WikiMembers members = WikiBase.getInstance()
052: .getWikiMembersInstance(virtualWiki);
053: logger.debug(members.getAllMembers().size() + " members found");
054: WikiMail mailer = WikiMail.getInstance();
055: Iterator anIterator = getMembers().iterator();
056: while (anIterator.hasNext()) {
057: String aUsername = (String) anIterator.next();
058: logger.debug("notification for " + aUsername);
059: WikiMember aMember = members.findMemberByName(aUsername);
060: String replyAddress = Environment.getInstance()
061: .getStringSetting(
062: Environment.PROPERTY_REPLY_ADDRESS);
063: StringBuffer buffer = new StringBuffer();
064: buffer.append(messages
065: .getString("mail.notification.body.line1"));
066: buffer.append(topicName);
067: buffer.append("\n");
068: if (!this .virtualWiki.equals(WikiBase.DEFAULT_VWIKI)) {
069: buffer.append(messages
070: .getString("mail.notification.body.line2"));
071: buffer.append(this .virtualWiki);
072: buffer.append("\n");
073: }
074: buffer.append(rootPath + "Wiki?"
075: + JSPUtils.encodeURL(topicName));
076: buffer.append("\n");
077: Topic topicObject = new Topic(topicName);
078: String author = null;
079: java.util.Date lastRevisionDate = null;
080: if (Environment.getInstance().isVersioningOn()) {
081: lastRevisionDate = topicObject
082: .getMostRecentRevisionDate(virtualWiki);
083: if (lastRevisionDate != null) {
084: buffer
085: .append(messages
086: .getString("mail.notification.body.revision")
087: + Utilities
088: .formatDateTime(lastRevisionDate)
089: + "\n");
090: Collection c = WikiBase.getInstance()
091: .getChangeLogInstance().getChanges(
092: virtualWiki, lastRevisionDate);
093: if (c != null) {
094: Iterator it = c.iterator();
095: while (it.hasNext()) {
096: Change this change = (Change) it.next();
097: if (this change.getTopic().equals(topicName)) {
098: author = this change.getUser();
099: }
100: }
101: }
102: }
103: }
104: if (author != null) {
105: buffer.append(messages
106: .getString("mail.notification.body.author")
107: + author + "\n");
108: }
109: buffer.append("\n"
110: + messages.getString("mail.notification.body.diff")
111: + "\n"
112: + topicObject.mostRecentDiff(this .virtualWiki,
113: false));
114: buffer.append("\n\n\n----\n\n");
115: buffer
116: .append(messages.getString("mail.unsubscribe")
117: + " <");
118: buffer.append(rootPath);
119: buffer.append("Wiki?action="
120: + Environment.getInstance().getActionNotify());
121: buffer.append("¬ify_action=notify_off&topic="
122: + JSPUtils.encodeURL(topicName));
123: buffer.append("&username=" + JSPUtils.encodeURL(aUsername)
124: + ">");
125: logger.debug("Sending notification email to "
126: + aMember.getEmail() + " for " + virtualWiki + "/"
127: + topicName);
128: String mailTopicName = topicName;
129: if (mailTopicName.length() > 25) {
130: mailTopicName = topicName.substring(0, 25);
131: }
132: mailer.sendMail(replyAddress, aMember.getEmail(), messages
133: .getString("mail.notification.subject")
134: + mailTopicName, buffer.toString());
135: }
136: return true;
137: }
138:
139: /**
140: *
141: */
142: public String getTopicName() {
143: return topicName;
144: }
145:
146: /**
147: *
148: */
149: public String getVirtualWiki() {
150: return virtualWiki;
151: }
152: }
|