Home | History | Annotate | Download | only in repository
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.eclipse.org/org/documents/epl-v10.php
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.sdklib.repository;
     18 
     19 
     20 import java.io.InputStream;
     21 
     22 /**
     23  * Public constants for the sdk-stats XML Schema.
     24  */
     25 public class SdkStatsConstants {
     26 
     27     /** The canonical URL filename for addons-list XML files. */
     28     public static final String URL_DEFAULT_FILENAME = "stats-1.xml";                //$NON-NLS-1$
     29 
     30     /** The URL where to find the official addons list fle. */
     31     public static final String URL_STATS =
     32         SdkRepoConstants.URL_GOOGLE_SDK_SITE + URL_DEFAULT_FILENAME;
     33 
     34     /** The base of our sdk-addons-list XML namespace. */
     35     private static final String NS_BASE =
     36         "http://schemas.android.com/sdk/android/stats/";                            //$NON-NLS-1$
     37 
     38     /**
     39      * The pattern of our sdk-stats XML namespace.
     40      * Matcher's group(1) is the schema version (integer).
     41      */
     42     public static final String NS_PATTERN = NS_BASE + "([1-9][0-9]*)";              //$NON-NLS-1$
     43 
     44     /** The latest version of the sdk-stats XML Schema.
     45      *  Valid version numbers are between 1 and this number, included. */
     46     public static final int NS_LATEST_VERSION = 1;
     47 
     48     /** The XML namespace of the latest sdk-stats XML. */
     49     public static final String NS_URI = getSchemaUri(NS_LATEST_VERSION);
     50 
     51     /** The root sdk-stats element */
     52     public static final String NODE_SDK_STATS = "sdk-stats";                        //$NON-NLS-1$
     53 
     54     /** A platform stat. */
     55     public static final String NODE_PLATFORM = "platform";                          //$NON-NLS-1$
     56 
     57     /** The Android API Level for the platform. An int > 0. */
     58     public static final String NODE_API_LEVEL = "api-level";                        //$NON-NLS-1$
     59 
     60     /** The official codename for this platform, for example "Cupcake". */
     61     public static final String NODE_CODENAME = "codename";                          //$NON-NLS-1$
     62 
     63     /** The official version name of this platform, for example "Android 1.5". */
     64     public static final String NODE_VERSION = "version";                            //$NON-NLS-1$
     65 
     66     /**
     67      * The <em>approximate</em> share percentage of that platform.
     68      * See the caveat in sdk-stats-1.xsd about value freshness and accuracy.
     69      */
     70     public static final String NODE_SHARE = "share";                                //$NON-NLS-1$
     71 
     72     /**
     73      * Returns a stream to the requested sdk-stats XML Schema.
     74      *
     75      * @param version Between 1 and {@link #NS_LATEST_VERSION}, included.
     76      * @return An {@link InputStream} object for the local XSD file or
     77      *         null if there is no schema for the requested version.
     78      */
     79     public static InputStream getXsdStream(int version) {
     80         String filename = String.format("sdk-stats-%d.xsd", version);       //$NON-NLS-1$
     81         return SdkStatsConstants.class.getResourceAsStream(filename);
     82     }
     83 
     84     /**
     85      * Returns the URI of the sdk-stats schema for the given version number.
     86      * @param version Between 1 and {@link #NS_LATEST_VERSION} included.
     87      */
     88     public static String getSchemaUri(int version) {
     89         return String.format(NS_BASE + "%d", version);                      //$NON-NLS-1$
     90     }
     91 }
     92