/** * Handles presence of custom elements (elements not part of the android or tools * namespaces). Such elements are merged unchanged into the resulting document, and * optionally, the namespace definition is added to the merged document root element. * @param customElement the custom element present in the lower priority document. * @param mergingReport the merging report to log errors and actions. */ private void handleCustomElement(@NonNull XmlElement customElement, @NonNull MergingReport.Builder mergingReport) { addElement(customElement, mergingReport); // add the custom namespace to the document generation. String nodeName = customElement.getXml().getNodeName(); if (!nodeName.contains(":")) { return; } @NonNull String prefix = nodeName.substring(0, nodeName.indexOf(':')); String namespace = customElement.getDocument().getRootNode() .getXml().getAttribute(SdkConstants.XMLNS_PREFIX + prefix); if (namespace != null) { getDocument().getRootNode().getXml().setAttributeNS( SdkConstants.XMLNS_URI, SdkConstants.XMLNS_PREFIX + prefix, namespace); } }
/** * Merges two children when this children's type allow multiple elements declaration with the * same key value. In that case, we only merge the lower priority child if there is not already * an element with the same key value that is equal to the lower priority child. Two children * are equals if they have the same attributes and children declared irrespective of the * declaration order. * * @param lowerPriorityChild the lower priority element's child. * @param mergingReport the merging report to log errors and actions. */ private void mergeChildrenWithMultipleDeclarations( @NonNull XmlElement lowerPriorityChild, @NonNull MergingReport.Builder mergingReport) { Preconditions.checkArgument(lowerPriorityChild.getType().areMultipleDeclarationAllowed()); if (lowerPriorityChild.getType().areMultipleDeclarationAllowed()) { for (XmlElement sameTypeChild : getAllNodesByType(lowerPriorityChild.getType())) { if (sameTypeChild.getId().equals(lowerPriorityChild.getId()) && sameTypeChild.isEquals(lowerPriorityChild)) { return; } } } // if we end up here, we never found a child of this element with the same key and strictly // equals to the lowerPriorityChild so we should merge it in. addElement(lowerPriorityChild, mergingReport); }
addElement(lowerPriorityChild, mergingReport); return; } else { if (!thisChild.isEquals(lowerPriorityChild)) { addElement(lowerPriorityChild, mergingReport);