[Htmlparser-cvs] htmlparser/src/org/htmlparser/util Generate.java,1.42,1.43 IteratorImpl.java,1.28,1
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-09-29 21:45:41
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util In directory sc8-pr-cvs1:/tmp/cvs-serv30684/util Modified Files: Generate.java IteratorImpl.java ParserUtils.java Log Message: Lexer Integration Removed old Parser classes. Removed EndTag, this class was replaced by a call to the new isEndTag() method on the Tag class The StringNode, RemarkNode and tags.Tag class now derive from their lexeme counterparts in lexer.nodes instead of the other way around. The beginnings of a node factory interface are included. This was added so the lexer could return 'visitable' nodes to the parser. The parser acts as it's own node factory, as does the Lexer. The node count for parsing goes up in most cases because every whitespace (i.e. newline) now counts as a StringNode. This has whacked out a lot of the tests that were expecting fewer nodes or a certain type of node at a particular index. Attributes now maintain their order and case. The count of attributes also went up because whitespace is maintained within tags too. The storage in a Vector means the element 0 Attribute is actually the name of the tag, rather than having the $TAGNAME entry in a HashTable. Index: Generate.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/Generate.java,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** Generate.java 22 Sep 2003 02:40:15 -0000 1.42 --- Generate.java 28 Sep 2003 15:33:59 -0000 1.43 *************** *** 37,41 **** import org.htmlparser.RemarkNode; import org.htmlparser.StringNode; - import org.htmlparser.tags.EndTag; import org.htmlparser.tags.LinkTag; import org.htmlparser.tags.Tag; --- 37,40 ---- *************** *** 186,195 **** { String contents = ((Tag)node).getText (); - if (contents.equals ("BR") || contents.equals ("P")) - buffer.append (nl); - } - else if (node instanceof EndTag) - { - String contents = ((EndTag)node).getText (); if (contents.equals ("BR") || contents.equals ("P")) buffer.append (nl); --- 185,188 ---- Index: IteratorImpl.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/IteratorImpl.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** IteratorImpl.java 22 Sep 2003 02:40:15 -0000 1.28 --- IteratorImpl.java 28 Sep 2003 15:33:59 -0000 1.29 *************** *** 32,49 **** import org.htmlparser.Node; ! import org.htmlparser.NodeReader; public class IteratorImpl implements PeekingIterator { ! NodeReader reader; Vector preRead; - String resourceLocn; ParserFeedback feedback; ! public IteratorImpl (NodeReader rd, String resource, ParserFeedback fb) { ! reader = rd; preRead = new Vector (25); - resourceLocn = resource; feedback = fb; } --- 32,47 ---- import org.htmlparser.Node; ! import org.htmlparser.lexer.Lexer; public class IteratorImpl implements PeekingIterator { ! Lexer mLexer; Vector preRead; ParserFeedback feedback; ! public IteratorImpl (Lexer lexer, ParserFeedback fb) { ! mLexer = lexer; preRead = new Vector (25); feedback = fb; } *************** *** 53,62 **** Node ret; ! if (null == reader) ret = null; else try { ! ret = reader.readElement(); if (null != ret) preRead.addElement (ret); --- 51,60 ---- Node ret; ! if (null == mLexer) ret = null; else try { ! ret = mLexer.nextNode (); if (null != ret) preRead.addElement (ret); *************** *** 65,71 **** StringBuffer msgBuffer = new StringBuffer(); msgBuffer.append("Unexpected Exception occurred while reading "); ! msgBuffer.append(resourceLocn); msgBuffer.append(", in nextHTMLNode"); ! reader.appendLineDetails(msgBuffer); ParserException ex = new ParserException(msgBuffer.toString(),e); feedback.error(msgBuffer.toString(),ex); --- 63,69 ---- StringBuffer msgBuffer = new StringBuffer(); msgBuffer.append("Unexpected Exception occurred while reading "); ! msgBuffer.append(mLexer.getPage ().getUrl ()); msgBuffer.append(", in nextHTMLNode"); ! // reader.appendLineDetails(msgBuffer); ParserException ex = new ParserException(msgBuffer.toString(),e); feedback.error(msgBuffer.toString(),ex); *************** *** 83,87 **** boolean ret; ! if (null == reader) ret = false; else if (0 != preRead.size ()) --- 81,85 ---- boolean ret; ! if (null == mLexer) ret = false; else if (0 != preRead.size ()) Index: ParserUtils.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/ParserUtils.java,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** ParserUtils.java 22 Sep 2003 02:40:15 -0000 1.30 --- ParserUtils.java 28 Sep 2003 15:33:59 -0000 1.31 *************** *** 34,38 **** import org.htmlparser.Node; ! import org.htmlparser.NodeReader; import org.htmlparser.tags.Tag; --- 34,38 ---- import org.htmlparser.Node; ! import org.htmlparser.Parser; import org.htmlparser.tags.Tag; *************** *** 57,71 **** } ! public static Map adjustScanners(NodeReader reader) { Map tempScanners = new Hashtable(); ! tempScanners = reader.getParser().getScanners(); // Remove all existing scanners ! reader.getParser().flushScanners(); return tempScanners; } ! public static void restoreScanners(NodeReader reader, Map tempScanners) { // Flush the scanners ! reader.getParser().setScanners(tempScanners); } --- 57,71 ---- } ! public static Map adjustScanners(Parser parser) { Map tempScanners = new Hashtable(); ! tempScanners = parser.getScanners(); // Remove all existing scanners ! parser.flushScanners(); return tempScanners; } ! public static void restoreScanners(Parser parser, Map tempScanners) { // Flush the scanners ! parser.setScanners(tempScanners); } |