001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/common/OnlineUserUtil.java,v 1.21 2008/01/17 04:20:19 minhnn Exp $
003: * $Author: minhnn $
004: * $Revision: 1.21 $
005: * $Date: 2008/01/17 04:20:19 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding mvnForum MUST remain
012: * intact in the scripts and in the outputted HTML.
013: * The "powered by" text/logo with a link back to
014: * http://www.mvnForum.com and http://www.MyVietnam.net in
015: * the footer of the pages MUST remain visible when the pages
016: * are viewed on the internet or intranet.
017: *
018: * This program is free software; you can redistribute it and/or modify
019: * it under the terms of the GNU General Public License as published by
020: * the Free Software Foundation; either version 2 of the License, or
021: * any later version.
022: *
023: * This program is distributed in the hope that it will be useful,
024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
026: * GNU General Public License for more details.
027: *
028: * You should have received a copy of the GNU General Public License
029: * along with this program; if not, write to the Free Software
030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
031: *
032: * Support can be obtained from support forums at:
033: * http://www.mvnForum.com/mvnforum/index
034: *
035: * Correspondence and Marketing Questions can be sent to:
036: * info at MyVietnam net
037: *
038: * @author: Hau Nguyen
039: */
040: package com.mvnforum.common;
041:
042: import java.util.*;
043:
044: import net.myvietnam.mvncore.exception.*;
045: import net.myvietnam.mvncore.util.AssertionUtil;
046: import net.myvietnam.mvncore.web.GenericRequest;
047:
048: import com.mvnforum.MVNForumConfig;
049: import com.mvnforum.auth.*;
050: import com.mvnforum.user.ActionInUserModule;
051:
052: public class OnlineUserUtil {
053:
054: // prevent instantiation
055: private OnlineUserUtil() {
056: }
057:
058: public static void setRequestAttributeOfOnlineActions(
059: GenericRequest request, int pageID, Object pageParam)
060: throws AuthenticationException, DatabaseException,
061: ObjectNotFoundException {
062:
063: AssertionUtil
064: .doAssert(
065: MVNForumConfig.getEnableOnlineUsers(),
066: "Cannot list online users because ONLINE_USERS feature is disabled by administrator.");
067:
068: OnlineUserManager onlineUserManager = OnlineUserManager
069: .getInstance();
070: onlineUserManager.getOnlineUser(request);
071:
072: boolean duplicateUsers = MVNForumConfig
073: .getEnableDuplicateOnlineUsers();
074: Collection onlineUserActions = onlineUserManager
075: .getOnlineUserActions(0, duplicateUsers);
076:
077: Collection userActions = new ArrayList();
078:
079: for (Iterator countIterator = onlineUserActions.iterator(); countIterator
080: .hasNext();) {
081:
082: OnlineUserAction onlineUserAction = (OnlineUserAction) countIterator
083: .next();
084:
085: if (onlineUserAction == null) {
086: continue;
087: }
088:
089: if (onlineUserAction.getMemberName().equals(
090: MVNForumConfig.getDefaultGuestName())) {
091: continue;
092: }
093:
094: int userPageID = onlineUserAction.getPageID();
095: if (userPageID == pageID) {
096: if (pageParam == null) {
097: userActions.add(onlineUserAction);
098: } else {// pageParam != null
099: Object userPageParam = onlineUserAction
100: .getPageParam();
101: if (pageParam.equals(userPageParam)) {
102: userActions.add(onlineUserAction);
103: }
104: }
105: }
106: }
107:
108: request.setAttribute("UserActions", userActions);
109:
110: }
111:
112: /**
113: * This method is used to update the Action of OnlineUser
114: * @param request
115: * @param requestURI
116: * @throws AuthenticationException
117: * @throws DatabaseException
118: * @throws MissingURLMapEntryException
119: */
120: public static void updateOnlineUserAction(GenericRequest request,
121: String requestURI) throws AuthenticationException,
122: DatabaseException, MissingURLMapEntryException {
123:
124: OnlineUserManager onlineUserManager = OnlineUserManager
125: .getInstance();
126:
127: // This will ensure that all time-out users are removed (if any)
128: onlineUserManager.getOnlineUser(request);
129:
130: // the following 2 lines fix the bug that no online user found in the first time request
131: Action action = new ActionInUserModule(request, requestURI);// may throw MissingURLMapEntryException
132: onlineUserManager.updateOnlineUserAction(request, action);
133:
134: }
135:
136: }
|