Checks that the resource is not locked by another user.<p>

@param resource the resource
@return true if the resource is not locked by another user

@throws CmsException if something goes wrong
3382
private boolean checkLock(CmsResource resource) throws CmsException {

        CmsLock lock = m_cms.getLock(resource);
        return lock.isUnlocked() || lock.getUserId().equals(m_cms.getRequestContext().getCurrentUser().getId());
    }
801894
protected void checkNewParentsInList(CmsObject userCms, List<CmsResource> resources) throws CmsException {

        Map<String, CmsResource> resourcesByPath = new HashMap<String, CmsResource>();
        CmsObject rootCms = OpenCms.initCmsObject(m_adminCms);
        rootCms.getRequestContext().setCurrentProject(userCms.getRequestContext().getCurrentProject());
        rootCms.getRequestContext().setSiteRoot("");
        for (CmsResource resource : resources) {
            resourcesByPath.put(resource.getRootPath(), resource);
        }
        for (CmsResource resource : resources) {
            if (resource.getState().isNew()) {
                String parentPath = CmsResource.getParentFolder(resource.getRootPath());
                CmsResource parent = resourcesByPath.get(parentPath);
                if (parent == null) {
                    parent = rootCms.readResource(parentPath);
                    if (parent.getState().isNew()) {
                        throw new CmsNewParentNotInWorkflowException(
                            Messages.get().container(
                                Messages.ERR_NEW_PARENT_NOT_IN_WORKFLOW_1,
                                resource.getRootPath()));
                    }
                }
            }
        }
    }
248193
public void finish() throws CmsException {

        m_finished = true;
        m_requiresCleanup = false;
        CmsProject project = getProject();
        CmsObject projectCms = OpenCms.initCmsObject(m_adminCms);
        projectCms.getRequestContext().setCurrentProject(project);
        if (m_configuration.isAutoPublish()) {
            // we don't necessarily publish with the user who has the locks on the resources, so we need to steal the locks
            List<CmsResource> projectResources = projectCms.readProjectView(project.getUuid(), CmsResource.STATE_KEEP);
            for (CmsResource projectResource : projectResources) {
                CmsLock lock = projectCms.getLock(projectResource);
                if (!lock.isUnlocked() && !lock.isLockableBy(projectCms.getRequestContext().getCurrentUser())) {
                    projectCms.changeLock(projectResource);
                }
            }
            OpenCms.getPublishManager().publishProject(
                projectCms,
                new CmsLogReport(Locale.ENGLISH, CmsUgcSession.class));
        } else {
            // try to unlock everything - we don't need this in case of auto-publish, since publishing already unlocks the resources
            projectCms.unlockProject(project.getUuid());
        }

    }
