aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/SdkAddonConstants.java
blob: 4af2276bfb1884b43d4456bc9bb946d6a77851fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.eclipse.org/org/documents/epl-v10.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.sdklib.repository;


import com.android.sdklib.internal.repository.sources.SdkSource;

import java.io.InputStream;

/**
 * Public constants for the sdk-addon XML Schema.
 */
public class SdkAddonConstants extends RepoConstants {

    /**
     * The default name looked for by {@link SdkSource} when trying to load an
     * sdk-addon XML if the URL doesn't match an existing resource.
     */
    public static final String URL_DEFAULT_FILENAME = "addon.xml";         //$NON-NLS-1$

    /** The base of our sdk-addon XML namespace. */
    private static final String NS_BASE =
        "http://schemas.android.com/sdk/android/addon/";                   //$NON-NLS-1$

    /**
     * The pattern of our sdk-addon XML namespace.
     * Matcher's group(1) is the schema version (integer).
     */
    public static final String NS_PATTERN = NS_BASE + "([1-9][0-9]*)";     //$NON-NLS-1$

    /**
     * The latest version of the sdk-addon XML Schema.
     * Valid version numbers are between 1 and this number, included.
     */
    public static final int NS_LATEST_VERSION = 5;

    /** The XML namespace of the latest sdk-addon XML. */
    public static final String NS_URI = getSchemaUri(NS_LATEST_VERSION);

    /** The root sdk-addon element */
    public static final String NODE_SDK_ADDON       = "sdk-addon";         //$NON-NLS-1$

    /** An add-on package. */
    public static final String NODE_ADD_ON          = "add-on";            //$NON-NLS-1$

    /** An extra package. */
    public static final String NODE_EXTRA           = "extra";             //$NON-NLS-1$

    /**
     * List of possible nodes in a repository XML. Used to populate options automatically
     * in the no-GUI mode.
     */
    public static final String[] NODES = {
        NODE_ADD_ON,
        NODE_EXTRA
    };

    /**
     * Returns a stream to the requested {@code sdk-addon} XML Schema.
     *
     * @param version Between 1 and {@link #NS_LATEST_VERSION}, included.
     * @return An {@link InputStream} object for the local XSD file or
     *         null if there is no schema for the requested version.
     */
    public static InputStream getXsdStream(int version) {
        return getXsdStream(NODE_SDK_ADDON, version);
    }

    /**
     * Returns the URI of the sdk-addon schema for the given version number.
     * @param version Between 1 and {@link #NS_LATEST_VERSION} included.
     */
    public static String getSchemaUri(int version) {
        return String.format(NS_BASE + "%d", version);           //$NON-NLS-1$
    }
}