001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/menu/CmsMirPrSameLockedActiveNotDeletedAlPermW.java,v $
003: * Date : $Date: 2008-02-27 12:05:22 $
004: * Version: $Revision: 1.2 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.explorer.menu;
033:
034: import org.opencms.file.CmsObject;
035: import org.opencms.file.CmsResourceFilter;
036: import org.opencms.lock.CmsLock;
037: import org.opencms.main.CmsException;
038: import org.opencms.main.OpenCms;
039: import org.opencms.security.CmsPermissionSet;
040: import org.opencms.workplace.explorer.CmsResourceUtil;
041:
042: /**
043: * Defines a menu item rule that sets the visibility to active if the current resource is not deleted or inactive
044: * if the current resource is deleted and locked by the current user.<p>
045: *
046: * Also checks if the current user has write permissions on the resource and sets the visibility to inactive if not.<p>
047: *
048: * @author Andreas Zahner
049: *
050: * @version $Revision: 1.2 $
051: *
052: * @since 6.5.6
053: */
054: public class CmsMirPrSameLockedActiveNotDeletedAlPermW extends
055: A_CmsMenuItemRule {
056:
057: /**
058: * @see org.opencms.workplace.explorer.menu.I_CmsMenuItemRule#getVisibility(org.opencms.file.CmsObject, CmsResourceUtil[])
059: */
060: public CmsMenuItemVisibilityMode getVisibility(CmsObject cms,
061: CmsResourceUtil[] resourceUtil) {
062:
063: try {
064: if (!resourceUtil[0].isEditable()
065: || !cms.hasPermissions(resourceUtil[0]
066: .getResource(),
067: CmsPermissionSet.ACCESS_WRITE, false,
068: CmsResourceFilter.ALL)) {
069: return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE
070: .addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_PERM_WRITE_0);
071: }
072: } catch (CmsException e) {
073: // error checking permissions, disable entry completely
074: return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
075: }
076: if (resourceUtil[0].getResource().getState().isDeleted()) {
077: return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE
078: .addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_DELETED_0);
079: }
080: return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE;
081: }
082:
083: /**
084: * @see org.opencms.workplace.explorer.menu.I_CmsMenuItemRule#matches(org.opencms.file.CmsObject, CmsResourceUtil[])
085: */
086: public boolean matches(CmsObject cms, CmsResourceUtil[] resourceUtil) {
087:
088: if (resourceUtil[0].isInsideProject()) {
089: CmsLock lock = resourceUtil[0].getLock();
090: boolean lockedForPublish = resourceUtil[0]
091: .getProjectState().isLockedForPublishing();
092: return (!lockedForPublish && !lock.isShared() && lock
093: .isOwnedInProjectBy(cms.getRequestContext()
094: .currentUser(), cms.getRequestContext()
095: .currentProject()))
096: || (!lockedForPublish && lock.isNullLock() && OpenCms
097: .getWorkplaceManager().autoLockResources());
098: }
099: // resource is not locked by the user in current project or not locked with enabled autolock, rule does not match
100: return false;
101: }
102:
103: }
|