com.android.sdklib.internal.repository
Class AddonsListFetcher

java.lang.Object
  extended by com.android.sdklib.internal.repository.AddonsListFetcher

public class AddonsListFetcher
extends java.lang.Object

Fetches and loads an sdk-addons-list XML.

Such an XML contains a simple list of add-ons site that are to be loaded by default by the SDK Manager.
The XML must conform to the sdk-addons-list-N.xsd.
Constants used in the XML are defined in SdkAddonsListConstants.


Nested Class Summary
static class AddonsListFetcher.Site
          An immutable structure representing an add-on site.
static class AddonsListFetcher.SiteType
           
 
Constructor Summary
AddonsListFetcher()
           
 
Method Summary
 AddonsListFetcher.Site[] fetch(java.lang.String url, DownloadCache cache, ITaskMonitor monitor)
          Fetches the addons list from the given URL.
protected  org.w3c.dom.Document getDocument(java.io.InputStream xml, ITaskMonitor monitor)
          Takes an XML document as a string as parameter and returns a DOM for it.
protected  int getXmlSchemaVersion(java.io.InputStream xml)
          Manually parses the root element of the XML to extract the schema version at the end of the xmlns:sdk="http://schemas.android.com/sdk/android/addons-list/$N" declaration.
protected  AddonsListFetcher.Site[] parseAddonsList(org.w3c.dom.Document doc, java.lang.String nsUri, java.lang.String baseUrl, ITaskMonitor monitor)
          Parse all sites defined in the Addons list XML and returns an array of sites.
protected  java.lang.String validateXml(java.io.InputStream xml, java.lang.String url, int version, java.lang.String[] outError, java.lang.Boolean[] validatorFound)
          Validates this XML against one of the requested SDK Repository schemas.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AddonsListFetcher

public AddonsListFetcher()
Method Detail

fetch

public AddonsListFetcher.Site[] fetch(java.lang.String url,
                                      DownloadCache cache,
                                      ITaskMonitor monitor)
Fetches the addons list from the given URL.

Parameters:
url - The URL of an XML file resource that conforms to the latest sdk-addons-list-N.xsd. For the default operation, use SdkAddonsListConstants.URL_ADDON_LIST. Cannot be null.
cache - The DownloadCache instance to use. Cannot be null.
monitor - A monitor to report errors. Cannot be null.
Returns:
An array of AddonsListFetcher.Site on success (possibly empty), or null on error.

getXmlSchemaVersion

protected int getXmlSchemaVersion(java.io.InputStream xml)
Manually parses the root element of the XML to extract the schema version at the end of the xmlns:sdk="http://schemas.android.com/sdk/android/addons-list/$N" declaration.

Returns:
1..SdkAddonsListConstants.NS_LATEST_VERSION for a valid schema version or 0 if no schema could be found.

validateXml

protected java.lang.String validateXml(java.io.InputStream xml,
                                       java.lang.String url,
                                       int version,
                                       java.lang.String[] outError,
                                       java.lang.Boolean[] validatorFound)
Validates this XML against one of the requested SDK Repository schemas. If the XML was correctly validated, returns the schema that worked. If it doesn't validate, returns null and stores the error in outError[0]. If we can't find a validator, returns null and set validatorFound[0] to false.


getDocument

protected org.w3c.dom.Document getDocument(java.io.InputStream xml,
                                           ITaskMonitor monitor)
Takes an XML document as a string as parameter and returns a DOM for it. On error, returns null and prints a (hopefully) useful message on the monitor.


parseAddonsList

protected AddonsListFetcher.Site[] parseAddonsList(org.w3c.dom.Document doc,
                                                   java.lang.String nsUri,
                                                   java.lang.String baseUrl,
                                                   ITaskMonitor monitor)
Parse all sites defined in the Addons list XML and returns an array of sites.

Parameters:
doc - The XML DOM to parse.
nsUri - The addons-list schema URI of the document.
baseUrl - The base URL of the caller (e.g. where addons-list-N.xml was fetched from.)
monitor - A non-null monitor to print to.