Package com.android.manifmerger
Class XmlElement
java.lang.Object
com.android.manifmerger.XmlNode
com.android.manifmerger.OrphanXmlElement
com.android.manifmerger.XmlElement
Xml
Element which is mergeable.
A mergeable element can contains 3 types of children :
- a child element, which itself may or may not be mergeable.
- xml attributes which are related to the element.
- tools oriented attributes to trigger specific behaviors from the merging tool
-
Nested Class Summary
Nested classes/interfaces inherited from class com.android.manifmerger.XmlNode
XmlNode.Name, XmlNode.NamespaceAwareName, XmlNode.NodeKey, XmlNode.NodeName -
Field Summary
Fields inherited from class com.android.manifmerger.XmlNode
NODE_TO_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAttribute(XmlAttribute attribute, String value) voidaddAttribute(String nsUri, String attrName, String attrValue) addChildElement(String childTagName) Add a new Child Element with no Attributes.voidaddChildElementWithSingleAttribute(String childTagName, String nsUri, String attrName, String attrValue) Add a new Element with a single specified Attribute to parentElementappendChild(XmlElement newChild) appendChild(Node newChild) voidapplyToFirstChildElementOfType(com.android.manifmerger.ManifestModel.NodeTypes nodeType, Consumer<XmlElement> nodeConsumer) Applies the provided consumer on the first child element of the provided node typeCompares this element with anotherXmlElementignoring all attributes belonging to theSdkConstants.TOOLS_URInamespace.createOrGetElementOfType(XmlDocument document, com.android.manifmerger.ManifestModel.NodeTypes nodeType, Consumer<XmlElement> postCreationAction) booleanelementUsesNamespacePrefix(String prefix) Check whether this element or any of its descendants have an attribute with the given namespacevoidenforceNamespaceDeclaration(String nsUri, String defaultPrefix) Check that given namespace is declared on the element and create one if not.findMergeableChild(Element childElement) com.google.common.collect.ImmutableList<XmlElement>getAllNodesByType(com.android.manifmerger.ManifestModel.NodeTypes type) Returns all immediate children of this node for a particular type, irrespective of their key.getAttribute(XmlNode.NodeName attributeName) Returns theXmlAttributefor an attribute present on this xml element, orOptional.empty()if not present.intcom.google.common.collect.ImmutableList<String>getAttributeNames(Predicate<Node> nodePredicate) Collection<Map.Entry<XmlNode.NodeName,com.android.manifmerger.AttributeOperationType>> com.android.manifmerger.AttributeOperationTypegetAttributeOperationType(XmlNode.NodeName attributeName) Get the attribute operation type as optionally specified by the user.Returns the list of attributes for this xml element.Returns the owningXmlDocumentcom.google.common.collect.ImmutableList<XmlElement>getNodeByTypeAndKey(com.android.manifmerger.ManifestModel.NodeTypes type, String keyValue) Returns a child of a particular type and a particular key.Get the node operation type as optionally specified by the user.List<com.android.manifmerger.OverrideLibrarySelector>com.android.ide.common.blame.SourcePositionReturns the element's positionReturns a potentially null (if not present) selector decoration on this element.com.android.ide.common.blame.SourceFileReturns the element's document xml source file location.insertBefore(XmlElement newChild, Node refChild) insertBefore(Node newChild, Node refChild) Inserts the node newChild before the existing child node refChild.booleanisEquals(XmlElement otherNode) voidmergeChildren(XmlElement lowerPriorityNode, MergingReport.Builder mergingReport, ManifestMerger2.ProcessCancellationChecker processCancellationChecker) voidmergeWithLowerPriorityNode(XmlElement lowerPriorityNode, MergingReport.Builder mergingReport, ManifestMerger2.ProcessCancellationChecker processCancellationChecker) Merge this xml element with a lower priority node.voidremoveAttribute(String name) voidremoveAttributeNS(String namespaceURI, String localName) removeChild(XmlElement oldChild) removeChild(Node oldChild) Removes given child from DOM and from this list ofmMergeableChildrenvoidsetAttribute(XmlAttribute attribute, String value) voidsetAttribute(String name, String value) voidsetAttributeNS(String namespaceURI, String qualifiedName, String value) booleanReturns true if this element supports having a tools:selector decoration, false otherwise.Methods inherited from class com.android.manifmerger.OrphanXmlElement
getAttributeInfo, getAttributeNode, getAttributeNodeNS, getAttributeValue, getId, getKey, getName, getNamespaceURI, getTagName, getType, getXml, isA, lookupNamespacePrefix, lookupNamespacePrefixMethods inherited from class com.android.manifmerger.XmlNode
fromNSName, fromXmlName, getOriginalId, getSourceFilePosition, printPosition, unwrapName
-
Constructor Details
-
XmlElement
-
-
Method Details
-
applyToFirstChildElementOfType
public void applyToFirstChildElementOfType(@NonNull com.android.manifmerger.ManifestModel.NodeTypes nodeType, Consumer<XmlElement> nodeConsumer) Applies the provided consumer on the first child element of the provided node type- Parameters:
nodeType-nodeConsumer-
-
elementUsesNamespacePrefix
Check whether this element or any of its descendants have an attribute with the given namespace- Parameters:
prefix- the namespace prefix under consideration- Returns:
- true if element or any of its descendants have an attribute with the given namespace, false otherwise.
-
getDocument
Returns the owningXmlDocument -
getAttributes
Returns the list of attributes for this xml element. -
removeChild
Removes given child from DOM and from this list ofmMergeableChildren- Parameters:
oldChild- Child element to be deleted.- Returns:
- Child element we deleted, null if the child could not be deleted.
-
removeChild
-
getAttributeCount
public int getAttributeCount() -
getAttributeNames
-
insertBefore
Inserts the node newChild before the existing child node refChild.- Parameters:
newChild- The node to insert.refChild- The node before which the new node must be inserted.- Returns:
- The inserted node.
-
insertBefore
-
appendChild
-
appendChild
-
addChildElement
Add a new Child Element with no Attributes.- Parameters:
childTagName- tag name of the child added to the element- Returns:
- child
XmlElementobject. - Throws:
RuntimeException- if we fail to add child element
-
addChildElementWithSingleAttribute
public void addChildElementWithSingleAttribute(String childTagName, String nsUri, String attrName, String attrValue) Add a new Element with a single specified Attribute to parentElement -
findMergeableChild
-
createOrGetElementOfType
@NonNull public XmlElement createOrGetElementOfType(XmlDocument document, com.android.manifmerger.ManifestModel.NodeTypes nodeType, Consumer<XmlElement> postCreationAction) -
setAttribute
-
setAttribute
-
addAttribute
-
addAttribute
-
removeAttributeNS
-
removeAttribute
-
setAttributeNS
-
getAttribute
Returns theXmlAttributefor an attribute present on this xml element, orOptional.empty()if not present.- Parameters:
attributeName- the attribute name.
-
getOperationType
Get the node operation type as optionally specified by the user. If the user did not explicitly specify how conflicting elements should be handled, aNodeOperationType.MERGEwill be returned. -
getAttributeOperationType
@NonNull public com.android.manifmerger.AttributeOperationType getAttributeOperationType(XmlNode.NodeName attributeName) Get the attribute operation type as optionally specified by the user. If the user did not explicitly specify how conflicting attributes should be handled, aAttributeOperationType.STRICTwill be returned. -
getAttributeOperations
@NonNull public Collection<Map.Entry<XmlNode.NodeName,com.android.manifmerger.AttributeOperationType>> getAttributeOperations() -
getOverrideUsesSdkLibrarySelectors
@NonNull public List<com.android.manifmerger.OverrideLibrarySelector> getOverrideUsesSdkLibrarySelectors() -
getPosition
@NonNull public com.android.ide.common.blame.SourcePosition getPosition()Description copied from class:XmlNodeReturns the element's position- Overrides:
getPositionin classOrphanXmlElement
-
getSourceFile
@NonNull public com.android.ide.common.blame.SourceFile getSourceFile()Description copied from class:XmlNodeReturns the element's document xml source file location.- Overrides:
getSourceFilein classOrphanXmlElement
-
mergeWithLowerPriorityNode
public void mergeWithLowerPriorityNode(@NonNull XmlElement lowerPriorityNode, @NonNull MergingReport.Builder mergingReport, ManifestMerger2.ProcessCancellationChecker processCancellationChecker) Merge this xml element with a lower priority node.For now, attributes will be merged. If present on both xml elements, a warning will be issued and the attribute merge will be rejected.
- Parameters:
lowerPriorityNode- lower priority Xml element to merge with.mergingReport- the merging report to log errors and actions.processCancellationChecker- checks if the request to merge is cancelled.
-
getMergeableElements
-
getNodeByTypeAndKey
@NonNull public Optional<XmlElement> getNodeByTypeAndKey(com.android.manifmerger.ManifestModel.NodeTypes type, @Nullable String keyValue) Returns a child of a particular type and a particular key.- Parameters:
type- the requested child type.keyValue- the requested child key.- Returns:
- the child of
Optional.empty()()} if no child of this type and key exist.
-
getAllNodesByType
@NonNull public com.google.common.collect.ImmutableList<XmlElement> getAllNodesByType(com.android.manifmerger.ManifestModel.NodeTypes type) Returns all immediate children of this node for a particular type, irrespective of their key.- Parameters:
type- the type of children element requested.- Returns:
- the list (potentially empty) of children.
-
mergeChildren
public void mergeChildren(@NonNull XmlElement lowerPriorityNode, @NonNull MergingReport.Builder mergingReport, @NonNull ManifestMerger2.ProcessCancellationChecker processCancellationChecker) -
supportsSelector
public boolean supportsSelector()Returns true if this element supports having a tools:selector decoration, false otherwise. -
enforceNamespaceDeclaration
Check that given namespace is declared on the element and create one if not.- Parameters:
nsUri- The namespace URI of which the prefix is to be founddefaultPrefix- The default prefix (root) to use if the namespace is not found. If null, do not create a new namespace if this URI is not defined for the document.- See Also:
-
XmlUtils.lookupNamespacePrefix(Node, String, boolean)
-
isEquals
-
getSelector
Returns a potentially null (if not present) selector decoration on this element. -
compareTo
Compares this element with anotherXmlElementignoring all attributes belonging to theSdkConstants.TOOLS_URInamespace.- Parameters:
other- the other element to compare against.- Returns:
- a
Stringdescribing the differences between the two XML elements orOptional.empty()()} if they are equals.
-