code: private byte[] renameNestedContainers(
          CmsFile targetContainerPage,
          CmsResource layoutResource,
          String oldName,
          String newName)
      throws Exception {
  
          byte[] contents = targetContainerPage.getContents();
          Set<String> replaceElementIds = new HashSet<String>();
          try {
              CmsXmlContainerPage page = CmsXmlContainerPageFactory.unmarshal(getCms(), targetContainerPage);
              for (CmsContainerElementBean element : page.getContainerPage(getCms()).getElements()) {
                  if (element.getId().equals(layoutResource.getStructureId()) && (element.getInstanceId() != null)) {
                      replaceElementIds.add(element.getInstanceId());
                  }
              }
              if (replaceElementIds.size() > 0) {
                  String encoding = CmsLocaleManager.getResourceEncoding(getCms(), targetContainerPage);
                  String content = new String(contents, encoding);
                  for (String instanceId : replaceElementIds) {
                      Pattern patt = Pattern.compile(
                          CmsJspTagContainer.getNestedContainerName(oldName, instanceId, null));
                      Matcher m = patt.matcher(content);
                      StringBuffer sb = new StringBuffer(content.length());
                      while (m.find()) {
                          m.appendReplacement(
                              sb,
                              Matcher.quoteReplacement(
                                  CmsJspTagContainer.getNestedContainerName(newName, instanceId, null)));
                      }
                      m.appendTail(sb);
                      content = sb.toString();
                  }
                  contents = content.getBytes(encoding);
              }
          } catch (Exception e) {
              LOG.error(e.getLocalizedMessage(), e);
              throw e;
          }
          return contents;
      }
docs: Renames a nested container within a container page XML.<p>
  
  @param targetContainerPage the target container page
  @param layoutResource the container element resource generating the nested container
  @param oldName the old container name
  @param newName the new container name
  
  @return the changed content bytes
  
  @throws Exception in case unmarshalling of the container page fails