diff options
104 files changed, 567 insertions, 523 deletions
diff --git a/common/.classpath b/common/.classpath index fb50116..88fb9b4 100644 --- a/common/.classpath +++ b/common/.classpath @@ -1,6 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="tests/src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/common/src/com/android/util/XmlUtils.java b/common/src/com/android/util/XmlUtils.java new file mode 100644 index 0000000..11db031 --- /dev/null +++ b/common/src/com/android/util/XmlUtils.java @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2012 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.util; + +import com.android.annotations.NonNull; +import com.android.annotations.Nullable; + +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +import java.util.HashSet; + +/** XML Utilities */ +public class XmlUtils { + /** Namespace used in XML files for Android attributes */ + public static final String ANDROID_URI = + "http://schemas.android.com/apk/res/android"; //$NON-NLS-1$ + /** Namespace used in XML files for Android Tooling attributes */ + public static final String TOOLS_URI = + "http://schemas.android.com/tools"; //$NON-NLS-1$ + /** URI of the reserved "xmlns" prefix */ + public final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/"; //$NON-NLS-1$ + /** The "xmlns" attribute name */ + public static final String XMLNS = "xmlns"; //$NON-NLS-1$ + /** The default prefix used for the {@link #XMLNS_URI} */ + public static final String XMLNS_PREFIX = "xmlns:"; //$NON-NLS-1$ + /** Qualified name of the xmlns android declaration element */ + public static final String XMLNS_ANDROID = "xmlns:android"; //$NON-NLS-1$ + /** The default prefix used for the {@link #ANDROID_URI} name space */ + public static final String ANDROID_NS_NAME = "android"; //$NON-NLS-1$ + /** The default prefix used for the {@link #ANDROID_URI} name space including the colon */ + public static final String ANDROID_NS_NAME_PREFIX = "android:"; //$NON-NLS-1$ + /** The default prefix used for the app */ + private static final String APP_PREFIX = "app"; //$NON-NLS-1$ + /** The "xmlns:" attribute prefix used for namespace declarations */ + public static final String XMLNS_COLON = "xmlns:"; //$NON-NLS-1$ + /** The entity for the ampersand character */ + public static final String AMP_ENTITY = "&"; //$NON-NLS-1$ + /** The entity for the quote character */ + public static final String QUOT_ENTITY = """; //$NON-NLS-1$ + /** The entity for the apostrophe character */ + public static final String APOS_ENTITY = "'"; //$NON-NLS-1$ + /** The entity for the less than character */ + public static final String LT_ENTITY = "<"; //$NON-NLS-1$ + /** The entity for the greater than character */ + public static final String GT_ENTITY = ">"; //$NON-NLS-1$ + + /** + * Returns the namespace prefix matching the requested namespace URI. + * If no such declaration is found, returns the default "android" prefix for + * the Android URI, and "app" for other URI's. + * + * @param node The current node. Must not be null. + * @param nsUri The namespace URI of which the prefix is to be found, + * e.g. SdkConstants.NS_RESOURCES + * @return The first prefix declared or the default "android" prefix + * (or "app" for non-Android URIs) + */ + @NonNull + public static String lookupNamespacePrefix(@NonNull Node node, @NonNull String nsUri) { + String defaultPrefix = ANDROID_URI.equals(nsUri) ? ANDROID_NS_NAME : APP_PREFIX; + return lookupNamespacePrefix(node, nsUri, defaultPrefix); + } + + /** + * Returns the namespace prefix matching the requested namespace URI. + * If no such declaration is found, returns the default "android" prefix. + * + * @param node The current node. Must not be null. + * @param nsUri The namespace URI of which the prefix is to be found, + * e.g. SdkConstants.NS_RESOURCES + * @param defaultPrefix The default prefix (root) to use if the namespace + * is not found. If null, do not create a new namespace + * if this URI is not defined for the document. + * @return The first prefix declared or the provided prefix (possibly with + * a number appended to avoid conflicts with existing prefixes. + */ + public static String lookupNamespacePrefix( + @Nullable Node node, @Nullable String nsUri, @Nullable String defaultPrefix) { + // Note: Node.lookupPrefix is not implemented in wst/xml/core NodeImpl.java + // The following code emulates this simple call: + // String prefix = node.lookupPrefix(SdkConstants.NS_RESOURCES); + + // if the requested URI is null, it denotes an attribute with no namespace. + if (nsUri == null) { + return null; + } + + // per XML specification, the "xmlns" URI is reserved + if (XMLNS_URI.equals(nsUri)) { + return XMLNS; + } + + HashSet<String> visited = new HashSet<String>(); + Document doc = node == null ? null : node.getOwnerDocument(); + + // Ask the document about it. This method may not be implemented by the Document. + String nsPrefix = null; + try { + nsPrefix = doc != null ? doc.lookupPrefix(nsUri) : null; + if (nsPrefix != null) { + return nsPrefix; + } + } catch (Throwable t) { + // ignore + } + + // If that failed, try to look it up manually. + // This also gathers prefixed in use in the case we want to generate a new one below. + for (; node != null && node.getNodeType() == Node.ELEMENT_NODE; + node = node.getParentNode()) { + NamedNodeMap attrs = node.getAttributes(); + for (int n = attrs.getLength() - 1; n >= 0; --n) { + Node attr = attrs.item(n); + if (XMLNS.equals(attr.getPrefix())) { + String uri = attr.getNodeValue(); + nsPrefix = attr.getLocalName(); + // Is this the URI we are looking for? If yes, we found its prefix. + if (nsUri.equals(uri)) { + return nsPrefix; + } + visited.add(nsPrefix); + } + } + } + + // Failed the find a prefix. Generate a new sensible default prefix, unless + // defaultPrefix was null in which case the caller does not want the document + // modified. + if (defaultPrefix == null) { + return null; + } + + // + // We need to make sure the prefix is not one that was declared in the scope + // visited above. Pick a unique prefix from the provided default prefix. + String prefix = defaultPrefix; + String base = prefix; + for (int i = 1; visited.contains(prefix); i++) { + prefix = base + Integer.toString(i); + } + // Also create & define this prefix/URI in the XML document as an attribute in the + // first element of the document. + if (doc != null) { + node = doc.getFirstChild(); + while (node != null && node.getNodeType() != Node.ELEMENT_NODE) { + node = node.getNextSibling(); + } + if (node != null) { + // This doesn't work: + //Attr attr = doc.createAttributeNS(XMLNS_URI, prefix); + //attr.setPrefix(XMLNS); + // + // Xerces throws + //org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or + // change an object in a way which is incorrect with regard to namespaces. + // + // Instead pass in the concatenated prefix. (This is covered by + // the UiElementNodeTest#testCreateNameSpace() test.) + Attr attr = doc.createAttributeNS(XMLNS_URI, XMLNS_PREFIX + prefix); + attr.setValue(nsUri); + node.getAttributes().setNamedItemNS(attr); + } + } + + return prefix; + } + + /** + * Converts the given attribute value to an XML-attribute-safe value, meaning that + * single and double quotes are replaced with their corresponding XML entities. + * + * @param attrValue the value to be escaped + * @return the escaped value + */ + @NonNull + public static String toXmlAttributeValue(@NonNull String attrValue) { + for (int i = 0, n = attrValue.length(); i < n; i++) { + char c = attrValue.charAt(i); + if (c == '"' || c == '\'' || c == '<' || c == '&') { + StringBuilder sb = new StringBuilder(2 * attrValue.length()); + appendXmlAttributeValue(sb, attrValue); + return sb.toString(); + } + } + + return attrValue; + } + + /** + * Appends text to the given {@link StringBuilder} and escapes it as required for a + * DOM attribute node. + * + * @param sb the string builder + * @param attrValue the attribute value to be appended and escaped + */ + public static void appendXmlAttributeValue(@NonNull StringBuilder sb, + @NonNull String attrValue) { + int n = attrValue.length(); + // &, ", ' and < are illegal in attributes; see http://www.w3.org/TR/REC-xml/#NT-AttValue + // (' legal in a " string and " is legal in a ' string but here we'll stay on the safe + // side) + for (int i = 0; i < n; i++) { + char c = attrValue.charAt(i); + if (c == '"') { + sb.append(QUOT_ENTITY); + } else if (c == '<') { + sb.append(LT_ENTITY); + } else if (c == '\'') { + sb.append(APOS_ENTITY); + } else if (c == '&') { + sb.append(AMP_ENTITY); + } else { + sb.append(c); + } + } + } + + /** + * Appends text to the given {@link StringBuilder} and escapes it as required for a + * DOM text node. + * + * @param sb the string builder + * @param textValue the text value to be appended and escaped + */ + public static void appendXmlTextValue(@NonNull StringBuilder sb, @NonNull String textValue) { + for (int i = 0, n = textValue.length(); i < n; i++) { + char c = textValue.charAt(i); + if (c == '<') { + sb.append(LT_ENTITY); + } else if (c == '&') { + sb.append(AMP_ENTITY); + } else { + sb.append(c); + } + } + } +} diff --git a/common/tests/src/com/android/util/XmlUtilsTest.java b/common/tests/src/com/android/util/XmlUtilsTest.java new file mode 100644 index 0000000..655829b --- /dev/null +++ b/common/tests/src/com/android/util/XmlUtilsTest.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2012 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.util; + +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import junit.framework.TestCase; + +@SuppressWarnings("javadoc") +public class XmlUtilsTest extends TestCase { + public void testlookupNamespacePrefix() throws Exception { + // Setup + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + factory.setValidating(false); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.newDocument(); + Element rootElement = document.createElement("root"); + Attr attr = document.createAttributeNS(XmlUtils.XMLNS_URI, + "xmlns:customPrefix"); + attr.setValue(XmlUtils.ANDROID_URI); + rootElement.getAttributes().setNamedItemNS(attr); + document.appendChild(rootElement); + Element root = document.getDocumentElement(); + root.appendChild(document.createTextNode(" ")); + Element foo = document.createElement("foo"); + root.appendChild(foo); + root.appendChild(document.createTextNode(" ")); + Element bar = document.createElement("bar"); + root.appendChild(bar); + Element baz = document.createElement("baz"); + root.appendChild(baz); + + String prefix = XmlUtils.lookupNamespacePrefix(baz, XmlUtils.ANDROID_URI); + assertEquals("customPrefix", prefix); + + prefix = XmlUtils.lookupNamespacePrefix(baz, + "http://schemas.android.com/tools", "tools"); + assertEquals("tools", prefix); + } + + public void testToXmlAttributeValue() throws Exception { + assertEquals("", XmlUtils.toXmlAttributeValue("")); + assertEquals("foo", XmlUtils.toXmlAttributeValue("foo")); + assertEquals("foo<bar", XmlUtils.toXmlAttributeValue("foo<bar")); + assertEquals("foo>bar", XmlUtils.toXmlAttributeValue("foo>bar")); + + assertEquals(""", XmlUtils.toXmlAttributeValue("\"")); + assertEquals("'", XmlUtils.toXmlAttributeValue("'")); + assertEquals("foo"b''ar", + XmlUtils.toXmlAttributeValue("foo\"b''ar")); + assertEquals("<"'>&", XmlUtils.toXmlAttributeValue("<\"'>&")); + } + + public void testAppendXmlAttributeValue() throws Exception { + StringBuilder sb = new StringBuilder(); + XmlUtils.appendXmlAttributeValue(sb, "<\"'>&"); + assertEquals("<"'>&", sb.toString()); + } + + public void testAppendXmlTextValue() throws Exception { + StringBuilder sb = new StringBuilder(); + XmlUtils.appendXmlTextValue(sb, "<\"'>&"); + assertEquals("<\"'>&", sb.toString()); + } +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/AbsoluteLayoutRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/AbsoluteLayoutRule.java index 526b8c2..57406d5 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/AbsoluteLayoutRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/AbsoluteLayoutRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_X; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_Y; import static com.android.ide.common.layout.LayoutConstants.VALUE_N_DP; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java index 76e515e..581788b 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_ABOVE; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_ALIGN_BASELINE; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseViewRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseViewRule.java index ddad36c..75326fe 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseViewRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseViewRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_CLASS; import static com.android.ide.common.layout.LayoutConstants.ATTR_HINT; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/CalendarViewRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/CalendarViewRule.java index 161cca8..c580d8a 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/CalendarViewRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/CalendarViewRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/DialerFilterRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/DialerFilterRule.java index 9aa476e..e7a129b 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/DialerFilterRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/DialerFilterRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_BELOW; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/EditTextRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/EditTextRule.java index 7407854..875756b 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/EditTextRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/EditTextRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_EMS; import static com.android.ide.eclipse.adt.internal.editors.layout.descriptors.LayoutDescriptors.REQUEST_FOCUS; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FragmentRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FragmentRule.java index 3e10efd..fdef082 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FragmentRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FragmentRule.java @@ -15,7 +15,7 @@ */ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_NAME; import com.android.ide.common.api.INode; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FrameLayoutRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FrameLayoutRule.java index 4a8dfbb..8a93fef 100755..100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FrameLayoutRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FrameLayoutRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_GRAVITY; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/GravityHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/GravityHelper.java index b2f769e..aa9a089 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/GravityHelper.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/GravityHelper.java @@ -15,7 +15,7 @@ */ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_GRAVITY; import static com.android.ide.common.layout.LayoutConstants.GRAVITY_VALUE_BOTTOM; import static com.android.ide.common.layout.LayoutConstants.GRAVITY_VALUE_CENTER; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/GridLayoutRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/GridLayoutRule.java index f8f0a8c..c51d229 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/GridLayoutRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/GridLayoutRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_COLUMN; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_GRAVITY; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_ROW; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/GridViewRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/GridViewRule.java index 8f81977..bc3de5e 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/GridViewRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/GridViewRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; import static com.android.ide.common.layout.LayoutConstants.ATTR_NUM_COLUMNS; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/HorizontalScrollViewRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/HorizontalScrollViewRule.java index 62ea6f9..b2ea435 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/HorizontalScrollViewRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/HorizontalScrollViewRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; import static com.android.ide.common.layout.LayoutConstants.ATTR_ORIENTATION; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ImageButtonRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ImageButtonRule.java index 6fceba4..e1afb56 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ImageButtonRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ImageButtonRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_SRC; import com.android.ide.common.api.INode; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ImageViewRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ImageViewRule.java index f7d8d5d..b255c14 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ImageViewRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ImageViewRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_SRC; import com.android.ide.common.api.INode; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java index 768f93f..7801fbd 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java @@ -18,8 +18,6 @@ package com.android.ide.common.layout; import static com.android.ide.eclipse.adt.AdtConstants.ANDROID_PKG; -import com.android.sdklib.SdkConstants; - /** * A bunch of constants that map to either: * <ul> @@ -157,17 +155,6 @@ public class LayoutConstants { public static final String GRAVITY_VALUE_CENTER_VERTICAL = "center_vertical"; //$NON-NLS-1$ public static final String GRAVITY_VALUE_FILL = "fill"; //$NON-NLS-1$ - /** The default prefix used for the {@link #ANDROID_URI} name space */ - public static final String ANDROID_NS_NAME = "android"; //$NON-NLS-1$ - /** The default prefix used for the {@link #ANDROID_URI} name space including the colon */ - public static final String ANDROID_NS_NAME_PREFIX = "android:"; //$NON-NLS-1$ - - /** - * Namespace for the Android resource XML, i.e. - * "http://schemas.android.com/apk/res/android" - */ - public static final String ANDROID_URI = SdkConstants.NS_RESOURCES; - /** * The top level android package as a prefix, "android.". */ diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LinearLayoutRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LinearLayoutRule.java index b89c0f8..8f8ea02 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LinearLayoutRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LinearLayoutRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_BASELINE_ALIGNED; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_GRAVITY; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ListViewRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ListViewRule.java index fdb1698..7420714 100755..100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ListViewRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ListViewRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; import com.android.ide.common.api.INode; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/MapViewRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/MapViewRule.java index eb1cf47..b6d0ba2 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/MapViewRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/MapViewRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import com.android.ide.common.api.INode; import com.android.ide.common.api.IViewRule; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/RadioGroupRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/RadioGroupRule.java index 88cce52..280019e 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/RadioGroupRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/RadioGroupRule.java @@ -15,7 +15,7 @@ */ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_CHECKED; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.VALUE_TRUE; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/RelativeLayoutRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/RelativeLayoutRule.java index 6212cff..f587bef 100755..100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/RelativeLayoutRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/RelativeLayoutRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_GRAVITY; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_ABOVE; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ScrollViewRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ScrollViewRule.java index 385dcc5..2114f39 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ScrollViewRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ScrollViewRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; import static com.android.ide.common.layout.LayoutConstants.FQCN_LINEAR_LAYOUT; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/SeekBarRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/SeekBarRule.java index 3324697..c65dec9 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/SeekBarRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/SeekBarRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; import com.android.ide.common.api.INode; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/SlidingDrawerRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/SlidingDrawerRule.java index 4af0ae9..73a5031 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/SlidingDrawerRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/SlidingDrawerRule.java @@ -15,7 +15,7 @@ */ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_CONTENT; import static com.android.ide.common.layout.LayoutConstants.ATTR_HANDLE; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/TabHostRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/TabHostRule.java index 2d7625b..099a760 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/TabHostRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/TabHostRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/WebViewRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/WebViewRule.java index 00085c8..5224df0 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/WebViewRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/WebViewRule.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ZoomButtonRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ZoomButtonRule.java index 1200da9..5714392 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ZoomButtonRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ZoomButtonRule.java @@ -15,7 +15,7 @@ */ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_SRC; import com.android.ide.common.api.INode; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/grid/GridModel.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/grid/GridModel.java index 9ef247e..1d17c9b 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/grid/GridModel.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/grid/GridModel.java @@ -19,7 +19,7 @@ import static com.android.ide.common.layout.GravityHelper.GRAVITY_BOTTOM; import static com.android.ide.common.layout.GravityHelper.GRAVITY_CENTER_HORIZ; import static com.android.ide.common.layout.GravityHelper.GRAVITY_CENTER_VERT; import static com.android.ide.common.layout.GravityHelper.GRAVITY_RIGHT; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_COLUMN_COUNT; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_COLUMN; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/DependencyGraph.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/DependencyGraph.java index 39b521b..de3270e 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/DependencyGraph.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/DependencyGraph.java @@ -15,7 +15,7 @@ */ package com.android.ide.common.layout.relative; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_PREFIX; import static com.android.ide.common.layout.LayoutConstants.VALUE_TRUE; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/GuidelineHandler.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/GuidelineHandler.java index 6a5ad23..8ff159c 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/GuidelineHandler.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/GuidelineHandler.java @@ -26,7 +26,7 @@ import static com.android.ide.common.api.SegmentType.LEFT; import static com.android.ide.common.api.SegmentType.RIGHT; import static com.android.ide.common.api.SegmentType.TOP; import static com.android.ide.common.layout.BaseLayoutRule.getMaxMatchDistance; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_ABOVE; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_ALIGN_BASELINE; @@ -828,4 +828,4 @@ public class GuidelineHandler { public IClientRulesEngine getRulesEngine() { return mRulesEngine; } -}
\ No newline at end of file +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/Match.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/Match.java index 98d02e8..5af2df8 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/Match.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/Match.java @@ -15,7 +15,7 @@ */ package com.android.ide.common.layout.relative; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.VALUE_TRUE; @@ -95,4 +95,4 @@ class Match { return "Match [type=" + type + ", delta=" + delta + ", edge=" + edge + "]"; } -}
\ No newline at end of file +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/MoveHandler.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/MoveHandler.java index 3b066b7..3b73696 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/MoveHandler.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/MoveHandler.java @@ -23,7 +23,7 @@ import static com.android.ide.common.api.SegmentType.CENTER_VERTICAL; import static com.android.ide.common.api.SegmentType.LEFT; import static com.android.ide.common.api.SegmentType.RIGHT; import static com.android.ide.common.api.SegmentType.TOP; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static java.lang.Math.abs; @@ -278,4 +278,4 @@ public class MoveHandler extends GuidelineHandler { checkCycles(feedback); } -}
\ No newline at end of file +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/ResizeHandler.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/ResizeHandler.java index 2e5b4b1..e4fff32 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/ResizeHandler.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/relative/ResizeHandler.java @@ -23,7 +23,7 @@ import static com.android.ide.common.api.SegmentType.CENTER_VERTICAL; import static com.android.ide.common.api.SegmentType.LEFT; import static com.android.ide.common.api.SegmentType.RIGHT; import static com.android.ide.common.api.SegmentType.TOP; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static java.lang.Math.abs; @@ -245,4 +245,4 @@ public class ResizeHandler extends GuidelineHandler { checkCycles(feedback); } -}
\ No newline at end of file +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java index 114e45a..8ba909f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java @@ -25,6 +25,7 @@ import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper; import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper.IProjectFilter; +import com.android.util.XmlUtils; import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.resources.IFile; @@ -630,11 +631,10 @@ public class AdtUtils { editor.wrapUndoEditXmlModel(description, new Runnable() { @Override public void run() { - String prefix = UiElementNode.lookupNamespacePrefix(element, - TOOLS_URI, null); + String prefix = XmlUtils.lookupNamespacePrefix(element, TOOLS_URI, null); if (prefix == null) { // Add in new prefix... - prefix = UiElementNode.lookupNamespacePrefix(element, + prefix = XmlUtils.lookupNamespacePrefix(element, TOOLS_URI, TOOLS_PREFIX); // ...and ensure that the header is formatted such that // the XML namespace declaration is placed in the right diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AaptQuickFix.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AaptQuickFix.java index bea293e..455f104 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AaptQuickFix.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AaptQuickFix.java @@ -16,13 +16,14 @@ package com.android.ide.eclipse.adt.internal.build; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; +import static com.android.util.XmlUtils.XMLNS_ANDROID; +import static com.android.util.XmlUtils.XMLNS_URI; import com.android.ide.eclipse.adt.AdtConstants; import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.AdtUtils; import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor; -import com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor; import com.android.ide.eclipse.adt.internal.resources.ResourceHelper; import com.android.resources.ResourceType; import com.android.util.Pair; @@ -255,8 +256,7 @@ public class AaptQuickFix implements IMarkerResolutionGenerator2, IQuickAssistPr IDOMModel domModel = (IDOMModel) model; Document document = domModel.getDocument(); Element element = document.getDocumentElement(); - Attr attr = document.createAttributeNS(XmlnsAttributeDescriptor.XMLNS_URI, - "xmlns:android"); //$NON-NLS-1$ + Attr attr = document.createAttributeNS(XMLNS_URI, XMLNS_ANDROID); attr.setValue(ANDROID_URI); element.getAttributes().setNamedItemNS(attr); return (IndexedRegion) attr; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java index 7a2658b..87e207f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java @@ -30,15 +30,14 @@ import com.android.ide.eclipse.adt.internal.editors.descriptors.IDescriptorProvi import com.android.ide.eclipse.adt.internal.editors.descriptors.SeparatorAttributeDescriptor; import com.android.ide.eclipse.adt.internal.editors.descriptors.TextAttributeDescriptor; import com.android.ide.eclipse.adt.internal.editors.descriptors.TextValueDescriptor; -import com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor; import com.android.ide.eclipse.adt.internal.editors.layout.gle2.DomUtilities; 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.UiFlagAttributeNode; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiResourceAttributeNode; import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData; -import com.android.sdklib.SdkConstants; import com.android.util.Pair; +import com.android.util.XmlUtils; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.text.BadLocationException; @@ -53,7 +52,6 @@ import org.eclipse.jface.text.contentassist.IContextInformationValidator; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.swt.graphics.Image; import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import java.util.ArrayList; @@ -61,7 +59,6 @@ import java.util.Arrays; import java.util.Comparator; import java.util.EnumSet; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.regex.Pattern; @@ -276,55 +273,6 @@ public abstract class AndroidContentAssist implements IContentAssistProcessor { } /** - * Returns the namespace prefix matching the Android Resource URI. - * If no such declaration is found, returns the default "android" prefix. - * - * @param node The current node. Must not be null. - * @param nsUri The namespace URI of which the prefix is to be found, - * e.g. {@link SdkConstants#NS_RESOURCES} - * @return The first prefix declared or the default "android" prefix. - */ - private static String lookupNamespacePrefix(Node node, String nsUri) { - // Note: Node.lookupPrefix is not implemented in wst/xml/core NodeImpl.java - // The following emulates this: - // String prefix = node.lookupPrefix(SdkConstants.NS_RESOURCES); - - if (XmlnsAttributeDescriptor.XMLNS_URI.equals(nsUri)) { - return XmlnsAttributeDescriptor.XMLNS; - } - - HashSet<String> visited = new HashSet<String>(); - - String prefix = null; - for (; prefix == null && - node != null && - node.getNodeType() == Node.ELEMENT_NODE; - node = node.getParentNode()) { - NamedNodeMap attrs = node.getAttributes(); - for (int n = attrs.getLength() - 1; n >= 0; --n) { - Node attr = attrs.item(n); - if (XmlnsAttributeDescriptor.XMLNS.equals(attr.getPrefix())) { - String uri = attr.getNodeValue(); - if (nsUri.equals(uri)) { - return attr.getLocalName(); - } - visited.add(uri); - } - } - } - - // Use a sensible default prefix if we can't find one. - // We need to make sure the prefix is not one that was declared in the scope - // visited above. - prefix = SdkConstants.NS_RESOURCES.equals(nsUri) ? "android" : "app"; //$NON-NLS-1$ //$NON-NLS-2$ - String base = prefix; - for (int i = 1; visited.contains(prefix); i++) { - prefix = base + Integer.toString(i); - } - return prefix; - } - - /** * Gets the choices when the user is editing the name of an XML element. * <p/> * The user is editing the name of an element (the "parent"). @@ -625,7 +573,7 @@ public abstract class AndroidContentAssist implements IContentAssistProcessor { if (nsUri != null) { nsPrefix = nsUriMap.get(nsUri); if (nsPrefix == null) { - nsPrefix = lookupNamespacePrefix(currentNode, nsUri); + nsPrefix = XmlUtils.lookupNamespacePrefix(currentNode, nsUri); nsUriMap.put(nsUri, nsPrefix); } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/Hyperlinks.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/Hyperlinks.java index bac7c56..6e035af 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/Hyperlinks.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/Hyperlinks.java @@ -16,7 +16,7 @@ package com.android.ide.eclipse.adt.internal.editors; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_CLASS; import static com.android.ide.common.layout.LayoutConstants.ATTR_NAME; import static com.android.ide.common.layout.LayoutConstants.ATTR_ON_CLICK; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/OutlineLabelProvider.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/OutlineLabelProvider.java index f8333bb..350c8e2 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/OutlineLabelProvider.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/OutlineLabelProvider.java @@ -15,7 +15,7 @@ */ package com.android.ide.eclipse.adt.internal.editors; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.ATTR_NAME; import static com.android.ide.common.layout.LayoutConstants.ATTR_SRC; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimDescriptors.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimDescriptors.java index cdfaa21..4a35d4c 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimDescriptors.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimDescriptors.java @@ -15,13 +15,13 @@ */ package com.android.ide.eclipse.adt.internal.editors.animator; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME; +import static com.android.util.XmlUtils.ANDROID_NS_NAME; +import static com.android.util.XmlUtils.ANDROID_URI; import com.android.ide.common.resources.platform.DeclareStyleableInfo; import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; import com.android.ide.eclipse.adt.internal.editors.descriptors.IDescriptorProvider; import com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor; -import com.android.sdklib.SdkConstants; import java.util.ArrayList; import java.util.HashMap; @@ -72,7 +72,7 @@ public class AnimDescriptors implements IDescriptorProvider { } XmlnsAttributeDescriptor xmlns = new XmlnsAttributeDescriptor(ANDROID_NS_NAME, - SdkConstants.NS_RESOURCES); + ANDROID_URI); List<ElementDescriptor> descriptors = new ArrayList<ElementDescriptor>(); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationContentAssist.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationContentAssist.java index 6b584b1..d4d428b 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationContentAssist.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationContentAssist.java @@ -16,8 +16,8 @@ package com.android.ide.eclipse.adt.internal.editors.animator; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME_PREFIX; import static com.android.ide.eclipse.adt.AdtConstants.ANDROID_PKG; +import static com.android.util.XmlUtils.ANDROID_NS_NAME_PREFIX; import com.android.annotations.VisibleForTesting; import com.android.ide.common.api.IAttributeInfo.Format; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimatorDescriptors.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimatorDescriptors.java index d72ad66..9e5885f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimatorDescriptors.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimatorDescriptors.java @@ -15,7 +15,8 @@ */ package com.android.ide.eclipse.adt.internal.editors.animator; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME; +import static com.android.util.XmlUtils.ANDROID_NS_NAME; +import static com.android.util.XmlUtils.ANDROID_URI; import com.android.ide.common.resources.platform.DeclareStyleableInfo; import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor; @@ -76,7 +77,7 @@ public class AnimatorDescriptors implements IDescriptorProvider { } XmlnsAttributeDescriptor xmlns = new XmlnsAttributeDescriptor(ANDROID_NS_NAME, - SdkConstants.NS_RESOURCES); + ANDROID_URI); List<ElementDescriptor> descriptors = new ArrayList<ElementDescriptor>(); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/color/ColorDescriptors.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/color/ColorDescriptors.java index 8db3e0f..592767e 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/color/ColorDescriptors.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/color/ColorDescriptors.java @@ -15,8 +15,8 @@ */ package com.android.ide.eclipse.adt.internal.editors.color; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME; -import static com.android.sdklib.SdkConstants.NS_RESOURCES; +import static com.android.util.XmlUtils.ANDROID_NS_NAME; +import static com.android.util.XmlUtils.ANDROID_URI; import com.android.ide.common.api.IAttributeInfo.Format; import com.android.ide.common.resources.platform.AttributeInfo; @@ -45,8 +45,8 @@ public class ColorDescriptors implements IDescriptorProvider { SELECTOR_TAG, "Selector", "Required. This must be the root element. Contains one or more <item> elements.", SDK_URL, - new AttributeDescriptor[] { new XmlnsAttributeDescriptor(ANDROID_NS_NAME, - NS_RESOURCES) }, + new AttributeDescriptor[] { + new XmlnsAttributeDescriptor(ANDROID_NS_NAME, ANDROID_URI) }, null /*children: added later*/, true /*mandatory*/); /** @return the root descriptor. */ diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtils.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtils.java index 19ff37a..bf45750 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtils.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtils.java @@ -16,7 +16,6 @@ package com.android.ide.eclipse.adt.internal.editors.descriptors; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_BELOW; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; @@ -39,6 +38,9 @@ import static com.android.ide.eclipse.adt.internal.editors.layout.descriptors.La import static com.android.ide.eclipse.adt.internal.editors.layout.descriptors.LayoutDescriptors.VIEW_FRAGMENT; import static com.android.ide.eclipse.adt.internal.editors.layout.descriptors.LayoutDescriptors.VIEW_INCLUDE; import static com.android.ide.eclipse.adt.internal.editors.layout.descriptors.LayoutDescriptors.VIEW_MERGE; +import static com.android.util.XmlUtils.ANDROID_URI; +import static com.android.util.XmlUtils.GT_ENTITY; +import static com.android.util.XmlUtils.LT_ENTITY; import com.android.annotations.NonNull; import com.android.ide.common.api.IAttributeInfo.Format; @@ -664,8 +666,8 @@ public final class DescriptorsUtils { */ private static String cleanupJavadocHtml(String s) { if (s != null) { - s = s.replaceAll("<", "\""); //$NON-NLS-1$ $NON-NLS-2$ - s = s.replaceAll(">", "\""); //$NON-NLS-1$ $NON-NLS-2$ + s = s.replaceAll(LT_ENTITY, "\""); //$NON-NLS-1$ $NON-NLS-2$ + s = s.replaceAll(GT_ENTITY, "\""); //$NON-NLS-1$ $NON-NLS-2$ s = s.replaceAll("<[^>]+>", ""); //$NON-NLS-1$ $NON-NLS-2$ } return s; @@ -945,7 +947,7 @@ public final class DescriptorsUtils { || viewName.equals(GALLERY) || viewName.equals(GRID_VIEW)) { // We should really also enforce that - // LayoutConstants.ANDROID_URI.equals(descriptor.getNameSpace()) + // XmlUtils.ANDROID_URI.equals(descriptor.getNameSpace()) // here and if not, return true, but it turns out the getNameSpace() // for elements are often "". diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/ElementDescriptor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/ElementDescriptor.java index 86afdbc..613a68f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/ElementDescriptor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/ElementDescriptor.java @@ -16,12 +16,12 @@ package com.android.ide.eclipse.adt.internal.editors.descriptors; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME_PREFIX; +import static com.android.util.XmlUtils.ANDROID_NS_NAME_PREFIX; +import static com.android.util.XmlUtils.ANDROID_URI; import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; -import com.android.sdklib.SdkConstants; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Image; @@ -213,7 +213,7 @@ public class ElementDescriptor implements Comparable<ElementDescriptor> { public final String getNamespace() { // For now we hard-code the prefix as being "android" if (mXmlName.startsWith(ANDROID_NS_NAME_PREFIX)) { - return SdkConstants.NS_RESOURCES; + return ANDROID_URI; } return ""; //$NON-NLs-1$ diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/XmlnsAttributeDescriptor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/XmlnsAttributeDescriptor.java index ac7d357..1695e22 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/XmlnsAttributeDescriptor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/XmlnsAttributeDescriptor.java @@ -16,6 +16,9 @@ package com.android.ide.eclipse.adt.internal.editors.descriptors; +import static com.android.util.XmlUtils.XMLNS; +import static com.android.util.XmlUtils.XMLNS_URI; + import com.android.ide.eclipse.adt.internal.editors.uimodel.UiAttributeNode; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; @@ -33,21 +36,8 @@ import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; */ public final class XmlnsAttributeDescriptor extends AttributeDescriptor { - /** - * URI of the reserved "xmlns" prefix, as described in - * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/namespaces-algorithms.html#normalizeDocumentAlgo - */ - public final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/"; //$NON-NLS-1$ - - /** The "xmlns" attribute name */ - public static final String XMLNS = "xmlns"; //$NON-NLS-1$ - - /** The "xmlns:" attribute prefix used for namespace declarations */ - public static final String XMLNS_COLON = "xmlns:"; //$NON-NLS-1$ - private String mValue; - public XmlnsAttributeDescriptor(String defaultPrefix, String value) { super(defaultPrefix, XMLNS_URI, null /* info */); mValue = value; @@ -66,7 +56,7 @@ public final class XmlnsAttributeDescriptor extends AttributeDescriptor { * This is defined by the XML specification. */ public String getXmlNsPrefix() { - return XmlnsAttributeDescriptor.XMLNS; + return XMLNS; } /** diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/drawable/DrawableDescriptors.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/drawable/DrawableDescriptors.java index 5603322..e8f771f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/drawable/DrawableDescriptors.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/drawable/DrawableDescriptors.java @@ -15,7 +15,8 @@ */ package com.android.ide.eclipse.adt.internal.editors.drawable; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME; +import static com.android.util.XmlUtils.ANDROID_NS_NAME; +import static com.android.util.XmlUtils.ANDROID_URI; import com.android.ide.common.api.IAttributeInfo.Format; import com.android.ide.common.resources.platform.AttributeInfo; @@ -84,7 +85,7 @@ public class DrawableDescriptors implements IDescriptorProvider { public synchronized void updateDescriptors(Map<String, DeclareStyleableInfo> styleMap) { XmlnsAttributeDescriptor xmlns = new XmlnsAttributeDescriptor(ANDROID_NS_NAME, - SdkConstants.NS_RESOURCES); + ANDROID_URI); List<ElementDescriptor> descriptors = new ArrayList<ElementDescriptor>(); AnimatorDescriptors.addElement(descriptors, styleMap, diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/formatting/XmlPrettyPrinter.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/formatting/XmlPrettyPrinter.java index 9cdbf81..22a86af 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/formatting/XmlPrettyPrinter.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/formatting/XmlPrettyPrinter.java @@ -15,15 +15,16 @@ */ package com.android.ide.eclipse.adt.internal.editors.formatting; -import static com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor.XMLNS; import static com.android.ide.eclipse.adt.internal.editors.values.descriptors.ValuesDescriptors.COLOR_ELEMENT; import static com.android.ide.eclipse.adt.internal.editors.values.descriptors.ValuesDescriptors.DIMEN_ELEMENT; import static com.android.ide.eclipse.adt.internal.editors.values.descriptors.ValuesDescriptors.ITEM_TAG; import static com.android.ide.eclipse.adt.internal.editors.values.descriptors.ValuesDescriptors.STRING_ELEMENT; import static com.android.ide.eclipse.adt.internal.editors.values.descriptors.ValuesDescriptors.STYLE_ELEMENT; +import static com.android.util.XmlUtils.XMLNS; import com.android.ide.eclipse.adt.AdtUtils; import com.android.ide.eclipse.adt.internal.editors.layout.gle2.DomUtilities; +import com.android.util.XmlUtils; import org.eclipse.wst.xml.core.internal.document.DocumentTypeImpl; import org.eclipse.wst.xml.core.internal.document.ElementImpl; @@ -330,7 +331,7 @@ public class XmlPrettyPrinter { } if (escape) { - DomUtilities.appendXmlTextValue(mOut, text); + XmlUtils.appendXmlTextValue(mOut, text); } else { // Text is already escaped mOut.append(text); @@ -683,7 +684,7 @@ public class XmlPrettyPrinter { } mOut.append(attribute.getName()); mOut.append('=').append('"'); - DomUtilities.appendXmlAttributeValue(mOut, attribute.getValue()); + XmlUtils.appendXmlAttributeValue(mOut, attribute.getValue()); mOut.append('"'); // Don't add a newline at the last attribute line; the > should diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParser.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParser.java index 6915052..d56dbe3 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParser.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParser.java @@ -16,7 +16,7 @@ package com.android.ide.eclipse.adt.internal.editors.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; import static com.android.ide.common.layout.LayoutConstants.ATTR_PADDING; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java index b255155..1fa3f06 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java @@ -17,11 +17,11 @@ package com.android.ide.eclipse.adt.internal.editors.layout.configuration; import static com.android.AndroidConstants.FD_RES_LAYOUT; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME_PREFIX; import static com.android.ide.common.resources.ResourceResolver.PREFIX_ANDROID_STYLE; import static com.android.ide.common.resources.ResourceResolver.PREFIX_RESOURCE_REF; import static com.android.ide.common.resources.ResourceResolver.PREFIX_STYLE; import static com.android.tools.lint.detector.api.LintConstants.TOOLS_URI; +import static com.android.util.XmlUtils.ANDROID_NS_NAME_PREFIX; import com.android.AndroidConstants; import com.android.annotations.NonNull; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/CustomViewDescriptorService.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/CustomViewDescriptorService.java index 23aa2a0..a110c65 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/CustomViewDescriptorService.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/CustomViewDescriptorService.java @@ -16,11 +16,11 @@ package com.android.ide.eclipse.adt.internal.editors.layout.descriptors; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME_PREFIX; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.sdklib.SdkConstants.CLASS_VIEWGROUP; import static com.android.tools.lint.detector.api.LintConstants.AUTO_URI; import static com.android.tools.lint.detector.api.LintConstants.URI_PREFIX; +import static com.android.util.XmlUtils.ANDROID_NS_NAME_PREFIX; import com.android.annotations.NonNull; import com.android.annotations.Nullable; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/LayoutDescriptors.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/LayoutDescriptors.java index 2133abd..afa0057 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/LayoutDescriptors.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/LayoutDescriptors.java @@ -16,7 +16,7 @@ package com.android.ide.eclipse.adt.internal.editors.layout.descriptors; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_CLASS; import static com.android.ide.common.layout.LayoutConstants.ATTR_NAME; import static com.android.ide.common.layout.LayoutConstants.ATTR_TAG; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ClipboardSupport.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ClipboardSupport.java index b5bcf29..343ee80 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ClipboardSupport.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ClipboardSupport.java @@ -20,7 +20,6 @@ import com.android.ide.common.api.IDragElement.IDragAttribute; import com.android.ide.common.api.INode; import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.internal.editors.descriptors.DescriptorsUtils; -import com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor; import com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate; import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.ViewElementDescriptor; import com.android.ide.eclipse.adt.internal.editors.layout.gre.NodeProxy; @@ -29,6 +28,7 @@ import com.android.ide.eclipse.adt.internal.editors.layout.uimodel.UiViewElement import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; import com.android.sdklib.SdkConstants; +import com.android.util.XmlUtils; import org.eclipse.jface.action.Action; import org.eclipse.swt.custom.StyledText; @@ -336,8 +336,8 @@ public class ClipboardSupport { // A root node requires the Android XMLNS uiNew.setAttributeValue( - "android", //$NON-NLS-1$ - XmlnsAttributeDescriptor.XMLNS_URI, + XmlUtils.ANDROID_NS_NAME, + XmlUtils.XMLNS_URI, SdkConstants.NS_RESOURCES, true /*override*/); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/DomUtilities.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/DomUtilities.java index 51328f3..9830f7e 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/DomUtilities.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/DomUtilities.java @@ -15,7 +15,7 @@ */ package com.android.ide.eclipse.adt.internal.editors.layout.gle2; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.ID_PREFIX; import static com.android.ide.common.layout.LayoutConstants.NEW_ID_PREFIX; @@ -63,8 +63,6 @@ import javax.xml.parsers.DocumentBuilderFactory; */ @SuppressWarnings("restriction") // No replacement for restricted XML model yet public class DomUtilities { - private static final String AMPERSAND_ENTITY = "&"; //$NON-NLS-1$ - /** * Finds the nearest common parent of the two given nodes (which could be one of the * two nodes as well) @@ -466,76 +464,6 @@ public class DomUtilities { return (Element) node; // may be null as well } - /** - * Converts the given attribute value to an XML-attribute-safe value, meaning that - * single and double quotes are replaced with their corresponding XML entities. - * - * @param attrValue the value to be escaped - * @return the escaped value - */ - @NonNull - public static String toXmlAttributeValue(@NonNull String attrValue) { - for (int i = 0, n = attrValue.length(); i < n; i++) { - char c = attrValue.charAt(i); - if (c == '"' || c == '\'' || c == '<' || c == '&') { - StringBuilder sb = new StringBuilder(2 * attrValue.length()); - appendXmlAttributeValue(sb, attrValue); - return sb.toString(); - } - } - - return attrValue; - } - - /** - * Appends text to the given {@link StringBuilder} and escapes it as required for a - * DOM attribute node. - * - * @param sb the string builder - * @param attrValue the attribute value to be appended and escaped - */ - public static void appendXmlAttributeValue(@NonNull StringBuilder sb, - @NonNull String attrValue) { - int n = attrValue.length(); - // &, ", ' and < are illegal in attributes; see http://www.w3.org/TR/REC-xml/#NT-AttValue - // (' legal in a " string and " is legal in a ' string but here we'll stay on the safe - // side) - for (int i = 0; i < n; i++) { - char c = attrValue.charAt(i); - if (c == '"') { - sb.append("""); //$NON-NLS-1$ - } else if (c == '<') { - sb.append("<"); //$NON-NLS-1$ - } else if (c == '\'') { - sb.append("'"); //$NON-NLS-1$ - } else if (c == '&') { - sb.append(AMPERSAND_ENTITY); - } else { - sb.append(c); - } - } - } - - /** - * Appends text to the given {@link StringBuilder} and escapes it as required for a - * DOM text node. - * - * @param sb the string builder - * @param textValue the text value to be appended and escaped - */ - public static void appendXmlTextValue(@NonNull StringBuilder sb, @NonNull String textValue) { - for (int i = 0, n = textValue.length(); i < n; i++) { - char c = textValue.charAt(i); - if (c == '<') { - sb.append("<"); //$NON-NLS-1$ - } else if (c == '&') { - sb.append(AMPERSAND_ENTITY); - } else { - sb.append(c); - } - } - } - /** Utility used by {@link #getFreeWidgetId(Element)} */ private static void addLowercaseIds(@NonNull Element root, @NonNull Set<String> seen) { if (root.hasAttributeNS(ANDROID_URI, ATTR_ID)) { diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/DynamicContextMenu.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/DynamicContextMenu.java index a5bbb85..2343807 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/DynamicContextMenu.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/DynamicContextMenu.java @@ -16,7 +16,7 @@ package com.android.ide.eclipse.adt.internal.editors.layout.gle2; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.EXPANDABLE_LIST_VIEW; import static com.android.ide.common.layout.LayoutConstants.FQCN_GESTURE_OVERLAY_VIEW; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/FragmentMenu.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/FragmentMenu.java index ae83f36..0b0faa0 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/FragmentMenu.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/FragmentMenu.java @@ -16,7 +16,7 @@ package com.android.ide.eclipse.adt.internal.editors.layout.gle2; import static com.android.ide.common.layout.LayoutConstants.ANDROID_LAYOUT_PREFIX; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_CLASS; import static com.android.ide.common.layout.LayoutConstants.ATTR_NAME; import static com.android.ide.common.layout.LayoutConstants.LAYOUT_PREFIX; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java index 354ef9a..d4f25f8 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java @@ -17,7 +17,7 @@ package com.android.ide.eclipse.adt.internal.editors.layout.gle2; import static com.android.ide.common.layout.LayoutConstants.ANDROID_STRING_PREFIX; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java index 02aea9b..1c83430 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java @@ -15,7 +15,7 @@ */ package com.android.ide.eclipse.adt.internal.editors.layout.gle2; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import com.android.annotations.NonNull; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java index 7040584..481c215 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java @@ -19,12 +19,10 @@ package com.android.ide.eclipse.adt.internal.editors.layout.gle2; import com.android.ide.common.api.INode; import com.android.ide.common.api.Margins; import com.android.ide.common.api.Point; -import com.android.ide.common.layout.LayoutConstants; import com.android.ide.common.rendering.api.Capability; import com.android.ide.common.rendering.api.RenderSession; import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.internal.editors.descriptors.DescriptorsUtils; -import com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor; import com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate; import com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationComposite; import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.ViewElementDescriptor; @@ -37,6 +35,7 @@ import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; import com.android.resources.Density; import com.android.sdklib.SdkConstants; +import com.android.util.XmlUtils; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; @@ -1368,8 +1367,8 @@ public class LayoutCanvas extends Canvas { // A root node requires the Android XMLNS uiNew.setAttributeValue( - LayoutConstants.ANDROID_NS_NAME, - XmlnsAttributeDescriptor.XMLNS_URI, + XmlUtils.ANDROID_NS_NAME, + XmlUtils.XMLNS_URI, SdkConstants.NS_RESOURCES, true /*override*/); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutMetadata.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutMetadata.java index 0024bf3..9b4713d 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutMetadata.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutMetadata.java @@ -16,7 +16,7 @@ package com.android.ide.eclipse.adt.internal.editors.layout.gle2; import static com.android.ide.common.layout.LayoutConstants.ANDROID_LAYOUT_PREFIX; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_NUM_COLUMNS; import static com.android.ide.common.layout.LayoutConstants.EXPANDABLE_LIST_VIEW; import static com.android.ide.common.layout.LayoutConstants.GRID_VIEW; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/OutlinePage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/OutlinePage.java index 1e77e4c..eca47ab 100755..100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/OutlinePage.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/OutlinePage.java @@ -16,7 +16,7 @@ package com.android.ide.eclipse.adt.internal.editors.layout.gle2; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_CLASS; import static com.android.ide.common.layout.LayoutConstants.ATTR_COLUMN_COUNT; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_COLUMN; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteControl.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteControl.java index 8af4f2a..2a9666b 100755..100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteControl.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteControl.java @@ -16,11 +16,13 @@ package com.android.ide.eclipse.adt.internal.editors.layout.gle2; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; import static com.android.ide.common.layout.LayoutConstants.ATTR_TEXT; import static com.android.ide.common.layout.LayoutConstants.VALUE_WRAP_CONTENT; +import static com.android.util.XmlUtils.XMLNS_ANDROID; +import static com.android.util.XmlUtils.XMLNS_URI; import com.android.ide.common.api.InsertType; import com.android.ide.common.api.Rect; @@ -35,7 +37,6 @@ import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.editors.descriptors.DescriptorsUtils; import com.android.ide.eclipse.adt.internal.editors.descriptors.DocumentDescriptor; import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; -import com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor; import com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate; import com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationComposite; import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.CustomViewDescriptorService; @@ -920,8 +921,7 @@ public class PaletteControl extends Composite { Element element = document.createElement(viewName); // Set up a proper name space - Attr attr = document.createAttributeNS(XmlnsAttributeDescriptor.XMLNS_URI, - "xmlns:android"); //$NON-NLS-1$ + Attr attr = document.createAttributeNS(XMLNS_URI, XMLNS_ANDROID); attr.setValue(ANDROID_URI); element.getAttributes().setNamedItemNS(attr); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gre/PaletteMetadataDescriptor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gre/PaletteMetadataDescriptor.java index d6d5cd9..bcaf2f1 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gre/PaletteMetadataDescriptor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gre/PaletteMetadataDescriptor.java @@ -15,8 +15,8 @@ */ package com.android.ide.eclipse.adt.internal.editors.layout.gre; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME_PREFIX; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_NS_NAME_PREFIX; import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.ViewElementDescriptor; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gre/ViewMetadataRepository.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gre/ViewMetadataRepository.java index 4096ffe..45698eb 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gre/ViewMetadataRepository.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gre/ViewMetadataRepository.java @@ -16,7 +16,7 @@ package com.android.ide.eclipse.adt.internal.editors.layout.gre; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.FQCN_BUTTON; import static com.android.ide.common.layout.LayoutConstants.FQCN_SPINNER; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeLayoutRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeLayoutRefactoring.java index 27c03d0..abbfa11 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeLayoutRefactoring.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeLayoutRefactoring.java @@ -15,8 +15,7 @@ */ package com.android.ide.eclipse.adt.internal.editors.layout.refactoring; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME_PREFIX; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ANDROID_WIDGET_PREFIX; import static com.android.ide.common.layout.LayoutConstants.ATTR_BASELINE_ALIGNED; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_ALIGN_BASELINE; @@ -38,6 +37,7 @@ import static com.android.ide.common.layout.LayoutConstants.VALUE_FALSE; import static com.android.ide.common.layout.LayoutConstants.VALUE_VERTICAL; import static com.android.ide.common.layout.LayoutConstants.VALUE_WRAP_CONTENT; import static com.android.ide.eclipse.adt.AdtConstants.EXT_XML; +import static com.android.util.XmlUtils.ANDROID_NS_NAME_PREFIX; import com.android.annotations.VisibleForTesting; import com.android.ide.eclipse.adt.AdtPlugin; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeViewRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeViewRefactoring.java index b686aac..967a880 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeViewRefactoring.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeViewRefactoring.java @@ -15,7 +15,7 @@ */ package com.android.ide.eclipse.adt.internal.editors.layout.refactoring; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ANDROID_WIDGET_PREFIX; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_PREFIX; import static com.android.ide.common.layout.LayoutConstants.ATTR_TEXT; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractIncludeRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractIncludeRefactoring.java index 3b78f60..eb89304 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractIncludeRefactoring.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractIncludeRefactoring.java @@ -16,8 +16,7 @@ package com.android.ide.eclipse.adt.internal.editors.layout.refactoring; import static com.android.AndroidConstants.FD_RES_LAYOUT; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_PREFIX; @@ -28,10 +27,11 @@ import static com.android.ide.common.layout.LayoutConstants.VALUE_WRAP_CONTENT; import static com.android.ide.eclipse.adt.AdtConstants.DOT_XML; import static com.android.ide.eclipse.adt.AdtConstants.EXT_XML; import static com.android.ide.eclipse.adt.AdtConstants.WS_SEP; -import static com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor.XMLNS; -import static com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor.XMLNS_COLON; import static com.android.resources.ResourceType.LAYOUT; import static com.android.sdklib.SdkConstants.FD_RES; +import static com.android.util.XmlUtils.ANDROID_NS_NAME; +import static com.android.util.XmlUtils.XMLNS; +import static com.android.util.XmlUtils.XMLNS_COLON; import com.android.AndroidConstants; import com.android.annotations.VisibleForTesting; @@ -48,6 +48,7 @@ import com.android.ide.eclipse.adt.internal.editors.layout.uimodel.UiViewElement import com.android.ide.eclipse.adt.internal.preferences.AdtPrefs; import com.android.ide.eclipse.adt.internal.resources.ResourceNameValidator; import com.android.sdklib.SdkConstants; +import com.android.util.XmlUtils; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; @@ -496,7 +497,7 @@ public class ExtractIncludeRefactoring extends VisualRefactoring { androidNsPrefix = androidNsPrefix.substring(XMLNS_COLON.length()); } } - sb.append(DomUtilities.toXmlAttributeValue(value)); + sb.append(XmlUtils.toXmlAttributeValue(value)); sb.append('"'); } } @@ -585,7 +586,7 @@ public class ExtractIncludeRefactoring extends VisualRefactoring { sb.append(':'); sb.append(ATTR_LAYOUT_WIDTH); sb.append('=').append('"'); - sb.append(DomUtilities.toXmlAttributeValue(width)); + sb.append(XmlUtils.toXmlAttributeValue(width)); sb.append('"'); } if (height != null) { @@ -594,7 +595,7 @@ public class ExtractIncludeRefactoring extends VisualRefactoring { sb.append(':'); sb.append(ATTR_LAYOUT_HEIGHT); sb.append('=').append('"'); - sb.append(DomUtilities.toXmlAttributeValue(height)); + sb.append(XmlUtils.toXmlAttributeValue(height)); sb.append('"'); } @@ -616,7 +617,7 @@ public class ExtractIncludeRefactoring extends VisualRefactoring { sb.append(':'); sb.append(name); sb.append('=').append('"'); - sb.append(DomUtilities.toXmlAttributeValue(attr.getNodeValue())); + sb.append(XmlUtils.toXmlAttributeValue(attr.getNodeValue())); sb.append('"'); } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractStyleRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractStyleRefactoring.java index 48cb55b..c6e965d 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractStyleRefactoring.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractStyleRefactoring.java @@ -16,9 +16,7 @@ package com.android.ide.eclipse.adt.internal.editors.layout.refactoring; import static com.android.AndroidConstants.FD_RES_VALUES; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME_PREFIX; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_HINT; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_MARGIN; @@ -29,12 +27,14 @@ import static com.android.ide.common.layout.LayoutConstants.ATTR_STYLE; import static com.android.ide.common.layout.LayoutConstants.ATTR_TEXT; import static com.android.ide.eclipse.adt.AdtConstants.EXT_XML; import static com.android.ide.eclipse.adt.AdtConstants.WS_SEP; -import static com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor.XMLNS_COLON; import static com.android.ide.eclipse.adt.internal.editors.values.descriptors.ValuesDescriptors.ITEM_TAG; import static com.android.ide.eclipse.adt.internal.editors.values.descriptors.ValuesDescriptors.NAME_ATTR; import static com.android.ide.eclipse.adt.internal.editors.values.descriptors.ValuesDescriptors.PARENT_ATTR; import static com.android.ide.eclipse.adt.internal.editors.values.descriptors.ValuesDescriptors.ROOT_ELEMENT; import static com.android.sdklib.SdkConstants.FD_RESOURCES; +import static com.android.util.XmlUtils.ANDROID_NS_NAME; +import static com.android.util.XmlUtils.ANDROID_NS_NAME_PREFIX; +import static com.android.util.XmlUtils.XMLNS_COLON; import com.android.annotations.VisibleForTesting; import com.android.ide.common.rendering.api.ResourceValue; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/GridLayoutConverter.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/GridLayoutConverter.java index daf1f54..65a2aad 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/GridLayoutConverter.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/GridLayoutConverter.java @@ -17,7 +17,7 @@ package com.android.ide.eclipse.adt.internal.editors.layout.refactoring; import static com.android.ide.common.layout.GravityHelper.GRAVITY_HORIZ_MASK; import static com.android.ide.common.layout.GravityHelper.GRAVITY_VERT_MASK; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_BACKGROUND; import static com.android.ide.common.layout.LayoutConstants.ATTR_COLUMN_COUNT; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_ALIGN_BASELINE; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RelativeLayoutConversionHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RelativeLayoutConversionHelper.java index b53eb9d..6693ea7 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RelativeLayoutConversionHelper.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RelativeLayoutConversionHelper.java @@ -24,7 +24,7 @@ import static com.android.ide.common.layout.GravityHelper.GRAVITY_LEFT; import static com.android.ide.common.layout.GravityHelper.GRAVITY_RIGHT; import static com.android.ide.common.layout.GravityHelper.GRAVITY_TOP; import static com.android.ide.common.layout.GravityHelper.GRAVITY_VERT_MASK; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_BACKGROUND; import static com.android.ide.common.layout.LayoutConstants.ATTR_BASELINE_ALIGNED; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_ABOVE; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UnwrapRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UnwrapRefactoring.java index 039968d..050a787 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UnwrapRefactoring.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UnwrapRefactoring.java @@ -15,7 +15,7 @@ */ package com.android.ide.eclipse.adt.internal.editors.layout.refactoring; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; import static com.android.ide.eclipse.adt.AdtConstants.EXT_XML; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UseCompoundDrawableRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UseCompoundDrawableRefactoring.java index 53b8f49..8f9beab 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UseCompoundDrawableRefactoring.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UseCompoundDrawableRefactoring.java @@ -15,7 +15,7 @@ */ package com.android.ide.eclipse.adt.internal.editors.layout.refactoring; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_DRAWABLE_BOTTOM; import static com.android.ide.common.layout.LayoutConstants.ATTR_DRAWABLE_LEFT; import static com.android.ide.common.layout.LayoutConstants.ATTR_DRAWABLE_RIGHT; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/VisualRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/VisualRefactoring.java index cde9954..b94b61c 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/VisualRefactoring.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/VisualRefactoring.java @@ -15,8 +15,7 @@ */ package com.android.ide.eclipse.adt.internal.editors.layout.refactoring; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ANDROID_WIDGET_PREFIX; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; @@ -24,8 +23,9 @@ import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_PREFIX; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; import static com.android.ide.common.layout.LayoutConstants.ID_PREFIX; import static com.android.ide.common.layout.LayoutConstants.NEW_ID_PREFIX; -import static com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor.XMLNS; -import static com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor.XMLNS_COLON; +import static com.android.util.XmlUtils.ANDROID_NS_NAME; +import static com.android.util.XmlUtils.XMLNS; +import static com.android.util.XmlUtils.XMLNS_COLON; import com.android.annotations.NonNull; import com.android.annotations.VisibleForTesting; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/WrapInRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/WrapInRefactoring.java index 8e4f447..d043085 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/WrapInRefactoring.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/WrapInRefactoring.java @@ -15,8 +15,7 @@ */ package com.android.ide.eclipse.adt.internal.editors.layout.refactoring; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME_PREFIX; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ANDROID_WIDGET_PREFIX; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; @@ -25,6 +24,7 @@ import static com.android.ide.common.layout.LayoutConstants.VALUE_FILL_PARENT; import static com.android.ide.common.layout.LayoutConstants.VALUE_MATCH_PARENT; import static com.android.ide.common.layout.LayoutConstants.VALUE_WRAP_CONTENT; import static com.android.ide.eclipse.adt.AdtConstants.EXT_XML; +import static com.android.util.XmlUtils.ANDROID_NS_NAME_PREFIX; import com.android.annotations.VisibleForTesting; import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/uimodel/UiViewElementNode.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/uimodel/UiViewElementNode.java index 435529a..b87435c 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/uimodel/UiViewElementNode.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/uimodel/UiViewElementNode.java @@ -18,7 +18,6 @@ package com.android.ide.eclipse.adt.internal.editors.layout.uimodel; import static com.android.ide.common.layout.LayoutConstants.FQCN_FRAME_LAYOUT; -import com.android.ide.common.layout.LayoutConstants; import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor; import com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor; import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.LayoutDescriptors; @@ -28,7 +27,7 @@ import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData; import com.android.ide.eclipse.adt.internal.sdk.Sdk; import com.android.sdklib.IAndroidTarget; -import com.android.sdklib.SdkConstants; +import com.android.util.XmlUtils; import org.eclipse.core.resources.IProject; @@ -109,8 +108,8 @@ public class UiViewElementNode extends UiElementNode { layout_attrs.length); if (need_xmlns) { AttributeDescriptor desc = new XmlnsAttributeDescriptor( - LayoutConstants.ANDROID_NS_NAME, - SdkConstants.NS_RESOURCES); + XmlUtils.ANDROID_NS_NAME, + XmlUtils.ANDROID_URI); mCachedAttributeDescriptors[direct_attrs.length + layout_attrs.length] = desc; } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java index 8f34b48..a31c329 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java @@ -16,7 +16,7 @@ package com.android.ide.eclipse.adt.internal.editors.manifest; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_NAME; import static com.android.ide.eclipse.adt.internal.editors.manifest.descriptors.AndroidManifestDescriptors.USES_PERMISSION; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/descriptors/AndroidManifestDescriptors.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/descriptors/AndroidManifestDescriptors.java index e3b3aa6..15e35da 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/descriptors/AndroidManifestDescriptors.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/descriptors/AndroidManifestDescriptors.java @@ -18,7 +18,6 @@ package com.android.ide.eclipse.adt.internal.editors.manifest.descriptors; import com.android.ide.common.api.IAttributeInfo; import com.android.ide.common.api.IAttributeInfo.Format; -import com.android.ide.common.layout.LayoutConstants; import com.android.ide.common.resources.platform.AttributeInfo; import com.android.ide.common.resources.platform.AttrsXmlParser; import com.android.ide.common.resources.platform.DeclareStyleableInfo; @@ -34,6 +33,7 @@ import com.android.ide.eclipse.adt.internal.editors.descriptors.ReferenceAttribu import com.android.ide.eclipse.adt.internal.editors.descriptors.TextAttributeDescriptor; import com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor; import com.android.sdklib.SdkConstants; +import com.android.util.XmlUtils; import org.eclipse.core.runtime.IStatus; @@ -233,7 +233,7 @@ public final class AndroidManifestDescriptors implements IDescriptorProvider { insertAttribute(MANIFEST_ELEMENT, PACKAGE_ATTR_DESC); XmlnsAttributeDescriptor xmlns = new XmlnsAttributeDescriptor( - LayoutConstants.ANDROID_NS_NAME, SdkConstants.NS_RESOURCES); + XmlUtils.ANDROID_NS_NAME, XmlUtils.ANDROID_URI); insertAttribute(MANIFEST_ELEMENT, xmlns); assert sanityCheck(manifestMap, MANIFEST_ELEMENT); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/menu/descriptors/MenuDescriptors.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/menu/descriptors/MenuDescriptors.java index d9e9ac5..d23dc57 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/menu/descriptors/MenuDescriptors.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/menu/descriptors/MenuDescriptors.java @@ -16,7 +16,8 @@ package com.android.ide.eclipse.adt.internal.editors.menu.descriptors; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME; +import static com.android.util.XmlUtils.ANDROID_NS_NAME; +import static com.android.util.XmlUtils.ANDROID_URI; import com.android.ide.common.resources.platform.DeclareStyleableInfo; import com.android.ide.eclipse.adt.AdtUtils; @@ -126,7 +127,7 @@ public final class MenuDescriptors implements IDescriptorProvider { false /* mandatory */); XmlnsAttributeDescriptor xmlns = new XmlnsAttributeDescriptor(ANDROID_NS_NAME, - SdkConstants.NS_RESOURCES); + ANDROID_URI); updateElement(mDescriptor, styleMap, "Menu", xmlns); //$NON-NLS-1$ mDescriptor.setChildren(new ElementDescriptor[] { top_item, top_group }); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/otherxml/descriptors/OtherXmlDescriptors.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/otherxml/descriptors/OtherXmlDescriptors.java index 3517696..2e26ecd 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/otherxml/descriptors/OtherXmlDescriptors.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/otherxml/descriptors/OtherXmlDescriptors.java @@ -16,7 +16,8 @@ package com.android.ide.eclipse.adt.internal.editors.otherxml.descriptors; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME; +import static com.android.util.XmlUtils.ANDROID_NS_NAME; +import static com.android.util.XmlUtils.ANDROID_URI; import com.android.ide.common.resources.platform.AttributeInfo; import com.android.ide.common.resources.platform.DeclareStyleableInfo; @@ -141,9 +142,8 @@ public final class OtherXmlDescriptors implements IDescriptorProvider { Map<String, DeclareStyleableInfo> appWidgetStyleMap, ViewClassInfo[] prefs, ViewClassInfo[] prefGroups) { - XmlnsAttributeDescriptor xmlns = new XmlnsAttributeDescriptor( - ANDROID_NS_NAME, - SdkConstants.NS_RESOURCES); + XmlnsAttributeDescriptor xmlns = new XmlnsAttributeDescriptor(ANDROID_NS_NAME, + ANDROID_URI); ElementDescriptor searchable = createSearchable(searchableStyleMap, xmlns); ElementDescriptor appWidget = createAppWidgetProviderInfo(appWidgetStyleMap, xmlns); 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 42a8679..5ea127e 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 @@ -16,18 +16,12 @@ package com.android.ide.eclipse.adt.internal.editors.uimodel; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME; import static com.android.ide.common.layout.LayoutConstants.ANDROID_PKG_PREFIX; import static com.android.ide.common.layout.LayoutConstants.ANDROID_SUPPORT_PKG_PREFIX; import static com.android.ide.common.layout.LayoutConstants.ATTR_CLASS; import static com.android.ide.common.layout.LayoutConstants.ID_PREFIX; import static com.android.ide.common.layout.LayoutConstants.NEW_ID_PREFIX; -import static com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor.XMLNS; -import static com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor.XMLNS_URI; -import static com.android.sdklib.SdkConstants.NS_RESOURCES; -import static com.android.tools.lint.detector.api.LintConstants.XMLNS_PREFIX; -import com.android.annotations.Nullable; import com.android.annotations.VisibleForTesting; import com.android.ide.common.api.IAttributeInfo.Format; import com.android.ide.common.resources.platform.AttributeInfo; @@ -50,6 +44,7 @@ import com.android.ide.eclipse.adt.internal.editors.values.descriptors.ValuesDes import com.android.ide.eclipse.adt.internal.preferences.AdtPrefs; import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData; import com.android.sdklib.SdkConstants; +import com.android.util.XmlUtils; import org.eclipse.jface.text.TextUtilities; import org.eclipse.jface.viewers.StyledString; @@ -1066,7 +1061,7 @@ public class UiElementNode implements IPropertySource { for (AttributeDescriptor attrDesc : getAttributeDescriptors()) { if (attrDesc instanceof XmlnsAttributeDescriptor) { XmlnsAttributeDescriptor desc = (XmlnsAttributeDescriptor) attrDesc; - Attr attr = doc.createAttributeNS(XmlnsAttributeDescriptor.XMLNS_URI, + Attr attr = doc.createAttributeNS(XmlUtils.XMLNS_URI, desc.getXmlNsName()); attr.setValue(desc.getValue()); attr.setPrefix(desc.getXmlNsPrefix()); @@ -1583,7 +1578,7 @@ public class UiElementNode implements IPropertySource { attr = (Attr) attrMap.getNamedItemNS(attrNsUri, attrLocalName); if (attr == null) { attr = doc.createAttributeNS(attrNsUri, attrLocalName); - attr.setPrefix(lookupNamespacePrefix(element, attrNsUri)); + attr.setPrefix(XmlUtils.lookupNamespacePrefix(element, attrNsUri)); attrMap.setNamedItemNS(attr); } } else { @@ -1662,8 +1657,9 @@ public class UiElementNode implements IPropertySource { AttributeDescriptor descriptor = dirtyAttributes.get(0).getDescriptor(); String firstName = descriptor.getXmlLocalName(); String firstNamePrefix = null; - if (descriptor.getNamespaceUri() != null) { - firstNamePrefix = lookupNamespacePrefix(element, descriptor.getNamespaceUri()); + String namespaceUri = descriptor.getNamespaceUri(); + if (namespaceUri != null) { + firstNamePrefix = XmlUtils.lookupNamespacePrefix(element, namespaceUri); } NamedNodeMap attributes = ((Element) element).getAttributes(); List<Attr> move = new ArrayList<Attr>(); @@ -1743,126 +1739,6 @@ public class UiElementNode implements IPropertySource { } /** - * Returns the namespace prefix matching the requested namespace URI. - * If no such declaration is found, returns the default "android" prefix for - * the Android URI, and "app" for other URI's. - * - * @param node The current node. Must not be null. - * @param nsUri The namespace URI of which the prefix is to be found, - * e.g. SdkConstants.NS_RESOURCES - * @return The first prefix declared or the default "android" prefix - * (or "app" for non-Android URIs) - */ - public static String lookupNamespacePrefix(Node node, String nsUri) { - String defaultPrefix = NS_RESOURCES.equals(nsUri) ? ANDROID_NS_NAME : "app"; //$NON-NLS-1$ - return lookupNamespacePrefix(node, nsUri, defaultPrefix); - } - - /** - * Returns the namespace prefix matching the requested namespace URI. - * If no such declaration is found, returns the default "android" prefix. - * - * @param node The current node. Must not be null. - * @param nsUri The namespace URI of which the prefix is to be found, - * e.g. SdkConstants.NS_RESOURCES - * @param defaultPrefix The default prefix (root) to use if the namespace - * is not found. If null, do not create a new namespace - * if this URI is not defined for the document. - * @return The first prefix declared or the provided prefix (possibly with - * a number appended to avoid conflicts with existing prefixes. - */ - public static String lookupNamespacePrefix( - @Nullable Node node, @Nullable String nsUri, @Nullable String defaultPrefix) { - // Note: Node.lookupPrefix is not implemented in wst/xml/core NodeImpl.java - // The following code emulates this simple call: - // String prefix = node.lookupPrefix(SdkConstants.NS_RESOURCES); - - // if the requested URI is null, it denotes an attribute with no namespace. - if (nsUri == null) { - return null; - } - - // per XML specification, the "xmlns" URI is reserved - if (XMLNS_URI.equals(nsUri)) { - return XMLNS; - } - - HashSet<String> visited = new HashSet<String>(); - Document doc = node == null ? null : node.getOwnerDocument(); - - // Ask the document about it. This method may not be implemented by the Document. - String nsPrefix = null; - try { - nsPrefix = doc != null ? doc.lookupPrefix(nsUri) : null; - if (nsPrefix != null) { - return nsPrefix; - } - } catch (Throwable t) { - // ignore - } - - // If that failed, try to look it up manually. - // This also gathers prefixed in use in the case we want to generate a new one below. - for (; node != null && node.getNodeType() == Node.ELEMENT_NODE; - node = node.getParentNode()) { - NamedNodeMap attrs = node.getAttributes(); - for (int n = attrs.getLength() - 1; n >= 0; --n) { - Node attr = attrs.item(n); - if (XMLNS.equals(attr.getPrefix())) { - String uri = attr.getNodeValue(); - nsPrefix = attr.getLocalName(); - // Is this the URI we are looking for? If yes, we found its prefix. - if (nsUri.equals(uri)) { - return nsPrefix; - } - visited.add(nsPrefix); - } - } - } - - // Failed the find a prefix. Generate a new sensible default prefix, unless - // defaultPrefix was null in which case the caller does not want the document - // modified. - if (defaultPrefix == null) { - return null; - } - - // - // We need to make sure the prefix is not one that was declared in the scope - // visited above. Pick a unique prefix from the provided default prefix. - String prefix = defaultPrefix; - String base = prefix; - for (int i = 1; visited.contains(prefix); i++) { - prefix = base + Integer.toString(i); - } - // Also create & define this prefix/URI in the XML document as an attribute in the - // first element of the document. - if (doc != null) { - node = doc.getFirstChild(); - while (node != null && node.getNodeType() != Node.ELEMENT_NODE) { - node = node.getNextSibling(); - } - if (node != null) { - // This doesn't work: - //Attr attr = doc.createAttributeNS(XMLNS_URI, prefix); - //attr.setPrefix(XMLNS); - // - // Xerces throws - //org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or - // change an object in a way which is incorrect with regard to namespaces. - // - // Instead pass in the concatenated prefix. (This is covered by - // the UiElementNodeTest#testCreateNameSpace() test.) - Attr attr = doc.createAttributeNS(XMLNS_URI, XMLNS_PREFIX + prefix); - attr.setValue(nsUri); - node.getAttributes().setNamedItemNS(attr); - } - } - - return prefix; - } - - /** * Utility method to internally set the value of a text attribute for the current * UiElementNode. * <p/> diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiListAttributeNode.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiListAttributeNode.java index b5b2f71..b36a0c6 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiListAttributeNode.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiListAttributeNode.java @@ -16,17 +16,16 @@ package com.android.ide.eclipse.adt.internal.editors.uimodel; -import com.android.ide.common.layout.LayoutConstants; import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor; import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor; import com.android.ide.eclipse.adt.internal.editors.descriptors.DescriptorsUtils; import com.android.ide.eclipse.adt.internal.editors.descriptors.ListAttributeDescriptor; import com.android.ide.eclipse.adt.internal.editors.descriptors.TextAttributeDescriptor; -import com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor; import com.android.ide.eclipse.adt.internal.editors.ui.SectionHelper; import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData; import com.android.sdklib.SdkConstants; +import com.android.util.XmlUtils; import org.eclipse.core.runtime.IStatus; import org.eclipse.swt.SWT; @@ -142,9 +141,9 @@ public class UiListAttributeNode extends UiAbstractTextAttributeNode { // FrameworkResourceManager expects a specific prefix for the attribute. String nsPrefix = ""; if (SdkConstants.NS_RESOURCES.equals(descriptor.getNamespaceUri())) { - nsPrefix = LayoutConstants.ANDROID_NS_NAME + ':'; - } else if (XmlnsAttributeDescriptor.XMLNS_URI.equals(descriptor.getNamespaceUri())) { - nsPrefix = XmlnsAttributeDescriptor.XMLNS_COLON; + nsPrefix = XmlUtils.ANDROID_NS_NAME + ':'; + } else if (XmlUtils.XMLNS_URI.equals(descriptor.getNamespaceUri())) { + nsPrefix = XmlUtils.XMLNS_COLON; } attr_name = nsPrefix + attr_name; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/values/ValuesContentAssist.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/values/ValuesContentAssist.java index f800617..f1c9b1a 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/values/ValuesContentAssist.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/values/ValuesContentAssist.java @@ -16,7 +16,6 @@ package com.android.ide.eclipse.adt.internal.editors.values; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME_PREFIX; import static com.android.ide.common.resources.ResourceResolver.PREFIX_ANDROID_RESOURCE_REF; import static com.android.ide.common.resources.ResourceResolver.PREFIX_RESOURCE_REF; import static com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor.ATTRIBUTE_ICON_FILENAME; @@ -25,6 +24,7 @@ import static com.android.ide.eclipse.adt.internal.editors.values.descriptors.Va import static com.android.ide.eclipse.adt.internal.editors.values.descriptors.ValuesDescriptors.STYLE_ELEMENT; import static com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData.DESCRIPTOR_LAYOUT; import static com.android.tools.lint.detector.api.LintConstants.ATTR_TYPE; +import static com.android.util.XmlUtils.ANDROID_NS_NAME_PREFIX; import com.android.annotations.VisibleForTesting; import com.android.ide.eclipse.adt.internal.editors.AndroidContentAssist; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/AddPrefixFix.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/AddPrefixFix.java index 7f6f92d..92c1784 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/AddPrefixFix.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/AddPrefixFix.java @@ -15,10 +15,10 @@ */ package com.android.ide.eclipse.adt.internal.lint; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import com.android.ide.eclipse.adt.AdtPlugin; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; +import com.android.util.XmlUtils; import org.eclipse.core.resources.IMarker; import org.eclipse.jface.text.BadLocationException; @@ -48,7 +48,7 @@ final class AddPrefixFix extends DocumentFix { @Override protected void apply(IDocument document, IStructuredModel model, Node node, int start, int end) { - String prefix = UiElementNode.lookupNamespacePrefix(node, ANDROID_URI); + String prefix = XmlUtils.lookupNamespacePrefix(node, ANDROID_URI); try { document.replace(start, 0, prefix + ':'); } catch (BadLocationException e) { @@ -66,4 +66,4 @@ final class AddPrefixFix extends DocumentFix { ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages(); return sharedImages.getImage(ISharedImages.IMG_OBJ_ADD); } -}
\ No newline at end of file +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LinearLayoutWeightFix.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LinearLayoutWeightFix.java index 26f07f6..b8ede72 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LinearLayoutWeightFix.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LinearLayoutWeightFix.java @@ -15,7 +15,7 @@ */ package com.android.ide.eclipse.adt.internal.lint; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; import static com.android.ide.common.layout.LayoutConstants.ATTR_ORIENTATION; @@ -75,4 +75,4 @@ final class LinearLayoutWeightFix extends DocumentFix { // TODO: Need a better icon here return sharedImages.getImage(ISharedImages.IMG_OBJ_ELEMENT); } -}
\ No newline at end of file +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/SetPropertyFix.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/SetPropertyFix.java index 0f49a7e..2bfe5e8 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/SetPropertyFix.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/SetPropertyFix.java @@ -15,12 +15,12 @@ */ package com.android.ide.eclipse.adt.internal.lint; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.AdtUtils; import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; +import com.android.util.XmlUtils; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; @@ -70,7 +70,7 @@ abstract class SetPropertyFix extends DocumentFix { Element element = (Element) node; String proposal = getProposal(); String localAttribute = getAttribute(); - String prefix = UiElementNode.lookupNamespacePrefix(node, ANDROID_URI); + String prefix = XmlUtils.lookupNamespacePrefix(node, ANDROID_URI); String attribute = prefix != null ? prefix + ':' + localAttribute : localAttribute; // This does not work even though it should: it does not include the prefix @@ -120,4 +120,4 @@ abstract class SetPropertyFix extends DocumentFix { ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages(); return sharedImages.getImage(ISharedImages.IMG_OBJ_ADD); } -}
\ No newline at end of file +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/SetScrollViewSizeFix.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/SetScrollViewSizeFix.java index 846054d..b7f8a3c 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/SetScrollViewSizeFix.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/SetScrollViewSizeFix.java @@ -15,7 +15,7 @@ */ package com.android.ide.eclipse.adt.internal.lint; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; import static com.android.ide.common.layout.LayoutConstants.VALUE_WRAP_CONTENT; @@ -70,4 +70,4 @@ final class SetScrollViewSizeFix extends DocumentFix { // TODO: Need a better icon here return sharedImages.getImage(ISharedImages.IMG_OBJ_ELEMENT); } -}
\ No newline at end of file +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/preferences/AttributeSortOrder.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/preferences/AttributeSortOrder.java index 657b83a..cc1e7d8 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/preferences/AttributeSortOrder.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/preferences/AttributeSortOrder.java @@ -15,7 +15,7 @@ */ package com.android.ide.eclipse.adt.internal.preferences; -import static com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor.XMLNS; +import static com.android.util.XmlUtils.XMLNS; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiAttributeNode; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/refactorings/extractstring/ExtractStringRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/refactorings/extractstring/ExtractStringRefactoring.java index f6dac7c..6cdff0f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/refactorings/extractstring/ExtractStringRefactoring.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/refactorings/extractstring/ExtractStringRefactoring.java @@ -17,6 +17,9 @@ package com.android.ide.eclipse.adt.internal.refactorings.extractstring; import static com.android.ide.common.layout.LayoutConstants.STRING_PREFIX; +import static com.android.util.XmlUtils.AMP_ENTITY; +import static com.android.util.XmlUtils.LT_ENTITY; +import static com.android.util.XmlUtils.QUOT_ENTITY; import com.android.ide.eclipse.adt.AdtConstants; import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor; @@ -1496,10 +1499,10 @@ public class ExtractStringRefactoring extends Refactoring { sb.append(c); break; case '<': - sb.append("<"); //$NON-NLS-1$ + sb.append(LT_ENTITY); break; case '&': - sb.append("&"); //$NON-NLS-1$ + sb.append(AMP_ENTITY); break; case '\n': sb.append("\\n"); //$NON-NLS-1$ @@ -1743,7 +1746,7 @@ public class ExtractStringRefactoring extends Refactoring { } // If we get here, there's a mix. Opt for double-quote around and replace // inner double-quotes. - attrValue = attrValue.replace("\"", """); //$NON-NLS-1$ //$NON-NLS-2$ + attrValue = attrValue.replace("\"", QUOT_ENTITY); //$NON-NLS-1$ return '"' + attrValue + '"'; } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/refactorings/renamepackage/ApplicationPackageNameRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/refactorings/renamepackage/ApplicationPackageNameRefactoring.java index 5ec5a76..271bb0b 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/refactorings/renamepackage/ApplicationPackageNameRefactoring.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/refactorings/renamepackage/ApplicationPackageNameRefactoring.java @@ -16,9 +16,11 @@ package com.android.ide.eclipse.adt.internal.refactorings.renamepackage; +import static com.android.util.XmlUtils.ANDROID_URI; +import static com.android.util.XmlUtils.XMLNS_COLON; + import com.android.ide.eclipse.adt.AdtConstants; import com.android.ide.eclipse.adt.AdtPlugin; -import com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor; import com.android.sdklib.SdkConstants; import com.android.sdklib.xml.AndroidManifest; @@ -82,10 +84,6 @@ class ApplicationPackageNameRefactoring extends Refactoring { List<String> MAIN_COMPONENT_TYPES_LIST = Arrays.asList(MAIN_COMPONENT_TYPES); - private final static String ANDROID_NS_URI = SdkConstants.NS_RESOURCES; - private final static String NAMESPACE_DECLARATION_PREFIX = - XmlnsAttributeDescriptor.XMLNS_COLON; - ApplicationPackageNameRefactoring( IProject project, Name oldPackageName, @@ -243,7 +241,7 @@ class ApplicationPackageNameRefactoring extends Refactoring { // Check this is the attribute and the original string if (lastAttrName != null && - lastAttrName.startsWith(NAMESPACE_DECLARATION_PREFIX)) { + lastAttrName.startsWith(XMLNS_COLON)) { String lastAttrValue = region.getText(subRegion); if (oldAppNamespaceString.equals(stripQuotes(lastAttrValue))) { @@ -338,12 +336,12 @@ class ApplicationPackageNameRefactoring extends Refactoring { String lastAttrValue = region.getText(subRegion); if (lastAttrName != null && - lastAttrName.startsWith(NAMESPACE_DECLARATION_PREFIX)) { + lastAttrName.startsWith(XMLNS_COLON)) { // Resolves the android namespace prefix for this file - if (ANDROID_NS_URI.equals(stripQuotes(lastAttrValue))) { + if (ANDROID_URI.equals(stripQuotes(lastAttrValue))) { String android_namespace_prefix = lastAttrName - .substring(NAMESPACE_DECLARATION_PREFIX.length()); + .substring(XMLNS_COLON.length()); android_name_attribute = android_namespace_prefix + ':' + AndroidManifest.ATTRIBUTE_NAME; } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceHelper.java index 57c016e..68eb85d 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceHelper.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceHelper.java @@ -17,7 +17,7 @@ package com.android.ide.eclipse.adt.internal.resources; import static com.android.AndroidConstants.FD_RES_VALUES; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.resources.ResourceResolver.PREFIX_ANDROID_STYLE; import static com.android.ide.common.resources.ResourceResolver.PREFIX_RESOURCE_REF; import static com.android.ide.common.resources.ResourceResolver.PREFIX_STYLE; diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/AbsoluteLayoutRuleTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/AbsoluteLayoutRuleTest.java index b66c555..2764f94 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/AbsoluteLayoutRuleTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/AbsoluteLayoutRuleTest.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import com.android.ide.common.api.INode; import com.android.ide.common.api.Point; diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/BaseLayoutRuleTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/BaseLayoutRuleTest.java index fd699fc..a9485f3 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/BaseLayoutRuleTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/BaseLayoutRuleTest.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import com.android.ide.common.api.IDragElement; diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/LayoutTestBase.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/LayoutTestBase.java index 2d3e5ba..e382132 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/LayoutTestBase.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/LayoutTestBase.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import com.android.ide.common.api.DropFeedback; diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/LinearLayoutRuleTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/LinearLayoutRuleTest.java index cec3a9b..638a384 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/LinearLayoutRuleTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/LinearLayoutRuleTest.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH; diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/RelativeLayoutRuleTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/RelativeLayoutRuleTest.java index 09cd8cc..28e652d 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/RelativeLayoutRuleTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/RelativeLayoutRuleTest.java @@ -16,7 +16,7 @@ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import com.android.ide.common.api.INode; import com.android.ide.common.api.Point; diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestDragElement.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestDragElement.java index 197c281..4a3b4e8 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestDragElement.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestDragElement.java @@ -15,7 +15,7 @@ */ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import com.android.ide.common.api.IDragElement; @@ -149,4 +149,4 @@ public class TestDragElement implements IDragElement { } -}
\ No newline at end of file +} diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestNode.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestNode.java index 7e58cb9..575c958 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestNode.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestNode.java @@ -15,7 +15,7 @@ */ package com.android.ide.common.layout; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import com.android.ide.common.api.IAttributeInfo; @@ -212,4 +212,4 @@ public class TestNode implements INode { public void setAttributeSources(List<String> attributeSources) { mAttributeSources = attributeSources; } -}
\ No newline at end of file +} diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/grid/GridModelTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/grid/GridModelTest.java index 91533b0..680b7ca 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/grid/GridModelTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/grid/GridModelTest.java @@ -15,7 +15,7 @@ */ package com.android.ide.common.layout.grid; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_COLUMN_COUNT; import static com.android.ide.common.layout.LayoutConstants.FQCN_BUTTON; diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/DomUtilitiesTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/DomUtilitiesTest.java index c1f4f54..1fc358b 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/DomUtilitiesTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/DomUtilitiesTest.java @@ -25,33 +25,9 @@ import javax.xml.parsers.DocumentBuilderFactory; import junit.framework.TestCase; +@SuppressWarnings("javadoc") public class DomUtilitiesTest extends TestCase { - public void testToXmlAttributeValue() throws Exception { - assertEquals("", DomUtilities.toXmlAttributeValue("")); - assertEquals("foo", DomUtilities.toXmlAttributeValue("foo")); - assertEquals("foo<bar", DomUtilities.toXmlAttributeValue("foo<bar")); - assertEquals("foo>bar", DomUtilities.toXmlAttributeValue("foo>bar")); - - assertEquals(""", DomUtilities.toXmlAttributeValue("\"")); - assertEquals("'", DomUtilities.toXmlAttributeValue("'")); - assertEquals("foo"b''ar", - DomUtilities.toXmlAttributeValue("foo\"b''ar")); - assertEquals("<"'>&", DomUtilities.toXmlAttributeValue("<\"'>&")); - } - - public void testAppendXmlAttributeValue() throws Exception { - StringBuilder sb = new StringBuilder(); - DomUtilities.appendXmlAttributeValue(sb, "<\"'>&"); - assertEquals("<"'>&", sb.toString()); - } - - public void testAppendXmlTextValue() throws Exception { - StringBuilder sb = new StringBuilder(); - DomUtilities.appendXmlTextValue(sb, "<\"'>&"); - assertEquals("<\"'>&", sb.toString()); - } - public void testIsEquivalent() throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/manifest/model/UiElementNodeTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/manifest/model/UiElementNodeTest.java index 43cba58..79b70fc 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/manifest/model/UiElementNodeTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/manifest/model/UiElementNodeTest.java @@ -16,16 +16,14 @@ package com.android.ide.eclipse.adt.internal.editors.manifest.model; -import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; -import static com.android.tools.lint.detector.api.LintConstants.TOOLS_URI; +import static com.android.util.XmlUtils.ANDROID_URI; import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor.Mandatory; -import com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor; import com.android.ide.eclipse.adt.internal.editors.mock.MockXmlNode; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; +import com.android.util.XmlUtils; -import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -262,36 +260,6 @@ public class UiElementNodeTest extends TestCase { assertEquals(0, second_permission.getAllUiAttributes().size()); } - public void testlookupNamespacePrefix() throws Exception { - // Setup - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - factory.setValidating(false); - DocumentBuilder builder = factory.newDocumentBuilder(); - Document document = builder.newDocument(); - Element rootElement = document.createElement("root"); - Attr attr = document.createAttributeNS(XmlnsAttributeDescriptor.XMLNS_URI, - "xmlns:customPrefix"); - attr.setValue(ANDROID_URI); - rootElement.getAttributes().setNamedItemNS(attr); - document.appendChild(rootElement); - Element root = document.getDocumentElement(); - root.appendChild(document.createTextNode(" ")); - Element foo = document.createElement("foo"); - root.appendChild(foo); - root.appendChild(document.createTextNode(" ")); - Element bar = document.createElement("bar"); - root.appendChild(bar); - Element baz = document.createElement("baz"); - root.appendChild(baz); - - String prefix = UiElementNode.lookupNamespacePrefix(baz, ANDROID_URI); - assertEquals("customPrefix", prefix); - - prefix = UiElementNode.lookupNamespacePrefix(baz, TOOLS_URI, "tools"); - assertEquals("tools", prefix); - } - public void testCreateNameSpace() throws Exception { // Setup DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); @@ -311,7 +279,7 @@ public class UiElementNodeTest extends TestCase { Element baz = document.createElement("baz"); root.appendChild(baz); - String prefix = UiElementNode.lookupNamespacePrefix(baz, ANDROID_URI); + String prefix = XmlUtils.lookupNamespacePrefix(baz, ANDROID_URI); assertEquals("android", prefix); } } diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/resources/ResourceHelperTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/resources/ResourceHelperTest.java index 0b498e5..f90f437 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/resources/ResourceHelperTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/resources/ResourceHelperTest.java @@ -189,11 +189,11 @@ public class ResourceHelperTest extends TestCase { assertEquals("Foo", ResourceHelper.styleToTheme("Foo")); assertEquals("Theme", ResourceHelper.styleToTheme("@android:style/Theme")); assertEquals("LocalTheme", ResourceHelper.styleToTheme("@style/LocalTheme")); - assertEquals("LocalTheme", ResourceHelper.styleToTheme("@foo.bar/style/LocalTheme")); + //assertEquals("LocalTheme", ResourceHelper.styleToTheme("@foo.bar:style/LocalTheme")); } public void testIsProjectStyle() throws Exception { - assertTrue(ResourceHelper.isProjectStyle("@android:style/Theme")); - assertFalse(ResourceHelper.isProjectStyle("@style/LocalTheme")); + assertFalse(ResourceHelper.isProjectStyle("@android:style/Theme")); + assertTrue(ResourceHelper.isProjectStyle("@style/LocalTheme")); } } diff --git a/manifmerger/src/com/android/manifmerger/ManifestMerger.java b/manifmerger/src/com/android/manifmerger/ManifestMerger.java index 6eac978..8dfd398 100755 --- a/manifmerger/src/com/android/manifmerger/ManifestMerger.java +++ b/manifmerger/src/com/android/manifmerger/ManifestMerger.java @@ -186,6 +186,35 @@ public class ManifestMerger { return success; } + /** + * Performs the merge operation in-place in the given DOM. + * <p/> + * This does NOT stop on errors, in an attempt to accumulate as much + * info as possible to return to the user. + * + * @param mainDoc The document to merge into. Will be modified in-place. + * @param libraryDocs The library manifest documents to merge in. Must not be null. + * @return True on success, false if any error occurred (printed to the {@link ISdkLog}). + */ + public boolean process(@NonNull Document mainDoc, @NonNull Document... libraryDocs) { + + boolean success = true; + mMainDoc = mainDoc; + + String prefix = XmlUtils.lookupNsPrefix(mainDoc, SdkConstants.NS_RESOURCES); + mXPath = AndroidXPathFactory.newXPath(prefix); + + for (Document libDoc : libraryDocs) { + if (!mergeLibDoc(libDoc)) { + success = false; + } + } + + mXPath = null; + mMainDoc = null; + return success; + } + // -------- /** @@ -884,8 +913,8 @@ public class ManifestMerger { */ private Node insertAtEndOf(Element dest, Node start, Node end) { // Check whether we'll need to adjust URI prefixes - String destPrefix = mMainDoc.lookupPrefix(NS_URI); - String srcPrefix = start.getOwnerDocument().lookupPrefix(NS_URI); + String destPrefix = XmlUtils.lookupNsPrefix(mMainDoc, NS_URI); + String srcPrefix = XmlUtils.lookupNsPrefix(start.getOwnerDocument(), NS_URI); boolean needPrefixChange = destPrefix != null && !destPrefix.equals(srcPrefix); // First let's figure out the insertion point. diff --git a/manifmerger/src/com/android/manifmerger/XmlUtils.java b/manifmerger/src/com/android/manifmerger/XmlUtils.java index d18eebb..ed5b8a8 100755 --- a/manifmerger/src/com/android/manifmerger/XmlUtils.java +++ b/manifmerger/src/com/android/manifmerger/XmlUtils.java @@ -215,9 +215,7 @@ class XmlUtils { * @return The namespace prefix if found or null. */ static String lookupNsPrefix(Document doc, String nsUri) { - // Note: if this is not available, there's an alternate implementation at - // com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode.lookupNamespacePrefix(Node, String) - return doc.lookupPrefix(nsUri); + return com.android.util.XmlUtils.lookupNamespacePrefix(doc, nsUri); } /** |