docs: @SuppressWarnings("deprecation")
      private CmsResource createSingleResource(CmsObject cms, String fileName, String targetFolder, byte[] content)
      throws CmsException, CmsLoaderException, CmsDbSqlException {
  
          String newResname = getNewResourceName(cms, fileName, targetFolder);
          CmsResource createdResource = null;
  
          // determine Title property value to set on new resource
          String title = fileName;
          if (title.lastIndexOf('.') != -1) {
              title = title.substring(0, title.lastIndexOf('.'));
          }
  
          // fileName really shouldn't contain the full path, but for some reason it does sometimes when the client is
          // running on IE7, so we eliminate anything before and including the last slash or backslash in the title
          // before setting it as a property.
  
          int backslashIndex = title.lastIndexOf('\\');
          if (backslashIndex != -1) {
              title = title.substring(backslashIndex + 1);
          }
  
          int slashIndex = title.lastIndexOf('/');
          if (slashIndex != -1) {
              title = title.substring(slashIndex + 1);
          }
  
          List<CmsProperty> properties = new ArrayList<CmsProperty>(1);
          CmsProperty titleProp = new CmsProperty();
          titleProp.setName(CmsPropertyDefinition.PROPERTY_TITLE);
          if (OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) {
              titleProp.setStructureValue(title);
          } else {
              titleProp.setResourceValue(title);
          }
          properties.add(titleProp);
  
          int plainId = OpenCms.getResourceManager().getResourceType(
              CmsResourceTypePlain.getStaticTypeName()).getTypeId();
          if (!cms.existsResource(newResname, CmsResourceFilter.IGNORE_EXPIRATION)) {
              // if the resource does not exist, create it
  
              try {
                  // create the resource
                  int resTypeId = OpenCms.getResourceManager().getDefaultTypeForName(newResname).getTypeId();
                  createdResource = cms.createResource(newResname, resTypeId, content, properties);
                  try {
                      cms.unlockResource(newResname);
                  } catch (CmsLockException e) {
                      LOG.info("Couldn't unlock uploaded file", e);
                  }
              } catch (CmsSecurityException e) {
                  // in case of not enough permissions, try to create a plain text file
                  createdResource = cms.createResource(newResname, plainId, content, properties);
                  cms.unlockResource(newResname);
              } catch (CmsDbSqlException sqlExc) {
                  // SQL error, probably the file is too large for the database settings, delete file
                  cms.lockResource(newResname);
                  cms.deleteResource(newResname, CmsResource.DELETE_PRESERVE_SIBLINGS);
                  throw sqlExc;
              } catch (OutOfMemoryError e) {
                  // the file is to large try to clear up
                  cms.lockResource(newResname);
                  cms.deleteResource(newResname, CmsResource.DELETE_PRESERVE_SIBLINGS);
                  throw e;
              }
  
          } else {
              // if the resource already exists, replace it
              CmsResource res = cms.readResource(newResname, CmsResourceFilter.ALL);
              boolean wasLocked = false;
              try {
                  if (!cms.getLock(res).isOwnedBy(cms.getRequestContext().getCurrentUser())) {
                      cms.lockResource(res);
                      wasLocked = true;
                  }
                  CmsFile file = cms.readFile(res);
                  byte[] contents = file.getContents();
                  try {
                      cms.replaceResource(newResname, res.getTypeId(), content, null);
                      createdResource = res;
                  } catch (CmsDbSqlException sqlExc) {
                      // SQL error, probably the file is too large for the database settings, restore content
                      file.setContents(contents);
                      cms.writeFile(file);
                      throw sqlExc;
                  } catch (OutOfMemoryError e) {
                      // the file is to large try to clear up
                      file.setContents(contents);
                      cms.writeFile(file);
                      throw e;
                  }
              } finally {
                  if (wasLocked) {
                      cms.unlockResource(res);
                  }
              }
          }
          return createdResource;
      }