@Override
    public CmsMenuItemVisibilityMode getSingleVisibility(CmsObject cms, CmsResource resource) {

        boolean prioritize = false;
        String inActiveKey = null;
        if (resource != null) {
            if (flag(roleeditor) && !OpenCms.getRoleManager().hasRoleForResource(cms, CmsRole.EDITOR, resource)) {
                return VISIBILITY_INVISIBLE;
            }
            if (flag(rolewpuser)
                && !OpenCms.getRoleManager().hasRoleForResource(cms, CmsRole.WORKPLACE_USER, resource)) {
                return VISIBILITY_INVISIBLE;
            }
        } else {
            if (flag(roleeditor) && !OpenCms.getRoleManager().hasRole(cms, CmsRole.EDITOR)) {
                return VISIBILITY_INVISIBLE;
            }

            if (flag(rolewpuser) && !OpenCms.getRoleManager().hasRole(cms, CmsRole.WORKPLACE_USER)) {
                return VISIBILITY_INVISIBLE;
            }
        }
        if (flag(notonline) && cms.getRequestContext().getCurrentProject().isOnlineProject()) {
            return VISIBILITY_INVISIBLE;
        }

        if ((resource != null)) {
            CmsResourceUtil resUtil = new CmsResourceUtil(cms, resource);
            if (flag(file) && !resource.isFile()) {
                return VISIBILITY_INVISIBLE;
            }

            if (flag(defaultfile)) {
                if (!resource.isFile()) {
                    return VISIBILITY_INVISIBLE;
                }
                try {
                    CmsResource parentFolder = cms.readParentFolder(resource.getStructureId());
                    if (parentFolder == null) {
                        return VISIBILITY_INVISIBLE;
                    }
                    CmsResource defaultFile = cms.readDefaultFile(parentFolder, CmsResourceFilter.IGNORE_EXPIRATION);
                    if ((defaultFile == null) || !(defaultFile.getStructureId().equals(resource.getStructureId()))) {
                        return VISIBILITY_INVISIBLE;
                    }
                } catch (CmsException e) {
                    LOG.error(e.getLocalizedMessage(), e);
                    return VISIBILITY_INVISIBLE;
                }
            }

            if (flag(folder) && resource.isFile()) {
                return VISIBILITY_INVISIBLE;
            }

            if (flag(pagefolder)) {
                if (!resource.isFolder()) {
                    return VISIBILITY_INVISIBLE;
                }
                try {
                    CmsResource defaultFile;
                    defaultFile = cms.readDefaultFile("" + resource.getStructureId());
                    if ((defaultFile == null) || !CmsResourceTypeXmlContainerPage.isContainerPage(defaultFile)) {
                        return VISIBILITY_INVISIBLE;
                    }
                } catch (CmsException e) {
                    LOG.warn(e.getLocalizedMessage(), e);
                    return VISIBILITY_INVISIBLE;
                }
            }

            if (flag(pointer)
                && !OpenCms.getResourceManager().matchResourceType(
                    CmsResourceTypePointer.getStaticTypeName(),
                    resource.getTypeId())) {
                return VISIBILITY_INVISIBLE;
            }

            if (flag(notpointer)
                && OpenCms.getResourceManager().matchResourceType(
                    CmsResourceTypePointer.getStaticTypeName(),
                    resource.getTypeId())) {
                return VISIBILITY_INVISIBLE;
            }

            if (flag(replacable)) {
                I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(resource);
                boolean usesDumpLoader = type.getLoaderId() == CmsDumpLoader.RESOURCE_LOADER_ID;
                if (!usesDumpLoader && !(type instanceof CmsResourceTypeImage)) {
                    return VISIBILITY_INVISIBLE;
                }

            }

            if (flag(hassourcecodeeditor)) {
                I_CmsResourceType type = resUtil.getResourceType();
                boolean hasSourcecodeEditor = (type instanceof CmsResourceTypeXmlContent)
                    || (type instanceof CmsResourceTypeXmlPage)
                    || (type instanceof CmsResourceTypePointer)
                    || OpenCms.getResourceManager().matchResourceType(
                        BundleType.PROPERTY.toString(),
                        resource.getTypeId());
                if (!hasSourcecodeEditor) {
                    return VISIBILITY_INVISIBLE;
                }
            }

            if (flag(unlocked)) {
                CmsLock lock = resUtil.getLock();
                if (!lock.isUnlocked()) {
                    return VISIBILITY_INVISIBLE;
                }
                prioritize = true;
            }

            if (flag(otherlock)) {
                CmsLock lock = resUtil.getLock();
                if (lock.isUnlocked() || lock.isOwnedBy(cms.getRequestContext().getCurrentUser())) {
                    return VISIBILITY_INVISIBLE;
                }
                prioritize = true;
            }

            if (flag(nootherlock)) {
                CmsLock lock = resUtil.getLock();
                if (!lock.isUnlocked() && !lock.isOwnedBy(cms.getRequestContext().getCurrentUser())) {
                    return VISIBILITY_INVISIBLE;
                }
            }

            if (flag(mylock)) {
                CmsLock lock = resUtil.getLock();
                if (!lock.isOwnedBy(cms.getRequestContext().getCurrentUser())) {
                    return VISIBILITY_INVISIBLE;
                }
                prioritize = true;
            }

            if (flag(noinheritedlock)) {
                CmsLock lock = resUtil.getLock();
                if (lock.isInherited()) {
                    return VISIBILITY_INVISIBLE;
                }
            }

            if (flag(notunchangedfile) && resource.isFile() && resUtil.getResource().getState().isUnchanged()) {
                inActiveKey = Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_UNCHANGED_0;
            }

            if (flag(notnew) && (inActiveKey == null) && resource.getState().isNew()) {
                inActiveKey = Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_NEW_UNCHANGED_0;
            }

            if (flag(xmlunmarshal)) {
                if (CmsResourceTypeXmlContent.isXmlContent(resource)) {
                    try {
                        CmsXmlContentFactory.unmarshal(cms, cms.readFile(resource));
                    } catch (Exception e) {
                        return VISIBILITY_INVISIBLE;
                    }
                }

            }

            if (flag(haseditor) && (OpenCms.getWorkplaceAppManager().getEditorForResource(resource, false) == null)) {
                return VISIBILITY_INVISIBLE;
            }

            if (flag(inproject) && (!resUtil.isInsideProject() || resUtil.getProjectState().isLockedForPublishing())) {
                return VISIBILITY_INVISIBLE;
            }

            if (flag(notinproject)
                && (resUtil.isInsideProject() || resUtil.getProjectState().isLockedForPublishing())) {
                return VISIBILITY_INVISIBLE;
            }

            if (flag(publishpermission)) {
                try {
                    if (!cms.hasPermissions(
                        resource,
                        CmsPermissionSet.ACCESS_DIRECT_PUBLISH,
                        false,
                        CmsResourceFilter.ALL)) {
                        return VISIBILITY_INVISIBLE;
                    }
                } catch (CmsException e) {
                    LOG.error(e.getLocalizedMessage(), e);
                }
            }

            if (flag(controlpermission)) {
                try {
                    if (!cms.hasPermissions(
                        resource,
                        CmsPermissionSet.ACCESS_CONTROL,
                        false,
                        CmsResourceFilter.IGNORE_EXPIRATION)) {
                        return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
                    }
                } catch (CmsException e) {
                    LOG.warn("Error checking context menu entry permissions", e);
                    return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
                }
            }

            if (flag(writepermisssion)) {
                try {
                    if (!resUtil.getLock().isLockableBy(cms.getRequestContext().getCurrentUser())) {
                        // set invisible if not lockable
                        return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
                    }
                    if (!resUtil.isEditable()
                        || !cms.hasPermissions(
                            resUtil.getResource(),
                            CmsPermissionSet.ACCESS_WRITE,
                            false,
                            CmsResourceFilter.ALL)) {
                        inActiveKey = Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_PERM_WRITE_0;
                    }
                } catch (CmsException e) {
                    LOG.debug("Error checking context menu entry permissions.", e);
                    return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
                }
            }

            if (flag(notdeleted) && (inActiveKey == null) && resUtil.getResource().getState().isDeleted()) {
                inActiveKey = Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_DELETED_0;
            }

            if (flag(deleted) && !resource.getState().isDeleted()) {
                return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
            }

        } else {
            return VISIBILITY_INVISIBLE;
        }
        if (inActiveKey != null) {
            return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE.addMessageKey(inActiveKey).prioritize(prioritize);
        }
        return VISIBILITY_ACTIVE.prioritize(prioritize);
    }
