forumthreadproxy.java
来自「Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统,这是Jive论坛」· Java 代码 · 共 255 行
JAVA
255 行
/** * $RCSfile: ForumThreadProxy.java,v $ * $Revision: 1.2 $ * $Date: 2002/03/28 04:21:23 $ * * Copyright (C) 1999-2001 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;/** * Protection proxy for ForumThread objects. It restricts access to protected * methods by throwing UnauthorizedExceptions if the user does not have * permission to access the class. */public class ForumThreadProxy implements ForumThread { private ForumThread thread; private Authorization authorization; protected ForumPermissions permissions; /** * Creates a new proxy. */ public ForumThreadProxy(ForumThread thread, Authorization authorization, ForumPermissions permissions) { this.thread = thread; this.authorization = authorization; this.permissions = permissions; } public long getID() { return thread.getID(); } public String getName() { return thread.getName(); } public Date getCreationDate() { return thread.getCreationDate(); } public void setCreationDate(Date creationDate) throws UnauthorizedException { if (isAdmin()) { thread.setCreationDate(creationDate); } else throw new UnauthorizedException(); } public Date getModifiedDate() { return thread.getModifiedDate(); } public void setModifiedDate(Date modifiedDate) throws UnauthorizedException { if (isAdmin()) { thread.setModifiedDate(modifiedDate); } else throw new UnauthorizedException(); } public int getModerationValue() { return thread.getModerationValue(); } public void setModerationValue(int value, Authorization auth) throws UnauthorizedException { if (isAdmin() || permissions.get(ForumPermissions.MODERATE_THREADS)) { thread.setModerationValue(value, auth); } else { throw new UnauthorizedException(); } } public String getProperty(String name) { return thread.getProperty(name); } public void setProperty(String name, String value) throws UnauthorizedException { if (isAllowedToEdit()) { thread.setProperty(name, value); } else { throw new UnauthorizedException(); } } public void deleteProperty(String name) throws UnauthorizedException { if (isAllowedToEdit()) { thread.deleteProperty(name); } else { throw new UnauthorizedException(); } } public Iterator propertyNames() { return thread.propertyNames(); } public Forum getForum() { Forum forum = thread.getForum(); if (forum == null) { return null; } else { return new ForumProxy(forum, authorization, permissions); } } public int getMessageCount() { return thread.getMessageCount(); } public int getMessageCount(ResultFilter resultFilter) { return thread.getMessageCount(resultFilter); } public ForumMessage getRootMessage() { ForumMessage message = thread.getRootMessage(); return new ForumMessageProxy(message, authorization, permissions); } public void addMessage(ForumMessage parentMessage, ForumMessage newMessage) throws UnauthorizedException { if (isAdmin() || permissions.get(ForumPermissions.CREATE_MESSAGE)) { thread.addMessage(parentMessage, newMessage); // Set permissions on the message proxy object to include forum // permissions. ForumPermissions msgPerms = ((ForumMessageProxy)newMessage).permissions; msgPerms = new ForumPermissions(msgPerms, permissions); ((ForumMessageProxy)newMessage).permissions = msgPerms; } else { throw new UnauthorizedException(); } } public void deleteMessage(ForumMessage message) throws UnauthorizedException { if (isAdmin() || permissions.get(ForumPermissions.MODERATE_THREADS) || permissions.get(ForumPermissions.MODERATE_MESSAGES)) { thread.deleteMessage(message); } else { throw new UnauthorizedException(); } } public ForumMessage getMessage(long messageID) throws ForumMessageNotFoundException { ForumMessage message = thread.getMessage(messageID); // Apply the protection proxy and return message. return new ForumMessageProxy(message, authorization, permissions); } public TreeWalker treeWalker() { return new TreeWalkerProxy(thread.treeWalker(), authorization, permissions); } public Iterator messages() { Iterator iterator = thread.messages(); return new IteratorProxy(JiveGlobals.MESSAGE, iterator, authorization, permissions); } public Iterator messages(ResultFilter resultFilter) { Iterator iterator = thread.messages(resultFilter); return new IteratorProxy(JiveGlobals.MESSAGE, iterator, authorization, permissions); } public boolean hasPermission(int type) { return permissions.get(type); } public String toString() { return thread.toString(); } /** * Allow access to the underlying thread object under two conditions: system * or forum admin, or the thread hasn't been added to a forum yet. */ public ForumThread getProxiedForumThread() throws UnauthorizedException { if (isAdmin() || getForum() == null) { return thread; } else { throw new UnauthorizedException(); } } /** * Returns true if editing of this thread is allowed under the current * permissions. See the ForumThread class for details about thread editing * policies. */ private boolean isAllowedToEdit() { // Admins or moderators can always edit threads. if (isAdmin() || permissions.get(ForumPermissions.MODERATE_THREADS)) { return true; } // If the thread has not yet been added to a forum, it can always // be edited. if (getForum() == null) { return true; } ForumMessage rootMessage = getRootMessage(); // Authors of the thread can always edit. if (!rootMessage.isAnonymous() && rootMessage.getUser().getID() == authorization.getUserID()) { return true; } // If all previous checks, not allowed to edit. return false; } /** * Returns true if user should be conisered an administrator. * * @return true if the user is an administrator. */ private boolean isAdmin() { return permissions.get(ForumPermissions.SYSTEM_ADMIN) || permissions.get(ForumPermissions.CATEGORY_ADMIN) || permissions.get(ForumPermissions.FORUM_ADMIN); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?