001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/menu/CmsMirEditControlcode.java,v $
003: * Date : $Date: 2008-02-27 12:05:22 $
004: * Version: $Revision: 1.6 $
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.security.CmsRole;
041: import org.opencms.workplace.explorer.CmsResourceUtil;
042:
043: /**
044: * Defines a menu item rule that sets the visibility for the "Edit controlcode" context menu entry,
045: * depending on the project and lock state of the resource.<p>
046: *
047: * @author Andreas Zahner
048: *
049: * @version $Revision: 1.6 $
050: *
051: * @since 6.9.2
052: */
053: public class CmsMirEditControlcode extends A_CmsMenuItemRule {
054:
055: /**
056: * @see org.opencms.workplace.explorer.menu.I_CmsMenuItemRule#getVisibility(org.opencms.file.CmsObject, CmsResourceUtil[])
057: */
058: public CmsMenuItemVisibilityMode getVisibility(CmsObject cms,
059: CmsResourceUtil[] resourceUtil) {
060:
061: try {
062: if (resourceUtil[0].isInsideProject()
063: && !cms.getRequestContext().currentProject()
064: .isOnlineProject()) {
065: // we are in the correct offline project and resource is not deleted
066: CmsLock lock = resourceUtil[0].getLock();
067: boolean lockedForPublish = resourceUtil[0]
068: .getProjectState().isLockedForPublishing();
069: if (lock.isNullLock()) {
070: // resource is not locked, check autolock
071: if (!lockedForPublish
072: && OpenCms.getWorkplaceManager()
073: .autoLockResources()
074: && !resourceUtil[0].getResource()
075: .getState().isDeleted()) {
076: if (OpenCms.getRoleManager().hasRole(cms,
077: CmsRole.DEVELOPER)
078: && cms.hasPermissions(resourceUtil[0]
079: .getResource(),
080: CmsPermissionSet.ACCESS_WRITE,
081: false, CmsResourceFilter.ALL)) {
082: return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE;
083: }
084: } else if (OpenCms.getRoleManager().hasRole(cms,
085: CmsRole.DEVELOPER)) {
086: if (resourceUtil[0].getResource().getState()
087: .isDeleted()) {
088: return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE
089: .addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_DELETED_0);
090: }
091: return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE
092: .addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_PERM_WRITE_0);
093: }
094: }
095: if (!lockedForPublish
096: && !lock.isShared()
097: && lock.isOwnedInProjectBy(cms
098: .getRequestContext().currentUser(), cms
099: .getRequestContext().currentProject())) {
100: // resource is exclusively locked by the current user
101: if (OpenCms.getRoleManager().hasRole(cms,
102: CmsRole.DEVELOPER)) {
103: if (!resourceUtil[0].getResource().getState()
104: .isDeleted()
105: && cms.hasPermissions(resourceUtil[0]
106: .getResource(),
107: CmsPermissionSet.ACCESS_WRITE,
108: false, CmsResourceFilter.ALL)) {
109: return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE;
110: } else {
111: if (resourceUtil[0].getResource()
112: .getState().isDeleted()) {
113: return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE
114: .addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_DELETED_0);
115: }
116: return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE
117: .addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_PERM_WRITE_0);
118: }
119: }
120: }
121:
122: }
123: } catch (CmsException e) {
124: // should not happen, anyway invisible is returned
125: }
126: // current user cannot see the entry
127: return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
128: }
129:
130: /**
131: * @see org.opencms.workplace.explorer.menu.I_CmsMenuItemRule#matches(org.opencms.file.CmsObject, CmsResourceUtil[])
132: */
133: public boolean matches(CmsObject cms, CmsResourceUtil[] resourceUtil) {
134:
135: // this rule always matches
136: return true;
137: }
138:
139: }
|