Rewrites all children/sub-tree of the given parent element.
For rewrite operations the given rewrite content handler is called.
@param parent Parent element
@param rewriteContentHandler Rewrite content handler
490900
public static void rewriteContent(@NotNull Element parent, @NotNull RewriteContentHandler rewriteContentHandler) {

    // iterate through content list and build new content list
    List<Content> originalContent = parent.getContent();
    List<Content> newContent = new ArrayList<Content>();
    for (Content contentElement : originalContent) {

      // handle element
      if (contentElement instanceof Element) {
        Element element = (Element)contentElement;

        // check if rewrite is needed for element
        List<Content> rewriteContent = rewriteContentHandler.rewriteElement(element);
        if (rewriteContent != null) {
          // element was removed
          if (rewriteContent.isEmpty()) {
            // do not add to newContent
          }

          // element is the same - rewrite child elements
          else if (rewriteContent.size() == 1 && rewriteContent.get(0) == element) { //NOPMD
            rewriteContent(element, rewriteContentHandler);
            newContent.add(element);
          }

          // element was replaced with other content - rewrite and add instead
          else {
            for (Content newContentItem : rewriteContent) {
              if (newContentItem instanceof Element) {
                Element newElement = (Element)newContentItem;
                rewriteContent(newElement, rewriteContentHandler);
              }
              newContent.add(newContentItem.clone());
            }
          }
        }

        // nothing to rewrite - do nothing, but rewrite child element
        else {
          rewriteContent(element, rewriteContentHandler);
          newContent.add(element);
        }

      }

      // handle text node
      else if (contentElement instanceof Text) {
        Text text = (Text)contentElement;

        // check if rewrite is needed for text node
        List<Content> rewriteContent = rewriteContentHandler.rewriteText(text);
        if (rewriteContent != null) {
          // element was removed
          if (rewriteContent.isEmpty()) {
            // do not add to newContent
          }

          // element is the same - ignore
          else if (rewriteContent.size() == 1 && rewriteContent.get(0) == text) { //NOPMD
            // add original element
            newContent.add(text);
          }

          // element was replaced with other content - add instead
          else {
            for (Content newContentItem : rewriteContent) {
              newContent.add(newContentItem.clone());
            }
          }
        }

        // nothing to rewrite - do nothing, but add original text element
        else {
          newContent.add(text);
        }

      }

      // unknown element - just add to new content
      else {
        newContent.add(contentElement);
      }

    }

    // replace original content with new content
    parent.removeContent();
    parent.addContent(newContent);

  }
503955
void rewriteProvidesAndRequires(Node externs, Node root) {
    checkState(!hasRewritingOccurred, "Cannot call rewriteProvidesAndRequires twice per instance");
    hasRewritingOccurred = true;

    collectProvidedNames(externs, root);

    for (ProvidedName pn : providedNames.values()) {
      pn.replace();
    }
    deleteNamespaceInitializationsFromPreviousProvides();

    if (requiresLevel.isOn()) {
      for (UnrecognizedRequire r : unrecognizedRequires) {
        checkForLateOrMissingProvide(r);
      }
    }

    for (Node closureRequire : requiresToBeRemoved) {
      compiler.reportChangeToEnclosingScope(closureRequire);
      closureRequire.detach();
    }
    for (Node forwardDeclare : forwardDeclaresToRemove) {
      NodeUtil.deleteNode(forwardDeclare, compiler);
    }
  }
64919
public static SourceSnippet callParentGetter(final Key<?> key,
      final GinjectorBindings parentBindings) {
    return new SourceSnippet() {
      public String getSource(InjectorWriteContext writeContext) {
        return writeContext.callParentGetter(key, parentBindings);
      }
    };
  }
