code: public static boolean ensureLock(CmsObject cms, CmsResource resource) throws CmsException {
  
          CmsLock lock = cms.getLock(resource);
          if (lock.isOwnedBy(cms.getRequestContext().getCurrentUser())) {
              return false;
          }
          cms.lockResourceTemporary(resource);
          return true;
      }
docs: Tries to lock a resource and throws an exception if it can't be locked.<p>
  
  Returns true only if the resource wasn't already locked before.<p>
  
  @param cms the CMS context
  @param resource the resource to lock
  @return true if the resource wasn't already locked
  
  @throws CmsException if something goes wrong