Tabnine Logo
XmlUtils.lookupNamespacePrefix
Code IndexAdd Tabnine to your IDE (free)

How to use
lookupNamespacePrefix
method
in
com.android.utils.XmlUtils

Best Java code snippets using com.android.utils.XmlUtils.lookupNamespacePrefix (Showing top 6 results out of 315)

origin: com.android.tools.build/manifest-merger

private static String getAndroidPrefix(@NonNull Element xml) {
  String toolsPrefix = XmlUtils.lookupNamespacePrefix(
      xml, SdkConstants.ANDROID_URI, SdkConstants.ANDROID_NS_NAME, false);
  if (!toolsPrefix.equals(SdkConstants.ANDROID_NS_NAME) && xml.getOwnerDocument()
      .getDocumentElement().getAttribute("xmlns:" + toolsPrefix) == null) {
    // this is weird, the document is using "android" prefix but it's not bound
    // to our namespace. Add the proper xmlns declaration.
    xml.setAttribute("xmlns:" + toolsPrefix, SdkConstants.ANDROID_URI);
  }
  return toolsPrefix;
}
origin: com.android.tools.build/manifest-merger

public OrphanXmlElement(@NonNull Element xml) {
  mXml = Preconditions.checkNotNull(xml);
  NodeTypes nodeType;
  String elementName = mXml.getNodeName();
  // this is bit more complicated than it should be. Look first if there is a namespace
  // prefix in the name, most elements don't. If they do, however, strip it off if it is the
  // android prefix, but if it's custom namespace prefix, classify the node as CUSTOM.
  int indexOfColon = elementName.indexOf(':');
  if (indexOfColon != -1) {
    String androidPrefix = XmlUtils.lookupNamespacePrefix(xml, SdkConstants.ANDROID_URI);
    if (androidPrefix.equals(elementName.substring(0, indexOfColon))) {
      nodeType = NodeTypes.fromXmlSimpleName(elementName.substring(indexOfColon + 1));
    } else {
      nodeType = NodeTypes.CUSTOM;
    }
  } else {
    nodeType = NodeTypes.fromXmlSimpleName(elementName);
  }
  mType = nodeType;
}
origin: com.android.tools.build/manifest-merger

  /**
   * Removes the android namespace from an element recursively.
   *
   * @param element the element
   */
  private void clearNodeNamespaces(Element element) {
    String androidPrefix = XmlUtils.lookupNamespacePrefix(element, SdkConstants.ANDROID_URI);

    String name = element.getNodeName();
    int colonIdx = name.indexOf(':');
    if (colonIdx != -1) {
      String prefix = name.substring(0, colonIdx);
      if (prefix.equals(androidPrefix)) {
        String newName = name.substring(colonIdx + 1);
        getXml().renameNode(element, null, newName);
      }
    }

    NodeList childrenNodeList = element.getChildNodes();
    for (int i = 0; i < childrenNodeList.getLength(); i++) {
      Node n = childrenNodeList.item(i);
      if (n instanceof Element) {
        clearNodeNamespaces((Element) n);
      }
    }
  }
}
origin: com.android.tools/common

/**
 * 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. By default the app namespace
 * will be created. If this is not desirable, call
 * {@link #lookupNamespacePrefix(Node, String, boolean)} instead.
 *
 * @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#ANDROID_URI}
 * @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, true /*create*/);
}
origin: com.android.tools/common

/**
 * 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.
 *            {@link SdkConstants#ANDROID_URI}
 * @param create whether the namespace declaration should be created, if
 *            necessary
 * @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,
    boolean create) {
  String defaultPrefix = ANDROID_URI.equals(nsUri) ? ANDROID_NS_NAME : APP_PREFIX;
  return lookupNamespacePrefix(node, nsUri, defaultPrefix, create);
}
origin: com.android.tools.build/manifest-merger

if (attributeName.indexOf(XmlUtils.NS_SEPARATOR) == -1) {
  String toolsPrefix = XmlUtils
      .lookupNamespacePrefix(getXml(), SdkConstants.TOOLS_URI,
          SdkConstants.ANDROID_NS_NAME, false);
com.android.utilsXmlUtilslookupNamespacePrefix

Javadoc

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. By default the app namespace will be created. If this is not desirable, call #lookupNamespacePrefix(Node,String,boolean) instead.

Popular methods of XmlUtils

  • parseDocument
    Parses the given XML string as a DOM document, using the JDK parser. The parser does not validate, a
  • parseDocumentSilently
    Parses the given XML string as a DOM document, using the JDK parser. The parser does not validate, a
  • parseUtfXmlFile
    Parses the given UTF file as a DOM document, using the JDK parser. The parser does not validate, and
  • toXmlAttributeValue
    Converts the given attribute value to an XML-attribute-safe value, meaning that single and double qu
  • toXml
  • toXmlTextValue
    Converts the given attribute value to an XML-text-safe value, meaning that less than and ampersand c
  • fromXmlAttributeValue
    Converts the given XML-attribute-safe value to a java string
  • getRootTagName
    Returns the name of the root element tag stored in the given file, or null if it can't be determined
  • getUtfReader
    Returns a character reader for the given file, which must be a UTF encoded file. The reader does no
  • append
    Dump node to string without indentation adjustments
  • appendXmlAttributeValue
    Appends text to the given StringBuilder and escapes it as required for a DOM attribute node.
  • appendXmlTextValue
    Appends text to the given StringBuilder and escapes it as required for a DOM text node.
  • appendXmlAttributeValue,
  • appendXmlTextValue,
  • getSourceFilePosition,
  • stripBom

Popular in Java

  • Creating JSON documents from java classes using gson
  • setScale (BigDecimal)
  • getApplicationContext (Context)
  • getSupportFragmentManager (FragmentActivity)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now