001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/categorytree/impl/ViewMemberPermissionsImpl.java,v 1.12 2007/12/17 09:09:39 minhnn Exp $
003: * $Author: minhnn $
004: * $Revision: 1.12 $
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: 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.auth.*;
047: import com.mvnforum.categorytree.CategoryTreeEvent;
048: import com.mvnforum.db.CategoryBean;
049: import com.mvnforum.db.ForumBean;
050:
051: import net.myvietnam.mvncore.exception.DatabaseException;
052: import net.myvietnam.mvncore.util.I18nUtil;
053: import net.myvietnam.mvncore.web.GenericRequest;
054:
055: import org.apache.commons.logging.Log;
056: import org.apache.commons.logging.LogFactory;
057:
058: import freemarker.cache.ClassTemplateLoader;
059: import freemarker.cache.TemplateLoader;
060: import freemarker.template.*;
061:
062: public class ViewMemberPermissionsImpl extends FtlCategoryTreeListener {
063:
064: private static Log log = LogFactory
065: .getLog(ViewMemberPermissionsImpl.class);
066:
067: // template can be shared between users after loaded
068: private static Template template;
069:
070: private MVNForumPermission permission;
071: private Locale locale;
072:
073: static {
074: Configuration conf = new Configuration();
075: TemplateLoader loader = new ClassTemplateLoader(
076: ViewMemberPermissionsImpl.class);
077: conf.setTemplateLoader(loader);
078: try {
079: template = conf.getTemplate("viewmemberpermissions.ftl");
080: } catch (IOException e) {
081: log.error(
082: "Cannot load template for View Member Permission",
083: e);
084: }
085: }
086:
087: public ViewMemberPermissionsImpl(GenericRequest request)
088: throws AuthenticationException, DatabaseException {
089:
090: permission = (MVNForumPermission) request
091: .getAttribute("Permissions");
092: locale = I18nUtil.getLocaleInRequest(request);
093: init(template);
094: }
095:
096: public String drawHeader(CategoryTreeEvent event) {
097: SimpleHash row = new SimpleHash();
098:
099: row.put("RowType", "Header");
100: rows.add(row);
101:
102: return "";
103: }
104:
105: public String drawFooter(CategoryTreeEvent event) {
106: SimpleHash row = new SimpleHash();
107:
108: row.put("RowType", "Footer");
109: boolean checkNoCategory = (event.getDepth() == 0);
110: row.put("checkNoCategory", checkNoCategory);
111: if (checkNoCategory) {
112: String no_category = MVNForumResourceBundle.getString(
113: locale,
114: "mvnforum.user.listforums.table.no_category");
115: row.put("no_category", no_category);
116: }
117:
118: rows.add(row);
119:
120: return "";
121: }
122:
123: public String drawCategory(CategoryTreeEvent event) {
124: SimpleHash row = new SimpleHash();
125: CategoryBean category = (CategoryBean) event.getSource();
126:
127: row.put("CategoryName", category.getCategoryName());
128: row.put("Empty", (event.hasForum() == false));
129: String no_forum = MVNForumResourceBundle.getString(locale,
130: "mvnforum.user.listforums.table.no_forum");
131: row.put("no_forum", no_forum);
132: row.put("RowType", "Category");
133:
134: rows.add(row);
135:
136: return "";
137: }
138:
139: public String drawForum(CategoryTreeEvent event) {
140: SimpleHash row = new SimpleHash();
141: ForumBean forum = (ForumBean) event.getSource();
142: int forumID = forum.getForumID();
143:
144: row.put("RowType", "Forum");
145: row.put("ForumID", String.valueOf(forumID));
146: row.put("ForumName", forum.getForumName());
147:
148: row.put("EditForum", permission.canEditForum(forumID));
149: row.put("DeleteForum", permission.canDeleteForum(forumID));
150: row.put("AssignForum", permission.canAssignToForum(forumID));
151:
152: row.put("AddThread", permission.canAddThread(forumID));
153: row
154: .put("ModerateThread", permission
155: .canModerateThread(forumID));
156:
157: row.put("ReadPost", permission.canReadPost(forumID));
158: row.put("AddPost", permission.canAddPost(forumID));
159: row.put("EditOwnPost", permission.canEditOwnPost(forumID));
160: row.put("EditAnyPost", permission.canEditPost(forumID));
161: row.put("DeletePost", permission.canDeletePost(forumID));
162:
163: row.put("AddAttachment", permission.canAddAttachment(forumID));
164: row.put("GetAttachment", permission.canGetAttachment(forumID));
165:
166: row.put("AddPoll", permission.canAddPoll(forumID));
167: row.put("EditOwnPoll", permission.canEditOwnPoll(forumID));
168: row.put("EditAnyPoll", permission.canEditPoll(forumID));
169: row.put("DeletePoll", permission.canDeletePoll(forumID));
170:
171: rows.add(row);
172:
173: return "";
174: }
175:
176: public String drawSeparator(CategoryTreeEvent event) {
177: return "";
178: }
179:
180: public void setDepthTree(int depth) {
181: // this.depth = depth;
182: }
183: }
|