📄 forumwebhandler.java
字号:
/*
* $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/ForumWebHandler.java,v 1.40 2006/04/14 17:05:27 minhnn Exp $
* $Author: minhnn $
* $Revision: 1.40 $
* $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.util.*;
import java.sql.Timestamp;
import javax.servlet.http.HttpServletRequest;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.util.*;
import net.myvietnam.mvncore.web.GenericRequest;
import com.mvnforum.MVNForumConfig;
import com.mvnforum.MVNForumResourceBundle;
import com.mvnforum.auth.*;
import com.mvnforum.common.ActiveThread;
import com.mvnforum.db.*;
public class ForumWebHandler {
private OnlineUserManager userManager = OnlineUserManager.getInstance();
public ForumWebHandler() {
}
public void prepareList(GenericRequest request, String requestURI)
throws AssertionException, DatabaseException, AuthenticationException, MissingURLMapEntryException {
Locale locale = I18nUtil.getLocaleInRequest(request);
// the following 3 lines fix the bug that no online user found in the first time request
OnlineUser onlineUser = userManager.getOnlineUser(request);
if (request.isServletRequest()) {
HttpServletRequest req = request.getServletRequest();
Action action = new ActionInUserModule(req, requestURI); // may throw MissingURLMapEntryException
userManager.updateOnlineUserAction(req, action);
}
MVNForumPermission permission = onlineUser.getPermission();
// Calculate to get the mosts
long now = DateUtil.getCurrentGMTTimestamp().getTime();
Timestamp since = new Timestamp(now - DateUtil.WEEK);
if (MVNForumConfig.getEnableMostActiveMembers()) {
Collection mostActiveMembers = PostCache.getInstance().getMostActiveMembers(since, MVNForumConfig.getMaxActiveMembers());
request.setAttribute("MostActiveMembers", mostActiveMembers);
}
if (MVNForumConfig.getEnableMostActiveThreads()) {
Collection mostActiveThreads = this.getMyMostActiveThreads(permission, since);
request.setAttribute("MostActiveThreads", mostActiveThreads);
}
if (MVNForumConfig.getEnableSiteStatisticsOverview()) {
int numberOfMembers = DAOFactory.getMemberDAO().getNumberOfMembers();
Collection memberBeans = DAOFactory.getMemberDAO().getMembers_withSortSupport_limit(0, 1, "MemberID", "DESC");
if (memberBeans.size() != 1) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.wrong_size", new Object[] {"MemberBeans", "==",new Integer(memberBeans.size())});
throw new AssertionException(localizedMessage);
//throw new AssertionException("Assertion: MemberBeans size == 1 (but the value = " + memberBeans.size() + ")");
}
MemberBean memberBean = (MemberBean)memberBeans.iterator().next();
request.setAttribute("MemberBean", memberBean);
request.setAttribute("NumberOfMembers", new Integer(numberOfMembers));
}
// now set the attribute
boolean duplicateUsers = MVNForumConfig.getEnableDuplicateOnlineUsers();
request.setAttribute("OnlineUserActions", userManager.getOnlineUserActions(0 /*default*/, duplicateUsers)); // no permission
}
public void prepareListIndex(GenericRequest request, String requestURI)
throws AssertionException, DatabaseException,
AuthenticationException, MissingURLMapEntryException {
Locale locale = I18nUtil.getLocaleInRequest(request);
// the following 3 lines fix the bug that no online user found in the first time request
OnlineUser onlineUser = userManager.getOnlineUser(request);
if (request.isServletRequest()) {
HttpServletRequest req = request.getServletRequest();
Action action = new ActionInUserModule(req, requestURI); // may throw MissingURLMapEntryException
userManager.updateOnlineUserAction(req, action);
}
MVNForumPermission permission = onlineUser.getPermission();
ForumCache forumCache = ForumCache.getInstance();
Collection forumBeans = forumCache.getBeans();
Collection cTotal = new ArrayList();
for (Iterator forumIterator = forumBeans.iterator(); forumIterator.hasNext(); ) {
ForumBean forumBean = (ForumBean) forumIterator.next();
Collection cThreadTemp = ThreadCache.getInstance().getNormalEnableThreads_inForum_withSortSupport_limit(forumBean.getForumID(), 0, 1, "ThreadLastPostDate", "DESC");
if (cThreadTemp.size() == 0) {
continue;
} else if (cThreadTemp.size() > 1) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.wrong_size", new Object[] {"ThreadBeans", "<=",new Integer(cThreadTemp.size())});
throw new AssertionException(localizedMessage);
//throw new AssertionException("Assertion: ThreadBeans size <= 1 (but the value = " + cThreadTemp.size() + ")");
}
ThreadBean threadBean = (ThreadBean) (cThreadTemp.iterator().next());
/*
Collection cPostTemp = DAOFactory.getPostDAO().getLastEnablePosts_inThread_limit(threadBean.getThreadID(), 1);
if (cPostTemp.size() != 1) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.wrong_size", new Object[] {"PostBeans", "==",new Integer(cPostTemp.size())});
throw new AssertionException(localizedMessage);
//throw new AssertionException("Assertion: PostBeans size == 1 (but the value = " + cPostTemp.size() + ")");
}
PostBean postBean = (PostBean) (cPostTemp.iterator().next());
*/
PostBean postBean = PostCache.getInstance().getLastEnablePost_inThread(threadBean.getThreadID());
Collection cGeneralInfo = new ArrayList(2);
cGeneralInfo.add(postBean);
cGeneralInfo.add(threadBean);
cTotal.add(cGeneralInfo);
}
// Calculate to get the mosts
long now = DateUtil.getCurrentGMTTimestamp().getTime();
Timestamp since = new Timestamp(now - DateUtil.WEEK);
if (MVNForumConfig.getEnableMostActiveMembers()) {
Collection mostActiveMembers = PostCache.getInstance().getMostActiveMembers(since, MVNForumConfig.getMaxActiveMembers());
request.setAttribute("MostActiveMembers", mostActiveMembers);
}
if (MVNForumConfig.getEnableMostActiveThreads()) {
Collection mostActiveThreads = this.getMyMostActiveThreads(permission, since);
request.setAttribute("MostActiveThreads", mostActiveThreads);
}
if (MVNForumConfig.getEnableSiteStatisticsOverview()) {
int numberOfMembers = DAOFactory.getMemberDAO().getNumberOfMembers();
Collection memberBeans = DAOFactory.getMemberDAO().getMembers_withSortSupport_limit(0, 1, "MemberID", "DESC");
if (memberBeans.size() != 1) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.wrong_size", new Object[] {"MemberBeans", "==",new Integer(memberBeans.size())});
throw new AssertionException(localizedMessage);
//throw new AssertionException("Assertion: MemberBeans size == 1 (but the value = " + memberBeans.size() + ")");
}
MemberBean memberBean = (MemberBean) memberBeans.iterator().next();
request.setAttribute("MemberBean", memberBean);
request.setAttribute("NumberOfMembers", new Integer(numberOfMembers));
}
// now set the attribute
boolean duplicateUsers = MVNForumConfig.getEnableDuplicateOnlineUsers();
request.setAttribute("OnlineUserActions", userManager.getOnlineUserActions(0 /*default*/, duplicateUsers)); // no permission
request.setAttribute("LastPosts", cTotal);
}
private Collection getMyMostActiveThreads(MVNForumPermission permission, Timestamp since)
throws DatabaseException {
// get more than 2 threads in case user doesnt have permission to view previous threads
Collection mostActiveThreads = PostCache.getInstance().getMostActiveThreads(since, MVNForumConfig.getMaxActiveThreads() + 2);
int remainCount = 0;
for (Iterator iter = mostActiveThreads.iterator(); iter.hasNext(); ) {
ActiveThread activeThread = (ActiveThread) iter.next();
if (permission.canReadPost(activeThread.getForumID()) == false) {
iter.remove();
} else if (++remainCount > MVNForumConfig.getMaxActiveThreads()) {
iter.remove();
}
}
return mostActiveThreads;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -