out-xpath: reuse xpathFactory and xpath
authorFrantišek Kučera <franta-hg@frantovo.cz>
Thu, 04 Sep 2014 16:18:59 +0200
changeset 669837e58e0754
parent 65 5c4ae2ed5d97
child 67 96ce967c0182
out-xpath: reuse xpathFactory and xpath
java/alt2xml-out-xpath/src/cz/frantovo/alt2xml/out/xpath/XPathAction.java
     1.1 --- a/java/alt2xml-out-xpath/src/cz/frantovo/alt2xml/out/xpath/XPathAction.java	Thu Sep 04 16:14:15 2014 +0200
     1.2 +++ b/java/alt2xml-out-xpath/src/cz/frantovo/alt2xml/out/xpath/XPathAction.java	Thu Sep 04 16:18:59 2014 +0200
     1.3 @@ -33,22 +33,23 @@
     1.4   */
     1.5  public class XPathAction extends AbstractDOMAction {
     1.6  
     1.7 +	private final XPathFactory xpathFactory;
     1.8 +	private final XPath xpath;
     1.9 +
    1.10  	public XPathAction(ActionContext actionContext) {
    1.11  		super(actionContext);
    1.12 +		xpathFactory = XPathFactory.newInstance();
    1.13 +		xpath = xpathFactory.newXPath();
    1.14  	}
    1.15  
    1.16  	@Override
    1.17  	public void run(DOMResult domResult) throws OutputActionException {
    1.18  
    1.19 -		// TODO: reuse
    1.20 -		XPathFactory xpf = XPathFactory.newInstance();
    1.21 -		XPath xp = xpf.newXPath();
    1.22 -
    1.23  		if (getActionContext().getActionData().size() == 1) {
    1.24  			String expressionString = getActionContext().getActionData().get(0);
    1.25  
    1.26  			try {
    1.27 -				XPathExpression xpe = xp.compile(expressionString);
    1.28 +				XPathExpression xpe = xpath.compile(expressionString);
    1.29  
    1.30  				String result = xpe.evaluate(domResult.getNode());
    1.31