001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/categorytree/impl/ListForums.java,v 1.30 2007/12/17 09:09:39 minhnn Exp $
003: * $Author: minhnn $
004: * $Revision: 1.30 $
005: * $Date: 2007/12/17 09:09:39 $
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: Phuong Pham Dinh Duy
039: */
040:
041: package com.mvnforum.categorytree.impl;
042:
043: import java.io.IOException;
044: import java.util.Locale;
045:
046: import net.myvietnam.mvncore.exception.DatabaseException;
047: import net.myvietnam.mvncore.security.Encoder;
048: import net.myvietnam.mvncore.service.MvnCoreServiceFactory;
049: import net.myvietnam.mvncore.service.URLResolverService;
050: import net.myvietnam.mvncore.util.I18nUtil;
051: import net.myvietnam.mvncore.web.*;
052:
053: import org.apache.commons.logging.Log;
054: import org.apache.commons.logging.LogFactory;
055:
056: import com.mvnforum.*;
057: import com.mvnforum.auth.*;
058: import com.mvnforum.categorytree.CategoryTreeEvent;
059: import com.mvnforum.db.*;
060: import com.mvnforum.user.WatchUtil;
061:
062: import freemarker.cache.ClassTemplateLoader;
063: import freemarker.cache.TemplateLoader;
064: import freemarker.template.*;
065:
066: public class ListForums extends FtlCategoryTreeListener {
067:
068: private static Log log = LogFactory.getLog(ListForums.class);
069:
070: private GenericRequest request;
071: private GenericResponse response;
072:
073: private OnlineUser onlineUser;
074: private MVNForumPermission permission;
075: private URLResolverService urlResolver = MvnCoreServiceFactory
076: .getMvnCoreService().getURLResolverService();
077:
078: private static Template template;
079:
080: private int count = 0;
081: private boolean flag = false;
082: private boolean hasReadActiveCurrentForum = false;
083: private boolean hasUnreadActiveCurrentForum = false;
084: private boolean hasReadClosedCurrentForum = false;
085: private boolean hasUnreadClosedCurrentForum = false;
086: private boolean hasReadLockedCurrentForum = false;
087: private boolean hasUnreadLockedCurrentForum = false;
088: private boolean hasReadDisabledCurrentForum = false;
089: private boolean hasUnreadDisabledCurrentForum = false;
090: private int forumCountInCurrentCategory = 0;
091: private Locale locale;
092: private CategoryBean category;
093:
094: static {
095: Configuration conf = new Configuration();
096: TemplateLoader loader = new ClassTemplateLoader(
097: ListForums.class);
098: conf.setTemplateLoader(loader);
099: try {
100: template = conf.getTemplate("listforums.ftl");
101: } catch (IOException e) {
102: log.error("Cannot load template for List Forums", e);
103: }
104: }
105:
106: public ListForums(GenericRequest request)
107: throws AuthenticationException, DatabaseException {
108:
109: this .request = request;
110: onlineUser = OnlineUserManager.getInstance().getOnlineUser(
111: request);
112: permission = onlineUser.getPermission();
113: locale = I18nUtil.getLocaleInRequest(request);
114: super .init(template);
115: }
116:
117: public ListForums(GenericRequest request, GenericResponse response)
118: throws AuthenticationException, DatabaseException {
119:
120: this .request = request;
121: this .response = response;
122: onlineUser = OnlineUserManager.getInstance().getOnlineUser(
123: request);
124: permission = onlineUser.getPermission();
125: locale = I18nUtil.getLocaleInRequest(request);
126: super .init(template);
127: }
128:
129: public String drawHeader(CategoryTreeEvent event) {
130:
131: SimpleHash row = new SimpleHash();
132:
133: row.put("name", "header");
134:
135: String forum_name_desc = MVNForumResourceBundle.getString(
136: locale,
137: "mvnforum.user.listforums.table.forum_name_desc");
138: row.put("forum_name_desc", forum_name_desc);
139: String thread_count = MVNForumResourceBundle.getString(locale,
140: "mvnforum.common.thread_count");
141: row.put("thread_count", thread_count);
142: String post_count = MVNForumResourceBundle.getString(locale,
143: "mvnforum.common.post_count");
144: row.put("post_count", post_count);
145: String last_post = MVNForumResourceBundle.getString(locale,
146: "mvnforum.common.last_post");
147: row.put("last_post", last_post);
148:
149: rows.add(row);
150:
151: return "";
152: }
153:
154: public String drawFooter(CategoryTreeEvent event) {
155:
156: SimpleHash row = new SimpleHash();
157: row.put("name", "footer");
158: boolean checkNoCategory = (count == 0);
159: row.put("checkNoCategory", checkNoCategory);
160: if (checkNoCategory) {
161: //there is no any category
162: String no_category = MVNForumResourceBundle.getString(
163: locale,
164: "mvnforum.user.listforums.table.no_category");
165: row.put("no_category", no_category);
166: }
167: //for last category
168: row.put("hasReadActiveCurrentForum", hasReadActiveCurrentForum);
169: row.put("hasUnreadActiveCurrentForum",
170: hasUnreadActiveCurrentForum);
171: row.put("hasReadClosedCurrentForum", hasReadClosedCurrentForum);
172: row.put("hasUnreadClosedCurrentForum",
173: hasUnreadClosedCurrentForum);
174: row.put("hasReadLockedCurrentForum", hasReadLockedCurrentForum);
175: row.put("hasUnreadLockedCurrentForum",
176: hasUnreadLockedCurrentForum);
177: row.put("hasReadDisabledCurrentForum",
178: hasReadDisabledCurrentForum);
179: row.put("hasUnreadDisabledCurrentForum",
180: hasUnreadDisabledCurrentForum);
181: row.put("ContextPath", request.getContextPath());
182:
183: if (hasReadActiveCurrentForum) {
184: String no_new = MVNForumResourceBundle.getString(locale,
185: "mvnforum.common.legend.forum.read_active");
186: row.put("no_new", no_new);
187: }
188: if (hasUnreadActiveCurrentForum) {
189: String has_new = MVNForumResourceBundle.getString(locale,
190: "mvnforum.common.legend.forum.unread_active");
191: row.put("has_new", has_new);
192: }
193: if (hasReadClosedCurrentForum) {
194: String no_new = MVNForumResourceBundle.getString(locale,
195: "mvnforum.common.legend.forum.read_closed");
196: row.put("closed_no_new", no_new);
197: }
198: if (hasUnreadClosedCurrentForum) {
199: String has_new = MVNForumResourceBundle.getString(locale,
200: "mvnforum.common.legend.forum.unread_closed");
201: row.put("closed_has_new", has_new);
202: }
203: if (hasReadLockedCurrentForum) {
204: String no_new = MVNForumResourceBundle.getString(locale,
205: "mvnforum.common.legend.forum.read_locked");
206: row.put("locked_no_new", no_new);
207: }
208: if (hasUnreadLockedCurrentForum) {
209: String has_new = MVNForumResourceBundle.getString(locale,
210: "mvnforum.common.legend.forum.unread_locked");
211: row.put("locked_has_new", has_new);
212: }
213: if (hasReadDisabledCurrentForum) {
214: String no_new = MVNForumResourceBundle.getString(locale,
215: "mvnforum.common.legend.forum.read_disabled");
216: row.put("disabled_no_new", no_new);
217: }
218: if (hasUnreadDisabledCurrentForum) {
219: String has_new = MVNForumResourceBundle.getString(locale,
220: "mvnforum.common.legend.forum.unread_disabled");
221: row.put("disabled_has_new", has_new);
222: }
223:
224: rows.add(row);
225:
226: return "";
227: }
228:
229: public String drawForum(CategoryTreeEvent event) {
230:
231: ForumBean forum = (ForumBean) event.getSource();
232: SimpleHash row = new SimpleHash();
233:
234: boolean checkForumToSee = ((forum.getCategoryID() == category
235: .getCategoryID())
236: && permission.canReadPost(forum.getForumID()) && (forum
237: .getForumStatus() != ForumBean.FORUM_STATUS_DISABLED));
238: row.put("checkForumToSee", checkForumToSee);
239: row.put("name", "forum");
240:
241: if (checkForumToSee) {
242: //this is not a disable forum
243: String forumIcon = MyUtil.getForumIconName(onlineUser
244: .getLastLogonTimestamp().getTime(), forum
245: .getForumLastPostDate().getTime(), forum
246: .getForumStatus(), forum.getForumThreadCount());
247: row.put("forumIcon", forumIcon);
248:
249: if (forumIcon.equals(MyUtil.FORUM_ICON_READ_ACTIVE)) {
250: hasReadActiveCurrentForum = true;
251: } else if (forumIcon
252: .equals(MyUtil.FORUM_ICON_UNREAD_ACTIVE)) {
253: hasUnreadActiveCurrentForum = true;
254: } else if (forumIcon.equals(MyUtil.FORUM_ICON_READ_CLOSED)) {
255: hasReadClosedCurrentForum = true;
256: } else if (forumIcon
257: .equals(MyUtil.FORUM_ICON_UNREAD_CLOSED)) {
258: hasUnreadClosedCurrentForum = true;
259: } else if (forumIcon.equals(MyUtil.FORUM_ICON_READ_LOCKED)) {
260: hasReadLockedCurrentForum = true;
261: } else if (forumIcon
262: .equals(MyUtil.FORUM_ICON_UNREAD_LOCKED)) {
263: hasUnreadLockedCurrentForum = true;
264: } else if (forumIcon
265: .equals(MyUtil.FORUM_ICON_READ_DISABLED)) {
266: hasReadDisabledCurrentForum = true;
267: } else if (forumIcon
268: .equals(MyUtil.FORUM_ICON_UNREAD_DISABLED)) {
269: hasUnreadDisabledCurrentForum = true;
270: }
271: row.put("forumCountInCurrentCategory", new Integer(
272: forumCountInCurrentCategory));
273: forumCountInCurrentCategory++;
274:
275: row.put("ContextPath", request.getContextPath());
276:
277: StringBuffer filter = new StringBuffer();
278: filter.append(MyUtil.filter(forum.getForumDesc(),
279: false/*html*/, true/*emotion*/, true/*mvnCode*/,
280: true/*newLine*/, true/*URL*/));
281: row.put("filter", filter.toString());
282:
283: row.put("ForumThreadCount", String.valueOf(forum
284: .getForumThreadCount()));
285: row.put("ForumPostCount", String.valueOf(forum
286: .getForumPostCount()));
287:
288: String listThreadsLink = urlResolver
289: .encodeURL(request, response, "listthreads?forum="
290: + forum.getForumID());
291: row.put("ForumName", forum.getForumName());
292: row.put("ListThreadsLink", listThreadsLink);
293:
294: row.put("no_post", MVNForumResourceBundle.getString(locale,
295: "mvnforum.user.listforums.table.no_post"));
296: row.put("by", MVNForumResourceBundle.getString(locale,
297: "mvnforum.common.by"));
298:
299: boolean checkCondition = (forum.getLastPostMemberName()
300: .length() == 0)
301: || (forum.getForumThreadCount() == 0);
302: row.put("checkCondition", checkCondition);
303:
304: row.put("GMTTimestampFormat",
305: onlineUser.getGMTTimestampFormat(forum
306: .getForumLastPostDate()));
307:
308: String viewmemberLink = urlResolver.encodeURL(request,
309: response, "viewmember?member="
310: + Encoder.encodeURL(forum
311: .getLastPostMemberName()));
312: row.put("viewmemberLink", viewmemberLink);
313:
314: row
315: .put("LastPostMemberName", forum
316: .getLastPostMemberName());
317: }
318:
319: rows.add(row);
320:
321: return "";
322: }
323:
324: public String drawSeparator(CategoryTreeEvent event) {
325:
326: SimpleHash row = new SimpleHash();
327: CategoryBean category = (CategoryBean) event.getSource();
328:
329: row.put("name", "Separator");
330: row.put("CategoryId", String.valueOf(category.getCategoryID()));
331:
332: rows.add(row);
333:
334: return "";
335: }
336:
337: public void setDepthTree(int depth) {
338: // default
339: }
340:
341: public String drawCategory(CategoryTreeEvent event) {
342:
343: SimpleHash row = new SimpleHash();
344: forumCountInCurrentCategory = 0;
345: if (count != 0) {
346: flag = true;
347: }
348: count++;
349:
350: row.put("flag", flag);
351:
352: category = (CategoryBean) event.getSource();
353: row.put("name", "category");
354:
355: row.put("CanViewForums", MyUtil.canViewAnyForumInCategory(
356: category.getCategoryID(), permission));
357: row.put("CategoryName", category.getCategoryName());
358: row.put("CategoryId", String.valueOf(category.getCategoryID()));
359: row.put("ContextPath", request.getContextPath());
360:
361: row.put("enableEasyWatching", new Boolean(MVNForumConfig
362: .getEnableEasyWatching()));
363: if (MVNForumConfig.getEnableEasyWatching()) {
364: // check whether this forum is being watched
365: Boolean isWatched = Boolean.FALSE;
366: if (onlineUser.isMember()) {
367: try {
368: isWatched = new Boolean(WatchUtil
369: .isCategoryWatched(
370: onlineUser.getMemberID(), category));
371: } catch (Exception ex) {
372: //do nothing
373: }
374: }
375: row.put("isWatched", isWatched);
376: if (isWatched.booleanValue() == false) {
377: String addWatchCategoryLink = urlResolver.encodeURL(
378: request, response, "addwatchprocess?WatchType="
379: + WatchBean.WATCH_TYPE_DEFAULT
380: + "&WatchSelector="
381: + WatchBean.SELECT_CATEGORY_WATCH
382: + "&category="
383: + category.getCategoryID());
384: row.put("addWatchCategoryLink", addWatchCategoryLink);
385:
386: String watchThisCategory = MVNForumResourceBundle
387: .getString(locale,
388: "mvnforum.user.listforums.table.watch_this_category");
389: row.put("WatchThisCategory", watchThisCategory);
390: } else {
391: String watchingThisCategory = MVNForumResourceBundle
392: .getString(locale,
393: "mvnforum.user.listforums.table.you_are_watching_this_category");
394: row.put("WatchingThisCategory", watchingThisCategory);
395: }
396:
397: }
398:
399: StringBuffer filter = new StringBuffer();
400: filter.append(MyUtil.filter(category.getCategoryDesc(),
401: false/*html*/, true/*emotion*/, true/*mvnCode*/,
402: true/*newLine*/, true/*URL*/));
403: row.put("filter", filter.toString());
404:
405: rows.add(row);
406:
407: return "";//default
408: }
409:
410: }
|