Home | History | Annotate | Download | only in repository
      1 /*
      2  * Copyright (C) 2009 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 com.android.sdklib.internal.repository.SdkSource;
     21 
     22 import java.io.InputStream;
     23 
     24 /**
     25  * Public constants for the sdk-repository XML Schema.
     26  */
     27 public class SdkRepoConstants extends RepoConstants {
     28 
     29     /** The latest version of the sdk-repository XML Schema.
     30      *  Valid version numbers are between 1 and this number, included. */
     31     public static final int NS_LATEST_VERSION = 5;
     32 
     33     /** The URL of the official Google sdk-repository site.
     34      *  The URL ends with a /, allowing easy concatenation. */
     35     public static final String URL_GOOGLE_SDK_SITE =
     36         "https://dl-ssl.google.com/android/repository/";                        //$NON-NLS-1$
     37 
     38     /** The default name looked for by {@link SdkSource} when trying to load an
     39      * sdk-repository XML if the URL doesn't match an existing resource. */
     40     public static final String URL_DEFAULT_FILENAME = "repository.xml";         //$NON-NLS-1$
     41 
     42     /** The pattern name looked by {@link SdkSource} when trying to load
     43      * the latest sdk-repository XML that is specific to the current XSD
     44      * schema revision.
     45      */
     46     public static final String URL_DEFAULT_FILENAME2 =
     47         String.format("repository-%d.xml", NS_LATEST_VERSION);                  //$NON-NLS-1$
     48 
     49     /** The base of our sdk-repository XML namespace. */
     50     private static final String NS_BASE =
     51         "http://schemas.android.com/sdk/android/repository/";                   //$NON-NLS-1$
     52 
     53     /**
     54      * The pattern of our sdk-repository XML namespace.
     55      * Matcher's group(1) is the schema version (integer).
     56      */
     57     public static final String NS_PATTERN = NS_BASE + "([1-9][0-9]*)";          //$NON-NLS-1$
     58 
     59     /** The XML namespace of the latest sdk-repository XML. */
     60     public static final String NS_URI = getSchemaUri(NS_LATEST_VERSION);
     61 
     62     /** The root sdk-repository element */
     63     public static final String NODE_SDK_REPOSITORY = "sdk-repository";        //$NON-NLS-1$
     64 
     65     /** A platform package. */
     66     public static final String NODE_PLATFORM        = "platform";             //$NON-NLS-1$
     67     /** A tool package. */
     68     public static final String NODE_TOOL            = "tool";                 //$NON-NLS-1$
     69     /** A platform-tool package. */
     70     public static final String NODE_PLATFORM_TOOL   = "platform-tool";        //$NON-NLS-1$
     71     /** A doc package. */
     72     public static final String NODE_DOC             = "doc";                  //$NON-NLS-1$
     73     /** A sample package. */
     74     public static final String NODE_SAMPLE          = "sample";               //$NON-NLS-1$
     75     /** A system-image package. */
     76     public static final String NODE_SYSTEM_IMAGE    = "system-image";         //$NON-NLS-1$
     77     /** A source package. */
     78     public static final String NODE_SOURCE          = "source";               //$NON-NLS-1$
     79 
     80     /* An included-ABI element for a system-image package. */
     81     public static final String NODE_ABI_INCLUDED    = "included-abi";         //$NON-NLS-1$
     82     /* An ABI element for a system-image package. */
     83     public static final String NODE_ABI             = "abi";                  //$NON-NLS-1$
     84 
     85 
     86     /**
     87      * List of possible nodes in a repository XML. Used to populate options automatically
     88      * in the no-GUI mode.
     89      */
     90     public static final String[] NODES = {
     91         NODE_PLATFORM,
     92         NODE_SYSTEM_IMAGE,
     93         NODE_TOOL,
     94         NODE_PLATFORM_TOOL,
     95         NODE_DOC,
     96         NODE_SAMPLE,
     97         NODE_EXTRA,
     98         NODE_SOURCE,
     99     };
    100 
    101     /**
    102      * Returns a stream to the requested {@code sdk-repository} XML Schema.
    103      *
    104      * @param version Between 1 and {@link #NS_LATEST_VERSION}, included.
    105      * @return An {@link InputStream} object for the local XSD file or
    106      *         null if there is no schema for the requested version.
    107      */
    108     public static InputStream getXsdStream(int version) {
    109         return getXsdStream(NODE_SDK_REPOSITORY, version);
    110     }
    111 
    112     /**
    113      * Returns the URI of the SDK Repository schema for the given version number.
    114      * @param version Between 1 and {@link #NS_LATEST_VERSION} included.
    115      */
    116     public static String getSchemaUri(int version) {
    117         return String.format(NS_BASE + "%d", version);           //$NON-NLS-1$
    118     }
    119 }
    120