001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/categorytree/impl/ModcpImpl.java,v 1.14 2007/12/17 09:09:40 minhnn Exp $
003: * $Author: minhnn $
004: * $Revision: 1.14 $
005: * $Date: 2007/12/17 09:09:40 $
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.categorytree.impl;
042:
043: import java.io.IOException;
044: import java.util.*;
045:
046: import org.apache.commons.logging.Log;
047: import org.apache.commons.logging.LogFactory;
048:
049: import net.myvietnam.mvncore.exception.DatabaseException;
050: import net.myvietnam.mvncore.service.MvnCoreServiceFactory;
051: import net.myvietnam.mvncore.service.URLResolverService;
052: import net.myvietnam.mvncore.util.I18nUtil;
053: import net.myvietnam.mvncore.web.*;
054:
055: import com.mvnforum.MVNForumResourceBundle;
056: import com.mvnforum.MyUtil;
057: import com.mvnforum.auth.*;
058: import com.mvnforum.categorytree.CategoryTreeEvent;
059: import com.mvnforum.db.CategoryBean;
060: import com.mvnforum.db.ForumBean;
061:
062: import freemarker.cache.ClassTemplateLoader;
063: import freemarker.cache.TemplateLoader;
064: import freemarker.template.*;
065:
066: public class ModcpImpl extends FtlCategoryTreeListener {
067:
068: private static Log log = LogFactory.getLog(ModcpImpl.class);
069:
070: private GenericRequest request;
071: private GenericResponse response;
072:
073: private OnlineUser onlineUser;
074: private MVNForumPermission permission;
075: private static URLResolverService urlResolver = MvnCoreServiceFactory
076: .getMvnCoreService().getURLResolverService();
077:
078: private static Template template;
079: private CategoryBean categoryBean;
080:
081: private static int count = 0;
082:
083: private static int forumCountInCurrentCategory = 0;
084: private Locale locale;
085: static {
086: Configuration conf = new Configuration();
087: TemplateLoader loader = new ClassTemplateLoader(ModcpImpl.class);
088: conf.setTemplateLoader(loader);
089: try {
090: template = conf.getTemplate("modcp.ftl");
091: } catch (IOException e) {
092: log.error("Cannot load template for Moderation", e);
093: }
094: }
095:
096: public ModcpImpl(GenericRequest request, GenericResponse response)
097: throws AuthenticationException, DatabaseException {
098:
099: this .request = request;
100: this .response = response;
101: onlineUser = OnlineUserManager.getInstance().getOnlineUser(
102: request);
103: permission = onlineUser.getPermission();
104: locale = I18nUtil.getLocaleInRequest(request);
105:
106: super .init(template);
107: }
108:
109: public String drawHeader(CategoryTreeEvent event) {
110:
111: SimpleHash subRoot = new SimpleHash();
112: subRoot.put("name", "header");
113:
114: String forum_name_desc = MVNForumResourceBundle.getString(
115: locale,
116: "mvnforum.user.listforums.table.forum_name_desc");
117: subRoot.put("forum_name_desc", forum_name_desc);
118: String pending_threads = MVNForumResourceBundle.getString(
119: locale, "mvnforum.common.numberof.pending_threads");
120: subRoot.put("pending_threads", pending_threads);
121: String threads_with_pending_posts = MVNForumResourceBundle
122: .getString(locale,
123: "mvnforum.common.numberof.threads_with_pending_posts");
124: subRoot.put("threads_with_pending_posts",
125: threads_with_pending_posts);
126: String pending_posts = MVNForumResourceBundle.getString(locale,
127: "mvnforum.common.numberof.pending_posts");
128: subRoot.put("pending_posts", pending_posts);
129:
130: rows.add(subRoot);
131: return "";
132: }
133:
134: public String drawFooter(CategoryTreeEvent event) {
135:
136: SimpleHash subRoot = new SimpleHash();
137: subRoot.put("name", "footer");
138:
139: boolean checkNoCategory = (event.getDepth() == 0);
140: subRoot.put("checkNoCategory", checkNoCategory);
141:
142: if (checkNoCategory) {
143: String no_category = MVNForumResourceBundle.getString(
144: locale,
145: "mvnforum.user.listforums.table.no_category");
146: subRoot.put("no_category", no_category);
147: }
148:
149: rows.add(subRoot);
150:
151: return "";
152: }
153:
154: public String drawCategory(CategoryTreeEvent event) {
155:
156: SimpleHash subRoot = new SimpleHash();
157: forumCountInCurrentCategory = 0;
158:
159: boolean check_Count = (count != 0);
160: subRoot.put("check_Count", check_Count);
161:
162: count++;
163:
164: categoryBean = (CategoryBean) event.getSource();
165:
166: subRoot.put("categoryId", String.valueOf(categoryBean
167: .getCategoryID()));
168: subRoot.put("categoryName", categoryBean.getCategoryName());
169: subRoot.put("name", "category");
170:
171: if (MyUtil.canViewAnyForumInCategory(categoryBean
172: .getCategoryID(), permission) == false)
173: return "";
174:
175: subRoot.put("MyUtilFilter", MyUtil.filter(categoryBean
176: .getCategoryDesc(), false/*html*/, true/*emotion*/,
177: true/*mvnCode*/, true/*newLine*/, true/*URL*/));
178:
179: rows.add(subRoot);
180:
181: return "";
182: }
183:
184: public String drawForum(CategoryTreeEvent event) {
185:
186: SimpleHash subRoot = new SimpleHash();
187: ForumBean forum = (ForumBean) event.getSource();
188:
189: subRoot.put("name", "forum");
190:
191: subRoot.put("forumName", forum.getForumName());
192:
193: int forumID = forum.getForumID();
194: subRoot.put("forumID", String.valueOf(forum.getForumID()));
195: boolean checkForumToSee = ((forum.getCategoryID() == categoryBean
196: .getCategoryID())
197: && permission.canModerateThread(forumID) && (forum
198: .getForumStatus() != ForumBean.FORUM_STATUS_DISABLED));
199: subRoot.put("checkForumToSee", checkForumToSee);
200:
201: if (checkForumToSee) {
202:
203: subRoot.put("forumCountInCurrentCategory", new Integer(
204: forumCountInCurrentCategory));
205: forumCountInCurrentCategory++;
206:
207: subRoot.put("urlListThreads", urlResolver.encodeURL(
208: request, response, "listthreads?forum=" + forumID));
209: subRoot.put("filterForumDesc", MyUtil.filter(forum
210: .getForumDesc(), false/*html*/, true/*emotion*/,
211: true/*mvnCode*/, true/*newLine*/, true/*URL*/));
212:
213: String PendingThreadCountClass = forum
214: .getPendingThreadCount() > 0 ? "pendingyes"
215: : "pendingno";
216: subRoot.put("PendingThreadCountClass",
217: PendingThreadCountClass);
218:
219: subRoot.put("PendingThreadCount", String.valueOf(forum
220: .getPendingThreadCount()));
221:
222: boolean checkPendingThreadCount = (forum
223: .getPendingThreadCount() > 0);
224: subRoot.put("checkPendingThreadCount",
225: checkPendingThreadCount);
226:
227: subRoot.put("moderatependingthreads", urlResolver
228: .encodeURL(request, response,
229: "moderatependingthreads?forum=" + forumID));
230:
231: String ThreadsWithPendingPostsCountClass = forum
232: .getThreadsWithPendingPostsCount() > 0 ? "pendingyes"
233: : "pendingno";
234: subRoot.put("ThreadsWithPendingPostsCountClass",
235: ThreadsWithPendingPostsCountClass);
236:
237: subRoot.put("ThreadsWithPendingPostsCount", String
238: .valueOf(forum.getThreadsWithPendingPostsCount()));
239:
240: boolean checkThreadsWithPendingPostsCount = (forum
241: .getThreadsWithPendingPostsCount() > 0);
242: subRoot.put("checkThreadsWithPendingPostsCount",
243: checkThreadsWithPendingPostsCount);
244:
245: subRoot.put("listthreadswithpendingposts", urlResolver
246: .encodeURL(request, response,
247: "listthreadswithpendingposts?forum="
248: + forumID));
249:
250: String PendingPostCountClass = forum.getPendingPostCount() > 0 ? "pendingyes"
251: : "pendingno";
252: subRoot.put("PendingPostCountClass", PendingPostCountClass);
253:
254: subRoot.put("PendingPostCount", String.valueOf(forum
255: .getPendingPostCount()));
256:
257: subRoot.put("pending_threads", MVNForumResourceBundle
258: .getString(locale,
259: "mvnforum.user.modcp.pending_threads"));
260: subRoot
261: .put(
262: "threads_has_pending_posts",
263: MVNForumResourceBundle
264: .getString(locale,
265: "mvnforum.user.modcp.threads_has_pending_posts"));
266: }
267: rows.add(subRoot);
268: return "";
269: }
270:
271: public String drawSeparator(CategoryTreeEvent event) {
272:
273: SimpleHash subRoot = new SimpleHash();
274: subRoot.put("name", "separator");
275:
276: boolean checkNoForum = (forumCountInCurrentCategory == 0);
277: subRoot.put("checkNoForum", checkNoForum);
278: if (checkNoForum) {
279: String no_forum = MVNForumResourceBundle.getString(locale,
280: "mvnforum.user.listforums.table.no_forum");
281: subRoot.put("no_forum", no_forum);
282: }
283: rows.add(subRoot);
284:
285: return "";
286: }
287:
288: public void setDepthTree(int depth) {
289: //this.depth = depth;
290: }
291: }
|