aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/com/android
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-08-10 18:30:26 -0700
committerXavier Ducrohet <xav@android.com>2012-08-13 17:37:44 -0700
commit81cefe2a26dd6db8a878e30874d12cdcbff0e83b (patch)
tree970e5de5045fe1fa5255c3dd868cecc413f23beb /common/src/com/android
parenteb0e35abd8ec368b10ec2026642583ac8b330929 (diff)
downloadsdk-81cefe2a26dd6db8a878e30874d12cdcbff0e83b.zip
sdk-81cefe2a26dd6db8a878e30874d12cdcbff0e83b.tar.gz
sdk-81cefe2a26dd6db8a878e30874d12cdcbff0e83b.tar.bz2
More refactoring.
Move stuff out of sdklib into common and ide_common. Remove androidprefs and move the one class into common. Change-Id: I71d126a13cf2ba413692e29616f4968a37d7b33a
Diffstat (limited to 'common/src/com/android')
-rw-r--r--common/src/com/android/SdkConstants.java508
-rw-r--r--common/src/com/android/prefs/AndroidLocation.java116
-rw-r--r--common/src/com/android/xml/AndroidManifest.java359
-rw-r--r--common/src/com/android/xml/AndroidXPathFactory.java113
4 files changed, 1096 insertions, 0 deletions
diff --git a/common/src/com/android/SdkConstants.java b/common/src/com/android/SdkConstants.java
new file mode 100644
index 0000000..b9be585
--- /dev/null
+++ b/common/src/com/android/SdkConstants.java
@@ -0,0 +1,508 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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;
+
+import com.android.AndroidConstants;
+
+import java.io.File;
+
+/**
+ * Constant definition class.<br>
+ * <br>
+ * Most constants have a prefix defining the content.
+ * <ul>
+ * <li><code>OS_</code> OS path constant. These paths are different depending on the platform.</li>
+ * <li><code>FN_</code> File name constant.</li>
+ * <li><code>FD_</code> Folder name constant.</li>
+ * </ul>
+ *
+ */
+public final class SdkConstants {
+ public final static int PLATFORM_UNKNOWN = 0;
+ public final static int PLATFORM_LINUX = 1;
+ public final static int PLATFORM_WINDOWS = 2;
+ public final static int PLATFORM_DARWIN = 3;
+
+ /**
+ * Returns current platform, one of {@link #PLATFORM_WINDOWS}, {@link #PLATFORM_DARWIN},
+ * {@link #PLATFORM_LINUX} or {@link #PLATFORM_UNKNOWN}.
+ */
+ public final static int CURRENT_PLATFORM = currentPlatform();
+
+ /**
+ * Charset for the ini file handled by the SDK.
+ */
+ public final static String INI_CHARSET = "UTF-8"; //$NON-NLS-1$
+
+ /** An SDK Project's AndroidManifest.xml file */
+ public static final String FN_ANDROID_MANIFEST_XML= "AndroidManifest.xml"; //$NON-NLS-1$
+ /** pre-dex jar filename. i.e. "classes.jar" */
+ public final static String FN_CLASSES_JAR = "classes.jar"; //$NON-NLS-1$
+ /** Dex filename inside the APK. i.e. "classes.dex" */
+ public final static String FN_APK_CLASSES_DEX = "classes.dex"; //$NON-NLS-1$
+
+ /** An SDK Project's build.xml file */
+ public final static String FN_BUILD_XML = "build.xml"; //$NON-NLS-1$
+
+ /** Name of the framework library, i.e. "android.jar" */
+ public static final String FN_FRAMEWORK_LIBRARY = "android.jar"; //$NON-NLS-1$
+ /** Name of the layout attributes, i.e. "attrs.xml" */
+ public static final String FN_ATTRS_XML = "attrs.xml"; //$NON-NLS-1$
+ /** Name of the layout attributes, i.e. "attrs_manifest.xml" */
+ public static final String FN_ATTRS_MANIFEST_XML = "attrs_manifest.xml"; //$NON-NLS-1$
+ /** framework aidl import file */
+ public static final String FN_FRAMEWORK_AIDL = "framework.aidl"; //$NON-NLS-1$
+ /** framework renderscript folder */
+ public static final String FN_FRAMEWORK_RENDERSCRIPT = "renderscript"; //$NON-NLS-1$
+ /** framework include folder */
+ public static final String FN_FRAMEWORK_INCLUDE = "include"; //$NON-NLS-1$
+ /** framework include (clang) folder */
+ public static final String FN_FRAMEWORK_INCLUDE_CLANG = "clang-include"; //$NON-NLS-1$
+ /** layoutlib.jar file */
+ public static final String FN_LAYOUTLIB_JAR = "layoutlib.jar"; //$NON-NLS-1$
+ /** widget list file */
+ public static final String FN_WIDGETS = "widgets.txt"; //$NON-NLS-1$
+ /** Intent activity actions list file */
+ public static final String FN_INTENT_ACTIONS_ACTIVITY = "activity_actions.txt"; //$NON-NLS-1$
+ /** Intent broadcast actions list file */
+ public static final String FN_INTENT_ACTIONS_BROADCAST = "broadcast_actions.txt"; //$NON-NLS-1$
+ /** Intent service actions list file */
+ public static final String FN_INTENT_ACTIONS_SERVICE = "service_actions.txt"; //$NON-NLS-1$
+ /** Intent category list file */
+ public static final String FN_INTENT_CATEGORIES = "categories.txt"; //$NON-NLS-1$
+
+ /** annotations support jar */
+ public static final String FN_ANNOTATIONS_JAR = "annotations.jar"; //$NON-NLS-1$
+
+ /** platform build property file */
+ public final static String FN_BUILD_PROP = "build.prop"; //$NON-NLS-1$
+ /** plugin properties file */
+ public final static String FN_PLUGIN_PROP = "plugin.prop"; //$NON-NLS-1$
+ /** add-on manifest file */
+ public final static String FN_MANIFEST_INI = "manifest.ini"; //$NON-NLS-1$
+ /** add-on layout device XML file. */
+ public final static String FN_DEVICES_XML = "devices.xml"; //$NON-NLS-1$
+ /** hardware properties definition file */
+ public final static String FN_HARDWARE_INI = "hardware-properties.ini"; //$NON-NLS-1$
+
+ /** project property file */
+ public final static String FN_PROJECT_PROPERTIES = "project.properties"; //$NON-NLS-1$
+
+ /** project local property file */
+ public final static String FN_LOCAL_PROPERTIES = "local.properties"; //$NON-NLS-1$
+
+ /** project ant property file */
+ public final static String FN_ANT_PROPERTIES = "ant.properties"; //$NON-NLS-1$
+
+ /** Skin layout file */
+ public final static String FN_SKIN_LAYOUT = "layout"; //$NON-NLS-1$
+
+ /** dx.jar file */
+ public static final String FN_DX_JAR = "dx.jar"; //$NON-NLS-1$
+
+ /** dx executable (with extension for the current OS) */
+ public final static String FN_DX =
+ "dx" + ext(".bat", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ /** aapt executable (with extension for the current OS) */
+ public final static String FN_AAPT =
+ "aapt" + ext(".exe", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ /** aidl executable (with extension for the current OS) */
+ public final static String FN_AIDL =
+ "aidl" + ext(".exe", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ /** renderscript executable (with extension for the current OS) */
+ public final static String FN_RENDERSCRIPT =
+ "llvm-rs-cc" + ext(".exe", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ /** adb executable (with extension for the current OS) */
+ public final static String FN_ADB =
+ "adb" + ext(".exe", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ /** emulator executable for the current OS */
+ public final static String FN_EMULATOR =
+ "emulator" + ext(".exe", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ /** zipalign executable (with extension for the current OS) */
+ public final static String FN_ZIPALIGN =
+ "zipalign" + ext(".exe", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ /** dexdump executable (with extension for the current OS) */
+ public final static String FN_DEXDUMP =
+ "dexdump" + ext(".exe", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ /** proguard executable (with extension for the current OS) */
+ public final static String FN_PROGUARD =
+ "proguard" + ext(".bat", ".sh"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ /** find_lock for Windows (with extension for the current OS) */
+ public final static String FN_FIND_LOCK =
+ "find_lock" + ext(".exe", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ /** properties file for SDK Updater packages */
+ public final static String FN_SOURCE_PROP = "source.properties"; //$NON-NLS-1$
+ /** properties file for content hash of installed packages */
+ public final static String FN_CONTENT_HASH_PROP = "content_hash.properties"; //$NON-NLS-1$
+ /** properties file for the SDK */
+ public final static String FN_SDK_PROP = "sdk.properties"; //$NON-NLS-1$
+
+ /**
+ * filename for gdbserver.
+ */
+ public final static String FN_GDBSERVER = "gdbserver"; //$NON-NLS-1$
+
+ /** global Android proguard config file */
+ public final static String FN_ANDROID_PROGUARD_FILE = "proguard-android.txt"; //$NON-NLS-1$
+ /** global Android proguard config file with optimization enabled */
+ public final static String FN_ANDROID_OPT_PROGUARD_FILE = "proguard-android-optimize.txt"; //$NON-NLS-1$
+ /** default proguard config file with new file extension (for project specific stuff) */
+ public final static String FN_PROJECT_PROGUARD_FILE = "proguard-project.txt"; //$NON-NLS-1$
+
+ /* Folder Names for Android Projects . */
+
+ /** Resources folder name, i.e. "res". */
+ public final static String FD_RESOURCES = "res"; //$NON-NLS-1$
+ /** Assets folder name, i.e. "assets" */
+ public final static String FD_ASSETS = "assets"; //$NON-NLS-1$
+ /** Default source folder name in an SDK project, i.e. "src".
+ * <p/>
+ * Note: this is not the same as {@link #FD_PKG_SOURCES}
+ * which is an SDK sources folder for packages. */
+ public final static String FD_SOURCES = "src"; //$NON-NLS-1$
+ /** Default generated source folder name, i.e. "gen" */
+ public final static String FD_GEN_SOURCES = "gen"; //$NON-NLS-1$
+ /** Default native library folder name inside the project, i.e. "libs"
+ * While the folder inside the .apk is "lib", we call that one libs because
+ * that's what we use in ant for both .jar and .so and we need to make the 2 development ways
+ * compatible. */
+ public final static String FD_NATIVE_LIBS = "libs"; //$NON-NLS-1$
+ /** Native lib folder inside the APK: "lib" */
+ public final static String FD_APK_NATIVE_LIBS = "lib"; //$NON-NLS-1$
+ /** Default output folder name, i.e. "bin" */
+ public final static String FD_OUTPUT = "bin"; //$NON-NLS-1$
+ /** Classes output folder name, i.e. "classes" */
+ public final static String FD_CLASSES_OUTPUT = "classes"; //$NON-NLS-1$
+ /** proguard output folder for mapping, etc.. files */
+ public final static String FD_PROGUARD = "proguard"; //$NON-NLS-1$
+ /** aidl output folder for copied aidl files */
+ public final static String FD_AIDL = "aidl"; //$NON-NLS-1$
+
+ /* Folder Names for the Android SDK */
+
+ /** Name of the SDK platforms folder. */
+ public final static String FD_PLATFORMS = "platforms"; //$NON-NLS-1$
+ /** Name of the SDK addons folder. */
+ public final static String FD_ADDONS = "add-ons"; //$NON-NLS-1$
+ /** Name of the SDK system-images folder. */
+ public final static String FD_SYSTEM_IMAGES = "system-images"; //$NON-NLS-1$
+ /** Name of the SDK sources folder where source packages are installed.
+ * <p/>
+ * Note this is not the same as {@link #FD_SOURCES} which is the folder name where sources
+ * are installed inside a project. */
+ public final static String FD_PKG_SOURCES = "sources"; //$NON-NLS-1$
+ /** Name of the SDK tools folder. */
+ public final static String FD_TOOLS = "tools"; //$NON-NLS-1$
+ /** Name of the SDK tools/support folder. */
+ public final static String FD_SUPPORT = "support"; //$NON-NLS-1$
+ /** Name of the SDK platform tools folder. */
+ public final static String FD_PLATFORM_TOOLS = "platform-tools"; //$NON-NLS-1$
+ /** Name of the SDK tools/lib folder. */
+ public final static String FD_LIB = "lib"; //$NON-NLS-1$
+ /** Name of the SDK docs folder. */
+ public final static String FD_DOCS = "docs"; //$NON-NLS-1$
+ /** Name of the doc folder containing API reference doc (javadoc) */
+ public static final String FD_DOCS_REFERENCE = "reference"; //$NON-NLS-1$
+ /** Name of the SDK images folder. */
+ public final static String FD_IMAGES = "images"; //$NON-NLS-1$
+ /** Name of the ABI to support. */
+ public final static String ABI_ARMEABI = "armeabi"; //$NON-NLS-1$
+ public final static String ABI_ARMEABI_V7A = "armeabi-v7a"; //$NON-NLS-1$
+ public final static String ABI_INTEL_ATOM = "x86"; //$NON-NLS-1$
+ public final static String ABI_MIPS = "mips"; //$NON-NLS-1$
+ /** Name of the CPU arch to support. */
+ public final static String CPU_ARCH_ARM = "arm"; //$NON-NLS-1$
+ public final static String CPU_ARCH_INTEL_ATOM = "x86"; //$NON-NLS-1$
+ public final static String CPU_ARCH_MIPS = "mips"; //$NON-NLS-1$
+ /** Name of the CPU model to support. */
+ public final static String CPU_MODEL_CORTEX_A8 = "cortex-a8"; //$NON-NLS-1$
+
+ /** Name of the SDK skins folder. */
+ public final static String FD_SKINS = "skins"; //$NON-NLS-1$
+ /** Name of the SDK samples folder. */
+ public final static String FD_SAMPLES = "samples"; //$NON-NLS-1$
+ /** Name of the SDK extras folder. */
+ public final static String FD_EXTRAS = "extras"; //$NON-NLS-1$
+ /** Name of the SDK templates folder, i.e. "templates" */
+ public final static String FD_TEMPLATES = "templates"; //$NON-NLS-1$
+ /** Name of the SDK Ant folder, i.e. "ant" */
+ public final static String FD_ANT = "ant"; //$NON-NLS-1$
+ /** Name of the SDK data folder, i.e. "data" */
+ public final static String FD_DATA = "data"; //$NON-NLS-1$
+ /** Name of the SDK renderscript folder, i.e. "rs" */
+ public final static String FD_RENDERSCRIPT = "rs"; //$NON-NLS-1$
+ /** Name of the SDK resources folder, i.e. "res" */
+ public final static String FD_RES = "res"; //$NON-NLS-1$
+ /** Name of the SDK font folder, i.e. "fonts" */
+ public final static String FD_FONTS = "fonts"; //$NON-NLS-1$
+ /** Name of the android sources directory */
+ public static final String FD_ANDROID_SOURCES = "sources"; //$NON-NLS-1$
+ /** Name of the addon libs folder. */
+ public final static String FD_ADDON_LIBS = "libs"; //$NON-NLS-1$
+
+ /** Name of the cache folder in the $HOME/.android. */
+ public final static String FD_CACHE = "cache"; //$NON-NLS-1$
+
+ /** API codename of a release (non preview) system image or platform. **/
+ public final static String CODENAME_RELEASE = "REL"; //$NON-NLS-1$
+
+ /** Namespace for the resource XML, i.e. "http://schemas.android.com/apk/res/android" */
+ public final static String NS_RESOURCES =
+ "http://schemas.android.com/apk/res/android"; //$NON-NLS-1$
+
+ /** Namespace for the device schema, i.e. "http://schemas.android.com/sdk/devices/1" */
+ public static final String NS_DEVICES_XSD =
+ "http://schemas.android.com/sdk/devices/1"; //$NON-NLS-1$
+
+
+ /** The name of the uses-library that provides "android.test.runner" */
+ public final static String ANDROID_TEST_RUNNER_LIB =
+ "android.test.runner"; //$NON-NLS-1$
+
+ /* Folder path relative to the SDK root */
+ /** Path of the documentation directory relative to the sdk folder.
+ * This is an OS path, ending with a separator. */
+ public final static String OS_SDK_DOCS_FOLDER = FD_DOCS + File.separator;
+
+ /** Path of the tools directory relative to the sdk folder, or to a platform folder.
+ * This is an OS path, ending with a separator. */
+ public final static String OS_SDK_TOOLS_FOLDER = FD_TOOLS + File.separator;
+
+ /** Path of the lib directory relative to the sdk folder, or to a platform folder.
+ * This is an OS path, ending with a separator. */
+ public final static String OS_SDK_TOOLS_LIB_FOLDER =
+ OS_SDK_TOOLS_FOLDER + FD_LIB + File.separator;
+
+ /**
+ * Path of the lib directory relative to the sdk folder, or to a platform
+ * folder. This is an OS path, ending with a separator.
+ */
+ public final static String OS_SDK_TOOLS_LIB_EMULATOR_FOLDER = OS_SDK_TOOLS_LIB_FOLDER
+ + "emulator" + File.separator; //$NON-NLS-1$
+
+ /** Path of the platform tools directory relative to the sdk folder.
+ * This is an OS path, ending with a separator. */
+ public final static String OS_SDK_PLATFORM_TOOLS_FOLDER = FD_PLATFORM_TOOLS + File.separator;
+
+ /** Path of the Platform tools Lib directory relative to the sdk folder.
+ * This is an OS path, ending with a separator. */
+ public final static String OS_SDK_PLATFORM_TOOLS_LIB_FOLDER =
+ OS_SDK_PLATFORM_TOOLS_FOLDER + FD_LIB + File.separator;
+
+ /** Path of the bin folder of proguard folder relative to the sdk folder.
+ * This is an OS path, ending with a separator. */
+ public final static String OS_SDK_TOOLS_PROGUARD_BIN_FOLDER =
+ SdkConstants.OS_SDK_TOOLS_FOLDER +
+ "proguard" + File.separator + //$NON-NLS-1$
+ "bin" + File.separator; //$NON-NLS-1$
+
+ /* Folder paths relative to a platform or add-on folder */
+
+ /** Path of the images directory relative to a platform or addon folder.
+ * This is an OS path, ending with a separator. */
+ public final static String OS_IMAGES_FOLDER = FD_IMAGES + File.separator;
+
+ /** Path of the skin directory relative to a platform or addon folder.
+ * This is an OS path, ending with a separator. */
+ public final static String OS_SKINS_FOLDER = FD_SKINS + File.separator;
+
+ /* Folder paths relative to a Platform folder */
+
+ /** Path of the data directory relative to a platform folder.
+ * This is an OS path, ending with a separator. */
+ public final static String OS_PLATFORM_DATA_FOLDER = FD_DATA + File.separator;
+
+ /** Path of the renderscript directory relative to a platform folder.
+ * This is an OS path, ending with a separator. */
+ public final static String OS_PLATFORM_RENDERSCRIPT_FOLDER = FD_RENDERSCRIPT + File.separator;
+
+
+ /** Path of the samples directory relative to a platform folder.
+ * This is an OS path, ending with a separator. */
+ public final static String OS_PLATFORM_SAMPLES_FOLDER = FD_SAMPLES + File.separator;
+
+ /** Path of the resources directory relative to a platform folder.
+ * This is an OS path, ending with a separator. */
+ public final static String OS_PLATFORM_RESOURCES_FOLDER =
+ OS_PLATFORM_DATA_FOLDER + FD_RES + File.separator;
+
+ /** Path of the fonts directory relative to a platform folder.
+ * This is an OS path, ending with a separator. */
+ public final static String OS_PLATFORM_FONTS_FOLDER =
+ OS_PLATFORM_DATA_FOLDER + FD_FONTS + File.separator;
+
+ /** Path of the android source directory relative to a platform folder.
+ * This is an OS path, ending with a separator. */
+ public final static String OS_PLATFORM_SOURCES_FOLDER = FD_ANDROID_SOURCES + File.separator;
+
+ /** Path of the android templates directory relative to a platform folder.
+ * This is an OS path, ending with a separator. */
+ public final static String OS_PLATFORM_TEMPLATES_FOLDER = FD_TEMPLATES + File.separator;
+
+ /** Path of the Ant build rules directory relative to a platform folder.
+ * This is an OS path, ending with a separator. */
+ public final static String OS_PLATFORM_ANT_FOLDER = FD_ANT + File.separator;
+
+ /** Path of the attrs.xml file relative to a platform folder. */
+ public final static String OS_PLATFORM_ATTRS_XML =
+ OS_PLATFORM_RESOURCES_FOLDER + AndroidConstants.FD_RES_VALUES + File.separator +
+ FN_ATTRS_XML;
+
+ /** Path of the attrs_manifest.xml file relative to a platform folder. */
+ public final static String OS_PLATFORM_ATTRS_MANIFEST_XML =
+ OS_PLATFORM_RESOURCES_FOLDER + AndroidConstants.FD_RES_VALUES + File.separator +
+ FN_ATTRS_MANIFEST_XML;
+
+ /** Path of the layoutlib.jar file relative to a platform folder. */
+ public final static String OS_PLATFORM_LAYOUTLIB_JAR =
+ OS_PLATFORM_DATA_FOLDER + FN_LAYOUTLIB_JAR;
+
+ /** Path of the renderscript include folder relative to a platform folder. */
+ public final static String OS_FRAMEWORK_RS =
+ FN_FRAMEWORK_RENDERSCRIPT + File.separator + FN_FRAMEWORK_INCLUDE;
+ /** Path of the renderscript (clang) include folder relative to a platform folder. */
+ public final static String OS_FRAMEWORK_RS_CLANG =
+ FN_FRAMEWORK_RENDERSCRIPT + File.separator + FN_FRAMEWORK_INCLUDE_CLANG;
+
+ /* Folder paths relative to a addon folder */
+ /** Path of the images directory relative to a folder folder.
+ * This is an OS path, ending with a separator. */
+ public final static String OS_ADDON_LIBS_FOLDER = FD_ADDON_LIBS + File.separator;
+
+ /** Skin default **/
+ public final static String SKIN_DEFAULT = "default"; //$NON-NLS-1$
+
+ /** SDK property: ant templates revision */
+ public final static String PROP_SDK_ANT_TEMPLATES_REVISION =
+ "sdk.ant.templates.revision"; //$NON-NLS-1$
+
+ /** SDK property: default skin */
+ public final static String PROP_SDK_DEFAULT_SKIN = "sdk.skin.default"; //$NON-NLS-1$
+
+ /* Android Class Constants */
+ public final static String CLASS_ACTIVITY = "android.app.Activity"; //$NON-NLS-1$
+ public final static String CLASS_APPLICATION = "android.app.Application"; //$NON-NLS-1$
+ public final static String CLASS_SERVICE = "android.app.Service"; //$NON-NLS-1$
+ public final static String CLASS_BROADCASTRECEIVER = "android.content.BroadcastReceiver"; //$NON-NLS-1$
+ public final static String CLASS_CONTENTPROVIDER = "android.content.ContentProvider"; //$NON-NLS-1$
+ public final static String CLASS_INSTRUMENTATION = "android.app.Instrumentation"; //$NON-NLS-1$
+ public final static String CLASS_INSTRUMENTATION_RUNNER =
+ "android.test.InstrumentationTestRunner"; //$NON-NLS-1$
+ public final static String CLASS_BUNDLE = "android.os.Bundle"; //$NON-NLS-1$
+ public final static String CLASS_R = "android.R"; //$NON-NLS-1$
+ public final static String CLASS_MANIFEST_PERMISSION = "android.Manifest$permission"; //$NON-NLS-1$
+ public final static String CLASS_INTENT = "android.content.Intent"; //$NON-NLS-1$
+ public final static String CLASS_CONTEXT = "android.content.Context"; //$NON-NLS-1$
+ public final static String CLASS_VIEW = "android.view.View"; //$NON-NLS-1$
+ public final static String CLASS_VIEWGROUP = "android.view.ViewGroup"; //$NON-NLS-1$
+ public final static String CLASS_NAME_LAYOUTPARAMS = "LayoutParams"; //$NON-NLS-1$
+ public final static String CLASS_VIEWGROUP_LAYOUTPARAMS =
+ CLASS_VIEWGROUP + "$" + CLASS_NAME_LAYOUTPARAMS; //$NON-NLS-1$
+ public final static String CLASS_NAME_FRAMELAYOUT = "FrameLayout"; //$NON-NLS-1$
+ public final static String CLASS_FRAMELAYOUT =
+ "android.widget." + CLASS_NAME_FRAMELAYOUT; //$NON-NLS-1$
+ public final static String CLASS_PREFERENCE = "android.preference.Preference"; //$NON-NLS-1$
+ public final static String CLASS_NAME_PREFERENCE_SCREEN = "PreferenceScreen"; //$NON-NLS-1$
+ public final static String CLASS_PREFERENCES =
+ "android.preference." + CLASS_NAME_PREFERENCE_SCREEN; //$NON-NLS-1$
+ public final static String CLASS_PREFERENCEGROUP = "android.preference.PreferenceGroup"; //$NON-NLS-1$
+ public final static String CLASS_PARCELABLE = "android.os.Parcelable"; //$NON-NLS-1$
+ public static final String CLASS_FRAGMENT = "android.app.Fragment"; //$NON-NLS-1$
+ public static final String CLASS_V4_FRAGMENT = "android.support.v4.app.Fragment"; //$NON-NLS-1$
+ /** MockView is part of the layoutlib bridge and used to display classes that have
+ * no rendering in the graphical layout editor. */
+ public final static String CLASS_MOCK_VIEW = "com.android.layoutlib.bridge.MockView"; //$NON-NLS-1$
+
+
+
+ /** Returns the appropriate name for the 'android' command, which is 'android.exe' for
+ * Windows and 'android' for all other platforms. */
+ public static String androidCmdName() {
+ String os = System.getProperty("os.name"); //$NON-NLS-1$
+ String cmd = "android"; //$NON-NLS-1$
+ if (os.startsWith("Windows")) { //$NON-NLS-1$
+ cmd += ".bat"; //$NON-NLS-1$
+ }
+ return cmd;
+ }
+
+ /** Returns the appropriate name for the 'mksdcard' command, which is 'mksdcard.exe' for
+ * Windows and 'mkdsdcard' for all other platforms. */
+ public static String mkSdCardCmdName() {
+ String os = System.getProperty("os.name"); //$NON-NLS-1$
+ String cmd = "mksdcard"; //$NON-NLS-1$
+ if (os.startsWith("Windows")) { //$NON-NLS-1$
+ cmd += ".exe"; //$NON-NLS-1$
+ }
+ return cmd;
+ }
+
+ /**
+ * Returns current platform
+ *
+ * @return one of {@link #PLATFORM_WINDOWS}, {@link #PLATFORM_DARWIN},
+ * {@link #PLATFORM_LINUX} or {@link #PLATFORM_UNKNOWN}.
+ */
+ public static int currentPlatform() {
+ String os = System.getProperty("os.name"); //$NON-NLS-1$
+ if (os.startsWith("Mac OS")) { //$NON-NLS-1$
+ return PLATFORM_DARWIN;
+ } else if (os.startsWith("Windows")) { //$NON-NLS-1$
+ return PLATFORM_WINDOWS;
+ } else if (os.startsWith("Linux")) { //$NON-NLS-1$
+ return PLATFORM_LINUX;
+ }
+
+ return PLATFORM_UNKNOWN;
+ }
+
+ /**
+ * Returns current platform's UI name
+ *
+ * @return one of "Windows", "Mac OS X", "Linux" or "other".
+ */
+ public static String currentPlatformName() {
+ String os = System.getProperty("os.name"); //$NON-NLS-1$
+ if (os.startsWith("Mac OS")) { //$NON-NLS-1$
+ return "Mac OS X"; //$NON-NLS-1$
+ } else if (os.startsWith("Windows")) { //$NON-NLS-1$
+ return "Windows"; //$NON-NLS-1$
+ } else if (os.startsWith("Linux")) { //$NON-NLS-1$
+ return "Linux"; //$NON-NLS-1$
+ }
+
+ return "Other";
+ }
+
+ private static String ext(String windowsExtension, String nonWindowsExtension) {
+ if (CURRENT_PLATFORM == PLATFORM_WINDOWS) {
+ return windowsExtension;
+ } else {
+ return nonWindowsExtension;
+ }
+ }
+}
diff --git a/common/src/com/android/prefs/AndroidLocation.java b/common/src/com/android/prefs/AndroidLocation.java
new file mode 100644
index 0000000..c36048a
--- /dev/null
+++ b/common/src/com/android/prefs/AndroidLocation.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.prefs;
+
+import java.io.File;
+
+/**
+ * Manages the location of the android files (including emulator files, ddms config, debug keystore)
+ */
+public final class AndroidLocation {
+ /**
+ * Virtual Device folder inside the path returned by {@link #getFolder()}
+ */
+ public static final String FOLDER_AVD = "avd";
+
+ /**
+ * Throw when the location of the android folder couldn't be found.
+ */
+ public static final class AndroidLocationException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public AndroidLocationException(String string) {
+ super(string);
+ }
+ }
+
+ private static String sPrefsLocation = null;
+
+ /**
+ * Returns the folder used to store android related files.
+ * @return an OS specific path, terminated by a separator.
+ * @throws AndroidLocationException
+ */
+ public final static String getFolder() throws AndroidLocationException {
+ if (sPrefsLocation == null) {
+ String home = findValidPath("ANDROID_SDK_HOME", "user.home", "HOME");
+
+ // if the above failed, we throw an exception.
+ if (home == null) {
+ throw new AndroidLocationException(
+ "Unable to get the Android SDK home directory.\n" +
+ "Make sure the environment variable ANDROID_SDK_HOME is set up.");
+ } else {
+ sPrefsLocation = home + File.separator + ".android" + File.separator;
+ }
+ }
+
+ // make sure the folder exists!
+ File f = new File(sPrefsLocation);
+ if (f.exists() == false) {
+ try {
+ f.mkdir();
+ } catch (SecurityException e) {
+ AndroidLocationException e2 = new AndroidLocationException(String.format(
+ "Unable to create folder '%1$s'. " +
+ "This is the path of preference folder expected by the Android tools.",
+ sPrefsLocation));
+ e2.initCause(e);
+ throw e2;
+ }
+ } else if (f.isFile()) {
+ throw new AndroidLocationException(sPrefsLocation +
+ " is not a directory! " +
+ "This is the path of preference folder expected by the Android tools.");
+ }
+
+ return sPrefsLocation;
+ }
+
+ /**
+ * Resets the folder used to store android related files. For testing.
+ */
+ public final static void resetFolder() {
+ sPrefsLocation = null;
+ }
+
+ /**
+ * Checks a list of system properties and/or system environment variables for validity, and
+ * existing director, and returns the first one.
+ * @param names
+ * @return the content of the first property/variable.
+ */
+ private static String findValidPath(String... names) {
+ for (String name : names) {
+ String path;
+ if (name.indexOf('.') != -1) {
+ path = System.getProperty(name);
+ } else {
+ path = System.getenv(name);
+ }
+
+ if (path != null) {
+ File f = new File(path);
+ if (f.isDirectory()) {
+ return path;
+ }
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/common/src/com/android/xml/AndroidManifest.java b/common/src/com/android/xml/AndroidManifest.java
new file mode 100644
index 0000000..d0f2126
--- /dev/null
+++ b/common/src/com/android/xml/AndroidManifest.java
@@ -0,0 +1,359 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.xml;
+
+import com.android.SdkConstants;
+import com.android.io.IAbstractFile;
+import com.android.io.IAbstractFolder;
+import com.android.io.StreamException;
+
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+
+/**
+ * Helper and Constants for the AndroidManifest.xml file.
+ *
+ */
+public final class AndroidManifest {
+
+ public final static String NODE_MANIFEST = "manifest";
+ public final static String NODE_APPLICATION = "application";
+ public final static String NODE_ACTIVITY = "activity";
+ public final static String NODE_ACTIVITY_ALIAS = "activity-alias";
+ public final static String NODE_SERVICE = "service";
+ public final static String NODE_RECEIVER = "receiver";
+ public final static String NODE_PROVIDER = "provider";
+ public final static String NODE_INTENT = "intent-filter";
+ public final static String NODE_ACTION = "action";
+ public final static String NODE_CATEGORY = "category";
+ public final static String NODE_USES_SDK = "uses-sdk";
+ public final static String NODE_INSTRUMENTATION = "instrumentation";
+ public final static String NODE_USES_LIBRARY = "uses-library";
+ public final static String NODE_SUPPORTS_SCREENS = "supports-screens";
+ public final static String NODE_USES_CONFIGURATION = "uses-configuration";
+ public final static String NODE_USES_FEATURE = "uses-feature";
+
+ public final static String ATTRIBUTE_PACKAGE = "package";
+ public final static String ATTRIBUTE_VERSIONCODE = "versionCode";
+ public final static String ATTRIBUTE_NAME = "name";
+ public final static String ATTRIBUTE_REQUIRED = "required";
+ public final static String ATTRIBUTE_GLESVERSION = "glEsVersion";
+ public final static String ATTRIBUTE_PROCESS = "process";
+ public final static String ATTRIBUTE_DEBUGGABLE = "debuggable";
+ public final static String ATTRIBUTE_LABEL = "label";
+ public final static String ATTRIBUTE_ICON = "icon";
+ public final static String ATTRIBUTE_MIN_SDK_VERSION = "minSdkVersion";
+ public final static String ATTRIBUTE_TARGET_SDK_VERSION = "targetSdkVersion";
+ public final static String ATTRIBUTE_TARGET_PACKAGE = "targetPackage";
+ public final static String ATTRIBUTE_TARGET_ACTIVITY = "targetActivity";
+ public final static String ATTRIBUTE_MANAGE_SPACE_ACTIVITY = "manageSpaceActivity";
+ public final static String ATTRIBUTE_EXPORTED = "exported";
+ public final static String ATTRIBUTE_RESIZEABLE = "resizeable";
+ public final static String ATTRIBUTE_ANYDENSITY = "anyDensity";
+ public final static String ATTRIBUTE_SMALLSCREENS = "smallScreens";
+ public final static String ATTRIBUTE_NORMALSCREENS = "normalScreens";
+ public final static String ATTRIBUTE_LARGESCREENS = "largeScreens";
+ public final static String ATTRIBUTE_REQ_5WAYNAV = "reqFiveWayNav";
+ public final static String ATTRIBUTE_REQ_NAVIGATION = "reqNavigation";
+ public final static String ATTRIBUTE_REQ_HARDKEYBOARD = "reqHardKeyboard";
+ public final static String ATTRIBUTE_REQ_KEYBOARDTYPE = "reqKeyboardType";
+ public final static String ATTRIBUTE_REQ_TOUCHSCREEN = "reqTouchScreen";
+ public static final String ATTRIBUTE_THEME = "theme";
+
+ /**
+ * Returns an {@link IAbstractFile} object representing the manifest for the given project.
+ *
+ * @param projectFolder The project containing the manifest file.
+ * @return An IAbstractFile object pointing to the manifest or null if the manifest
+ * is missing.
+ */
+ public static IAbstractFile getManifest(IAbstractFolder projectFolder) {
+ IAbstractFile file = projectFolder.getFile(SdkConstants.FN_ANDROID_MANIFEST_XML);
+ if (file.exists()) {
+ return file;
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the package for a given project.
+ * @param projectFolder the folder of the project.
+ * @return the package info or null (or empty) if not found.
+ * @throws XPathExpressionException
+ * @throws StreamException If any error happens when reading the manifest.
+ */
+ public static String getPackage(IAbstractFolder projectFolder)
+ throws XPathExpressionException, StreamException {
+ IAbstractFile file = getManifest(projectFolder);
+ if (file != null) {
+ return getPackage(file);
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the package for a given manifest.
+ * @param manifestFile the manifest to parse.
+ * @return the package info or null (or empty) if not found.
+ * @throws XPathExpressionException
+ * @throws StreamException If any error happens when reading the manifest.
+ */
+ public static String getPackage(IAbstractFile manifestFile)
+ throws XPathExpressionException, StreamException {
+ XPath xPath = AndroidXPathFactory.newXPath();
+
+ return xPath.evaluate(
+ "/" + NODE_MANIFEST +
+ "/@" + ATTRIBUTE_PACKAGE,
+ new InputSource(manifestFile.getContents()));
+ }
+
+ /**
+ * Returns whether the manifest is set to make the application debuggable.
+ *
+ * If the give manifest does not contain the debuggable attribute then the application
+ * is considered to not be debuggable.
+ *
+ * @param manifestFile the manifest to parse.
+ * @return true if the application is debuggable.
+ * @throws XPathExpressionException
+ * @throws StreamException If any error happens when reading the manifest.
+ */
+ public static boolean getDebuggable(IAbstractFile manifestFile)
+ throws XPathExpressionException, StreamException {
+ XPath xPath = AndroidXPathFactory.newXPath();
+
+ String value = xPath.evaluate(
+ "/" + NODE_MANIFEST +
+ "/" + NODE_APPLICATION +
+ "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
+ ":" + ATTRIBUTE_DEBUGGABLE,
+ new InputSource(manifestFile.getContents()));
+
+ // default is not debuggable, which is the same behavior as parseBoolean
+ return Boolean.parseBoolean(value);
+ }
+
+ /**
+ * Returns the value of the versionCode attribute or -1 if the value is not set.
+ * @param manifestFile the manifest file to read the attribute from.
+ * @return the integer value or -1 if not set.
+ * @throws XPathExpressionException
+ * @throws StreamException If any error happens when reading the manifest.
+ */
+ public static int getVersionCode(IAbstractFile manifestFile)
+ throws XPathExpressionException, StreamException {
+ XPath xPath = AndroidXPathFactory.newXPath();
+
+ String result = xPath.evaluate(
+ "/" + NODE_MANIFEST +
+ "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
+ ":" + ATTRIBUTE_VERSIONCODE,
+ new InputSource(manifestFile.getContents()));
+
+ try {
+ return Integer.parseInt(result);
+ } catch (NumberFormatException e) {
+ return -1;
+ }
+ }
+
+ /**
+ * Returns whether the version Code attribute is set in a given manifest.
+ * @param manifestFile the manifest to check
+ * @return true if the versionCode attribute is present and its value is not empty.
+ * @throws XPathExpressionException
+ * @throws StreamException If any error happens when reading the manifest.
+ */
+ public static boolean hasVersionCode(IAbstractFile manifestFile)
+ throws XPathExpressionException, StreamException {
+ XPath xPath = AndroidXPathFactory.newXPath();
+
+ Object result = xPath.evaluate(
+ "/" + NODE_MANIFEST +
+ "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
+ ":" + ATTRIBUTE_VERSIONCODE,
+ new InputSource(manifestFile.getContents()),
+ XPathConstants.NODE);
+
+ if (result != null) {
+ Node node = (Node)result;
+ if (node.getNodeValue().length() > 0) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns the value of the minSdkVersion attribute.
+ * <p/>
+ * If the attribute is set with an int value, the method returns an Integer object.
+ * <p/>
+ * If the attribute is set with a codename, it returns the codename as a String object.
+ * <p/>
+ * If the attribute is not set, it returns null.
+ *
+ * @param manifestFile the manifest file to read the attribute from.
+ * @return the attribute value.
+ * @throws XPathExpressionException
+ * @throws StreamException If any error happens when reading the manifest.
+ */
+ public static Object getMinSdkVersion(IAbstractFile manifestFile)
+ throws XPathExpressionException, StreamException {
+ XPath xPath = AndroidXPathFactory.newXPath();
+
+ String result = xPath.evaluate(
+ "/" + NODE_MANIFEST +
+ "/" + NODE_USES_SDK +
+ "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
+ ":" + ATTRIBUTE_MIN_SDK_VERSION,
+ new InputSource(manifestFile.getContents()));
+
+ try {
+ return Integer.valueOf(result);
+ } catch (NumberFormatException e) {
+ return result.length() > 0 ? result : null;
+ }
+ }
+
+ /**
+ * Returns the value of the targetSdkVersion attribute (defaults to 1 if the attribute is
+ * not set), or -1 if the value is a codename.
+ * @param manifestFile the manifest file to read the attribute from.
+ * @return the integer value or -1 if not set.
+ * @throws XPathExpressionException
+ * @throws StreamException If any error happens when reading the manifest.
+ */
+ public static Integer getTargetSdkVersion(IAbstractFile manifestFile)
+ throws XPathExpressionException, StreamException {
+ XPath xPath = AndroidXPathFactory.newXPath();
+
+ String result = xPath.evaluate(
+ "/" + NODE_MANIFEST +
+ "/" + NODE_USES_SDK +
+ "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
+ ":" + ATTRIBUTE_TARGET_SDK_VERSION,
+ new InputSource(manifestFile.getContents()));
+
+ try {
+ return Integer.valueOf(result);
+ } catch (NumberFormatException e) {
+ return result.length() > 0 ? -1 : null;
+ }
+ }
+
+ /**
+ * Returns the application icon for a given manifest.
+ * @param manifestFile the manifest to parse.
+ * @return the icon or null (or empty) if not found.
+ * @throws XPathExpressionException
+ * @throws StreamException If any error happens when reading the manifest.
+ */
+ public static String getApplicationIcon(IAbstractFile manifestFile)
+ throws XPathExpressionException, StreamException {
+ XPath xPath = AndroidXPathFactory.newXPath();
+
+ return xPath.evaluate(
+ "/" + NODE_MANIFEST +
+ "/" + NODE_APPLICATION +
+ "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
+ ":" + ATTRIBUTE_ICON,
+ new InputSource(manifestFile.getContents()));
+ }
+
+ /**
+ * Returns the application label for a given manifest.
+ * @param manifestFile the manifest to parse.
+ * @return the label or null (or empty) if not found.
+ * @throws XPathExpressionException
+ * @throws StreamException If any error happens when reading the manifest.
+ */
+ public static String getApplicationLabel(IAbstractFile manifestFile)
+ throws XPathExpressionException, StreamException {
+ XPath xPath = AndroidXPathFactory.newXPath();
+
+ return xPath.evaluate(
+ "/" + NODE_MANIFEST +
+ "/" + NODE_APPLICATION +
+ "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
+ ":" + ATTRIBUTE_LABEL,
+ new InputSource(manifestFile.getContents()));
+ }
+
+ /**
+ * Combines a java package, with a class value from the manifest to make a fully qualified
+ * class name
+ * @param javaPackage the java package from the manifest.
+ * @param className the class name from the manifest.
+ * @return the fully qualified class name.
+ */
+ public static String combinePackageAndClassName(String javaPackage, String className) {
+ if (className == null || className.length() == 0) {
+ return javaPackage;
+ }
+ if (javaPackage == null || javaPackage.length() == 0) {
+ return className;
+ }
+
+ // the class name can be a subpackage (starts with a '.'
+ // char), a simple class name (no dot), or a full java package
+ boolean startWithDot = (className.charAt(0) == '.');
+ boolean hasDot = (className.indexOf('.') != -1);
+ if (startWithDot || hasDot == false) {
+
+ // add the concatenation of the package and class name
+ if (startWithDot) {
+ return javaPackage + className;
+ } else {
+ return javaPackage + '.' + className;
+ }
+ } else {
+ // just add the class as it should be a fully qualified java name.
+ return className;
+ }
+ }
+
+ /**
+ * Given a fully qualified activity name (e.g. com.foo.test.MyClass) and given a project
+ * package base name (e.g. com.foo), returns the relative activity name that would be used
+ * the "name" attribute of an "activity" element.
+ *
+ * @param fullActivityName a fully qualified activity class name, e.g. "com.foo.test.MyClass"
+ * @param packageName The project base package name, e.g. "com.foo"
+ * @return The relative activity name if it can be computed or the original fullActivityName.
+ */
+ public static String extractActivityName(String fullActivityName, String packageName) {
+ if (packageName != null && fullActivityName != null) {
+ if (packageName.length() > 0 && fullActivityName.startsWith(packageName)) {
+ String name = fullActivityName.substring(packageName.length());
+ if (name.length() > 0 && name.charAt(0) == '.') {
+ return name;
+ }
+ }
+ }
+
+ return fullActivityName;
+ }
+}
diff --git a/common/src/com/android/xml/AndroidXPathFactory.java b/common/src/com/android/xml/AndroidXPathFactory.java
new file mode 100644
index 0000000..ee5b87b
--- /dev/null
+++ b/common/src/com/android/xml/AndroidXPathFactory.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.xml;
+
+import com.android.SdkConstants;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathFactory;
+
+/**
+ * XPath factory with automatic support for the android name space.
+ */
+public class AndroidXPathFactory {
+ /** Default prefix for android name space: 'android' */
+ public final static String DEFAULT_NS_PREFIX = "android"; //$NON-NLS-1$
+
+ private final static XPathFactory sFactory = XPathFactory.newInstance();
+
+ /** Name space context for Android resource XML files. */
+ private static class AndroidNamespaceContext implements NamespaceContext {
+ private final static AndroidNamespaceContext sThis = new AndroidNamespaceContext(
+ DEFAULT_NS_PREFIX);
+
+ private final String mAndroidPrefix;
+ private final List<String> mAndroidPrefixes;
+
+ /**
+ * Returns the default {@link AndroidNamespaceContext}.
+ */
+ private static AndroidNamespaceContext getDefault() {
+ return sThis;
+ }
+
+ /**
+ * Construct the context with the prefix associated with the android namespace.
+ * @param androidPrefix the Prefix
+ */
+ public AndroidNamespaceContext(String androidPrefix) {
+ mAndroidPrefix = androidPrefix;
+ mAndroidPrefixes = Collections.singletonList(mAndroidPrefix);
+ }
+
+ @Override
+ public String getNamespaceURI(String prefix) {
+ if (prefix != null) {
+ if (prefix.equals(mAndroidPrefix)) {
+ return SdkConstants.NS_RESOURCES;
+ }
+ }
+
+ return XMLConstants.NULL_NS_URI;
+ }
+
+ @Override
+ public String getPrefix(String namespaceURI) {
+ if (SdkConstants.NS_RESOURCES.equals(namespaceURI)) {
+ return mAndroidPrefix;
+ }
+
+ return null;
+ }
+
+ @Override
+ public Iterator<?> getPrefixes(String namespaceURI) {
+ if (SdkConstants.NS_RESOURCES.equals(namespaceURI)) {
+ return mAndroidPrefixes.iterator();
+ }
+
+ return null;
+ }
+ }
+
+ /**
+ * Creates a new XPath object, specifying which prefix in the query is used for the
+ * android namespace.
+ * @param androidPrefix The namespace prefix.
+ */
+ public static XPath newXPath(String androidPrefix) {
+ XPath xpath = sFactory.newXPath();
+ xpath.setNamespaceContext(new AndroidNamespaceContext(androidPrefix));
+ return xpath;
+ }
+
+ /**
+ * Creates a new XPath object using the default prefix for the android namespace.
+ * @see #DEFAULT_NS_PREFIX
+ */
+ public static XPath newXPath() {
+ XPath xpath = sFactory.newXPath();
+ xpath.setNamespaceContext(AndroidNamespaceContext.getDefault());
+ return xpath;
+ }
+}