use of org.intellij.plugins.xpathView.support.XPathSupport in project intellij-community by JetBrains.
the class XPathEvalAction method evaluateExpression.
private boolean evaluateExpression(EvalExpressionDialog.Context context, XmlElement contextNode, Editor editor, Config cfg) {
final Project project = editor.getProject();
try {
final XPathSupport support = XPathSupport.getInstance();
final XPath xpath = support.createXPath((XmlFile) contextNode.getContainingFile(), context.input.expression, context.input.namespaces);
xpath.setVariableContext(new CachedVariableContext(context.input.variables, xpath, contextNode));
// evaluate the expression on the whole document
final Object result = xpath.evaluate(contextNode);
LOG.debug("result = " + result);
LOG.assertTrue(result != null, "null result?");
if (result instanceof List<?>) {
final List<?> list = (List<?>) result;
if (!list.isEmpty()) {
if (cfg.HIGHLIGHT_RESULTS) {
highlightResult(contextNode, editor, list);
}
if (cfg.SHOW_USAGE_VIEW) {
showUsageView(editor, xpath, contextNode, list);
}
if (!cfg.SHOW_USAGE_VIEW && !cfg.HIGHLIGHT_RESULTS) {
final String s = StringUtil.pluralize("match", list.size());
Messages.showInfoMessage(project, "Expression produced " + list.size() + " " + s, "XPath Result");
}
} else {
return Messages.showOkCancelDialog(project, "Sorry, your expression did not return any result", "XPath Result", "OK", "Edit Expression", Messages.getInformationIcon()) != Messages.OK;
}
} else if (result instanceof String) {
Messages.showMessageDialog("'" + result.toString() + "'", "XPath result (String)", Messages.getInformationIcon());
} else if (result instanceof Number) {
Messages.showMessageDialog(result.toString(), "XPath result (Number)", Messages.getInformationIcon());
} else if (result instanceof Boolean) {
Messages.showMessageDialog(result.toString(), "XPath result (Boolean)", Messages.getInformationIcon());
} else {
LOG.error("Unknown XPath result: " + result);
}
} catch (XPathSyntaxException e) {
LOG.debug(e);
// TODO: Better layout of the error message with non-fixed size fonts
return Messages.showOkCancelDialog(project, e.getMultilineMessage(), "XPath syntax error", "Edit Expression", "Cancel", Messages.getErrorIcon()) == Messages.OK;
} catch (SAXPathException e) {
LOG.debug(e);
Messages.showMessageDialog(project, e.getMessage(), "XPath error", Messages.getErrorIcon());
}
return false;
}
Aggregations