626891
def write_parent (self, url_data):
        """"""
        self.write(u"<tr><td>"+self.part("parenturl")+
                   u'</td><td><a target="top" href="'+
                   url_data.parent_url+u'">'+
                   cgi.escape(url_data.parent_url)+u"</a>")
        if url_data.line > 0:
            self.write(_(", line %d") % url_data.line)
        if url_data.column > 0:
            self.write(_(", col %d") % url_data.column)
        if url_data.page > 0:
            self.write(_(", page %d") % url_data.page)
        if not url_data.valid:
            # on errors show HTML and CSS validation for parent url
            vhtml = validate_html % {'uri': url_data.parent_url}
            vcss = validate_css % {'uri': url_data.parent_url}
            self.writeln()
            self.writeln(u'(<a href="'+vhtml+u'">HTML</a>)')
            self.write(u'(<a href="'+vcss+u'">CSS</a>)')
        self.writeln(u"</td></tr>")
1084981
public static void lazyAppend(Element parent, Element child) {
        if (!parent.contains(child)) {
            parent.appendChild(child);
        }
    }
296425
private void rewriteReturns(Node fnNode) {
    checkState(fnNode.isFunction());
    final Node body = fnNode.getLastChild();
    NodeUtil.visitPostOrder(
      body,
      new NodeUtil.Visitor() {
        @Override
        public void visit(Node n) {
          if (n.isReturn() && n.hasOneChild()) {
            Node result = n.getFirstChild();
            boolean keepValue = !isRemovableValue(result);
            result.detach();
            if (keepValue) {
              n.getParent().addChildBefore(IR.exprResult(result).srcref(result), n);
            } else {
              NodeUtil.markFunctionsDeleted(result, compiler);
            }
            compiler.reportChangeToEnclosingScope(body);
          }
        }
      },
      new NodeUtil.MatchShallowStatement());
  }
1230241
@Override
  public MtasSpanQuery rewrite(IndexReader reader) throws IOException {
    MtasSpanQuery newQuery = query.rewrite(reader);
    if (maximumRecurrence == 1) {
      return newQuery;
    } else {
      MtasSpanQuery newIgnoreQuery = (ignoreQuery != null)
          ? ignoreQuery.rewrite(reader) : null;
      if (newQuery instanceof MtasSpanRecurrenceQuery) {
        // for now too difficult, possibly merge later
      }
      if (!newQuery.equals(query)
          || (newIgnoreQuery != null && !newIgnoreQuery.equals(ignoreQuery))) {
        return new MtasSpanRecurrenceQuery(newQuery, minimumRecurrence,
            maximumRecurrence, newIgnoreQuery, maximumIgnoreLength)
                .rewrite(reader);
      } else {
        return super.rewrite(reader);
      }
    }
  }
472287
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();
    }
554312
@Override
    public void perform(Rewrite event, EvaluationContext context)
    {
        perform((GraphRewrite) event, context);
    }
163291
private void insertAfter(final URI hrefValue, final StringBuffer parentResult, final CharSequence tmpContent) {
        int insertpoint = parentResult.lastIndexOf("</");
        final int end = parentResult.indexOf(">", insertpoint);

        if (insertpoint == -1 || end == -1) {
            logger.error(MessageUtils.getMessage("DOTJ033E", hrefValue.toString()).toString());
        } else {
            if (ELEMENT_NAME_DITA.equals(parentResult.substring(insertpoint, end).trim())) {
                insertpoint = parentResult.lastIndexOf("</", insertpoint - 1);
            }
            parentResult.insert(insertpoint, tmpContent);
        }
    }
671727
private void writeParent(Account account, XmlStreamWriter writer)
            throws Exception {
        // Sequence block
        writer.writeStartElement("RDF:Seq");
        writer.writeAttribute("RDF:about", account.getId());
        for (Account child : account.getChildren()) {
            logger.fine("    Write-RDF:li: " + child.getId());
            writer.writeStartElement("RDF:li");
            writer.writeAttribute("RDF:resource", child.getId());
            writer.writeEndElement();
        }
        writer.writeEndElement();

        // Descriptions of all elements including the parent
        writeDescription(account, writer);
        for (Account child : account.getChildren()) {
            logger.fine("Write-RDF:Desc: " + child.getName());
            writeDescription(child, writer);
        }

        // Recurse into the children
        for (Account child : account.getChildren()) {
            if (child.getChildren().size() > 0) {
                writeParent(child, writer);
            }
        }
    }
