forummessageproxy.java
来自「Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统,这是Jive论坛」· Java 代码 · 共 273 行
JAVA
273 行
/** * $RCSfile: ForumMessageProxy.java,v $ * $Revision: 1.2 $ * $Date: 2002/03/28 04:21:23 $ * * 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.*;import java.io.InputStream;/** * A protection proxy for ForumMessage objects. * * @author Matt Tucker */public class ForumMessageProxy implements ForumMessage { private ForumMessage message; private Authorization authorization; protected ForumPermissions permissions; /** * Creates a new ForumMessageProxy to protect the supplied message with * the specified permissions */ public ForumMessageProxy(ForumMessage message, Authorization authorization, ForumPermissions permissions) { this.message = message; this.authorization = authorization; this.permissions = permissions; } //FROM THE FORUMMESSAGE INTERFACE// public long getID() { return message.getID(); } public Date getCreationDate() { return message.getCreationDate(); } public void setCreationDate(Date creationDate) throws UnauthorizedException { if (isAdmin()) { message.setCreationDate(creationDate); } else { throw new UnauthorizedException(); } } public Date getModifiedDate() { return message.getModifiedDate(); } public void setModifiedDate(Date modifiedDate) throws UnauthorizedException { if (isAdmin()) { message.setModifiedDate(modifiedDate); } else { throw new UnauthorizedException(); } } public String getSubject() { return message.getSubject(); } public String getUnfilteredSubject() { return message.getUnfilteredSubject(); } public void setSubject(String subject) throws UnauthorizedException { if (isAllowedToEdit()) { message.setSubject(subject); } else { throw new UnauthorizedException(); } } public String getBody() { return message.getBody(); } public String getUnfilteredBody() { return message.getUnfilteredBody(); } public void setBody(String body) throws UnauthorizedException { if (isAllowedToEdit()) { message.setBody(body); } else { throw new UnauthorizedException(); } } public User getUser() { User user = message.getUser(); if (user == null) { return null; } ForumPermissions userPermissions = user.getPermissions(authorization); ForumPermissions newPermissions = new ForumPermissions(permissions, userPermissions); return new UserProxy(user, authorization, newPermissions); } public Attachment createAttachment(String name, String contentType, InputStream data) throws IllegalStateException, AttachmentException, UnauthorizedException { if (isAdmin() || permissions.get(ForumPermissions.CREATE_ATTACHMENT)) { return message.createAttachment(name, contentType, data); } else { throw new UnauthorizedException(); } } public int getAttachmentCount() { return message.getAttachmentCount(); } public void deleteAttachment(Attachment attachment) throws AttachmentException, UnauthorizedException { if (isAllowedToEdit()) { message.deleteAttachment(attachment); } else { throw new UnauthorizedException(); } } public Iterator attachments() { return message.attachments(); } public int getModerationValue() { return message.getModerationValue(); } public void setModerationValue(int value, Authorization auth) throws UnauthorizedException { if (isAdmin() || permissions.get(ForumPermissions.MODERATE_MESSAGES)) { message.setModerationValue(value, auth); } else { throw new UnauthorizedException(); } } public String getProperty(String name) { return message.getProperty(name); } public String getUnfilteredProperty(String name) { return message.getUnfilteredProperty(name); } public void setProperty(String name, String value) throws UnauthorizedException { if (isAllowedToEdit()) { message.setProperty(name, value); } else { throw new UnauthorizedException(); } } public void deleteProperty(String name) throws UnauthorizedException { if (isAllowedToEdit()) { message.deleteProperty(name); } else { throw new UnauthorizedException(); } } public Iterator propertyNames() { return message.propertyNames(); } public boolean isAnonymous() { return message.isAnonymous(); } public ForumThread getForumThread() { return message.getForumThread(); } public boolean hasPermission(int type) { return permissions.get(type); } //OTHER METHODS// /** * Converts the object to a String by returning the subject of the message. * This functionality is primarily for Java applications that might be * accessing CoolForum objects through a GUI. */ public String toString() { return message.toString(); } /** * Allow access to the underlying message object under two conditions: * system or forum admin, or the message hasn't been added to a thread yet. */ public ForumMessage getProxiedForumMessage() throws UnauthorizedException { if (isAdmin() || getForumThread() == null) { return message; } else { throw new UnauthorizedException(); } } private boolean isAdmin() { return permissions.get(ForumPermissions.SYSTEM_ADMIN) || permissions.get(ForumPermissions.CATEGORY_ADMIN) || permissions.get(ForumPermissions.FORUM_ADMIN); } /** * Returns true if editing of this message is allowed under the current * permissions. See the ForumMessage class for details about message editing * policies. */ private boolean isAllowedToEdit() { // Admins or moderators can always edit messages. if (isAdmin() || permissions.get(ForumPermissions.MODERATE_THREADS) || permissions.get(ForumPermissions.MODERATE_MESSAGES)) { return true; } // Authors of the message can always edit. if (!isAnonymous() && getUser().getID() == authorization.getUserID()) { return true; } // Anonymous messages can only be edited before being added to a thread. if (getUser() == null && getForumThread() == null) { return true; } // If all previous checks, not allowed to edit. return false; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?