code: private void transformResource(CmsResource resource, Function<String, String> transformation)
      throws CmsException, UnsupportedEncodingException {
  
          CmsFile file = getCms().readFile(resource);
          if (CmsResourceTypeXmlContent.isXmlContent(file)) {
              CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(getCms(), file);
              xmlContent.setAutoCorrectionEnabled(true);
              file = xmlContent.correctXmlStructure(getCms());
          }
          String encoding = CmsLocaleManager.getResourceEncoding(getCms(), file);
          String content = new String(file.getContents(), encoding);
          content = transformation.apply(content);
          file.setContents(content.getBytes(encoding));
          lockResource(getCms(), file);
          getCms().writeFile(file);
  
      }
docs: Reads a file into a string, applies a transformation to the string, and writes the string back to the file.<p>
  
  @param resource the resource to transform
  @param transformation the transformation to apply
  @throws CmsException if something goes wrong
  @throws UnsupportedEncodingException in case the encoding is not supported