docs: public void rewriteLinks() throws CmsException {
  
          init();
          List<CmsRelation> relationsToCorrect = findRelationsFromTargetToSource();
          // group relations by the structure id of their source
          Multimap<CmsUUID, CmsRelation> relationsBySourceId = ArrayListMultimap.create();
          for (CmsRelation relation : relationsToCorrect) {
              LOG.info(
                  "Found relation which needs to be corrected: "
                      + relation.getSourcePath()
                      + " -> "
                      + relation.getTargetPath()
                      + " ["
                      + relation.getType().getName()
                      + "]");
              relationsBySourceId.put(relation.getSourceId(), relation);
          }
  
          // make sure we have a lock on the target folder before doing any write operations
          CmsLock lock = m_cms.getLock(m_targetPath);
          if (lock.isUnlocked() || !lock.isOwnedBy(m_cms.getRequestContext().getCurrentUser())) {
              // fail if locked by another user
              m_cms.lockResource(m_targetPath);
          }
  
          for (CmsUUID structureId : relationsBySourceId.keySet()) {
  
              Collection<CmsRelation> relationsForResource = relationsBySourceId.get(structureId);
              CmsResource resource = null;
              try {
                  resource = getResource(structureId);
                  rewriteLinks(resource, relationsForResource);
              } catch (Exception e) {
                  LOG.error(e.getLocalizedMessage(), e);
              }
          }
          if (!m_rewriteAllXmlContents) {
              return;
          }
          for (Map.Entry<CmsUUID, CmsResource> entry : m_cachedResources.entrySet()) {
              CmsUUID key = entry.getKey();
              CmsResource resource = entry.getValue();
              if (isInTargets(resource.getRootPath()) && !m_rewrittenContent.contains(key)) {
                  I_CmsResourceType resType = OpenCms.getResourceManager().getResourceType(resource.getTypeId());
                  // rewrite content for other files so
                  if (resType instanceof A_CmsResourceTypeLinkParseable) {
                      try {
                          CmsFile file = m_cms.readFile(resource);
                          if (resType instanceof CmsResourceTypeXmlContent) {
                              CmsXmlContent content = CmsXmlContentFactory.unmarshal(m_cms, file);
                              try {
                                  content.validateXmlStructure(new CmsXmlEntityResolver(m_cms));
                              } catch (CmsException e) {
                                  LOG.info("XML content was corrected automatically for resource " + file.getRootPath());
                                  content.setAutoCorrectionEnabled(true);
                                  content.correctXmlStructure(m_cms);
                                  file.setContents(content.marshal());
                              }
                          }
                          m_cms.writeFile(file);
                      } catch (CmsException e) {
                          LOG.error(e.getLocalizedMessage(), e);
                      }
                  }
              }
          }
          copyLocaleRelations();
      }