1 27 package org.htmlparser.visitors; 28 29 import org.htmlparser.Parser; 30 import org.htmlparser.tags.BodyTag; 31 import org.htmlparser.tags.TableTag; 32 import org.htmlparser.Tag; 33 import org.htmlparser.tags.TitleTag; 34 import org.htmlparser.util.NodeList; 35 36 public class HtmlPage extends NodeVisitor { 37 private String title; 38 private NodeList nodesInBody; 39 private NodeList tables; 40 41 public HtmlPage(Parser parser) { 42 super(true); 43 title = ""; 44 nodesInBody = new NodeList(); 45 tables = new NodeList(); 46 } 47 48 public String getTitle() { 49 return title; 50 } 51 52 public void setTitle(String title) { 53 this.title = title; 54 } 55 56 public void visitTag(Tag tag) 57 { 58 if (isTable(tag)) 59 tables.add(tag); 60 else if (isBodyTag(tag)) 61 nodesInBody = tag.getChildren (); 62 else if (isTitleTag(tag)) 63 title = ((TitleTag)tag).getTitle(); 64 } 65 66 private boolean isTable(Tag tag) 67 { 68 return (tag instanceof TableTag); 69 } 70 71 private boolean isBodyTag(Tag tag) 72 { 73 return (tag instanceof BodyTag); 74 } 75 76 private boolean isTitleTag(Tag tag) 77 { 78 return (tag instanceof TitleTag); 79 } 80 81 public NodeList getBody() { 82 return nodesInBody; 83 } 84 85 public TableTag [] getTables() 86 { 87 TableTag [] tableArr = new TableTag[tables.size()]; 88 tables.copyToNodeArray (tableArr); 89 return tableArr; 90 } 91 } 92 | Popular Tags |