com.android.sdklib.internal.repository.packages
Class PackageParserUtils

java.lang.Object
  extended by com.android.sdklib.internal.repository.packages.PackageParserUtils

public class PackageParserUtils
extends java.lang.Object

Misc utilities to help extracting elements and attributes out of an XML document.


Constructor Summary
PackageParserUtils()
           
 
Method Summary
static org.w3c.dom.Node findChildElement(org.w3c.dom.Node node, java.lang.String xmlLocalName)
          Returns the first child element with the given XML local name.
static java.lang.Object getEnumAttribute(org.w3c.dom.Node archiveNode, java.lang.String attrName, java.lang.Object[] values, java.lang.Object defaultValue)
          Retrieve an attribute which value must match one of the given enums using a case-insensitive name match.
static java.lang.String getOptionalXmlString(org.w3c.dom.Node node, java.lang.String xmlLocalName)
          Retrieves the value of that XML element as a string.
static int getXmlInt(org.w3c.dom.Node node, java.lang.String xmlLocalName, int defaultValue)
          Retrieves the value of that XML element as an integer.
static long getXmlLong(org.w3c.dom.Node node, java.lang.String xmlLocalName, long defaultValue)
          Retrieves the value of that XML element as a long.
static java.lang.String getXmlString(org.w3c.dom.Node node, java.lang.String xmlLocalName)
          Retrieves the value of that XML element as a string.
static FullRevision parseFullRevisionElement(org.w3c.dom.Node revisionNode)
          Parses a full revision element such as or .
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PackageParserUtils

public PackageParserUtils()
Method Detail

parseFullRevisionElement

public static FullRevision parseFullRevisionElement(org.w3c.dom.Node revisionNode)
Parses a full revision element such as or . This supports both the single-integer format as well as the full revision format with major/minor/micro/preview sub-elements.

Parameters:
revisionNode - The node to parse.
Returns:
A new FullRevision. If parsing failed, major is set to FullRevision.MISSING_MAJOR_REV.

findChildElement

public static org.w3c.dom.Node findChildElement(org.w3c.dom.Node node,
                                                java.lang.String xmlLocalName)
Returns the first child element with the given XML local name. If xmlLocalName is null, returns the very first child element.


getXmlString

public static java.lang.String getXmlString(org.w3c.dom.Node node,
                                            java.lang.String xmlLocalName)
Retrieves the value of that XML element as a string. Returns an empty string whether the element is missing or empty, so you can't tell the difference.

Note: use getOptionalXmlString(Node, String) if you need to know when the element is missing versus empty.

Parameters:
node - The XML parent node to parse.
xmlLocalName - The XML local name to find in the parent node.
Returns:
The text content of the element. Returns an empty string whether the element is missing or empty, so you can't tell the difference.

getOptionalXmlString

public static java.lang.String getOptionalXmlString(org.w3c.dom.Node node,
                                                    java.lang.String xmlLocalName)
Retrieves the value of that XML element as a string. Returns null when the element is missing, so you can tell between a missing element and an empty one.

Note: use getXmlString(Node, String) if you don't need to know when the element is missing versus empty.

Parameters:
node - The XML parent node to parse.
xmlLocalName - The XML local name to find in the parent node.
Returns:
The text content of the element. Returns null when the element is missing. Returns an empty string whether the element is present but empty.

getXmlInt

public static int getXmlInt(org.w3c.dom.Node node,
                            java.lang.String xmlLocalName,
                            int defaultValue)
Retrieves the value of that XML element as an integer. Returns the default value when the element is missing or is not an integer.


getXmlLong

public static long getXmlLong(org.w3c.dom.Node node,
                              java.lang.String xmlLocalName,
                              long defaultValue)
Retrieves the value of that XML element as a long. Returns the default value when the element is missing or is not an integer.


getEnumAttribute

public static java.lang.Object getEnumAttribute(org.w3c.dom.Node archiveNode,
                                                java.lang.String attrName,
                                                java.lang.Object[] values,
                                                java.lang.Object defaultValue)
Retrieve an attribute which value must match one of the given enums using a case-insensitive name match. Returns defaultValue if the attribute does not exist or its value does not match the given enum values.