001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/categorytree/impl/ListAllForumImpl.java,v 1.11 2007/12/17 09:09:40 minhnn Exp $
003: * $Author: minhnn $
004: * $Revision: 1.11 $
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: Phuong Pham Dinh Duy
039: */
040: package com.mvnforum.categorytree.impl;
041:
042: import java.io.IOException;
043: import java.util.Locale;
044:
045: import com.mvnforum.MVNForumResourceBundle;
046: import com.mvnforum.MyUtil;
047: import com.mvnforum.auth.*;
048: import com.mvnforum.categorytree.CategoryTreeEvent;
049: import com.mvnforum.db.CategoryBean;
050: import com.mvnforum.db.ForumBean;
051:
052: import net.myvietnam.mvncore.exception.DatabaseException;
053: import net.myvietnam.mvncore.service.MvnCoreServiceFactory;
054: import net.myvietnam.mvncore.service.URLResolverService;
055: import net.myvietnam.mvncore.util.I18nUtil;
056: import net.myvietnam.mvncore.web.*;
057:
058: import org.apache.commons.logging.Log;
059: import org.apache.commons.logging.LogFactory;
060:
061: import freemarker.cache.ClassTemplateLoader;
062: import freemarker.cache.TemplateLoader;
063: import freemarker.template.*;
064:
065: public class ListAllForumImpl extends FtlCategoryTreeListener {
066:
067: private static Log log = LogFactory.getLog(ListAllForumImpl.class);
068:
069: private GenericRequest request;
070: private GenericResponse response;
071:
072: private OnlineUser onlineUser;
073: private MVNForumPermission permission;
074: private URLResolverService urlResolver = MvnCoreServiceFactory
075: .getMvnCoreService().getURLResolverService();
076:
077: private static Template template;
078:
079: private int count = 0;
080: private boolean flag = false;
081: private Locale locale;
082:
083: static {
084: Configuration conf = new Configuration();
085: TemplateLoader loader = new ClassTemplateLoader(
086: ListAllForumImpl.class);
087: conf.setTemplateLoader(loader);
088: try {
089: template = conf.getTemplate("listforums_index.ftl");
090: } catch (IOException e) {
091: log.error("Cannot load template for List All Forums", e);
092: }
093: }
094:
095: public ListAllForumImpl(GenericRequest request)
096: throws AuthenticationException, DatabaseException {
097:
098: this .request = request;
099: onlineUser = OnlineUserManager.getInstance().getOnlineUser(
100: request);
101: permission = onlineUser.getPermission();
102: locale = I18nUtil.getLocaleInRequest(request);
103: super .init(template);
104: }
105:
106: public ListAllForumImpl(GenericRequest request,
107: GenericResponse response) throws AuthenticationException,
108: DatabaseException {
109:
110: this .request = request;
111: this .response = response;
112: onlineUser = OnlineUserManager.getInstance().getOnlineUser(
113: request);
114: permission = onlineUser.getPermission();
115: locale = I18nUtil.getLocaleInRequest(request);
116: super .init(template);
117: }
118:
119: public String drawHeader(CategoryTreeEvent event) {
120:
121: SimpleHash row = new SimpleHash();
122: row.put("RowType", "header");
123: row.put("urlOfListforums", urlResolver.encodeURL(request,
124: response, "listforums"));
125:
126: String title = MVNForumResourceBundle.getString(locale,
127: "mvnforum.user.listforums.title");
128: row.put("title", title);
129: rows.add(row);
130:
131: return "";
132: }
133:
134: public String drawFooter(CategoryTreeEvent event) {
135:
136: SimpleHash row = new SimpleHash();
137: row.put("RowType", "footer");
138:
139: boolean checkNoCategory = (event.getDepth() == 0);
140: row.put("checkNoCategory", checkNoCategory);
141:
142: if (checkNoCategory) {
143: String no_category = MVNForumResourceBundle.getString(
144: locale,
145: "mvnforum.user.listforums.table.no_category");
146: row.put("no_category", no_category);
147: }
148: rows.add(row);
149:
150: return "";
151: }
152:
153: public String drawForum(CategoryTreeEvent event) {
154:
155: SimpleHash row = new SimpleHash();
156: ForumBean forum = (ForumBean) event.getSource();
157: String listThreadsLink = urlResolver.encodeURL(request,
158: response, "listthreads?forum=" + forum.getForumID());
159:
160: row.put("ForumName", forum.getForumName());
161: row.put("ListThreadsLink", listThreadsLink);
162: row.put("CanReadPost", permission.canReadPost(forum
163: .getForumID()));
164: row
165: .put(
166: "NotDisabled",
167: forum.getForumStatus() != ForumBean.FORUM_STATUS_DISABLED);
168: row.put("RowType", "Forum");
169:
170: rows.add(row);
171:
172: return "";
173: }
174:
175: public String drawSeparator(CategoryTreeEvent event) {
176:
177: SimpleHash row = new SimpleHash();
178: CategoryBean category = (CategoryBean) event.getSource();
179:
180: row.put("RowType", "Separator");
181: row.put("CategoryId", String.valueOf(category.getCategoryID()));
182:
183: rows.add(row);
184:
185: return "";
186: }
187:
188: public void setDepthTree(int depth) {
189: // default
190: }
191:
192: public String drawCategory(CategoryTreeEvent event) {
193:
194: SimpleHash row = new SimpleHash();
195: boolean check_count = (count != 0);
196:
197: row.put("check_count", check_count);
198:
199: if (count != 0) {
200: flag = true;
201: }
202: count++;
203:
204: row.put("flag", flag);
205:
206: CategoryBean category = (CategoryBean) event.getSource();
207: row.put("RowType", "Category");
208: row.put("CanViewForums", MyUtil.canViewAnyForumInCategory(
209: category.getCategoryID(), permission));
210:
211: StringBuffer id1_buffer = new StringBuffer();
212: id1_buffer.append("category_").append(category.getCategoryID());
213: row.put("id1", id1_buffer.toString());
214:
215: row.put("ListForumsLink", urlResolver.encodeURL(request,
216: response, "listforums?category="
217: + category.getCategoryID()));
218: row.put("CategoryName", category.getCategoryName());
219: row.put("CategoryId", String.valueOf(category.getCategoryID()));
220: row.put("ContextPath", request.getContextPath());
221:
222: rows.add(row);
223:
224: return "";//default
225: }
226:
227: }
|