diff options
author | Raphael Moll <ralf@android.com> | 2010-07-02 15:55:40 -0700 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2010-07-02 15:55:40 -0700 |
commit | 07af07ab94581a73a81eb92ba030a4c558ed6135 (patch) | |
tree | bd6af034412f058c6f9d50434950a5a23a1ce481 | |
parent | 18dbfd01e0c0df1863d21d1cf8327a02a8ec4454 (diff) | |
parent | f6ad088e2c38b663fd1b0408ca78a05bd4852f05 (diff) | |
download | sdk-07af07ab94581a73a81eb92ba030a4c558ed6135.zip sdk-07af07ab94581a73a81eb92ba030a4c558ed6135.tar.gz sdk-07af07ab94581a73a81eb92ba030a4c558ed6135.tar.bz2 |
Merge "ADT: Fix NPE in resource editor on Eclipse 3.6"
2 files changed, 72 insertions, 13 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/model/UiManifestElementNode.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/model/UiManifestElementNode.java index 5dc8544..0b78a22 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/model/UiManifestElementNode.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/model/UiManifestElementNode.java @@ -24,6 +24,7 @@ import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData; import com.android.sdklib.SdkConstants; +import org.w3c.dom.DOMException; import org.w3c.dom.Element; /** @@ -80,11 +81,13 @@ public final class UiManifestElementNode extends UiElementNode { if (desc != manifestDescriptors.getManifestElement() && desc != manifestDescriptors.getApplicationElement()) { Element elem = (Element) getXmlNode(); - String attr = elem.getAttributeNS(SdkConstants.NS_RESOURCES, - AndroidManifestDescriptors.ANDROID_NAME_ATTR); + String attr = _Element_getAttributeNS(elem, + SdkConstants.NS_RESOURCES, + AndroidManifestDescriptors.ANDROID_NAME_ATTR); if (attr == null || attr.length() == 0) { - attr = elem.getAttributeNS(SdkConstants.NS_RESOURCES, - AndroidManifestDescriptors.ANDROID_LABEL_ATTR); + attr = _Element_getAttributeNS(elem, + SdkConstants.NS_RESOURCES, + AndroidManifestDescriptors.ANDROID_LABEL_ATTR); } if (attr != null && attr.length() > 0) { return String.format("%1$s (%2$s)", attr, getDescriptor().getUiName()); @@ -94,5 +97,30 @@ public final class UiManifestElementNode extends UiElementNode { return String.format("%1$s", getDescriptor().getUiName()); } + + /** + * Retrieves an attribute value by local name and namespace URI. + * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>] + * , applications must use the value <code>null</code> as the + * <code>namespaceURI</code> parameter for methods if they wish to have + * no namespace. + * <p/> + * Note: This is a wrapper around {@link Element#getAttributeNS(String, String)}. + * In some versions of webtools, the getAttributeNS implementation crashes with an NPE. + * This wrapper will return null instead. + * + * @see Element#getAttributeNS(String, String) + * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=318108">https://bugs.eclipse.org/bugs/show_bug.cgi?id=318108</a> + * @return The result from {@link Element#getAttributeNS(String, String)} or or an empty string. + */ + private String _Element_getAttributeNS(Element element, + String namespaceURI, + String localName) { + try { + return element.getAttributeNS(namespaceURI, localName); + } catch (Exception ignore) { + return ""; + } + } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java index 9cce764..280f518 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java @@ -204,22 +204,28 @@ public class UiElementNode implements IPropertySource { // just using the UI name below. Element elem = (Element) mXmlNode; - String attr = elem.getAttributeNS(SdkConstants.NS_RESOURCES, - AndroidManifestDescriptors.ANDROID_NAME_ATTR); + String attr = _Element_getAttributeNS(elem, + SdkConstants.NS_RESOURCES, + AndroidManifestDescriptors.ANDROID_NAME_ATTR); if (attr == null || attr.length() == 0) { - attr = elem.getAttributeNS(SdkConstants.NS_RESOURCES, - AndroidManifestDescriptors.ANDROID_LABEL_ATTR); + attr = _Element_getAttributeNS(elem, + SdkConstants.NS_RESOURCES, + AndroidManifestDescriptors.ANDROID_LABEL_ATTR); } if (attr == null || attr.length() == 0) { - attr = elem.getAttributeNS(SdkConstants.NS_RESOURCES, - XmlDescriptors.PREF_KEY_ATTR); + attr = _Element_getAttributeNS(elem, + SdkConstants.NS_RESOURCES, + XmlDescriptors.PREF_KEY_ATTR); } if (attr == null || attr.length() == 0) { - attr = elem.getAttribute(ResourcesDescriptors.NAME_ATTR); + attr = _Element_getAttributeNS(elem, + null, // no namespace + ResourcesDescriptors.NAME_ATTR); } if (attr == null || attr.length() == 0) { - attr = elem.getAttributeNS(SdkConstants.NS_RESOURCES, - LayoutDescriptors.ID_ATTR); + attr = _Element_getAttributeNS(elem, + SdkConstants.NS_RESOURCES, + LayoutDescriptors.ID_ATTR); if (attr != null && attr.length() > 0) { for (String prefix : ID_PREFIXES) { @@ -239,6 +245,31 @@ public class UiElementNode implements IPropertySource { } /** + * Retrieves an attribute value by local name and namespace URI. + * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>] + * , applications must use the value <code>null</code> as the + * <code>namespaceURI</code> parameter for methods if they wish to have + * no namespace. + * <p/> + * Note: This is a wrapper around {@link Element#getAttributeNS(String, String)}. + * In some versions of webtools, the getAttributeNS implementation crashes with an NPE. + * This wrapper will return null instead. + * + * @see Element#getAttributeNS(String, String) + * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=318108">https://bugs.eclipse.org/bugs/show_bug.cgi?id=318108</a> + * @return The result from {@link Element#getAttributeNS(String, String)} or an empty string. + */ + private String _Element_getAttributeNS(Element element, + String namespaceURI, + String localName) { + try { + return element.getAttributeNS(namespaceURI, localName); + } catch (Exception ignore) { + return ""; + } + } + + /** * Computes a "breadcrumb trail" description for this node. * It will look something like "Manifest > Application > .myactivity (Activity) > Intent-Filter" * |