public void removeContentReferences(
      Map<ContentVersionVO, RegistryVO> contentVersionRegistryPair,
      InfoGluePrincipal infoGluePrincipal,
      Database db)
      throws SystemException, Exception {
    ContentVersionVO contentVersionVO;
    RegistryVO registryVO;
    for (Map.Entry<ContentVersionVO, RegistryVO> pair : contentVersionRegistryPair.entrySet()) {
      contentVersionVO = pair.getKey();
      registryVO = pair.getValue();
      if (logger.isDebugEnabled()) {
        logger.debug(
            "About to clean ContentVersion "
                + contentVersionVO.getContentVersionId()
                + " for references to: "
                + registryVO.getEntityName()
                + "<"
                + registryVO.getEntityId()
                + ">");
      }
      String versionValue = contentVersionVO.getVersionValue();

      if (registryVO.getReferenceType().equals(RegistryVO.INLINE_LINK))
        versionValue = deleteInlineLinks(versionValue, new Integer(registryVO.getEntityId()), db);
      if (registryVO.getReferenceType().equals(RegistryVO.INLINE_ASSET))
        versionValue = deleteInlineAssets(versionValue, new Integer(registryVO.getEntityId()));
      if (registryVO.getReferenceType().equals(RegistryVO.INLINE_SITE_NODE_RELATION))
        versionValue =
            deleteInlineSiteNodeRelations(versionValue, new Integer(registryVO.getEntityId()));
      if (registryVO.getReferenceType().equals(RegistryVO.INLINE_CONTENT_RELATION))
        versionValue =
            deleteInlineContentRelations(versionValue, new Integer(registryVO.getEntityId()));

      contentVersionVO.setVersionModifier(infoGluePrincipal.getName());
      contentVersionVO.setModifiedDateTime(DateHelper.getSecondPreciseDate());
      contentVersionVO.setVersionValue(versionValue);

      // ContentVersionController.getContentVersionController().update(contentVersionVO.getContentId(), contentVersionVO.getLanguageId(), contentVersionVO, db);
      ContentVersionController.getContentVersionController()
          .update(
              contentVersionVO.getContentId(),
              contentVersionVO.getLanguageId(),
              contentVersionVO,
              infoGluePrincipal,
              true,
              db,
              true);
    }
  }
  /**
   * @deprecated This method handles clean up of ContentVersions poorly. Please refer to {@link
   *     #removeContentReferences(Map, InfoGluePrincipal, Database)} and {@link
   *     #removeSiteNodeReferences(Map, InfoGluePrincipal, Database)} instead.
   */
  public void removeReferences(Integer registryId, InfoGluePrincipal infoGluePrincipal, Database db)
      throws SystemException, Exception {
    RegistryVO registryVO = RegistryController.getController().getRegistryVOWithId(registryId, db);
    String referencingEntityName = registryVO.getReferencingEntityName();
    String referencingEntityCompletingName = registryVO.getReferencingEntityCompletingName();
    Integer referencingEntityId = new Integer(registryVO.getReferencingEntityId());

    if (referencingEntityCompletingName.equals(SiteNode.class.getName())) {
      SiteNodeVO siteNodeVO =
          SiteNodeController.getController()
              .getSiteNodeVOWithId(new Integer(registryVO.getReferencingEntityCompletingId()), db);
      if (siteNodeVO != null) {
        Integer metaInfoContentId = siteNodeVO.getMetaInfoContentId();
        LanguageVO masterLanguageVO =
            LanguageController.getController().getMasterLanguage(siteNodeVO.getRepositoryId(), db);
        String pageStructure =
            ContentController.getContentController()
                .getContentAttribute(
                    db, metaInfoContentId, masterLanguageVO.getId(), "ComponentStructure");

        if (registryVO.getReferenceType().equals(RegistryVO.PAGE_COMPONENT))
          pageStructure =
              deleteComponentFromXML(pageStructure, new Integer(registryVO.getEntityId()));
        if (registryVO.getReferenceType().equals(RegistryVO.PAGE_COMPONENT_BINDING))
          pageStructure =
              deleteComponentBindingFromXML(
                  pageStructure, new Integer(registryVO.getEntityId()), registryVO.getEntityName());

        ContentVersionVO contentVersionVO =
            ContentVersionController.getContentVersionController()
                .getLatestActiveContentVersionVO(metaInfoContentId, masterLanguageVO.getId(), db);
        ContentVersionController.getContentVersionController()
            .updateAttributeValue(
                contentVersionVO.getContentVersionId(),
                "ComponentStructure",
                pageStructure,
                infoGluePrincipal,
                db);
      }
    } else if (referencingEntityCompletingName.equals(Content.class.getName())) {
      if (referencingEntityName.equals(ContentVersion.class.getName())) {
        ContentVersionVO contentVersionVO =
            ContentVersionController.getContentVersionController()
                .getContentVersionVOWithId(referencingEntityId, db);
        if (contentVersionVO != null) {
          String versionValue = contentVersionVO.getVersionValue();

          if (registryVO.getReferenceType().equals(RegistryVO.INLINE_LINK))
            versionValue =
                deleteInlineLinks(versionValue, new Integer(registryVO.getEntityId()), db);
          if (registryVO.getReferenceType().equals(RegistryVO.INLINE_ASSET))
            versionValue = deleteInlineAssets(versionValue, new Integer(registryVO.getEntityId()));
          if (registryVO.getReferenceType().equals(RegistryVO.INLINE_SITE_NODE_RELATION))
            versionValue =
                deleteInlineSiteNodeRelations(versionValue, new Integer(registryVO.getEntityId()));
          if (registryVO.getReferenceType().equals(RegistryVO.INLINE_CONTENT_RELATION))
            versionValue =
                deleteInlineContentRelations(versionValue, new Integer(registryVO.getEntityId()));

          contentVersionVO.setVersionModifier(infoGluePrincipal.getName());
          contentVersionVO.setModifiedDateTime(DateHelper.getSecondPreciseDate());
          contentVersionVO.setVersionValue(versionValue);

          ContentVersionController.getContentVersionController()
              .update(
                  contentVersionVO.getContentVersionId(), contentVersionVO, infoGluePrincipal, db);
        }
      }
    } else {
      logger.error(
          "The registry contained a not supported referencingEntityCompletingName:"
              + referencingEntityCompletingName);
    }
  }