docs: public CmsContainerElementBean replaceContainerElement(
          CmsResource targetPage,
          CmsContainerElementBean originalElement)
      throws CmsException, NoCustomReplacementException {
          // if (m_elementReplacements.containsKey(originalElement.getId()
  
          CmsObject targetCms = OpenCms.initCmsObject(m_cms);
  
          CmsSite site = OpenCms.getSiteManager().getSiteForRootPath(m_targetFolder.getRootPath());
          if (site != null) {
              targetCms.getRequestContext().setSiteRoot(site.getSiteRoot());
          }
  
          if ((originalElement.getFormatterId() == null) || (originalElement.getId() == null)) {
              String rootPath = m_originalPage != null ? m_originalPage.getRootPath() : "???";
              LOG.warn("Skipping container element because of missing id in page: " + rootPath);
              return null;
          }
  
          if (m_elementReplacements.containsKey(originalElement.getId())) {
              return new CmsContainerElementBean(
                  m_elementReplacements.get(originalElement.getId()),
                  maybeReplaceFormatter(originalElement.getFormatterId()),
                  maybeReplaceFormatterInSettings(originalElement.getIndividualSettings()),
                  originalElement.isCreateNew());
          } else {
              CmsResource originalResource = m_cms.readResource(
                  originalElement.getId(),
                  CmsResourceFilter.IGNORE_EXPIRATION);
              I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(originalResource);
              CmsADEConfigData config = OpenCms.getADEManager().lookupConfiguration(m_cms, targetPage.getRootPath());
              CmsResourceTypeConfig typeConfig = config.getResourceType(type.getTypeName());
              if ((m_copyMode != CopyMode.reuse)
                  && (typeConfig != null)
                  && (originalElement.isCreateNew() || typeConfig.isCopyInModels())
                  && !type.getTypeName().equals(CmsResourceTypeXmlContainerPage.MODEL_GROUP_TYPE_NAME)) {
                  CmsResource resourceCopy = typeConfig.createNewElement(
                      targetCms,
                      originalResource,
                      targetPage.getRootPath());
                  CmsContainerElementBean copy = new CmsContainerElementBean(
                      resourceCopy.getStructureId(),
                      maybeReplaceFormatter(originalElement.getFormatterId()),
                      maybeReplaceFormatterInSettings(originalElement.getIndividualSettings()),
                      originalElement.isCreateNew());
                  m_elementReplacements.put(originalElement.getId(), resourceCopy.getStructureId());
                  LOG.info(
                      "Copied container element " + originalResource.getRootPath() + " -> " + resourceCopy.getRootPath());
                  CmsLockActionRecord record = null;
                  try {
                      record = CmsLockUtil.ensureLock(m_cms, resourceCopy);
                      adjustLocalesForElement(resourceCopy);
                  } finally {
                      if ((record != null) && (record.getChange() == LockChange.locked)) {
                          m_cms.unlockResource(resourceCopy);
                      }
                  }
                  return copy;
              } else if (m_customReplacements != null) {
                  CmsUUID replacementId = m_customReplacements.get(originalElement.getId());
                  if (replacementId != null) {
  
                      return new CmsContainerElementBean(
                          replacementId,
                          maybeReplaceFormatter(originalElement.getFormatterId()),
                          maybeReplaceFormatterInSettings(originalElement.getIndividualSettings()),
                          originalElement.isCreateNew());
                  } else {
                      if ((m_typesWithRequiredReplacements != null)
                          && m_typesWithRequiredReplacements.contains(type.getTypeName())) {
                          throw new NoCustomReplacementException(originalResource);
                      } else {
                          return originalElement;
                      }
  
                  }
              } else {
                  LOG.info("Reusing container element: " + originalResource.getRootPath());
                  return originalElement;
              }
          }
      }