001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/ForumWebHandler.java,v 1.92 2007/12/07 02:59:00 minhnn Exp $
003: * $Author: minhnn $
004: * $Revision: 1.92 $
005: * $Date: 2007/12/07 02:59:00 $
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: Minh Nguyen
039: * @author: Mai Nguyen
040: */
041: package com.mvnforum.user;
042:
043: import java.sql.Timestamp;
044: import java.util.*;
045:
046: import net.myvietnam.mvncore.exception.*;
047: import net.myvietnam.mvncore.util.*;
048: import net.myvietnam.mvncore.web.GenericRequest;
049: import net.myvietnam.mvncore.web.GenericResponse;
050:
051: import org.apache.commons.logging.Log;
052: import org.apache.commons.logging.LogFactory;
053:
054: import com.mvnforum.*;
055: import com.mvnforum.auth.*;
056: import com.mvnforum.categorytree.*;
057: import com.mvnforum.categorytree.impl.CategoryTreePath;
058: import com.mvnforum.common.OnlineUserUtil;
059: import com.mvnforum.db.*;
060: import com.mvnforum.service.CategoryService;
061: import com.mvnforum.service.MvnForumServiceFactory;
062:
063: public class ForumWebHandler {
064:
065: private static Log log = LogFactory.getLog(ForumWebHandler.class);
066:
067: private OnlineUserManager onlineUserManager = OnlineUserManager
068: .getInstance();
069:
070: private static CategoryService categoryService = MvnForumServiceFactory
071: .getMvnForumService().getCategoryService();
072:
073: public ForumWebHandler() {
074: }
075:
076: public void prepareList(GenericRequest request,
077: GenericResponse response, String requestURI)
078: throws DatabaseException, AuthenticationException,
079: MissingURLMapEntryException, BadInputException,
080: ObjectNotFoundException {
081:
082: OnlineUserUtil.updateOnlineUserAction(request, requestURI);
083:
084: Locale locale = I18nUtil.getLocaleInRequest(request);
085:
086: OnlineUser onlineUser = onlineUserManager
087: .getOnlineUser(request);
088:
089: MVNForumPermission permission = onlineUser.getPermission();
090:
091: // Calculate to get the mosts
092: long now = DateUtil.getCurrentGMTTimestamp().getTime();
093: Timestamp since = new Timestamp(now - DateUtil.WEEK);
094:
095: if (MVNForumConfig.getEnableMostActiveMembers()) {
096: Collection mostActiveMembers = PostCache.getInstance()
097: .getMostActiveMembers(since,
098: MVNForumConfig.getMaxActiveMembers());
099:
100: request
101: .setAttribute("MostActiveMembers",
102: mostActiveMembers);
103: }
104: if (MVNForumConfig.getEnableMostActiveThreads()) {
105: Collection mostActiveThreads = PostUtil
106: .getMyMostActiveThreads(permission, since);
107:
108: request
109: .setAttribute("MostActiveThreads",
110: mostActiveThreads);
111: }
112:
113: if (MVNForumConfig.getEnableSiteStatisticsOverview()) {
114:
115: if (MVNForumConfig.getEnableListNewMembersInRecentDays()) {
116: int recentDays = MVNForumConfig
117: .getDaysToShowRecentMembers();
118: Timestamp fromDate = DateUtil
119: .getCurrentGMTTimestampExpiredDay(-recentDays);
120: Timestamp toDate = DateUtil.getCurrentGMTTimestamp();
121: Collection memberBeans = MyUtil
122: .getNewMembersInRecentDays(fromDate, toDate,
123: "MemberCreationDate", "DESC");
124:
125: request.setAttribute("MemberBeans", memberBeans);
126: }
127:
128: Collection memberBeans = DAOFactory.getMemberDAO()
129: .getMembers_withSortSupport_limit(0, 1, "MemberID",
130: "DESC", MemberDAO.ALL_MEMBER_STATUS);
131: if (memberBeans.size() != 1) {
132: String localizedMessage = MVNForumResourceBundle
133: .getString(
134: locale,
135: "java.lang.AssertionError.wrong_size",
136: new Object[] { "MemberBeans", "==",
137: new Integer(memberBeans.size()) });
138: throw new AssertionError(localizedMessage);
139: //throw new AssertionError("Assertion: MemberBeans size == 1 (but the value = " + memberBeans.size() + ")");
140: }
141:
142: MemberBean memberBean = (MemberBean) memberBeans.iterator()
143: .next();
144: request.setAttribute("MemberBean", memberBean);
145:
146: int numberOfMembers = DAOFactory.getMemberDAO()
147: .getNumberOfMembers();
148: request.setAttribute("NumberOfMembers", new Integer(
149: numberOfMembers));
150: }
151:
152: // now set the attribute
153: boolean duplicateUsers = MVNForumConfig
154: .getEnableDuplicateOnlineUsers();
155: request.setAttribute("OnlineUserActions", onlineUserManager
156: .getOnlineUserActions(0 /*default*/, duplicateUsers)); // no permission
157:
158: int categoryId = GenericParamUtil.getParameterInt(request,
159: "category", 0);
160: boolean other_category = GenericParamUtil.getParameterBoolean(
161: request, "other_category_invisible");
162: boolean show_sub_category = GenericParamUtil
163: .getParameterBoolean(request, "show_sub_category");
164:
165: CategoryBuilder treebuilder = new DefaultCategoryBuilder();
166: CategoryTree categorytree = new CategoryTree(treebuilder);
167: CategoryTreeListener treelistener = new CategoryTreePath(
168: request, response,
169: CategoryTreePath.FORUMID_IN_LIST_CATEGORY_CASE,
170: categoryId, null);
171: categorytree.addCategeoryTreeListener(treelistener);
172: request.setAttribute("tree", categorytree.build());
173:
174: CategoryBuilder builder = new ExtensionCategoryBuilder();
175: CategoryTree tree = new CategoryTree(builder);
176: CategoryBean category = null;
177: if (categoryId != 0) {
178: category = CategoryCache.getInstance().getBean(categoryId);
179: tree.setRoot(category);
180: }
181: CategoryTreeListener listener = categoryService
182: .getManagementListForums(request, response, category,
183: other_category, show_sub_category);
184: tree.addCategeoryTreeListener(listener);
185:
186: request.setAttribute("Result", tree.build());
187:
188: if (tree.getID().equals("") == false) {
189: request.setAttribute("id", tree.getID());
190: }
191: }
192:
193: public void prepareListIndex(GenericRequest request,
194: GenericResponse response, String requestURI)
195: throws DatabaseException, AuthenticationException,
196: MissingURLMapEntryException, ObjectNotFoundException {
197:
198: OnlineUserUtil.updateOnlineUserAction(request, requestURI);
199:
200: Locale locale = I18nUtil.getLocaleInRequest(request);
201:
202: OnlineUser onlineUser = onlineUserManager
203: .getOnlineUser(request);
204:
205: MVNForumPermission permission = onlineUser.getPermission();
206:
207: ForumCache forumCache = ForumCache.getInstance();
208: Collection forumBeans = forumCache.getBeans();
209: Collection cTotal = new ArrayList();
210:
211: for (Iterator forumIterator = forumBeans.iterator(); forumIterator
212: .hasNext();) {
213: ForumBean forumBean = (ForumBean) forumIterator.next();
214:
215: Collection cThreadTemp = ThreadCache
216: .getInstance()
217: .getNormalEnableThreads_inForum_withSortSupport_limit(
218: forumBean.getForumID(), 0, 1,
219: "ThreadLastPostDate", "DESC");
220: if (cThreadTemp.size() == 0) {
221: continue;
222: } else if (cThreadTemp.size() > 1) {
223: String localizedMessage = MVNForumResourceBundle
224: .getString(
225: locale,
226: "java.lang.AssertionError.wrong_size",
227: new Object[] { "ThreadBeans", "<=",
228: new Integer(cThreadTemp.size()) });
229: throw new AssertionError(localizedMessage);
230: //throw new AssertionError("Assertion: ThreadBeans size <= 1 (but the value = " + cThreadTemp.size() + ")");
231: }
232: ThreadBean threadBean = (ThreadBean) (cThreadTemp
233: .iterator().next());
234:
235: /*
236: Collection cPostTemp = DAOFactory.getPostDAO().getLastEnablePosts_inThread_limit(threadBean.getThreadID(), 1);
237: if (cPostTemp.size() != 1) {
238: String localizedMessage = MVNForumResourceBundle.getString(locale, "java.lang.AssertionError.wrong_size", new Object[] {"PostBeans", "==",new Integer(cPostTemp.size())});
239: throw new AssertionError(localizedMessage);
240: //throw new AssertionError("Assertion: PostBeans size == 1 (but the value = " + cPostTemp.size() + ")");
241: }
242: PostBean postBean = (PostBean) (cPostTemp.iterator().next());
243: */
244: PostBean postBean = PostCache.getInstance()
245: .getLastEnablePost_inThread(
246: threadBean.getThreadID());
247:
248: Collection cGeneralInfo = new ArrayList(2);
249: cGeneralInfo.add(postBean);
250: cGeneralInfo.add(threadBean);
251: cTotal.add(cGeneralInfo);
252: }
253:
254: // Calculate to get the mosts
255: long now = DateUtil.getCurrentGMTTimestamp().getTime();
256: Timestamp since = new Timestamp(now - DateUtil.WEEK);
257:
258: if (MVNForumConfig.getEnableMostActiveMembers()) {
259: Collection mostActiveMembers = PostCache.getInstance()
260: .getMostActiveMembers(since,
261: MVNForumConfig.getMaxActiveMembers());
262:
263: request
264: .setAttribute("MostActiveMembers",
265: mostActiveMembers);
266: }
267:
268: if (MVNForumConfig.getEnableMostActiveThreads()) {
269: Collection mostActiveThreads = PostUtil
270: .getMyMostActiveThreads(permission, since);
271:
272: request
273: .setAttribute("MostActiveThreads",
274: mostActiveThreads);
275: }
276:
277: if (MVNForumConfig.getEnableSiteStatisticsOverview()) {
278:
279: if (MVNForumConfig.getEnableListNewMembersInRecentDays()) {
280: int recentDays = MVNForumConfig
281: .getDaysToShowRecentMembers();
282: Timestamp fromDate = DateUtil
283: .getCurrentGMTTimestampExpiredDay(-recentDays);
284: Timestamp toDate = DateUtil.getCurrentGMTTimestamp();
285: Collection memberBeans = MyUtil
286: .getNewMembersInRecentDays(fromDate, toDate,
287: "MemberCreationDate", "DESC");
288: request.setAttribute("MemberBeans", memberBeans);
289: }
290:
291: Collection memberBeans = DAOFactory.getMemberDAO()
292: .getMembers_withSortSupport_limit(0, 1, "MemberID",
293: "DESC", MemberDAO.ALL_MEMBER_STATUS);
294: if (memberBeans.size() != 1) {
295: String localizedMessage = MVNForumResourceBundle
296: .getString(
297: locale,
298: "java.lang.AssertionError.wrong_size",
299: new Object[] { "MemberBeans", "==",
300: new Integer(memberBeans.size()) });
301: throw new AssertionError(localizedMessage);
302: //throw new AssertionError("Assertion: MemberBeans size == 1 (but the value = " + memberBeans.size() + ")");
303: }
304:
305: MemberBean memberBean = (MemberBean) memberBeans.iterator()
306: .next();
307: request.setAttribute("MemberBean", memberBean);
308:
309: int numberOfMembers = DAOFactory.getMemberDAO()
310: .getNumberOfMembers();
311: request.setAttribute("NumberOfMembers", new Integer(
312: numberOfMembers));
313: }
314:
315: // now set the attribute
316: boolean duplicateUsers = MVNForumConfig
317: .getEnableDuplicateOnlineUsers();
318: request.setAttribute("OnlineUserActions", onlineUserManager
319: .getOnlineUserActions(0 /*default*/, duplicateUsers)); // no permission
320: request.setAttribute("LastPosts", cTotal);
321:
322: CategoryBuilder treebuilder = new DefaultCategoryBuilder();
323: CategoryTree categorytree = new CategoryTree(treebuilder);
324: CategoryTreeListener treelistener = new CategoryTreePath(
325: request, response,
326: CategoryTreePath.FORUMID_IN_LIST_CATEGORY_CASE, 0, null);
327: categorytree.addCategeoryTreeListener(treelistener);
328: request.setAttribute("tree", categorytree.build());
329:
330: CategoryBuilder builder = new DefaultCategoryBuilder();
331: CategoryTree tree = new CategoryTree(builder);
332: CategoryTreeListener listener = categoryService
333: .getManagementListAllForum(request, response);
334: tree.addCategeoryTreeListener(listener);
335: request.setAttribute("Result", tree.build());
336: }
337:
338: }
|