Merge change 8196 into donut
* changes: Refactored AndroidXPathFactory into sdklib.
This commit is contained in:
@@ -18,10 +18,10 @@ package com.android.ant;
|
|||||||
|
|
||||||
import com.android.sdklib.IAndroidTarget;
|
import com.android.sdklib.IAndroidTarget;
|
||||||
import com.android.sdklib.ISdkLog;
|
import com.android.sdklib.ISdkLog;
|
||||||
import com.android.sdklib.SdkConstants;
|
|
||||||
import com.android.sdklib.SdkManager;
|
import com.android.sdklib.SdkManager;
|
||||||
import com.android.sdklib.IAndroidTarget.IOptionalLibrary;
|
import com.android.sdklib.IAndroidTarget.IOptionalLibrary;
|
||||||
import com.android.sdklib.internal.project.ProjectProperties;
|
import com.android.sdklib.internal.project.ProjectProperties;
|
||||||
|
import com.android.sdklib.xml.AndroidXPathFactory;
|
||||||
|
|
||||||
import org.apache.tools.ant.BuildException;
|
import org.apache.tools.ant.BuildException;
|
||||||
import org.apache.tools.ant.Project;
|
import org.apache.tools.ant.Project;
|
||||||
@@ -35,13 +35,9 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import javax.xml.XMLConstants;
|
|
||||||
import javax.xml.namespace.NamespaceContext;
|
|
||||||
import javax.xml.xpath.XPath;
|
import javax.xml.xpath.XPath;
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
import javax.xml.xpath.XPathFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup/Import Ant task. This task accomplishes:
|
* Setup/Import Ant task. This task accomplishes:
|
||||||
@@ -227,32 +223,10 @@ public final class SetupTask extends ImportTask {
|
|||||||
try {
|
try {
|
||||||
File manifest = new File(antProject.getBaseDir(), "AndroidManifest.xml");
|
File manifest = new File(antProject.getBaseDir(), "AndroidManifest.xml");
|
||||||
|
|
||||||
XPath xPath = XPathFactory.newInstance().newXPath();
|
XPath xPath = AndroidXPathFactory.newXPath();
|
||||||
xPath.setNamespaceContext(new NamespaceContext() {
|
|
||||||
public String getNamespaceURI(String prefix) {
|
|
||||||
if (prefix != null) {
|
|
||||||
if (prefix.equals("android")) {
|
|
||||||
return SdkConstants.NS_RESOURCES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return XMLConstants.NULL_NS_URI;
|
String value = xPath.evaluate("/manifest/uses-sdk/@" +
|
||||||
}
|
AndroidXPathFactory.DEFAULT_NS_PREFIX + ":minSdkVersion",
|
||||||
|
|
||||||
public String getPrefix(String namespaceURI) {
|
|
||||||
// This isn't necessary for our use.
|
|
||||||
assert false;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterator getPrefixes(String namespaceURI) {
|
|
||||||
// This isn't necessary for our use.
|
|
||||||
assert false;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
String value = xPath.evaluate("/manifest/uses-sdk/@android:minSdkVersion",
|
|
||||||
new InputSource(new FileInputStream(manifest)));
|
new InputSource(new FileInputStream(manifest)));
|
||||||
|
|
||||||
if (codename.equals(value) == false) {
|
if (codename.equals(value) == false) {
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ import com.android.ide.eclipse.adt.internal.editors.manifest.pages.OverviewPage;
|
|||||||
import com.android.ide.eclipse.adt.internal.editors.manifest.pages.PermissionPage;
|
import com.android.ide.eclipse.adt.internal.editors.manifest.pages.PermissionPage;
|
||||||
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiAttributeNode;
|
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiAttributeNode;
|
||||||
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
|
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
|
||||||
import com.android.ide.eclipse.adt.internal.project.AndroidXPathFactory;
|
|
||||||
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceMonitor;
|
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceMonitor;
|
||||||
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceMonitor.IFileListener;
|
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceMonitor.IFileListener;
|
||||||
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
|
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
|
||||||
|
import com.android.sdklib.xml.AndroidXPathFactory;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IMarker;
|
import org.eclipse.core.resources.IMarker;
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ import com.android.ide.eclipse.adt.AndroidConstants;
|
|||||||
import com.android.ide.eclipse.adt.internal.editors.AndroidEditor;
|
import com.android.ide.eclipse.adt.internal.editors.AndroidEditor;
|
||||||
import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor;
|
import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor;
|
||||||
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
|
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
|
||||||
import com.android.ide.eclipse.adt.internal.project.AndroidXPathFactory;
|
|
||||||
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
|
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
|
||||||
|
import com.android.sdklib.xml.AndroidXPathFactory;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.ui.IEditorInput;
|
import org.eclipse.ui.IEditorInput;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import com.android.ide.eclipse.adt.internal.editors.AndroidEditor;
|
|||||||
import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor;
|
import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor;
|
||||||
import com.android.ide.eclipse.adt.internal.editors.resources.descriptors.ResourcesDescriptors;
|
import com.android.ide.eclipse.adt.internal.editors.resources.descriptors.ResourcesDescriptors;
|
||||||
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
|
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
|
||||||
import com.android.ide.eclipse.adt.internal.project.AndroidXPathFactory;
|
import com.android.sdklib.xml.AndroidXPathFactory;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package com.android.ide.eclipse.adt.internal.refactorings.extractstring;
|
package com.android.ide.eclipse.adt.internal.refactorings.extractstring;
|
||||||
|
|
||||||
import com.android.ide.eclipse.adt.internal.project.AndroidXPathFactory;
|
import com.android.sdklib.xml.AndroidXPathFactory;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2007 The Android Open Source Project
|
* Copyright (C) 2009 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Eclipse Public License, Version 1.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.eclipse.org/org/documents/epl-v10.php
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.ide.eclipse.adt.internal.project;
|
package com.android.sdklib.xml;
|
||||||
|
|
||||||
import com.android.sdklib.SdkConstants;
|
import com.android.sdklib.SdkConstants;
|
||||||
|
|
||||||
@@ -26,17 +26,28 @@ import javax.xml.xpath.XPath;
|
|||||||
import javax.xml.xpath.XPathFactory;
|
import javax.xml.xpath.XPathFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XPath factory with automatic support for the android namespace.
|
* XPath factory with automatic support for the android name space.
|
||||||
*/
|
*/
|
||||||
public class AndroidXPathFactory {
|
public class AndroidXPathFactory {
|
||||||
|
/** Default prefix for android name space: 'android' */
|
||||||
public final static String DEFAULT_NS_PREFIX = "android"; //$NON-NLS-1$
|
public final static String DEFAULT_NS_PREFIX = "android"; //$NON-NLS-1$
|
||||||
|
|
||||||
private final static XPathFactory sFactory = XPathFactory.newInstance();
|
private final static XPathFactory sFactory = XPathFactory.newInstance();
|
||||||
|
|
||||||
/** Namespace context for Android resource XML files. */
|
/** Name space context for Android resource XML files. */
|
||||||
private static class AndroidNamespaceContext implements NamespaceContext {
|
private static class AndroidNamespaceContext implements NamespaceContext {
|
||||||
|
private final static AndroidNamespaceContext sThis = new AndroidNamespaceContext(
|
||||||
|
DEFAULT_NS_PREFIX);
|
||||||
|
|
||||||
private String mAndroidPrefix;
|
private String mAndroidPrefix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the default {@link AndroidNamespaceContext}.
|
||||||
|
*/
|
||||||
|
private static AndroidNamespaceContext getDefault() {
|
||||||
|
return sThis;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the context with the prefix associated with the android namespace.
|
* Construct the context with the prefix associated with the android namespace.
|
||||||
* @param androidPrefix the Prefix
|
* @param androidPrefix the Prefix
|
||||||
@@ -84,6 +95,8 @@ public class AndroidXPathFactory {
|
|||||||
* @see #DEFAULT_NS_PREFIX
|
* @see #DEFAULT_NS_PREFIX
|
||||||
*/
|
*/
|
||||||
public static XPath newXPath() {
|
public static XPath newXPath() {
|
||||||
return newXPath(DEFAULT_NS_PREFIX);
|
XPath xpath = sFactory.newXPath();
|
||||||
|
xpath.setNamespaceContext(AndroidNamespaceContext.getDefault());
|
||||||
|
return xpath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user