1 27 package org.htmlparser.util; 28 29 import org.htmlparser.Node; 30 import org.htmlparser.Tag; 31 import org.htmlparser.lexer.Cursor; 32 import org.htmlparser.lexer.Lexer; 33 import org.htmlparser.lexer.Page; 34 import org.htmlparser.scanners.Scanner; 35 import org.htmlparser.util.NodeIterator; 36 37 public class IteratorImpl implements NodeIterator 38 { 39 Lexer mLexer; 40 ParserFeedback mFeedback; 41 Cursor mCursor; 42 43 public IteratorImpl (Lexer lexer, ParserFeedback fb) 44 { 45 mLexer = lexer; 46 mFeedback = fb; 47 mCursor = new Cursor (mLexer.getPage (), 0); 48 } 49 50 54 public boolean hasMoreNodes() throws ParserException 55 { 56 boolean ret; 57 58 mCursor.setPosition (mLexer.getPosition ()); 59 ret = Page.EOF != mLexer.getPage ().getCharacter (mCursor); 61 return (ret); 62 } 63 64 69 public Node nextNode () throws ParserException 70 { 71 Tag tag; 72 Scanner scanner; 73 NodeList stack; 74 Node ret; 75 76 try 77 { 78 ret = mLexer.nextNode (); 79 if (null != ret) 80 { 81 if (ret instanceof Tag) 83 { 84 tag = (Tag)ret; 85 if (!tag.isEndTag ()) 86 { 87 scanner = tag.getThisScanner (); 89 if (null != scanner) 90 { 91 stack = new NodeList (); 92 ret = scanner.scan (tag, mLexer, stack); 93 } 94 } 95 } 96 } 97 } 98 catch (ParserException pe) 99 { 100 throw pe; } 102 catch (Exception e) 103 { 104 StringBuffer msgBuffer = new StringBuffer (); 105 msgBuffer.append ("Unexpected Exception occurred while reading "); 106 msgBuffer.append (mLexer.getPage ().getUrl ()); 107 msgBuffer.append (", in nextNode"); 108 ParserException ex = new ParserException (msgBuffer.toString (), e); 110 mFeedback.error (msgBuffer.toString (), ex); 111 throw ex; 112 } 113 114 return (ret); 115 } 116 } 117 | Popular Tags |