blob: 0cc52152cf4cfa166f2271ebdd58fe120e53e65d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
package org.apache.fop.fo;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.NoSuchElementException;
public class RecursiveCharIterator extends AbstractCharIterator {
Iterator childIter = null; // Child flow objects
CharIterator curCharIter = null; // Children's characters
private FONode fobj;
private FONode curChild;
public RecursiveCharIterator(FObj fobj) {
// Set up first child iterator
this.fobj = fobj;
this.childIter = fobj.getChildren();
getNextCharIter();
}
public RecursiveCharIterator(FObj fobj, FONode child) {
// Set up first child iterator
this.fobj = fobj;
this.childIter = fobj.getChildren(child);
getNextCharIter();
}
public CharIterator mark() {
return (CharIterator) this.clone();
}
public Object clone() {
RecursiveCharIterator ci = (RecursiveCharIterator)super.clone();
ci.childIter = fobj.getChildren(ci.curChild);
// Need to advance to the next child, else we get the same one!!!
ci.childIter.next();
ci.curCharIter = (CharIterator)curCharIter.clone();
return ci;
}
public void replaceChar(char c) {
if (curCharIter != null) {
curCharIter.replaceChar(c);
}
}
private void getNextCharIter() {
if (childIter.hasNext()) {
this.curChild = (FONode)childIter.next();
this.curCharIter = curChild.charIterator();
}
else {
curChild = null;
curCharIter = null;
}
}
public boolean hasNext() {
while (curCharIter != null) {
if (curCharIter.hasNext()==false) {
getNextCharIter();
}
else return true;
}
return false;
}
public char nextChar() throws NoSuchElementException {
if (curCharIter != null) {
return curCharIter.nextChar();
}
else throw new NoSuchElementException();
}
public void remove() {
if (curCharIter != null) {
curCharIter.remove();
}
}
}
|