com.android.manifmerger
Class XmlElement

java.lang.Object
  extended by com.android.manifmerger.XmlNode
      extended by com.android.manifmerger.OrphanXmlElement
          extended by com.android.manifmerger.XmlElement

public class XmlElement
extends OrphanXmlElement

Xml Element which is mergeable. A mergeable element can contains 3 types of children :

The two main responsibilities of this class is to be capable of comparing itself against another instance of the same type as well as providing XML element merging capabilities.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.android.manifmerger.XmlNode
XmlNode.NodeKey, XmlNode.NodeName
 
Field Summary
 
Fields inherited from class com.android.manifmerger.XmlNode
NODE_TO_NAME
 
Constructor Summary
XmlElement(org.w3c.dom.Element xml, XmlDocument document)
           
 
Method Summary
 com.google.common.base.Optional<java.lang.String> compareTo(java.lang.Object other)
          Compares this element with another XmlElement ignoring all attributes belonging to the SdkConstants.TOOLS_URI namespace.
 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.
 com.google.common.base.Optional<XmlAttribute> getAttribute(XmlNode.NodeName attributeName)
          Returns the XmlAttribute for an attribute present on this xml element, or Optional.absent() if not present.
 java.util.Collection<java.util.Map.Entry<XmlNode.NodeName,com.android.manifmerger.AttributeOperationType>> getAttributeOperations()
           
 com.android.manifmerger.AttributeOperationType getAttributeOperationType(XmlNode.NodeName attributeName)
          Get the attribute operation type as optionally specified by the user.
 java.util.List<XmlAttribute> getAttributes()
          Returns the list of attributes for this xml element.
 XmlDocument getDocument()
          Returns the owning XmlDocument
 com.google.common.collect.ImmutableList<XmlElement> getMergeableElements()
           
 com.google.common.base.Optional<XmlElement> getNodeByTypeAndKey(com.android.manifmerger.ManifestModel.NodeTypes type, java.lang.String keyValue)
          Returns a child of a particular type and a particular key.
 NodeOperationType getOperationType()
          Get the node operation type as optionally specified by the user.
 java.util.List<Selector> getOverrideUsesSdkLibrarySelectors()
           
 com.android.utils.PositionXmlParser.Position getPosition()
          Returns the element's position
 Selector getSelector()
          Returns a potentially null (if not present) selector decoration on this element.
 XmlLoader.SourceLocation getSourceLocation()
          Returns the element's document xml source file location.
 boolean isEquals(XmlElement otherNode)
           
 void mergeChildren(XmlElement lowerPriorityNode, com.android.manifmerger.MergingReport.Builder mergingReport)
           
 void mergeWithLowerPriorityNode(XmlElement lowerPriorityNode, com.android.manifmerger.MergingReport.Builder mergingReport)
          Merge this xml element with a lower priority node.
 boolean supportsSelector()
          Returns true if this element supports having a tools:selector decoration, false otherwise.
 
Methods inherited from class com.android.manifmerger.OrphanXmlElement
getId, getKey, getName, getType, getXml, isA
 
Methods inherited from class com.android.manifmerger.XmlNode
fromNSName, fromXmlName, getColumn, getLine, printPosition, printPosition, unwrapName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlElement

public XmlElement(@NonNull
                  org.w3c.dom.Element xml,
                  @NonNull
                  XmlDocument document)
Method Detail

getDocument

@NonNull
public XmlDocument getDocument()
Returns the owning XmlDocument


getAttributes

public java.util.List<XmlAttribute> getAttributes()
Returns the list of attributes for this xml element.


getAttribute

public com.google.common.base.Optional<XmlAttribute> getAttribute(XmlNode.NodeName attributeName)
Returns the XmlAttribute for an attribute present on this xml element, or Optional.absent() if not present.

Parameters:
attributeName - the attribute name.

getOperationType

public NodeOperationType 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, a NodeOperationType.MERGE will be returned.


getAttributeOperationType

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, a AttributeOperationType.STRICT will be returned.


getAttributeOperations

public java.util.Collection<java.util.Map.Entry<XmlNode.NodeName,com.android.manifmerger.AttributeOperationType>> getAttributeOperations()

getOverrideUsesSdkLibrarySelectors

@NonNull
public java.util.List<Selector> getOverrideUsesSdkLibrarySelectors()

getPosition

@NonNull
public com.android.utils.PositionXmlParser.Position getPosition()
Description copied from class: XmlNode
Returns the element's position

Overrides:
getPosition in class OrphanXmlElement

getSourceLocation

@NonNull
public XmlLoader.SourceLocation getSourceLocation()
Description copied from class: XmlNode
Returns the element's document xml source file location.

Overrides:
getSourceLocation in class OrphanXmlElement

mergeWithLowerPriorityNode

public void mergeWithLowerPriorityNode(XmlElement lowerPriorityNode,
                                       com.android.manifmerger.MergingReport.Builder mergingReport)
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.

getMergeableElements

public com.google.common.collect.ImmutableList<XmlElement> getMergeableElements()

getNodeByTypeAndKey

public com.google.common.base.Optional<XmlElement> getNodeByTypeAndKey(com.android.manifmerger.ManifestModel.NodeTypes type,
                                                                       @Nullable
                                                                       java.lang.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.absent() if no child of this type and key exist.

getAllNodesByType

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(XmlElement lowerPriorityNode,
                          com.android.manifmerger.MergingReport.Builder mergingReport)

supportsSelector

public boolean supportsSelector()
Returns true if this element supports having a tools:selector decoration, false otherwise.


isEquals

public boolean isEquals(XmlElement otherNode)

getSelector

@Nullable
public Selector getSelector()
Returns a potentially null (if not present) selector decoration on this element.


compareTo

public com.google.common.base.Optional<java.lang.String> compareTo(java.lang.Object other)
Compares this element with another XmlElement ignoring all attributes belonging to the SdkConstants.TOOLS_URI namespace.

Parameters:
other - the other element to compare against.
Returns:
a String describing the differences between the two XML elements or Optional.absent() if they are equals.