use of javax.xml.xpath.XPathFactory in project camel by apache.
the class XmlSignatureHelper method getXPathExpression.
@SuppressWarnings("unchecked")
public static XPathExpression getXPathExpression(XPathFilterParameterSpec xpathFilter) throws XPathExpressionException {
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
if (xpathFilter.getNamespaceMap() != null) {
xpath.setNamespaceContext(new XPathNamespaceContext(xpathFilter.getNamespaceMap()));
}
return xpath.compile(xpathFilter.getXPath());
}
use of javax.xml.xpath.XPathFactory in project camel by apache.
the class XAdESSignaturePropertiesTest method getXpath.
static XPathExpression getXpath(String xpathString, final Map<String, String> prefix2Namespace) throws XPathExpressionException {
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
NamespaceContext nc = new NamespaceContext() {
@SuppressWarnings("rawtypes")
@Override
public Iterator getPrefixes(String namespaceURI) {
return null;
}
@Override
public String getPrefix(String namespaceURI) {
return null;
}
@Override
public String getNamespaceURI(String prefix) {
return prefix2Namespace.get(prefix);
}
};
xpath.setNamespaceContext(nc);
XPathExpression expr = xpath.compile(xpathString);
return expr;
}
use of javax.xml.xpath.XPathFactory in project camel by apache.
the class XmlSignatureTest method checkXpath.
private Object checkXpath(MockEndpoint mock, String xpathString, final Map<String, String> prefix2Namespace) throws XPathExpressionException, SAXException, IOException, ParserConfigurationException {
Message mess = getMessage(mock);
InputStream body = mess.getBody(InputStream.class);
assertNotNull(body);
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
NamespaceContext nc = new NamespaceContext() {
@SuppressWarnings("rawtypes")
@Override
public Iterator getPrefixes(String namespaceURI) {
return null;
}
@Override
public String getPrefix(String namespaceURI) {
return null;
}
@Override
public String getNamespaceURI(String prefix) {
return prefix2Namespace.get(prefix);
}
};
xpath.setNamespaceContext(nc);
XPathExpression expr = xpath.compile(xpathString);
Object result = expr.evaluate(XmlSignatureHelper.newDocumentBuilder(true).parse(body), XPathConstants.NODE);
assertNotNull("The xpath " + xpathString + " returned a null value", result);
return result;
}
use of javax.xml.xpath.XPathFactory in project buck by facebook.
the class SchemeGeneratorTest method launchActionShouldContainRemoteRunnableWhenProvided.
@Test
public void launchActionShouldContainRemoteRunnableWhenProvided() throws Exception {
ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder = ImmutableMap.builder();
PBXTarget rootTarget = new PBXNativeTarget("rootRule");
rootTarget.setGlobalID("rootGID");
rootTarget.setProductReference(new PBXFileReference("root.a", "root.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
rootTarget.setProductType(ProductType.STATIC_LIBRARY);
Path pbxprojectPath = Paths.get("foo/Foo.xcodeproj/project.pbxproj");
targetToProjectPathMapBuilder.put(rootTarget, pbxprojectPath);
SchemeGenerator schemeGenerator = new SchemeGenerator(projectFilesystem, Optional.of(rootTarget), ImmutableSet.of(rootTarget), ImmutableSet.of(), ImmutableSet.of(), "TestScheme", Paths.get("_gen/Foo.xcworkspace/scshareddata/xcshemes"), false, /* primaryTargetIsBuildWithBuck */
false, /* parallelizeBuild */
Optional.empty(), /* runnablePath */
Optional.of("/RemoteApp"), /* remoteRunnablePath */
SchemeActionType.DEFAULT_CONFIG_NAMES, targetToProjectPathMapBuilder.build(), XCScheme.LaunchAction.LaunchStyle.AUTO);
Path schemePath = schemeGenerator.writeScheme();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document scheme = dBuilder.parse(projectFilesystem.newFileInputStream(schemePath));
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath remoteRunnableLaunchActionXPath = xpathFactory.newXPath();
XPathExpression remoteRunnableLaunchActionExpr = remoteRunnableLaunchActionXPath.compile("//LaunchAction/RemoteRunnable");
NodeList remoteRunnables = (NodeList) remoteRunnableLaunchActionExpr.evaluate(scheme, XPathConstants.NODESET);
assertThat(remoteRunnables.getLength(), equalTo(1));
Node remoteRunnable = remoteRunnables.item(0);
assertThat(remoteRunnable.getAttributes().getNamedItem("runnableDebuggingMode").getNodeValue(), equalTo("2"));
assertThat(remoteRunnable.getAttributes().getNamedItem("BundleIdentifier").getNodeValue(), equalTo("com.apple.springboard"));
assertThat(remoteRunnable.getAttributes().getNamedItem("RemotePath").getNodeValue(), equalTo("/RemoteApp"));
XPath buildXpath = xpathFactory.newXPath();
XPathExpression buildExpr = buildXpath.compile("//LaunchAction//BuildableReference/@BlueprintIdentifier");
NodeList buildNodes = (NodeList) buildExpr.evaluate(scheme, XPathConstants.NODESET);
// Make sure both copies of the BuildableReference are present.
assertThat(buildNodes.getLength(), equalTo(2));
assertThat(buildNodes.item(0).getNodeValue(), equalTo("rootGID"));
assertThat(buildNodes.item(1).getNodeValue(), equalTo("rootGID"));
}
use of javax.xml.xpath.XPathFactory in project buck by facebook.
the class SchemeGeneratorTest method enablingParallelizeBuild.
@Test
public void enablingParallelizeBuild() throws Exception {
ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder = ImmutableMap.builder();
PBXTarget rootTarget = new PBXNativeTarget("rootRule");
rootTarget.setGlobalID("rootGID");
rootTarget.setProductReference(new PBXFileReference("root.a", "root.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
rootTarget.setProductType(ProductType.STATIC_LIBRARY);
Path pbxprojectPath = Paths.get("foo/Foo.xcodeproj/project.pbxproj");
targetToProjectPathMapBuilder.put(rootTarget, pbxprojectPath);
SchemeGenerator schemeGenerator = new SchemeGenerator(projectFilesystem, Optional.of(rootTarget), ImmutableSet.of(rootTarget), ImmutableSet.of(), ImmutableSet.of(), "TestScheme", Paths.get("_gen/Foo.xcworkspace/scshareddata/xcshemes"), true, /* primaryTargetIsBuildWithBuck */
true, /* parallelizeBuild */
Optional.empty(), /* runnablePath */
Optional.empty(), /* remoteRunnablePath */
SchemeActionType.DEFAULT_CONFIG_NAMES, targetToProjectPathMapBuilder.build(), XCScheme.LaunchAction.LaunchStyle.AUTO);
Path schemePath = schemeGenerator.writeScheme();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document scheme = dBuilder.parse(projectFilesystem.newFileInputStream(schemePath));
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath buildActionXpath = xpathFactory.newXPath();
XPathExpression buildActionExpr = buildActionXpath.compile("//BuildAction");
NodeList buildActionNodes = (NodeList) buildActionExpr.evaluate(scheme, XPathConstants.NODESET);
assertThat(buildActionNodes.getLength(), is(1));
Node buildActionNode = buildActionNodes.item(0);
assertThat(buildActionNode.getAttributes().getNamedItem("buildImplicitDependencies").getNodeValue(), equalTo("YES"));
assertThat(buildActionNode.getAttributes().getNamedItem("parallelizeBuildables").getNodeValue(), equalTo("YES"));
}
Aggregations