[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/lexerTests AttributeTests.java,1.6,1.7 TagTests
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-12-07 23:42:15
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests In directory sc8-pr-cvs1:/tmp/cvs-serv16537/tests/lexerTests Modified Files: AttributeTests.java TagTests.java Log Message: Remove most of the scanners. The only scanners left are ones that really do something different (script and jsp). Instead of registering a scanner to enable returning a specific tag you now add a tag to the a PrototypicalNodeFactory. All known tags are 'registered' by default in a new Parser which is similar to having called the old 'registerDOMScanners()', so tags are fully nested. This is different behaviour, and specifically, you will need to recurse into returned nodes to get at what you want. I've tried to adjust the applications accordingly, but worked examples are still scarce. If you want to return only some of the derived tags while keeping most as generic tags, there are various constructors and manipulators on the factory. See the javadocs and examples in the tests package. Nearly all the old scanner tests are folded into the tag tests. toString() has been revamped. This means that the default Parser mainline now returns an indented listing of tags, making it easy to see the structure of a page. The downside is the text of the page had to have newlines, tabs etc. turned into escape sequences. But if you were really interested in content you would be using toHtml() or toPlainTextString(). Index: AttributeTests.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests/AttributeTests.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** AttributeTests.java 9 Nov 2003 17:07:14 -0000 1.6 --- AttributeTests.java 7 Dec 2003 23:41:41 -0000 1.7 *************** *** 35,38 **** --- 35,39 ---- import org.htmlparser.Parser; + import org.htmlparser.PrototypicalNodeFactory; import org.htmlparser.lexer.nodes.Attribute; import org.htmlparser.lexer.nodes.PageAttribute; *************** *** 68,71 **** --- 69,73 ---- html = "<" + tagContents + ">"; createParser (html); + parser.setNodeFactory (new PrototypicalNodeFactory (true)); try { Index: TagTests.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests/TagTests.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TagTests.java 9 Nov 2003 17:07:14 -0000 1.6 --- TagTests.java 7 Dec 2003 23:41:41 -0000 1.7 *************** *** 33,36 **** --- 33,37 ---- import org.htmlparser.Node; import org.htmlparser.Parser; + import org.htmlparser.PrototypicalNodeFactory; import org.htmlparser.tags.LinkTag; import org.htmlparser.tags.MetaTag; *************** *** 92,95 **** --- 93,97 ---- createParser(testHtml); + parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(1); assertType("should be Tag",Tag.class,node[0]); *************** *** 107,110 **** --- 109,113 ---- String html = "<custom/>"; createParser(html); + parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(1); assertType("should be Tag",Tag.class,node[0]); *************** *** 121,124 **** --- 124,128 ---- public void testTagWithCloseTagSymbolInAttribute() throws ParserException { createParser("<tag att=\"a>b\">"); + parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(1); assertType("should be Tag",Tag.class,node[0]); *************** *** 129,132 **** --- 133,137 ---- public void testTagWithOpenTagSymbolInAttribute() throws ParserException { createParser("<tag att=\"a<b\">"); + parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(1); assertType("should be Tag",Tag.class,node[0]); *************** *** 138,141 **** --- 143,147 ---- String html = "<tag att=\'a<b\'>"; createParser(html); + parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(1); assertType("should be Tag",Tag.class,node[0]); *************** *** 154,158 **** String html = "<meta name=\"foo\" content=\"foo<bar>\">"; createParser(html); - parser.registerScanners (); parseAndAssertNodeCount (1); assertType ("should be MetaTag", MetaTag.class, node[0]); --- 160,163 ---- *************** *** 169,173 **** String html = "<meta name=\"foo\" content=\"foo<bar\">"; createParser(html); - parser.registerScanners (); parseAndAssertNodeCount (1); assertType ("should be MetaTag", MetaTag.class, node[0]); --- 174,177 ---- *************** *** 184,188 **** String html = "<meta name=\"foo\" content=\"foobar>\">"; createParser(html); - parser.registerScanners (); parseAndAssertNodeCount (1); assertType ("should be MetaTag", MetaTag.class, node[0]); --- 188,191 ---- *************** *** 199,203 **** String html = "<meta name=\"foo\" content=\"foo\nbar>\">"; createParser(html); - parser.registerScanners (); parseAndAssertNodeCount (1); assertType ("should be MetaTag", MetaTag.class, node[0]); --- 202,205 ---- *************** *** 220,224 **** String html = "<meta name=\"foo\" content=\"<foo>\nbar\">"; createParser(html); - parser.registerScanners (); parseAndAssertNodeCount (1); assertType ("should be MetaTag", MetaTag.class, node[0]); --- 222,225 ---- *************** *** 241,245 **** String html = "<meta name=\"foo\" content=\"foo>\nbar\">"; createParser(html); - parser.registerScanners (); parseAndAssertNodeCount (1); assertType ("should be MetaTag", MetaTag.class, node[0]); --- 242,245 ---- *************** *** 262,266 **** String html = "<meta name=\"foo\" content=\"<foo\nbar\""; createParser(html); - parser.registerScanners (); parseAndAssertNodeCount (1); assertType ("should be MetaTag", MetaTag.class, node[0]); --- 262,265 ---- *************** *** 284,287 **** --- 283,287 ---- { createParser("<html></html>"); + parser.setNodeFactory (new PrototypicalNodeFactory (true)); String testHtml1 = "<a HREF=\"/cgi-bin/view_search?query_text=postdate>20020701&txt_clr=White&bg_clr=Red&url=http://localhost/Testing/Report1.html\">20020702 Report 1</A>" + TEST_HTML; *************** *** 361,367 **** this.id = id; this.max = max; ! this.parser = ! Parser.createParser(testHtml); ! parser.registerScanners(); } --- 361,365 ---- this.id = id; this.max = max; ! this.parser = Parser.createParser(testHtml); } *************** *** 411,414 **** --- 409,413 ---- String html = "<input disabled>"; createParser(html); + parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount (1); assertType ("should be Tag", Tag.class, node[0]); *************** *** 424,427 **** --- 423,427 ---- String html = "<input disabled=>"; createParser(html); + parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount (1); assertType ("should be Tag", Tag.class, node[0]); |