@ Override public CmsMenuItemVisibilityMode getSingleVisibility ( CmsObject cms , CmsResource resource ) { boolean prioritize = false ; String inActiveKey = null ; if ( resource != null ) { if ( flag ( roleeditor ) && ! OpenCms . getRoleManager ( ) . hasRoleForResource ( cms , CmsRole . EDITOR , resource ) ) { return VISIBILITY_INVISIBLE ; } if ( flag ( rolewpuser ) && ! OpenCms . getRoleManager ( ) . hasRoleForResource ( cms , CmsRole . WORKPLACE_USER , resource ) ) { return VISIBILITY_INVISIBLE ; } } else { if ( flag ( roleeditor ) && ! OpenCms . getRoleManager ( ) . hasRole ( cms , CmsRole . EDITOR ) ) { return VISIBILITY_INVISIBLE ; } if ( flag ( rolewpuser ) && ! OpenCms . getRoleManager ( ) . hasRole ( cms , CmsRole . WORKPLACE_USER ) ) { return VISIBILITY_INVISIBLE ; } } if ( flag ( notonline ) && cms . getRequestContext ( ) . getCurrentProject ( ) . isOnlineProject ( ) ) { return VISIBILITY_INVISIBLE ; } if ( ( resource != null ) ) { CmsResourceUtil resUtil = new CmsResourceUtil ( cms , resource ) ; if ( flag ( file ) && ! resource . isFile ( ) ) { return VISIBILITY_INVISIBLE ; } if ( flag ( defaultfile ) ) { if ( ! resource . isFile ( ) ) { return VISIBILITY_INVISIBLE ; } try { CmsResource parentFolder = cms . readParentFolder ( resource . getStructureId ( ) ) ; if ( parentFolder == null ) { return VISIBILITY_INVISIBLE ; } CmsResource defaultFile = cms . readDefaultFile ( parentFolder , CmsResourceFilter . IGNORE_EXPIRATION ) ; if ( ( defaultFile == null ) || ! ( defaultFile . getStructureId ( ) . equals ( resource . getStructureId ( ) ) ) ) { return VISIBILITY_INVISIBLE ; } } catch ( CmsException e ) { LOG . error ( e . getLocalizedMessage ( ) , e ) ; return VISIBILITY_INVISIBLE ; } } if ( flag ( folder ) && resource . isFile ( ) ) { return VISIBILITY_INVISIBLE ; } if ( flag ( pagefolder ) ) { if ( ! resource . isFolder ( ) ) { return VISIBILITY_INVISIBLE ; } try { CmsResource defaultFile ; defaultFile = cms . readDefaultFile ( "" + resource . getStructureId ( ) ) ; if ( ( defaultFile == null ) || ! CmsResourceTypeXmlContainerPage . isContainerPage ( defaultFile ) ) { return VISIBILITY_INVISIBLE ; } } catch ( CmsException e ) { LOG . warn ( e . getLocalizedMessage ( ) , e ) ; return VISIBILITY_INVISIBLE ; } } if ( flag ( pointer ) && ! OpenCms . getResourceManager ( ) . matchResourceType ( CmsResourceTypePointer . getStaticTypeName ( ) , resource . getTypeId ( ) ) ) { return VISIBILITY_INVISIBLE ; } if ( flag ( notpointer ) && OpenCms . getResourceManager ( ) . matchResourceType ( CmsResourceTypePointer . getStaticTypeName ( ) , resource . getTypeId ( ) ) ) { return VISIBILITY_INVISIBLE ; } if ( flag ( replacable ) ) { I_CmsResourceType type = OpenCms . getResourceManager ( ) . getResourceType ( resource ) ; boolean usesDumpLoader = type . getLoaderId ( ) == CmsDumpLoader . RESOURCE_LOADER_ID ; if ( ! usesDumpLoader && ! ( type instanceof CmsResourceTypeImage ) ) { return VISIBILITY_INVISIBLE ; } } if ( flag ( hassourcecodeeditor ) ) { I_CmsResourceType type = resUtil . getResourceType ( ) ; boolean hasSourcecodeEditor = ( type instanceof CmsResourceTypeXmlContent ) || ( type instanceof CmsResourceTypeXmlPage ) || ( type instanceof CmsResourceTypePointer ) || OpenCms . getResourceManager ( ) . matchResourceType ( BundleType . PROPERTY . toString ( ) , resource . getTypeId ( ) ) ; if ( ! hasSourcecodeEditor ) { return VISIBILITY_INVISIBLE ; } } if ( flag ( unlocked ) ) { CmsLock lock = resUtil . getLock ( ) ; if ( ! lock . isUnlocked ( ) ) { return VISIBILITY_INVISIBLE ; } prioritize = true ; } if ( flag ( otherlock ) ) { CmsLock lock = resUtil . getLock ( ) ; if ( lock . isUnlocked ( ) || lock . isOwnedBy ( cms . getRequestContext ( ) . getCurrentUser ( ) ) ) { return VISIBILITY_INVISIBLE ; } prioritize = true ; } if ( flag ( nootherlock ) ) { CmsLock lock = resUtil . getLock ( ) ; if ( ! lock . isUnlocked ( ) && ! lock . isOwnedBy ( cms . getRequestContext ( ) . getCurrentUser ( ) ) ) { return VISIBILITY_INVISIBLE ; } } if ( flag ( mylock ) ) { CmsLock lock = resUtil . getLock ( ) ; if ( ! lock . isOwnedBy ( cms . getRequestContext ( ) . getCurrentUser ( ) ) ) { return VISIBILITY_INVISIBLE ; } prioritize = true ; } if ( flag ( noinheritedlock ) ) { CmsLock lock = resUtil . getLock ( ) ; if ( lock . isInherited ( ) ) { return VISIBILITY_INVISIBLE ; } } if ( flag ( notunchangedfile ) && resource . isFile ( ) && resUtil . getResource ( ) . getState ( ) . isUnchanged ( ) ) { inActiveKey = Messages . GUI_CONTEXTMENU_TITLE_INACTIVE_UNCHANGED_0 ; } if ( flag ( notnew ) && ( inActiveKey == null ) && resource . getState ( ) . isNew ( ) ) { inActiveKey = Messages . GUI_CONTEXTMENU_TITLE_INACTIVE_NEW_UNCHANGED_0 ; } if ( flag ( xmlunmarshal ) ) { if ( CmsResourceTypeXmlContent . isXmlContent ( resource ) ) { try { CmsXmlContentFactory . unmarshal ( cms , cms . readFile ( resource ) ) ; } catch ( Exception e ) { return VISIBILITY_INVISIBLE ; } } } if ( flag ( haseditor ) && ( OpenCms . getWorkplaceAppManager ( ) . getEditorForResource ( resource , false ) == null ) ) { return VISIBILITY_INVISIBLE ; } if ( flag ( inproject ) && ( ! resUtil . isInsideProject ( ) || resUtil . getProjectState ( ) . isLockedForPublishing ( ) ) ) { return VISIBILITY_INVISIBLE ; } if ( flag ( notinproject ) && ( resUtil . isInsideProject ( ) || resUtil . getProjectState ( ) . isLockedForPublishing ( ) ) ) { return VISIBILITY_INVISIBLE ; } if ( flag ( publishpermission ) ) { try { if ( ! cms . hasPermissions ( resource , CmsPermissionSet . ACCESS_DIRECT_PUBLISH , false , CmsResourceFilter . ALL ) ) { return VISIBILITY_INVISIBLE ; } } catch ( CmsException e ) { LOG . error ( e . getLocalizedMessage ( ) , e ) ; } } if ( flag ( controlpermission ) ) { try { if ( ! cms . hasPermissions ( resource , CmsPermissionSet . ACCESS_CONTROL , false , CmsResourceFilter . IGNORE_EXPIRATION ) ) { return CmsMenuItemVisibilityMode . VISIBILITY_INVISIBLE ; } } catch ( CmsException e ) { LOG . warn ( "Error checking context menu entry permissions" , e ) ; return CmsMenuItemVisibilityMode . VISIBILITY_INVISIBLE ; } } if ( flag ( writepermisssion ) ) { try { if ( ! resUtil . getLock ( ) . isLockableBy ( cms . getRequestContext ( ) . getCurrentUser ( ) ) ) { return CmsMenuItemVisibilityMode . VISIBILITY_INVISIBLE ; } if ( ! resUtil . isEditable ( ) || ! cms . hasPermissions ( resUtil . getResource ( ) , CmsPermissionSet . ACCESS_WRITE , false , CmsResourceFilter . ALL ) ) { inActiveKey = Messages . GUI_CONTEXTMENU_TITLE_INACTIVE_PERM_WRITE_0 ; } } catch ( CmsException e ) { LOG . debug ( "Error checking context menu entry permissions." , e ) ; return CmsMenuItemVisibilityMode . VISIBILITY_INVISIBLE ; } } if ( flag ( notdeleted ) && ( inActiveKey == null ) && resUtil . getResource ( ) . getState ( ) . isDeleted ( ) ) { inActiveKey = Messages . GUI_CONTEXTMENU_TITLE_INACTIVE_DELETED_0 ; } if ( flag ( deleted ) && ! resource . getState ( ) . isDeleted ( ) ) { return CmsMenuItemVisibilityMode . VISIBILITY_INVISIBLE ; } } else { return VISIBILITY_INVISIBLE ; } if ( inActiveKey != null ) { return CmsMenuItemVisibilityMode . VISIBILITY_INACTIVE . addMessageKey ( inActiveKey ) . prioritize ( prioritize ) ; } return VISIBILITY_ACTIVE . prioritize ( prioritize ) ; }
@see org.opencms.ui.contextmenu.A_CmsSimpleVisibilityCheck#getSingleVisibility(org.opencms.file.CmsObject, org.opencms.file.CmsResource)