?? watchmail.java
字號:
/*
* $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/WatchMail.java,v 1.11 2004/06/17 20:20:30 minhnn Exp $
* $Author: minhnn $
* $Revision: 1.11 $
* $Date: 2004/06/17 20:20:30 $
*
* ====================================================================
*
* Copyright (C) 2002-2004 by MyVietnam.net
*
* 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.
*
* 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 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@MyVietnam.net
*
* @author: Minh Nguyen minhnn@MyVietnam.net
* @author: Mai Nguyen mai.nh@MyVietnam.net
* @author: Cord cord_sw@lupinex.com
*/
package com.mvnforum.user;
import java.io.IOException;
import java.io.StringWriter;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.util.*;
import com.mvnforum.MVNForumConfig;
import com.mvnforum.MVNForumGlobal;
import com.mvnforum.db.*;
import freemarker.template.*;
import net.myvietnam.mvncore.exception.DatabaseException;
import net.myvietnam.mvncore.exception.ObjectNotFoundException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
class WatchMail {
// static variable
private static Log log = LogFactory.getLog(WatchMail.class);
private ArrayList m_threadList = new ArrayList();
private DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT);
private String m_forumBase = null;
private Timestamp m_lastSent = null;
private Timestamp m_now = null;
private Map m_root = new HashMap();
private ArrayList m_threadWatchList = new ArrayList();
WatchMail(String forumBase, Timestamp lastSent, Timestamp now) {
m_forumBase = forumBase;
m_lastSent = lastSent;
m_now = now;
m_root.put("lastSent", dateFormat.format(m_lastSent));
m_root.put("now", dateFormat.format(m_now));
m_root.put("forumBase", forumBase);
m_root.put("threadWatchList", m_threadWatchList);
}
boolean haveAtLeastOneNewThread() {
return (m_threadList.size() > 0);
}
void appendWatch(WatchBean watchBean)
throws ObjectNotFoundException, DatabaseException {
Timestamp lastSent = watchBean.getWatchLastSentDate();
int categoryID = watchBean.getCategoryID();
int forumID = watchBean.getForumID();
int threadID = watchBean.getThreadID();
log.debug("appendWatch called!!! c = " + categoryID + " f = " + forumID + " t = " + threadID);
Collection threadBeans = null;
if (categoryID != 0) {
threadBeans = DAOFactory.getThreadDAO().getEnableThreads_inCategory(categoryID, lastSent);
} else if (forumID != 0) {
threadBeans = DAOFactory.getThreadDAO().getEnableThreads_inForum(forumID, lastSent);
} else if (threadID != 0) {
if (shouldProcessThread(threadID)) {
threadBeans = DAOFactory.getThreadDAO().getEnableThreads_inThread(threadID, lastSent);
} else {
return;//ignore the reduntdant thread
}
} else {
threadBeans = DAOFactory.getThreadDAO().getEnableThreads_inGlobal(lastSent);
}
if (threadBeans.size() == 0) {
return;// no new thread
}
// remember that this WatchMail has process these thread
rememberThread(threadBeans);
createWatchMessageBean(threadBeans);
}
private void createWatchMessageBean(Collection threadBeans)
throws DatabaseException, ObjectNotFoundException {
// now, has at least one new thread, then we get the mail content
int lastForumID = -1;//init it to a not existed forumID
for (Iterator iterator = threadBeans.iterator(); iterator.hasNext(); ) {
ThreadBean thread = (ThreadBean)iterator.next();
SimpleHash beanWatchMail = new SimpleHash();
m_threadWatchList.add(beanWatchMail);
// if move to a new forum, then we print the summary of category and forum
if (thread.getForumID() != lastForumID) {
lastForumID = thread.getForumID();
beanWatchMail.put("leader", true);
} else {
beanWatchMail.put("leader", false);
}
ForumBean forumBean = ForumCache.getInstance().getBean(thread.getForumID());
CategoryBean categoryBean = CategoryCache.getInstance().getBean(forumBean.getCategoryID());
String forumName = forumBean.getForumName();
String categoryName = categoryBean.getCategoryName();
beanWatchMail.put("categoryName", categoryName);
beanWatchMail.put("forumName", forumName);
beanWatchMail.put("threadTopic", thread.getThreadTopic());
beanWatchMail.put("memberName", thread.getMemberName());
beanWatchMail.put("lastPostMemberName", thread.getLastPostMemberName());
beanWatchMail.put("threadLastPostDate", dateFormat.format(thread.getThreadLastPostDate()));
beanWatchMail.put("threadUrl", m_forumBase + "/viewthread?thread=" + thread.getThreadID());
}
}
private boolean shouldProcessThread(int threadID) {
int size = m_threadList.size();
for (int i = 0; i < size; i++) {
int currentThreadID = ((Integer)m_threadList.get(i)).intValue();
if (currentThreadID == threadID) {
return false;
}
}
return true;
}
/**
* Also remove the redundant thread in this threadBeans
* @param threadBeans : the threads to remember
*/
private void rememberThread(Collection threadBeans) {
for (Iterator iter = threadBeans.iterator(); iter.hasNext(); ) {
int currentThreadID = ((ThreadBean)iter.next()).getThreadID();
if (shouldProcessThread(currentThreadID)) {
m_threadList.add(new Integer(currentThreadID));
} else {
iter.remove();
}
}
}
String getWatchSubject() throws IOException, TemplateException {
// Prepare the FreeMarker configuration;
Configuration cfg = MVNForumConfig.getFreeMarkerConfiguration();
StringWriter subjectWriter = new StringWriter(256);
Template subjectTemplate = cfg.getTemplate(MVNForumGlobal.TEMPLATE_WATCHMAIL_SUBJECT);
subjectTemplate.process(m_root, subjectWriter);
return subjectWriter.toString();
}
String getMailContent() throws IOException, TemplateException {
// Prepare the FreeMarker configuration;
Configuration cfg = MVNForumConfig.getFreeMarkerConfiguration();
StringWriter bodyWriter = new StringWriter(4096);
Template bodyTemplate = cfg.getTemplate(MVNForumGlobal.TEMPLATE_WATCHMAIL_BODY);
bodyTemplate.process(m_root, bodyWriter);
return bodyWriter.toString();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -