Class XmlResourceHelper

java.lang.Object
com.pnfsoftware.jeb.core.units.code.android.XmlResourceHelper
Direct Known Subclasses:
ApkXmlResourceHelper

public class XmlResourceHelper extends Object
This helper class facilitates access to the data contained in an XML resource. In particular, the readAttributeXxx methods allow easy retrieval of attribute values by tag names, throughout the entire document.
  • Field Details

    • doc

      protected Document doc
      Source XML document.
    • rootElt

      protected Element rootElt
      Root element of the source document.
  • Constructor Details

    • XmlResourceHelper

      public XmlResourceHelper(IXmlUnit xml)
      Create a helper around the provided XML unit.
      Parameters:
      xml - XML unit
    • XmlResourceHelper

      public XmlResourceHelper(Document doc)
      Create a helper around the provided low-level XML document object.
      Parameters:
      doc - XML document
  • Method Details

    • prepare

      protected void prepare(Document doc)
      The default implementation retrieves sets the doc and rootElt attributes. Overrides must call this implementation first.
      Parameters:
      doc - XML document
    • getRootElement

      public Element getRootElement()
      This low-level method offers access to the org.w3c.dom.Element holding the root.
      Returns:
      the document root element
    • buildAttributeName

      protected String buildAttributeName(String name)
      Build an attribute name usable for lookups.
      Parameters:
      name - attribute name
      Returns:
      the lookup name
    • convertNodelist

      protected List<Node> convertNodelist(NodeList nodelist)
      Convert a DOM node list to a Java list.
      Parameters:
      nodelist - DOM node list
      Returns:
      the converted list
    • convertEltlist

      protected List<Element> convertEltlist(NodeList nodelist)
      Convert a DOM node list to a Java list of elements.
      Parameters:
      nodelist - DOM node list of elements
      Returns:
      the converted list
    • readAttribute

      public String readAttribute(String tagName, String attrName)
      Retrieve the attribute value of the first tag having the provided name.
      Parameters:
      tagName - tag name, or null for the root manifest element
      attrName - attribute name
      Returns:
      the value (possibly empty if the attribute is not found in the tag), or null (if no element with the provided tag name was found in the document)
    • readAttributes

      public List<String> readAttributes(String tagName, String attrName)
      Retrieve the attribute values for all tags having the provided name.
      Parameters:
      tagName - tag name, or null for the root manifest element
      attrName - attribute name
      Returns:
      a list of non-null strings
    • hasAttributeValue

      public boolean hasAttributeValue(String tagName, String attrName, String wantedAttrValue)
      Determine if a tag has a specific attribute value.
      Parameters:
      tagName - tag name, or null for the root manifest element
      attrName - attribute name
      wantedAttrValue - expected attribute value
      Returns:
      true if the value is present
    • readMultiAttributes

      public List<List<String>> readMultiAttributes(String tagName, String... attrNames)
      Retrieve several attribute values for all tags having the provided name.
      Parameters:
      tagName - tag name, or null for the root manifest element
      attrNames - a collection of attributes to be retrieved
      Returns:
      rows of attribute values, one row per matching element
    • getAttr

      protected String getAttr(Element elt, String name)
      Retrieve an attribute value from an element.
      Parameters:
      elt - element
      name - attribute name
      Returns:
      the attribute value, or an empty string
    • isFullyQualifiedName

      protected boolean isFullyQualifiedName(String name)
      Determine if an attribute name includes a namespace prefix.
      Parameters:
      name - attribute name
      Returns:
      true if the name contains a prefix separator
    • isSimpleName

      protected boolean isSimpleName(String name)
      Determine if an attribute name has no namespace prefix.
      Parameters:
      name - attribute name
      Returns:
      true if the name is simple
    • getSimpleName

      protected String getSimpleName(String name)
      Remove a namespace prefix from a name.
      Parameters:
      name - attribute or element name
      Returns:
      the simple name