in taverna-xpath-activity-ui/src/main/java/org/apache/taverna/activities/xpath/ui/config/XPathActivityConfigurationPanel.java [1088:1168]
public int runXPath(boolean displayResults) {
// ----- RUNNING THE XPath EXPRESSION -----
XPath expr = null;
try {
expr = DocumentHelper.createXPath(this.tfXPathExpression.getText());
expr.setNamespaceURIs(this.xpathNamespaceMap);
} catch (InvalidXPathException e) {
if (displayResults) {
JOptionPane
.showMessageDialog(
thisPanel,
"Incorrect XPath Expression\n\n"
+ "Please check the expression if you have manually modified it;\n"
+ "Alternatively, try to select another node from the XML tree.\n\n"
+ "------------------------------------------------------------------------------------\n\n"
+ "XPath processing library reported the following error:\n"
+ e.getMessage(), "XPath Activity",
JOptionPane.ERROR_MESSAGE);
}
return (-1);
}
Document doc = xmlTree.getDocumentUsedToPopulateTree();
List<Node> matchingNodes = null;
int matchingNodeCount = -1;
try {
matchingNodes = expr.selectNodes(doc);
matchingNodeCount = matchingNodes.size();
} catch (XPathException e) {
if (displayResults) {
JOptionPane
.showMessageDialog(
thisPanel,
"Unexpected error has occurred while executing the XPath expression.\n\n"
+ "If you have manually modified the XPath expression and/or namespace mappings,\n"
+ "please check you changes. Alternatively, make your selection in the XML tree and\n"
+ "a correct XPath expression with corresponding namespace mapping will be generated.\n\n"
+ "-------------------------------------------------------------------------------------------------------------\n\n"
+ "XPath processing library reported the following error:\n"
+ e.getMessage(), "XPath Activity",
JOptionPane.ERROR_MESSAGE);
}
return (-1);
}
// ----- DISPLAYING THE RESULTS -----
if (displayResults) {
tfExecutedXPathExpression.setText(expr.getText());
tfMatchingElementCount.setText("" + matchingNodeCount);
StringBuffer outNodesText = new StringBuffer();
StringBuffer outNodesXML = new StringBuffer();
for (Node n : matchingNodes) {
if (n.getStringValue() != null
&& n.getStringValue().length() > 0) {
outNodesText.append(n.getStringValue() + "\n");
}
outNodesXML.append(n.asXML() + "\n");
}
// tpExecutedXPathExpressionResults.setSelectedIndex(0); // open the
// first tab (should be the one with textual results) // TODO -
// enable if needed
taExecutedXPathExpressionResultsAsText.setText(outNodesText
.toString());
taExecutedXPathExpressionResultsAsText.setBackground(Color.WHITE);
taExecutedXPathExpressionResultsAsText.setCaretPosition(0);
spExecutedXPathExpressionResultsAsText.setBorder(BorderFactory
.createLineBorder(Color.WHITE, 3));
taExecutedXPathExpressionResultsAsXML.setText(outNodesXML
.toString());
taExecutedXPathExpressionResultsAsXML.setBackground(Color.WHITE);
taExecutedXPathExpressionResultsAsXML.setCaretPosition(0);
spExecutedXPathExpressionResultsAsXML.setBorder(BorderFactory
.createLineBorder(Color.WHITE, 3));
}
return (matchingNodeCount);
}