use of javax.xml.xpath.XPathVariableResolver in project jstl-api by eclipse-ee4j.
the class JSTLNodeList method valueOf.
/**
* Evaluate an XPath expression to a String value.
*/
public String valueOf(Node contextNode, String xpathString) throws JspTagException {
// p("******** valueOf(" + n + ", " + xpathString + ")");
XPathVariableResolver jxvr = new JSTLXPathVariableResolver(pageContext);
XPath xpath = XPATH_FACTORY.newXPath();
xpath.setNamespaceContext(jstlXPathNamespaceContext);
xpath.setXPathVariableResolver(jxvr);
try {
return xpath.evaluate(xpathString, contextNode);
} catch (XPathExpressionException ex) {
throw new JspTagException(ex.toString(), ex);
}
}
use of javax.xml.xpath.XPathVariableResolver in project jstl-api by eclipse-ee4j.
the class JSTLNodeList method selectSingleNode.
/**
* Evaluate an XPath expression to a single node.
*/
public Node selectSingleNode(Node contextNode, String xpathString) throws JspTagException {
// p("selectSingleNode of XPathUtil = passed node:" +
// "xpathString => " + n + " : " + xpathString );
XPathVariableResolver jxvr = new JSTLXPathVariableResolver(pageContext);
try {
XPath xpath = XPATH_FACTORY.newXPath();
xpath.setNamespaceContext(jstlXPathNamespaceContext);
xpath.setXPathVariableResolver(jxvr);
return (Node) xpath.evaluate(xpathString, contextNode, XPathConstants.NODE);
} catch (XPathExpressionException ex) {
throw new JspTagException(ex.toString(), ex);
}
}
use of javax.xml.xpath.XPathVariableResolver in project jstl-api by eclipse-ee4j.
the class JSTLNodeList method selectNodes.
/**
* Evaluate an XPath expression to a List of nodes.
*/
public List<Node> selectNodes(Node contextNode, String xpathString) throws JspTagException {
XPathVariableResolver jxvr = new JSTLXPathVariableResolver(pageContext);
try {
XPath xpath = XPATH_FACTORY.newXPath();
xpath.setNamespaceContext(jstlXPathNamespaceContext);
xpath.setXPathVariableResolver(jxvr);
Object nl = xpath.evaluate(xpathString, contextNode, JSTLXPathConstants.OBJECT);
return new JSTLNodeList(nl);
} catch (XPathExpressionException ex) {
throw new JspTagException(ex.toString(), ex);
}
}
use of javax.xml.xpath.XPathVariableResolver in project jvarkit by lindenb.
the class VcfFilterXPath method doWork.
@Override
public int doWork(List<String> args) {
if (this.infoTag == null || this.infoTag.isEmpty()) {
LOG.error("Info Tag is undefined");
return -1;
}
if (this.xpathExpression == null || this.xpathExpression.isEmpty()) {
LOG.error("XPath Expression is undefined");
return -1;
}
for (final String s : __prefix2uri) {
int eq = s.indexOf('=');
if (eq <= 0) {
LOG.error("'=' missing in " + s);
return -1;
}
this.prefix2uri.put(s.substring(0, eq), s.substring(eq + 1));
}
try {
XPathFactory xpf = XPathFactory.newInstance();
XPath xpath = xpf.newXPath();
xpath.setXPathVariableResolver(new XPathVariableResolver() {
@Override
public Object resolveVariable(QName qname) {
return xpathVariableMap.get(qname);
}
});
xpath.setNamespaceContext(new NamespaceContext() {
@Override
public Iterator<String> getPrefixes(String namespaceURI) {
final List<String> L = new ArrayList<>();
for (final String pfx : prefix2uri.keySet()) {
if (prefix2uri.get(pfx).equals(namespaceURI)) {
L.add(pfx);
}
}
return L.iterator();
}
@Override
public String getPrefix(final String namespaceURI) {
for (String pfx : prefix2uri.keySet()) {
if (prefix2uri.get(pfx).equals(namespaceURI)) {
return pfx;
}
}
return null;
}
@Override
public String getNamespaceURI(String prefix) {
return prefix2uri.get(prefix);
}
});
this.xpathExpr = xpath.compile(this.xpathExpression);
return doVcfToVcf(args, outputFile);
} catch (Exception er) {
LOG.error(er);
return -1;
}
}
use of javax.xml.xpath.XPathVariableResolver in project jbpm by kiegroup.
the class XPATHReturnValueEvaluator method evaluate.
public Object evaluate(final ProcessContext context) throws Exception {
XPathFactory factory = XPathFactory.newInstance();
XPath xpathEvaluator = factory.newXPath();
xpathEvaluator.setXPathFunctionResolver(new XPathFunctionResolver() {
public XPathFunction resolveFunction(QName functionName, int arity) {
String localName = functionName.getLocalPart();
if ("getVariable".equals(localName)) {
return new GetVariableData();
} else {
throw new IllegalArgumentException("Unknown BPMN function: " + functionName);
}
}
class GetVariableData implements XPathFunction {
public Object evaluate(List args) throws XPathFunctionException {
String varname = (String) args.get(0);
return context.getVariable(varname);
}
}
});
xpathEvaluator.setXPathVariableResolver(new XPathVariableResolver() {
public Object resolveVariable(QName variableName) {
return context.getVariable(variableName.getLocalPart());
}
});
xpathEvaluator.setNamespaceContext(new NamespaceContext() {
private static final String DROOLS_NAMESPACE_URI = "http://www.jboss.org/drools";
private String[] prefixes = { "drools", "bpmn2" };
@Override
public Iterator getPrefixes(String namespaceURI) {
return Arrays.asList(prefixes).iterator();
}
@Override
public String getPrefix(String namespaceURI) {
if (DROOLS_NAMESPACE_URI.equalsIgnoreCase(namespaceURI)) {
return "bpmn2";
}
return null;
}
@Override
public String getNamespaceURI(String prefix) {
if ("bpmn2".equalsIgnoreCase(prefix)) {
return DROOLS_NAMESPACE_URI;
}
return null;
}
});
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
return xpathEvaluator.evaluate(this.expression, builder.newDocument(), XPathConstants.BOOLEAN);
}
Aggregations