1108361
public void setParentId(String parentId)
   {
      this.parentId = (parentId == null || parentId.equals("") ? null : parentId);
      setGroupName(groupName);
   }
507307
public static void resizeAncestor(Widget parent) {

        while (parent != null) {
            if (parent instanceof I_CmsDescendantResizeHandler) {
                ((I_CmsDescendantResizeHandler)parent).onResizeDescendant();
                return;
            } else {
                parent = parent.getParent();
            }
        }
    }
59398
public void createSubEntry(final CmsClientSitemapEntry parent, final CmsUUID structureId) {

        CmsSitemapTreeItem item = CmsSitemapTreeItem.getItemById(parent.getId());
        AsyncCallback<CmsClientSitemapEntry> callback = new AsyncCallback<CmsClientSitemapEntry>() {

            public void onFailure(Throwable caught) {

                // nothing to do
            }

            public void onSuccess(CmsClientSitemapEntry result) {

                makeNewEntry(parent, new I_CmsSimpleCallback<CmsClientSitemapEntry>() {

                    public void execute(CmsClientSitemapEntry newEntry) {

                        createSubEntry(newEntry, parent.getId(), structureId);
                    }
                });

            }

        };

        if (item.getLoadState().equals(LoadState.UNLOADED)) {
            getChildren(parent.getId(), true, callback);
        } else {
            callback.onSuccess(parent);
        }
    }
131403
function processURLSegments(parentNode, segments) {
		segments.forEach(function(segment) {
			if (segment.urlStr){
				var link = document.createElement("a"); //$NON-NLS-0$
		        link.href = segment.urlStr;
		        link.appendChild(document.createTextNode(segment.segmentStr));
		        link.dir = bidiUtils.getTextDirection(segment.segmentStr);
				parentNode.appendChild(link);
			} else {
				var plainText = document.createElement("span"); //$NON-NLS-0$
				plainText.textContent = segment.segmentStr;
				plainText.dir = bidiUtils.getTextDirection(segment.segmentStr);
				parentNode.appendChild(plainText);
			}
		});
	}
1164847
protected void rewriteLinks(CmsResource resource, Collection<CmsRelation> relations) throws CmsException {

        LOG.info("Rewriting relations for resource " + resource.getRootPath());
        I_CmsResourceType resourceType = OpenCms.getResourceManager().getResourceType(resource.getTypeId());
        boolean hasContentLinks = false;
        boolean hasOtherLinks = false;

        for (CmsRelation relation : relations) {
            if (relation.getType().isDefinedInContent()) {
                hasContentLinks = true;
            } else {
                hasOtherLinks = true;
            }
        }
        if (hasContentLinks) {
            LOG.info("The resource " + resource.getRootPath() + " has links in the content.");
        }
        if (hasOtherLinks) {
            LOG.info("The resource " + resource.getRootPath() + " has non-content links.");
        }

        if (hasContentLinks) {
            if (resourceType instanceof I_CmsLinkParseable) {
                CmsFile file = m_cms.readFile(resource);
                rewriteContent(file, relations);
                m_rewrittenContent.add(file.getStructureId());
            }
        }
        if (hasOtherLinks) {
            rewriteOtherRelations(resource, relations);
        }
    }
552944
@Override
    public Node getParentNode(String parentNodeId)
    {
        NodeLink link = new NodeLink(parentNodeId, getNodeId());

        if (this.parents == null)
        {
            return null;
        }
        else
        {
            return this.parents.get(link);
        }
    }