use of com.android.tools.build.bundletool.xml.XmlNamespaceContext in project bundletool by google.
the class DumpManager method printManifest.
void printManifest(BundleModuleName moduleName, Optional<String> xPathExpression) {
// Extract the manifest from the bundle.
ZipPath manifestPath = ZipPath.create(moduleName.getName()).resolve(SpecialModuleEntry.ANDROID_MANIFEST.getPath());
XmlProtoNode manifestProto = new XmlProtoNode(extractAndParse(bundlePath, manifestPath, XmlNode::parseFrom));
// Convert the proto to real XML.
Document document = XmlProtoToXmlConverter.convert(manifestProto);
// Select the output.
String output;
if (xPathExpression.isPresent()) {
try {
XPath xPath = XPathFactory.newInstance().newXPath();
xPath.setNamespaceContext(new XmlNamespaceContext(manifestProto));
XPathExpression compiledXPathExpression = xPath.compile(xPathExpression.get());
XPathResult xPathResult = XPathResolver.resolve(document, compiledXPathExpression);
output = xPathResult.toString();
} catch (XPathExpressionException e) {
throw InvalidCommandException.builder().withInternalMessage("Error in the XPath expression: " + xPathExpression).withCause(e).build();
}
} else {
output = XmlUtils.documentToString(document);
}
// Print the output.
printStream.println(output.trim());
}
Aggregations