code: protected void tryToUnlock(CmsObject cms, String folderPath) throws CmsException {
  
          // Get path of first ancestor that actually exists
          while (!cms.existsResource(folderPath)) {
              folderPath = CmsResource.getParentFolder(folderPath);
          }
          CmsResource resource = cms.readResource(folderPath);
          CmsLock lock = cms.getLock(resource);
          // we are only interested in locks we can safely unlock, i.e. locks by the current user
          if (lock.isOwnedBy(cms.getRequestContext().getCurrentUser())) {
              // walk up the tree until we get to the location from which the lock is inherited
              while (lock.isInherited()) {
                  folderPath = CmsResource.getParentFolder(folderPath);
                  resource = cms.readResource(folderPath);
                  lock = cms.getLock(resource);
              }
              cms.unlockResource(folderPath);
          }
      }
docs: Tries to remove a lock on an ancestor of a given path owned by the current user.<p>
  
  @param cms the CMS context
  @param folderPath the path for which the lock should be removed
  
  @throws CmsException if something goes wrong