code: private boolean lockResource(CmsObject cms, CmsResource cmsResource) throws CmsException {
  
          CmsLock lock = cms.getLock(cms.getSitePath(cmsResource));
          // check the lock
          if ((lock != null)
              && lock.isOwnedBy(cms.getRequestContext().getCurrentUser())
              && lock.isOwnedInProjectBy(
                  cms.getRequestContext().getCurrentUser(),
                  cms.getRequestContext().getCurrentProject())) {
              // prove is current lock from current user in current project
              return true;
          } else if ((lock != null) && !lock.isUnlocked() && !lock.isOwnedBy(cms.getRequestContext().getCurrentUser())) {
              // the resource is not locked by the current user, so can not lock it
              return false;
          } else if ((lock != null)
              && !lock.isUnlocked()
              && lock.isOwnedBy(cms.getRequestContext().getCurrentUser())
              && !lock.isOwnedInProjectBy(
                  cms.getRequestContext().getCurrentUser(),
                  cms.getRequestContext().getCurrentProject())) {
              // prove is current lock from current user but not in current project
              // file is locked by current user but not in current project
  
              cms.changeLock(cms.getSitePath(cmsResource));
          } else if ((lock != null) && lock.isUnlocked()) {
              // lock resource from current user in current project
              cms.lockResource(cms.getSitePath(cmsResource));
          }
          lock = cms.getLock(cms.getSitePath(cmsResource));
          if ((lock != null)
              && lock.isOwnedBy(cms.getRequestContext().getCurrentUser())
              && !lock.isOwnedInProjectBy(
                  cms.getRequestContext().getCurrentUser(),
                  cms.getRequestContext().getCurrentProject())) {
              // resource could not be locked
              return false;
          }
          // resource is locked successfully
          return true;
      }
docs: Locks the current resource.<p>
  
  @param cms the current CmsObject
  @param cmsResource the resource to lock
  
  @return <code>true</code> if the given resource was locked was successfully
  
  @throws CmsException if some goes wrong