archivemanagerproxy.java

来自「Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统,这是Jive论坛」· Java 代码 · 共 198 行

JAVA
198
字号
/** * $RCSfile: ArchiveManagerProxy.java,v $ * $Revision: 1.3 $ * $Date: 2002/07/11 01:56:20 $ * * Copyright (C) 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;/** * Protection proxy for the ArchiveManager class. * * @author Matt Tucker */public class ArchiveManagerProxy implements ArchiveManager {    private ArchiveManager archiveManager;	private Authorization authorization;	private ForumPermissions permissions;    public ArchiveManagerProxy(ArchiveManager archiveManager,            Authorization authorization, ForumPermissions permissions)    {        this.archiveManager = archiveManager;        this.authorization = authorization;        this.permissions = permissions;    }    public boolean isArchivingEnabled(Forum forum) {        return archiveManager.isArchivingEnabled(forum);    }    public void setArchivingEnabled(Forum forum, boolean enabled)            throws UnauthorizedException    {        if (isAdmin(forum)) {            archiveManager.setArchivingEnabled(forum, enabled);        }        else {            throw new UnauthorizedException();        }    }    public int getArchiveDays(Forum forum) {        return archiveManager.getArchiveDays(forum);    }    public void setArchiveDays(Forum forum, int days)            throws UnauthorizedException    {        if (isAdmin(forum)) {            archiveManager.setArchiveDays(forum, days);        }        else {            throw new UnauthorizedException();        }    }    public int getArchiveMode(Forum forum) {        return archiveManager.getArchiveMode(forum);    }    public void setArchiveMode(Forum forum, int mode)            throws UnauthorizedException    {        if (isAdmin(forum)) {            archiveManager.setArchiveMode(forum, mode);        }        else {            throw new UnauthorizedException();        }    }    public Forum getArchiveForum(Forum forum) throws UnauthorizedException {        if (isAdmin(forum)) {            Forum archiveForum = archiveManager.getArchiveForum(forum);            // If the archiveForum is null, return null since no forum            // has been selected            if (archiveForum == null) {                return null;            }            // Load permissions on the forum.            ForumPermissions forumPermissions = archiveForum.getPermissions(authorization);            // Create a new permissions object with the combination of the            // permissions.            ForumPermissions newPermissions =                    new ForumPermissions(permissions, forumPermissions);            // Check and see if the user has read permissions. If not, throw an            // an UnauthorizedException.            if (!(                newPermissions.get(ForumPermissions.READ_FORUM) ||                newPermissions.get(ForumPermissions.CATEGORY_ADMIN) ||                newPermissions.get(ForumPermissions.FORUM_ADMIN) ||                newPermissions.get(ForumPermissions.MODERATE_THREADS) ||                newPermissions.get(ForumPermissions.MODERATE_MESSAGES) ||                newPermissions.get(ForumPermissions.SYSTEM_ADMIN)                ))            {                throw new UnauthorizedException();            }            return new ForumProxy(archiveForum, authorization, newPermissions);        }        else {            throw new UnauthorizedException();        }    }    public void setArchiveForum(Forum forum, Forum archiveForum)            throws UnauthorizedException    {        if (isAdmin(forum) && isAdmin(archiveForum)) {            archiveManager.setArchiveForum(forum, archiveForum);        }        else {            throw new UnauthorizedException();        }    }    public boolean isAutoArchiveEnabled() throws UnauthorizedException    {        if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) {            return archiveManager.isAutoArchiveEnabled();        }        else {            throw new UnauthorizedException();        }    }    public void setAutoArchiveEnabled(boolean enabled)            throws UnauthorizedException    {        if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) {            archiveManager.setAutoArchiveEnabled(enabled);        }        else {            throw new UnauthorizedException();        }    }    public int getAutoArchiveInterval() throws UnauthorizedException    {        if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) {            return archiveManager.getAutoArchiveInterval();        }        else {            throw new UnauthorizedException();        }    }    public void setAutoArchiveInterval(int interval) throws UnauthorizedException {        if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) {            archiveManager.setAutoArchiveInterval(interval);        }        else {            throw new UnauthorizedException();        }    }    public boolean isBusy() throws UnauthorizedException {        if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) {            return archiveManager.isBusy();        }        else {            throw new UnauthorizedException();        }    }    public Date getLastArchivedDate() throws UnauthorizedException {        if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) {            return archiveManager.getLastArchivedDate();        }        else {            throw new UnauthorizedException();        }    }    public void runArchiver() throws UnauthorizedException {        if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) {            archiveManager.runArchiver();        }        else {            throw new UnauthorizedException();        }    }    private boolean isAdmin(Forum forum) {        return permissions.get(ForumPermissions.SYSTEM_ADMIN) ||               forum.hasPermission(ForumPermissions.CATEGORY_ADMIN) ||               forum.hasPermission(ForumPermissions.FORUM_ADMIN);    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?