1 17 18 19 20 package org.apache.fop.fo; 21 22 import java.util.Iterator ; 23 import java.util.NoSuchElementException ; 24 25 31 public class RecursiveCharIterator extends CharIterator { 32 33 private FONode fobj; 34 35 private Iterator childIter = null; 36 37 38 private FONode curChild; 39 40 private CharIterator curCharIter = null; 41 42 46 public RecursiveCharIterator(FObj fobj) { 47 this.fobj = fobj; 49 this.childIter = fobj.getChildNodes(); 50 getNextCharIter(); 51 } 52 53 58 public RecursiveCharIterator(FObj fobj, FONode child) { 59 this.fobj = fobj; 61 this.childIter = fobj.getChildNodes(child); 62 getNextCharIter(); 63 } 64 65 68 public CharIterator mark() { 69 return (CharIterator) this.clone(); 70 } 71 72 75 public Object clone() { 76 RecursiveCharIterator ci = (RecursiveCharIterator) super.clone(); 77 ci.childIter = fobj.getChildNodes(ci.curChild); 78 ci.childIter.next(); 80 ci.curCharIter = (CharIterator) curCharIter.clone(); 81 return ci; 82 } 83 84 90 public void replaceChar(char c) { 91 if (curCharIter != null) { 92 curCharIter.replaceChar(c); 93 } 94 } 95 96 101 private void getNextCharIter() { 102 if (childIter != null && childIter.hasNext()) { 103 this.curChild = (FONode) childIter.next(); 104 this.curCharIter = curChild.charIterator(); 105 } else { 106 curChild = null; 107 curCharIter = null; 108 } 109 } 110 111 114 public boolean hasNext() { 115 while (curCharIter != null) { 116 if (curCharIter.hasNext() == false) { 117 getNextCharIter(); 118 } else { 119 return true; 120 } 121 } 122 return false; 123 } 124 125 128 public char nextChar() throws NoSuchElementException { 129 if (curCharIter != null) { 130 return curCharIter.nextChar(); 131 } else { 132 throw new NoSuchElementException (); 133 } 134 } 135 136 139 public void remove() { 140 if (curCharIter != null) { 141 curCharIter.remove(); 142 } 143 } 144 } 145 146 | Popular Tags |