1015360
public CmsLock getLock() {

        if (m_lock == null) {
            try {
                m_lock = getCms().getLock(m_resource);
            } catch (Throwable e) {
                m_lock = CmsLock.getNullLock();
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
        return m_lock;
    }
742694
public CmsLock getLock(CmsDbContext dbc, CmsResource resource) throws CmsException {

        return m_lockManager.getLock(dbc, resource);
    }
411339
@Override
    protected boolean performDialogOperation() throws CmsException {

        // check if the current resource is a folder for single operation
        boolean isFolder = isOperationOnFolder();
        // on folder move operation display "please wait" screen, not for simple file move operation
        if ((isMultiOperation() || isFolder) && !DIALOG_WAIT.equals(getParamAction())) {
            // return false, this will trigger the "please wait" screen
            return false;
        }

        // get the target name
        String target = getParamTarget();
        if (target == null) {
            target = "";
        }

        String siteRootFolder = null;
        try {
            // check if a site root was added to the target name
            String sitePrefix = "";
            if (OpenCms.getSiteManager().getSiteRoot(target) != null) {
                siteRootFolder = getCms().getRequestContext().getSiteRoot();
                if (siteRootFolder.endsWith("/")) {
                    siteRootFolder = siteRootFolder.substring(0, siteRootFolder.length() - 1);
                }
                sitePrefix = siteRootFolder;
                getCms().getRequestContext().setSiteRoot("/");
            }

            Iterator<String> i = getResourceList().iterator();
            // iterate the resources to move
            while (i.hasNext()) {
                String resName = i.next();
                try {
                    performSingleMoveOperation(resName, target, sitePrefix);
                } catch (CmsException e) {
                    if (isMultiOperation()) {
                        // collect exceptions to create a detailed output
                        addMultiOperationException(e);
                    } else {
                        // for single operation, throw the exception immediately
                        throw e;
                    }
                }
            }
            // check if exceptions occurred
            checkMultiOperationException(Messages.get(), Messages.ERR_MOVE_MULTI_0);
        } finally {
            if (siteRootFolder != null) {
                getCms().getRequestContext().setSiteRoot(siteRootFolder);
            }
        }
        return true;
    }
437291
public void parse(CmsResource resource) throws CmsException {

        CmsFile file = m_cms.readFile(resource);
        m_resource = resource;
        CmsXmlContent content = CmsXmlContentFactory.unmarshal(m_cms, file);
        parse(content);
    }
1159275
protected boolean isEditable() {

        if (m_isEditable == null) {

            if (getCms().getRequestContext().getCurrentProject().isOnlineProject()
                || !getCms().isInsideCurrentProject(getParamResource())) {
                // we are in the online project or resource does not belong to project, no editing allowed
                m_isEditable = Boolean.FALSE;

            } else {
                // we are in an offline project

                // check permissions
                if (!checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE, false)) {
                    getSettings().setErrorMessage(null);
                    m_isEditable = Boolean.FALSE;
                    return m_isEditable.booleanValue();
                }

                // check lock state
                String resourceName = getParamResource();
                CmsResource file = null;
                CmsLock lock = null;
                try {
                    file = getCms().readResource(resourceName, CmsResourceFilter.ALL);
                    // check if resource is a folder
                    if (file.isFolder() && !resourceName.endsWith("/")) {
                        resourceName += "/";
                    }
                } catch (CmsException e) {
                    // should usually never happen
                    if (LOG.isInfoEnabled()) {
                        LOG.info(e.getLocalizedMessage());
                    }
                }

                try {
                    // get the lock for the resource
                    lock = getCms().getLock(file);
                } catch (CmsException e) {
                    lock = CmsLock.getNullLock();

                    if (LOG.isErrorEnabled()) {
                        LOG.error(e.getLocalizedMessage(), e);
                    }
                }

                if (!lock.isNullLock()) {
                    // determine if resource is editable...
                    if (lock.isDirectlyOwnedBy(getCms().getRequestContext().getCurrentUser())) {
                        // lock is exclusive and belongs to the current user
                        if (lock.isInProject(getCms().getRequestContext().getCurrentProject())
                            || Boolean.valueOf(getParamUsetempfileproject()).booleanValue()) {
                            // resource is locked in the current project or the tempfileproject is used
                            m_isEditable = Boolean.TRUE;
                            return m_isEditable.booleanValue();
                        }
                    }
                } else if (OpenCms.getWorkplaceManager().autoLockResources()) {
                    if ((file == null) || file.isFolder()) {
                        // check locked resources in folder
                        try {
                            List<String> lockedResources = getCms().getLockedResources(
                                resourceName,
                                CmsLockFilter.FILTER_ALL.filterNotOwnedByUserId(
                                    getCms().getRequestContext().getCurrentUser().getId()));
                            if (!lockedResources.isEmpty()) {
                                m_isEditable = Boolean.FALSE;
                                return m_isEditable.booleanValue();
                            }
                        } catch (CmsException e1) {
                            // should usually never happen
                            if (LOG.isErrorEnabled()) {
                                LOG.error(e1.getLocalizedMessage(), e1);
                            }
                        }
                    }
                    m_isEditable = Boolean.TRUE;
                    return m_isEditable.booleanValue();
                }
                // lock is null or belongs to other user and/or project, properties are not editable
                m_isEditable = Boolean.FALSE;
            }
        }
        return m_isEditable.booleanValue();
    }
1340886
public boolean hasSubOUs() throws CmsException {

        List<CmsOrganizationalUnit> orgUnits = OpenCms.getOrgUnitManager().getOrganizationalUnits(
            getCms(),
            m_paramOufqn,
            true);
        if (orgUnits == null) {
            return false;
        }
        if (orgUnits.size() < 1) {
            return false;
        }
        return true;
    }
1254401
public boolean requiresPasswordChange(CmsObject cms, CmsUser user) {

        if (user.isManaged()
            || user.isWebuser()
            || OpenCms.getDefaultUsers().isDefaultUser(user.getName())
            || OpenCms.getRoleManager().hasRole(cms, user.getName(), CmsRole.ROOT_ADMIN)) {
            return false;
        }
        String lastPasswordChangeStr = (String)user.getAdditionalInfo().get(
            CmsUserSettings.ADDITIONAL_INFO_LAST_PASSWORD_CHANGE);
        if (lastPasswordChangeStr == null) {
            return false;
        }
        long lastPasswordChange = Long.parseLong(lastPasswordChangeStr);
        if ((System.currentTimeMillis() - lastPasswordChange) > getPasswordChangeInterval()) {
            return true;
        }
        return false;
    }
787077
public boolean canLockBecauseOfInactivity(CmsObject cms, CmsUser user) {

        return !user.isManaged()
            && !user.isWebuser()
            && !OpenCms.getDefaultUsers().isDefaultUser(user.getName())
            && !OpenCms.getRoleManager().hasRole(cms, user.getName(), CmsRole.ROOT_ADMIN);
    }
1285949
private boolean hasNavigationProperty(CmsObject cms, CmsResource resource) throws CmsException {

        List<CmsProperty> props = cms.readPropertyObjects(resource, false);
        Map<String, String> propMap = CmsProperty.toMap(props);
        return propMap.containsKey(CmsPropertyDefinition.PROPERTY_NAVPOS)
            || propMap.containsKey(CmsPropertyDefinition.PROPERTY_NAVTEXT);
    }
58436
public boolean hasCorrectLockstate() {

        org.opencms.lock.CmsLock lock = null;
        try {
            // get the lock state for the current resource
            lock = getCms().getLock(getParamResource());
        } catch (CmsException e) {
            // error getting lock state, log the error and return false
            LOG.error(e.getLocalizedMessage(getLocale()), e);
            return false;
        }
        // check if auto lock feature is enabled
        boolean autoLockFeature = lock.isNullLock() && OpenCms.getWorkplaceManager().autoLockResources();
        return autoLockFeature || lock.isExclusive() || lock.isInherited();
    }
129908
@SuppressWarnings("deprecation")
    public boolean isInheritedContainer(CmsObject cms) throws CmsException {

        if (m_resource == null) {
            initResource(cms);
        }
        return OpenCms.getResourceManager().getResourceType(
            CmsResourceTypeXmlContainerPage.INHERIT_CONTAINER_TYPE_NAME).getTypeId() == m_resource.getTypeId();
    }
357744
public static boolean existsEditor(CmsResource resource) {

        int plainId;
        try {
            plainId = OpenCms.getResourceManager().getResourceType(
                CmsResourceTypePlain.getStaticTypeName()).getTypeId();
        } catch (CmsLoaderException e) {
            // this should really never happen
            plainId = CmsResourceTypePlain.getStaticTypeId();
        }
        if ((CmsResourceTypeJsp.isJsp(resource))
            || (resource.getTypeId() == plainId)
            || CmsResourceTypeXmlPage.isXmlPage(resource)) {
            return true;
        }
        return false;
    }
845478
protected void ensureLock() throws CmsException {

        CmsLock lock = m_cms.getLock(m_resource);
        if (lock.isUnlocked() || !lock.isLockableBy(m_cms.getRequestContext().getCurrentUser())) {
            m_cms.lockResourceTemporary(m_cms.getSitePath(m_resource));
            m_needToUnlock = true;
        }
    }
1068317
public void lockResource(CmsResource resource) throws CmsException {

        getResourceType(resource).lockResource(this, m_securityManager, resource, CmsLockType.EXCLUSIVE);
    }