docs: public synchronized String createTempFile(CmsObject cms, String resourceName, CmsUUID currentProjectId)
      throws CmsException {
  
          // check that the current user has write permissions
          if (!cms.hasPermissions(cms.readResource(resourceName, CmsResourceFilter.ALL), CmsPermissionSet.ACCESS_WRITE)) {
              throw new CmsPermissionViolationException(
                  org.opencms.db.Messages.get().container(org.opencms.db.Messages.ERR_PERM_DENIED_2, resourceName, "w"));
          }
  
          // initialize admin cms context
          CmsObject adminCms = getAdminCms(cms);
  
          // generate the filename of the temporary file
          String temporaryFilename = CmsWorkplace.getTemporaryFileName(resourceName);
  
          // check if the temporary file is already present
          if (adminCms.existsResource(temporaryFilename, CmsResourceFilter.ALL)) {
              // delete old temporary file
              if (!cms.getLock(temporaryFilename).isUnlocked()) {
                  // steal lock
                  cms.changeLock(temporaryFilename);
              } else {
                  // lock resource to current user
                  cms.lockResource(temporaryFilename);
              }
              cms.deleteResource(temporaryFilename, CmsResource.DELETE_PRESERVE_SIBLINGS);
          }
  
          try {
              // switch to the temporary file project
              adminCms.getRequestContext().setCurrentProject(cms.readProject(getTempFileProjectId()));
              // copy the file to edit to a temporary file
              adminCms.copyResource(resourceName, temporaryFilename, CmsResource.COPY_AS_NEW);
          } finally {
              // switch back to current project
              adminCms.getRequestContext().setCurrentProject(cms.readProject(currentProjectId));
          }
  
          try {
              // switch to the temporary file project
              cms.getRequestContext().setCurrentProject(
                  cms.readProject(OpenCms.getWorkplaceManager().getTempFileProjectId()));
              // lock the temporary file
              cms.changeLock(temporaryFilename);
              // touch the temporary file
              cms.setDateLastModified(temporaryFilename, System.currentTimeMillis(), false);
              // set the temporary file flag
              CmsResource tempFile = cms.readResource(temporaryFilename, CmsResourceFilter.ALL);
              int flags = tempFile.getFlags();
              if ((flags & CmsResource.FLAG_TEMPFILE) == 0) {
                  flags += CmsResource.FLAG_TEMPFILE;
              }
              cms.chflags(temporaryFilename, flags);
              // remove eventual release & expiration date from temporary file to make preview in editor work
              cms.setDateReleased(temporaryFilename, CmsResource.DATE_RELEASED_DEFAULT, false);
              cms.setDateExpired(temporaryFilename, CmsResource.DATE_EXPIRED_DEFAULT, false);
              // remove visibility permissions for everybody on temporary file if possible
              if (cms.hasPermissions(tempFile, CmsPermissionSet.ACCESS_CONTROL)) {
                  cms.chacc(
                      temporaryFilename,
                      I_CmsPrincipal.PRINCIPAL_GROUP,
                      OpenCms.getDefaultUsers().getGroupUsers(),
                      "-v");
              }
          } finally {
              // switch back to current project
              cms.getRequestContext().setCurrentProject(cms.readProject(currentProjectId));
          }
  
          return temporaryFilename;
      }