1 package org
.argeo
.cms
.gcr
.xml
;
3 import java
.util
.Iterator
;
4 import java
.util
.NoSuchElementException
;
6 import org
.argeo
.api
.gcr
.Content
;
7 import org
.w3c
.dom
.Element
;
8 import org
.w3c
.dom
.Node
;
9 import org
.w3c
.dom
.NodeList
;
11 public class ElementIterator
implements Iterator
<Content
> {
12 private final DomContentSession contentSession
;
13 private final NodeList nodeList
;
15 private int currentIndex
;
16 private final int length
;
17 private Element nextElement
= null;
19 public ElementIterator(DomContentSession contentSession
, NodeList nodeList
) {
20 this.contentSession
= contentSession
;
21 this.nodeList
= nodeList
;
23 this.length
= nodeList
.getLength();
24 this.currentIndex
= 0;
25 this.nextElement
= findNext();
28 private Element
findNext() {
29 while (currentIndex
< length
) {
30 Node node
= nodeList
.item(currentIndex
);
31 if (node
instanceof Element
) {
32 return (Element
) node
;
40 public boolean hasNext() {
41 return nextElement
!= null;
45 public Content
next() {
46 if (nextElement
== null)
47 throw new NoSuchElementException();
48 DomContent result
= new DomContent(contentSession
, nextElement
);
50 nextElement
= findNext();