Java Code Examples for com.android.utils.XmlUtils#lookupNamespacePrefix()
The following examples show how to use
com.android.utils.XmlUtils#lookupNamespacePrefix() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrphanXmlElement.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: OrphanXmlElement.java From javaide with GNU General Public License v3.0 | 6 votes |
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; }
Example 3
Source File: ManifestMerger2.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
private static String getAndroidPrefix(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; }
Example 4
Source File: ManifestMerger.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
/** * 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. * <p/> * The method might modify the input XML documents in-place for its own processing. * * @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. * These will be modified in-place. * @return True on success, false if any error occurred (printed to the {@link IMergerLog}). */ public boolean process(@NonNull Document mainDoc, @NonNull Document... libraryDocs) { boolean success = true; mMainDoc = mainDoc; MergerXmlUtils.decorateDocument(mainDoc, IMergerLog.MAIN_MANIFEST); String prefix = XmlUtils.lookupNamespacePrefix(mainDoc, SdkConstants.NS_RESOURCES); mXPath = AndroidXPathFactory.newXPath(prefix); expandFqcns(mainDoc); for (Document libDoc : libraryDocs) { MergerXmlUtils.decorateDocument(libDoc, IMergerLog.LIBRARY); if (!mergeLibDoc(cleanupToolsAttributes(libDoc))) { success = false; } } cleanupToolsAttributes(mainDoc); if (mExtractPackagePrefix) { extractFqcns(mainDoc); } if (mInsertSourceMarkers) { insertSourceMarkers(mainDoc); } mXPath = null; mMainDoc = null; return success; }
Example 5
Source File: ManifestMerger2.java From javaide with GNU General Public License v3.0 | 5 votes |
private static String getAndroidPrefix(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; }
Example 6
Source File: ManifestMerger.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * 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. * <p/> * The method might modify the input XML documents in-place for its own processing. * * @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. * These will be modified in-place. * @return True on success, false if any error occurred (printed to the {@link IMergerLog}). */ public boolean process(@NonNull Document mainDoc, @NonNull Document... libraryDocs) { boolean success = true; mMainDoc = mainDoc; MergerXmlUtils.decorateDocument(mainDoc, IMergerLog.MAIN_MANIFEST); String prefix = XmlUtils.lookupNamespacePrefix(mainDoc, SdkConstants.NS_RESOURCES); mXPath = AndroidXPathFactory.newXPath(prefix); expandFqcns(mainDoc); for (Document libDoc : libraryDocs) { MergerXmlUtils.decorateDocument(libDoc, IMergerLog.LIBRARY); if (!mergeLibDoc(cleanupToolsAttributes(libDoc))) { success = false; } } cleanupToolsAttributes(mainDoc); if (mExtractPackagePrefix) { extractFqcns(mainDoc); } if (mInsertSourceMarkers) { insertSourceMarkers(mainDoc); } mXPath = null; mMainDoc = null; return success; }
Example 7
Source File: ManifestMerger.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
/** * 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. * <p/> * The method might modify the input XML document in-place for its own processing. * * @param mainDoc The document to merge into. Will be modified in-place. * @param libraryFiles The library manifest paths to read. Must not be null. * These will be modified in-place. * @param injectAttributes A map of attributes to inject in the form [pseudo-xpath] => value. * The key is "/manifest/elements...|attribute-ns-uri attribute-local-name", * for example "/manifest/uses-sdk|http://schemas.android.com/apk/res/android minSdkVersion". * (note the space separator between the attribute URI and its local name.) * The elements will be created if they don't exists. Existing attributes will be modified. * The replacement is done on the main document <em>before</em> merging. * @param packageOverride an optional package override. This only affects the package attribute, * all components (activities, receivers, etc...) are not affected by this. * @return True on success, false if any error occurred (printed to the {@link IMergerLog}). */ public boolean process( Document mainDoc, File[] libraryFiles, Map<String, String> injectAttributes, String packageOverride) { boolean success = true; mMainDoc = mainDoc; MergerXmlUtils.decorateDocument(mainDoc, IMergerLog.MAIN_MANIFEST); MergerXmlUtils.injectAttributes(mainDoc, injectAttributes, mLog); String prefix = XmlUtils.lookupNamespacePrefix(mainDoc, SdkConstants.NS_RESOURCES); mXPath = AndroidXPathFactory.newXPath(prefix); expandFqcns(mainDoc); for (File libFile : libraryFiles) { Document libDoc = MergerXmlUtils.parseDocument(libFile, mLog, this); if (libDoc == null || !mergeLibDoc(cleanupToolsAttributes(libDoc))) { success = false; } } if (packageOverride != null) { MergerXmlUtils.injectAttributes(mainDoc, Collections.singletonMap("/manifest| package", packageOverride), mLog); } cleanupToolsAttributes(mainDoc); if (mExtractPackagePrefix) { extractFqcns(mainDoc); } if (mInsertSourceMarkers) { insertSourceMarkers(mainDoc); } mXPath = null; mMainDoc = null; return success; }
Example 8
Source File: ManifestMerger.java From javaide with GNU General Public License v3.0 | 4 votes |
/** * 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. * <p/> * The method might modify the input XML document in-place for its own processing. * * @param mainDoc The document to merge into. Will be modified in-place. * @param libraryFiles The library manifest paths to read. Must not be null. * These will be modified in-place. * @param injectAttributes A map of attributes to inject in the form [pseudo-xpath] => value. * The key is "/manifest/elements...|attribute-ns-uri attribute-local-name", * for example "/manifest/uses-sdk|http://schemas.android.com/apk/res/android minSdkVersion". * (note the space separator between the attribute URI and its local name.) * The elements will be created if they don't exists. Existing attributes will be modified. * The replacement is done on the main document <em>before</em> merging. * @param packageOverride an optional package override. This only affects the package attribute, * all components (activities, receivers, etc...) are not affected by this. * @return True on success, false if any error occurred (printed to the {@link IMergerLog}). */ public boolean process( Document mainDoc, File[] libraryFiles, Map<String, String> injectAttributes, String packageOverride) { boolean success = true; mMainDoc = mainDoc; MergerXmlUtils.decorateDocument(mainDoc, IMergerLog.MAIN_MANIFEST); MergerXmlUtils.injectAttributes(mainDoc, injectAttributes, mLog); String prefix = XmlUtils.lookupNamespacePrefix(mainDoc, SdkConstants.NS_RESOURCES); mXPath = AndroidXPathFactory.newXPath(prefix); expandFqcns(mainDoc); for (File libFile : libraryFiles) { Document libDoc = MergerXmlUtils.parseDocument(libFile, mLog, this); if (libDoc == null || !mergeLibDoc(cleanupToolsAttributes(libDoc))) { success = false; } } if (packageOverride != null) { MergerXmlUtils.injectAttributes(mainDoc, Collections.singletonMap("/manifest| package", packageOverride), mLog); } cleanupToolsAttributes(mainDoc); if (mExtractPackagePrefix) { extractFqcns(mainDoc); } if (mInsertSourceMarkers) { insertSourceMarkers(mainDoc); } mXPath = null; mMainDoc = null; return success; }