code: public void checkLock(String resource, CmsLockType type) throws CmsException {
  
          CmsResource res = getCms().readResource(resource, CmsResourceFilter.ALL);
          CmsLock lock = getCms().getLock(res);
          boolean lockable = lock.isLockableBy(getCms().getRequestContext().getCurrentUser());
  
          if (OpenCms.getWorkplaceManager().autoLockResources()) {
              // autolock is enabled, check the lock state of the resource
              if (lockable) {
                  // resource is lockable, so lock it automatically
                  if (type == CmsLockType.TEMPORARY) {
                      getCms().lockResourceTemporary(resource);
                  } else {
                      getCms().lockResource(resource);
                  }
              } else {
                  throw new CmsException(Messages.get().container(Messages.ERR_WORKPLACE_LOCK_RESOURCE_1, resource));
              }
          } else {
              if (!lockable) {
                  throw new CmsException(Messages.get().container(Messages.ERR_WORKPLACE_LOCK_RESOURCE_1, resource));
              }
          }
      }
docs: Checks the lock state of the resource and locks it if the autolock feature is enabled.<p>
  
  @param resource the resource name which is checked
  @param type indicates the mode {@link CmsLockType#EXCLUSIVE} or {@link CmsLockType#TEMPORARY}
  
  @throws CmsException if reading or locking the resource fails