use of javax.xml.xpath.XPathFactory in project buck by facebook.
the class SchemeGeneratorTest method allActionsShouldBePresentInSchemeWithDefaultBuildConfigurations.
@Test
public void allActionsShouldBePresentInSchemeWithDefaultBuildConfigurations() 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.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 schemeChildrenXPath = xpathFactory.newXPath();
XPathExpression schemeChildrenExpr = schemeChildrenXPath.compile("/Scheme/node()");
NodeList actions = (NodeList) schemeChildrenExpr.evaluate(scheme, XPathConstants.NODESET);
assertThat(actions.getLength(), equalTo(6));
Node buildAction = actions.item(0);
assertThat(buildAction.getNodeName(), equalTo("BuildAction"));
assertThat(buildAction.getAttributes().getNamedItem("buildConfiguration"), nullValue());
Node testAction = actions.item(1);
assertThat(testAction.getNodeName(), equalTo("TestAction"));
assertThat(testAction.getAttributes().getNamedItem("buildConfiguration").getNodeValue(), equalTo("Debug"));
Node launchAction = actions.item(2);
assertThat(launchAction.getNodeName(), equalTo("LaunchAction"));
assertThat(launchAction.getAttributes().getNamedItem("buildConfiguration").getNodeValue(), equalTo("Debug"));
Node profileAction = actions.item(3);
assertThat(profileAction.getNodeName(), equalTo("ProfileAction"));
assertThat(profileAction.getAttributes().getNamedItem("buildConfiguration").getNodeValue(), equalTo("Release"));
Node analyzeAction = actions.item(4);
assertThat(analyzeAction.getNodeName(), equalTo("AnalyzeAction"));
assertThat(analyzeAction.getAttributes().getNamedItem("buildConfiguration").getNodeValue(), equalTo("Debug"));
Node archiveAction = actions.item(5);
assertThat(archiveAction.getNodeName(), equalTo("ArchiveAction"));
assertThat(archiveAction.getAttributes().getNamedItem("buildConfiguration").getNodeValue(), equalTo("Release"));
}
use of javax.xml.xpath.XPathFactory in project openhab1-addons by openhab.
the class AutelisBinding method execute.
/**
* @{inheritDoc}
*/
@Override
protected void execute() {
logger.trace("Connecting to {}" + baseURL);
clearState();
String xmlDoc = fetchStateFromController();
if (xmlDoc == null) {
return;
}
for (AutelisBindingProvider provider : providers) {
for (String itemName : provider.getItemNames()) {
Item item = provider.getItem(itemName);
String config = provider.getAutelisBindingConfigString(itemName);
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
try {
InputSource is = new InputSource(new StringReader(xmlDoc));
String value = xpath.evaluate("response/" + config.replace('.', '/'), is);
State state = toState(item.getClass(), value);
State oldState = stateMap.put(itemName, state);
if (!state.equals(oldState)) {
logger.debug("updating item {} with state {}", itemName, state);
eventPublisher.postUpdate(itemName, state);
}
} catch (XPathExpressionException e) {
logger.warn("could not parse xml", e);
}
}
}
}
use of javax.xml.xpath.XPathFactory in project camel by apache.
the class XPathTest method testXPathFunctionSubstringUsingSaxon.
@Test
public void testXPathFunctionSubstringUsingSaxon() throws Exception {
String xml = "<foo><bar>Hello World</bar></foo>";
XPathFactory fac = new XPathFactoryImpl();
XPathBuilder builder = XPathBuilder.xpath("substring(/foo/bar, 7)").factory(fac);
String result = builder.resultType(String.class).evaluate(context, xml, String.class);
assertEquals("World", result);
result = builder.evaluate(context, xml);
assertEquals("World", result);
}
use of javax.xml.xpath.XPathFactory in project camel by apache.
the class XPathBuilder method createDefaultXPathFactory.
protected static XPathFactory createDefaultXPathFactory() throws XPathFactoryConfigurationException {
XPathFactory factory = null;
// read system property and see if there is a factory set
Properties properties = System.getProperties();
for (Map.Entry<Object, Object> prop : properties.entrySet()) {
String key = (String) prop.getKey();
if (key.startsWith(XPathFactory.DEFAULT_PROPERTY_NAME)) {
String uri = ObjectHelper.after(key, ":");
if (uri != null) {
factory = XPathFactory.newInstance(uri);
LOG.info("Using system property {} with value {} when created default XPathFactory {}", new Object[] { key, uri, factory });
}
}
}
if (factory == null) {
factory = XPathFactory.newInstance();
LOG.info("Created default XPathFactory {}", factory);
}
return factory;
}
use of javax.xml.xpath.XPathFactory in project sonarqube by SonarSource.
the class XpathParser method parse.
public void parse(String xml) {
try {
String fixedXml = fixUnicodeChar(xml);
doc = builder.parse(new ByteArrayInputStream(fixedXml.getBytes(StandardCharsets.UTF_8)));
XPathFactory factory = XPathFactory.newInstance();
xpath = factory.newXPath();
} catch (IOException | SAXException e) {
throw new XmlParserException(CAN_NOT_PARSE_XML + xml, e);
}
}
Aggregations