forumcategoryproxy.java
来自「Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统,这是Jive论坛」· Java 代码 · 共 307 行
JAVA
307 行
/** * $RCSfile: ForumCategoryProxy.java,v $ * $Revision: 1.5 $ * $Date: 2002/04/02 21:16:56 $ * * Copyright (C) 1999-2002 CoolServlets, Inc. All rights reserved. * * This software is the proprietary information of CoolServlets, Inc. * Use is subject to license terms. */package com.jivesoftware.forum;import java.util.Date;import java.util.Iterator;/** * A protection proxy for ForumCategories. A proxy has a set of permissions that * are specified at creation time of the proxy. Subsequently, those permissions * are use to restrict access to protected methods. If a user does not have the * right to execute a particular method, an UnauthorizedException is thrown. * * @see ForumCategory * @see ForumPermissions * @see UnauthorizedException * @author Matt Tucker */public class ForumCategoryProxy implements ForumCategory { private ForumCategory category; private Authorization authorization; private ForumPermissions permissions; /** * Creates a new ForumCategoryProxy object. * * @param category the category to protect by proxy * @param authorization the user's authorization token * @param permissions the permissions to use with this proxy. */ public ForumCategoryProxy(ForumCategory category, Authorization authorization, ForumPermissions permissions) { this.category = category; this.authorization = authorization; this.permissions = permissions; } //FROM THE FORUMCATEGORY INTERFACE// public long getID() { return category.getID(); } public String getName() { return category.getName(); } public void setName(String name) throws UnauthorizedException { if (isAdmin()) { category.setName(name); } else { throw new UnauthorizedException(); } } public String getDescription() { return category.getDescription(); } public void setDescription(String description) throws UnauthorizedException { if (isAdmin()) { category.setDescription(description); } else { throw new UnauthorizedException(); } } public Date getCreationDate() { return category.getCreationDate(); } public void setCreationDate(Date creationDate) throws UnauthorizedException { if (isAdmin()) { category.setCreationDate(creationDate); } else { throw new UnauthorizedException(); } } public Date getModifiedDate() { return category.getModifiedDate(); } public void setModifiedDate(Date modifiedDate) throws UnauthorizedException { if (isAdmin()) { category.setModifiedDate(modifiedDate); } else { throw new UnauthorizedException(); } } public String getProperty(String name) { return category.getProperty(name); } public void setProperty(String name, String value) throws UnauthorizedException { if (isAdmin()) { category.setProperty(name, value); } else { throw new UnauthorizedException(); } } public void deleteProperty(String name) throws UnauthorizedException { if (isAdmin()) { category.deleteProperty(name); } else { throw new UnauthorizedException(); } } public Iterator propertyNames() { return category.propertyNames(); } public int getForumCount() { return category.getForumCount(); } public int getForumCount(ResultFilter resultFilter) { return category.getForumCount(resultFilter); } public int getRecursiveForumCount() { return category.getRecursiveForumCount(); } public int getRecursiveForumCount(ResultFilter resultFilter) { return category.getRecursiveForumCount(resultFilter); } public Iterator forums() { return new IteratorProxy(JiveGlobals.FORUM, category.forums(), authorization, permissions); } public Iterator forums(ResultFilter resultFilter) { return new IteratorProxy(JiveGlobals.FORUM, category.forums(resultFilter), authorization, permissions); } public Iterator recursiveForums() { return new IteratorProxy(JiveGlobals.FORUM, category.recursiveForums(), authorization, permissions); } public Iterator recursiveForums(ResultFilter resultFilter) { return new IteratorProxy(JiveGlobals.FORUM, category.recursiveForums( resultFilter), authorization, permissions); } public void setForumIndex(Forum forum, int newIndex) throws UnauthorizedException { if (isAdmin()) { category.setForumIndex(forum, newIndex); } else { throw new UnauthorizedException(); } } public void moveForum(Forum forum, ForumCategory destinationCategory) throws UnauthorizedException { // User must be an admin of this category and destination category. if (isAdmin() && (destinationCategory.hasPermission(ForumPermissions.SYSTEM_ADMIN) || destinationCategory.hasPermission(ForumPermissions.CATEGORY_ADMIN))) { category.moveForum(forum, destinationCategory); } else { throw new UnauthorizedException(); } } public ForumCategory getParentCategory() { return category.getParentCategory(); } public int getCategoryCount() { return category.getCategoryCount(); } public Iterator categories() { return new IteratorProxy(JiveGlobals.FORUM_CATEGORY, category.categories(), authorization, permissions); } public int getRecursiveCategoryCount() { return category.getRecursiveCategoryCount(); } public Iterator recursiveCategories() { return new IteratorProxy(JiveGlobals.FORUM_CATEGORY, category.recursiveCategories(), authorization, permissions); } public int getCategoryDepth() { return category.getCategoryDepth(); } public void setCategoryIndex(ForumCategory forumCategory, int newIndex) throws UnauthorizedException { if (isAdmin()) { category.setCategoryIndex(forumCategory, newIndex); } else { throw new UnauthorizedException(); } } public void moveCategory(ForumCategory forumCategory, ForumCategory destinationCategory) throws UnauthorizedException { if (isAdmin()&& (destinationCategory.hasPermission(ForumPermissions.SYSTEM_ADMIN) || destinationCategory.hasPermission(ForumPermissions.CATEGORY_ADMIN))) { category.moveCategory(forumCategory, destinationCategory); } else { throw new UnauthorizedException(); } } public ForumCategory createCategory(String name, String description) throws UnauthorizedException { if (isAdmin()) { ForumCategory newCat = category.createCategory(name, description); ForumPermissions catPerms = newCat.getPermissions(authorization); catPerms = new ForumPermissions(permissions, catPerms); return new ForumCategoryProxy(newCat, authorization, catPerms); } else { throw new UnauthorizedException(); } } public void deleteCategory(ForumCategory forumCategory) throws UnauthorizedException { if (isAdmin()) { category.deleteCategory(forumCategory); } else { throw new UnauthorizedException(); } } public PermissionsManager getPermissionsManager() throws UnauthorizedException { if (isAdmin()) { return category.getPermissionsManager(); } else { throw new UnauthorizedException(); } } public ForumPermissions getPermissions(Authorization authorization) { return category.getPermissions(authorization); } public boolean hasPermission(int type) { return permissions.get(type); } public String toString() { return category.toString(); } private boolean isAdmin() { return permissions.get(ForumPermissions.CATEGORY_ADMIN) || permissions.get(ForumPermissions.SYSTEM_ADMIN); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?