# HG changeset patch # User František Kučera # Date 1409840339 -7200 # Node ID 9837e58e0754983e3195666f7cb3667b57e2c91c # Parent 5c4ae2ed5d97de714b7ee6315c53ce15b0574ff6 out-xpath: reuse xpathFactory and xpath diff -r 5c4ae2ed5d97 -r 9837e58e0754 java/alt2xml-out-xpath/src/cz/frantovo/alt2xml/out/xpath/XPathAction.java --- a/java/alt2xml-out-xpath/src/cz/frantovo/alt2xml/out/xpath/XPathAction.java Thu Sep 04 16:14:15 2014 +0200 +++ b/java/alt2xml-out-xpath/src/cz/frantovo/alt2xml/out/xpath/XPathAction.java Thu Sep 04 16:18:59 2014 +0200 @@ -33,22 +33,23 @@ */ public class XPathAction extends AbstractDOMAction { + private final XPathFactory xpathFactory; + private final XPath xpath; + public XPathAction(ActionContext actionContext) { super(actionContext); + xpathFactory = XPathFactory.newInstance(); + xpath = xpathFactory.newXPath(); } @Override public void run(DOMResult domResult) throws OutputActionException { - // TODO: reuse - XPathFactory xpf = XPathFactory.newInstance(); - XPath xp = xpf.newXPath(); - if (getActionContext().getActionData().size() == 1) { String expressionString = getActionContext().getActionData().get(0); try { - XPathExpression xpe = xp.compile(expressionString); + XPathExpression xpe = xpath.compile(expressionString); String result = xpe.evaluate(domResult.getNode());