001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/menu/CmsMirDirectPublish.java,v $
003: * Date : $Date: 2008-02-27 12:05:22 $
004: * Version: $Revision: 1.10 $
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.CmsResource;
036: import org.opencms.lock.CmsLock;
037: import org.opencms.main.CmsException;
038: import org.opencms.main.CmsLog;
039: import org.opencms.security.CmsPermissionSet;
040: import org.opencms.workplace.explorer.CmsResourceUtil;
041:
042: import org.apache.commons.logging.Log;
043:
044: /**
045: * Defines a menu item rule that sets the visibility to active
046: * if the current resource can be directly published by the current user.<p>
047: *
048: * @author Andreas Zahner
049: *
050: * @version $Revision: 1.10 $
051: *
052: * @since 6.5.6
053: */
054: public class CmsMirDirectPublish extends A_CmsMenuItemRule {
055:
056: /** The log object for this class. */
057: private static final Log LOG = CmsLog
058: .getLog(CmsMirDirectPublish.class);
059:
060: /**
061: * @see org.opencms.workplace.explorer.menu.I_CmsMenuItemRule#getVisibility(org.opencms.file.CmsObject, CmsResourceUtil[])
062: */
063: public CmsMenuItemVisibilityMode getVisibility(CmsObject cms,
064: CmsResourceUtil[] resourceUtil) {
065:
066: if (!resourceUtil[0].isInsideProject()) {
067: CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE
068: .addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_PUBLISH_OTHERPROJECT_0);
069: }
070:
071: CmsLock lock = resourceUtil[0].getLock();
072: if (lock.isNullLock()
073: || (lock.isExclusiveOwnedInProjectBy(cms
074: .getRequestContext().currentUser(), cms
075: .getRequestContext().currentProject()))) {
076: // resource is not locked or exclusively locked by current user in current project
077:
078: try {
079: if (cms.hasPermissions(resourceUtil[0].getResource(),
080: CmsPermissionSet.ACCESS_DIRECT_PUBLISH)) {
081: // only activate if user has direct publish permissions
082: if (resourceUtil[0].getResource().isFolder()
083: || !resourceUtil[0].getResource()
084: .getState().isUnchanged()) {
085: // resource is a folder or not unchanged
086: CmsResource parent = cms.readFolder(CmsResource
087: .getParentFolder(cms
088: .getSitePath(resourceUtil[0]
089: .getResource())));
090: if (parent.getState().isNew()) {
091: return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE
092: .addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_PUBLISH_PARENTFOLDER_0);
093: }
094: return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE;
095: } else if (!resourceUtil[0].getResource()
096: .isFolder()
097: && resourceUtil[0].getResource().getState()
098: .isUnchanged()) {
099: return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE
100: .addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_UNCHANGED_0);
101: }
102: } else {
103: return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE
104: .addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_PERM_PUBLISH_0);
105: }
106: } catch (CmsException e) {
107: if (LOG.isErrorEnabled()) {
108: LOG.error(e.getLocalizedMessage(), e);
109: }
110: }
111: }
112:
113: if (lock.isInherited()) {
114: return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE
115: .addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_PUBLISH_INHERITED_0);
116: }
117: return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE
118: .addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_PUBLISH_NOT_LOCKED_0);
119: }
120:
121: /**
122: * @see org.opencms.workplace.explorer.menu.I_CmsMenuItemRule#matches(org.opencms.file.CmsObject, CmsResourceUtil[])
123: */
124: public boolean matches(CmsObject cms, CmsResourceUtil[] resourceUtil) {
125:
126: return true;
127: }
128:
129: }
|