4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
XPathNodeIterator.java
Go to the documentation of this file.
1 /*
2  * Project: Server for annotations sharing
3  * Subproject: Position of fragment of text in XML document
4  * Author: Michael Angelov
5  * Edited by: Ing. Jaroslav Dytrych idytrych@fit.vutbr.cz
6  * File: XPathNodeIterator.java
7  * Description: Exact XPath node iterator
8  */
9 
10 /**
11  * @file XPathNodeIterator.java
12  *
13  * @brief Exact XPath node iterator
14  */
15 
16 package cz.vutbr.fit.knot.annotations.fragmentUpdater.nodeIterators;
17 
19 import javax.xml.xpath.XPathExpression;
20 import javax.xml.xpath.XPathExpressionException;
21 import org.w3c.dom.Document;
22 import org.w3c.dom.Node;
23 
24 /**
25  * Exact XPath node iterator
26  *
27  * @brief Exact XPath node iterator
28  * @author Michael Angelov
29  */
30 public class XPathNodeIterator extends NodeIterator {
31 
32  /**
33  * Overriden initialization method.
34  *
35  * @param document document whose nodes will be iterated through
36  * @param expr expression according to which iterating will be provided
37  */
38  @Override
39  public void init(Document document, XPathExpression expr) throws XPathExpressionException {
40  this.document = document;
41  this.nodeList = XPathHelper.evaluateXPath(document, expr);
42  this.currentNodeIndex = 0;
43  }
44 
45  /**
46  * Overriden method for iterator's next node
47  *
48  * @return iterator's next node
49  */
50  @Override
51  public Node nextNode() {
52  return nodeList.item(currentNodeIndex++);
53 
54  }
55 
56  /**
57  * Overriden toString() method
58  *
59  * @return string representation of class
60  */
61  @Override
62  public String toString() {
63  return "XPath";
64  }
65 } // class XPathNodeIterator