📄 watchwebhandler.java
字号:
/*
* $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/WatchWebHandler.java,v 1.27 2006/04/14 17:05:27 minhnn Exp $
* $Author: minhnn $
* $Revision: 1.27 $
* $Date: 2006/04/14 17:05:27 $
*
* ====================================================================
*
* Copyright (C) 2002-2006 by MyVietnam.net
*
* All copyright notices regarding mvnForum MUST remain
* intact in the scripts and in the outputted HTML.
* The "powered by" text/logo with a link back to
* http://www.mvnForum.com and http://www.MyVietnam.net in
* the footer of the pages MUST remain visible when the pages
* are viewed on the internet or intranet.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Support can be obtained from support forums at:
* http://www.mvnForum.com/mvnforum/index
*
* Correspondence and Marketing Questions can be sent to:
* info at MyVietnam net
*
* @author: Minh Nguyen
* @author: Mai Nguyen
*/
package com.mvnforum.user;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.Timestamp;
import java.util.*;
import javax.mail.MessagingException;
import com.mvnforum.MVNForumConfig;
import com.mvnforum.MVNForumResourceBundle;
import com.mvnforum.auth.*;
import com.mvnforum.db.*;
import freemarker.template.TemplateException;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.util.*;
import net.myvietnam.mvncore.web.GenericRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class WatchWebHandler {
private static Log log = LogFactory.getLog(WatchWebHandler.class);
private OnlineUserManager userManager = OnlineUserManager.getInstance();
//private DateFormat dateFormat = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.DEFAULT, SimpleDateFormat.DEFAULT);
public WatchWebHandler() {
}
void sendMail()
throws AssertionException, DatabaseException, MessagingException, BadInputException, ObjectNotFoundException, TemplateException, IOException {
if (MVNForumConfig.getEnableWatch() == false) {
log.warn("Ingore Watch sendMail because this feature is disabled by administrator.");
return;
}
String forumBase = ParamUtil.getServerPath() + ParamUtil.getContextPath() + UserModuleConfig.getUrlPattern();
//log.debug("Forum base = " + forumBase);
//get the list of watch for each member, the watch is choosen based on oldest lastsent time
Collection beans = DAOFactory.getWatchDAO().getMemberBeans();
//log.debug("Watch: total member = " + beans.size());
Iterator iterator = beans.iterator();
while (iterator.hasNext()) {
WatchBean watchBean = (WatchBean)iterator.next();
int memberID = watchBean.getMemberID();
// check if member is enable here
if (DAOFactory.getMemberDAO().getActivateCode(memberID).equals(MemberBean.MEMBER_ACTIVATECODE_ACTIVATED) == false) {
// Not activated, then we continue with the next user
continue;
}
// Check the frequency of the update
Timestamp lastSent = watchBean.getWatchLastSentDate();
Timestamp now = DateUtil.getCurrentGMTTimestamp();
// We will now support a single watch standard, but should be
// bitmasked in future to support multiple watch schedule for the same
// thread or forum
long minimumWaitTime = 0;
int watchOption = watchBean.getWatchOption();
if (watchOption == WatchBean.WATCH_OPTION_DEFAULT) {
watchOption = MVNForumConfig.getDefaultWatchOption();
}
switch (watchOption) {
case WatchBean.WATCH_OPTION_LIVE:
minimumWaitTime = 0;
break;
case WatchBean.WATCH_OPTION_HOURLY:
minimumWaitTime = DateUtil.HOUR;
break;
case WatchBean.WATCH_OPTION_DAILY:
minimumWaitTime = DateUtil.DAY;
break;
case WatchBean.WATCH_OPTION_WEEKLY:
minimumWaitTime = DateUtil.WEEK;
break;
default:// currently only default is processed (WatchOption = 0)
// note that watch option might have any value so we have to have default fallback
minimumWaitTime = DateUtil.DAY;
break;
}
if ( (now.getTime() - lastSent.getTime()) > minimumWaitTime ) {
sendMail_forMember(memberID, forumBase, lastSent);
}
}
}
void sendMail_forMember(int memberID, String forumBase, Timestamp lastSent)
throws AssertionException, DatabaseException, MessagingException, BadInputException, ObjectNotFoundException, TemplateException, IOException {
MVNForumPermission permission = null;
try {
permission = MVNForumPermissionFactory.getAuthenticatedPermission(memberID);
} catch (AssertionException e) {
log.error("Cannot create watch mail for Guest with id = " + memberID, e);
return;// do nothing, just return if member is guest.
}
if (permission.isActivated() == false) {
// if member is not activated, then we ignore this member
return;
}
Collection watchBeans = DAOFactory.getWatchDAO().getWatches_forMember(memberID);
//log.debug("Watch size = " + watchBeans.size() + " for memberid = " + memberID);
Timestamp now = DateUtil.getCurrentGMTTimestamp();
MemberBean receiver = null;
try {
receiver = DAOFactory.getMemberDAO().getMember_forViewCurrentMember(memberID);
} catch (ObjectNotFoundException e) {
log.error("Cannot get member with id = " + memberID, e);
return;// do nothing just return if member does not exist
}
//then optimize the watchBeans
watchBeans = WatchUtil.optimize(watchBeans);
WatchMail watchMail = new WatchMail(receiver, permission, forumBase, lastSent, now);
for (Iterator watchIterator = watchBeans.iterator(); watchIterator.hasNext(); ) {
WatchBean watchBean = (WatchBean)watchIterator.next();
watchMail.appendWatch(watchBean);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -