use of org.apache.commons.jxpath.JXPathContext in project freud by LMAX-Exchange.
the class CssRuleJdom method parseDeclarations.
@SuppressWarnings("unchecked")
private void parseDeclarations() {
cssDeclarationList = new ArrayList<CssDeclaration>();
JXPathContext context = JXPathContext.newContext(ruleElement);
List<Element> cssSelectorElementList = (List<Element>) context.selectNodes("/" + CssTokenType.PROPERTY.name());
for (Element element : cssSelectorElementList) {
cssDeclarationList.add(new CssDeclarationJdom(this, element));
}
}
use of org.apache.commons.jxpath.JXPathContext in project opennms by OpenNMS.
the class JsonCollectorSolarisZonesIT method testXpath.
/**
* Test to verify XPath content.
*
* @throws Exception the exception
*/
@Test
@SuppressWarnings("unchecked")
public void testXpath() throws Exception {
JSONObject json = MockDocumentBuilder.getJSONDocument();
JXPathContext context = JXPathContext.newContext(json);
Iterator<Pointer> itr = context.iteratePointers("/zones/zone");
while (itr.hasNext()) {
Pointer resPtr = itr.next();
JXPathContext relativeContext = context.getRelativeContext(resPtr);
String resourceName = (String) relativeContext.getValue("@name");
Assert.assertNotNull(resourceName);
String value = (String) relativeContext.getValue("parameter[@key='nproc']/@value");
Assert.assertNotNull(Integer.valueOf(value));
}
}
use of org.apache.commons.jxpath.JXPathContext in project galley by Commonjava.
the class JXPathContextAncestryTest method basicJXPathTest.
@Test
@Ignore
public void basicJXPathTest() throws Exception {
final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("jxpath/simple.pom.xml");
final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
final JXPathContext ctx = JXPathContext.newContext(document);
document.getDocumentElement().removeAttribute("xmlns");
final String projectGroupIdPath = "ancestor::project/groupId";
// NOT what's failing...just populating the node set to traverse in order to feed the ancestor:: axis test.
final List<?> nodes = ctx.selectNodes("/project/dependencies/dependency");
for (final Object object : nodes) {
final Node node = (Node) object;
dump(node);
final Stack<Node> revPath = new Stack<Node>();
Node parent = node;
while (parent != null) {
revPath.push(parent);
parent = parent.getParentNode();
}
JXPathContext nodeCtx = null;
while (!revPath.isEmpty()) {
final Node part = revPath.pop();
if (nodeCtx == null) {
nodeCtx = JXPathContext.newContext(part);
} else {
nodeCtx = JXPathContext.newContext(nodeCtx, part);
}
}
System.out.println("Path derived from context: '" + nodeCtx.getNamespaceContextPointer().asPath() + "'");
// brute-force approach...try to force population of the parent pointers by painstakingly constructing contexts for all intermediate nodes.
System.out.println("Selecting groupId for declaring project using path-derived context...");
System.out.println(nodeCtx.getValue(projectGroupIdPath));
// Naive approach...this has all the context info it needs to get parent contexts up to and including the document!
System.out.println("Selecting groupId for declaring project using non-derived context...");
System.out.println(JXPathContext.newContext(node).getValue(projectGroupIdPath));
}
}
use of org.apache.commons.jxpath.JXPathContext in project camel by apache.
the class JXPathExpression method evaluate.
public <T> T evaluate(Exchange exchange, Class<T> tClass) {
try {
JXPathContext context = JXPathContext.newContext(exchange);
context.setLenient(lenient);
Object result = getJXPathExpression().getValue(context, type);
assertResultType(exchange, result);
return exchange.getContext().getTypeConverter().convertTo(tClass, result);
} catch (JXPathException e) {
throw new ExpressionEvaluationException(this, exchange, e);
}
}
use of org.apache.commons.jxpath.JXPathContext in project freud by LMAX-Exchange.
the class AnnotationJdom method getAnnotationValueForElement.
private String getAnnotationValueForElement(final Element element) {
final JXPathContext context = JXPathContext.newContext(element);
final Element expr = (Element) context.selectSingleNode("/" + JavaSourceTokenType.EXPR.name() + "/*");
if (expr != null) {
return expr.getText();
} else {
final List<Element> exprList = context.selectNodes("//" + JavaSourceTokenType.EXPR.name() + "/*");
StringBuilder sb = new StringBuilder("{");
for (Element item : exprList) {
sb.append(item.getText()).append(",");
}
sb.setCharAt(sb.length() - 1, '}');
return sb.toString();
}
}
Aggregations