📄 urltreenode.java
字号:
/* * UrlTreeNode.java * * Created on September 20, 2004, 11:20 AM */import javax.swing.*;import javax.swing.tree.*;import java.util.*;import java.net.*;/** * Class used to hold information about a web site that has * been searched by the spider class * * @author Mark Pendergast */public class UrlTreeNode { /** URL */ private URL url; /** base web address for this page */ private URL base; /** is match, set to true if node matched search criteria */ private boolean isMatch; /** set if the node is a plain text and not url */ private boolean isText = false; /** list of keywords matched by this node */ private Vector keywords = new Vector(3,2); /** title of web page */ private String title = ""; /** number of text characters on page */ private int nChars = 0; /** number of images on page */ private int nImages = 0; /** number of links on page */ private int nLinks = 0; /** Creates a new instance of UrlTreeNode * @param aurl url of the web page */ public UrlTreeNode(URL aurl) { url = aurl; isMatch = false; base = url; // initialize default value of base isText = false; } /** Creates a new instance of UrlTreeNode * @param atext text for the node */ public UrlTreeNode(String atext) { isMatch = false; base = null; isText = true; title = atext; } /** * return url string for display on screen * @return String representation of the object */ public String toString() { if(isText) return title; else { // return url.getProtocol()+"://"+url.getHost()+url.getPath(); return title+" - "+url.getProtocol()+"://"+url.getHost()+url.getPath(); } } /** * get the keywords found in this node * @return all keywords in this node as a single comma separated string */ public String getKeywords() { String s =""; if(keywords.size() > 0) { s += (String)keywords.get(0); for(int i = 1; i < keywords.size(); i++) s += ", "+(String)keywords.get(i); } return s; } /** * return state of node * @return true if node matched search criteria */ public boolean isMatch() { return isMatch; } /** * returns the url object for this node or null if it is a text node * @return url of the node or null */ public URL getUrl() { if(isText) return null; else return url; } /** * * returns whether or not this node contains a match for the spiders search criteria * @param keyword keyword found in web site. */ public void setMatch(String keyword) { isMatch = true; if(!keywords.contains(keyword)) keywords.addElement(keyword); } /** * sets the base location for the node, called in response to finding a base tag in the web page * * @param abase base url to use for relative addressing */ public void setBase(String abase) { try{ base = new URL(abase); } catch(MalformedURLException e) { } } /** * returns base url * @return base url */ public URL getBase() { return base; } /** * sets the title attribute of the node * @param atitle title of web page from <TITLE> tag */ public void setTitle(String atitle) { title = atitle; } /** * test for equality * @param urlstr string containing url to compare * @return true if it is the same page */ public boolean equals(String urlstr) { if(isText) return title.equals(urlstr); else return urlstr.equals(url.getProtocol()+"://"+url.getHost()+url.getPath()); } /** * Increments character count * @param n number of characters to add */ public void addChars(int n) { nChars += n; } /** * Increments link count * @param n number of linkss to add */ public void addLinks(int n) { nLinks += n; } /** * Increments image count * @param n number of images to add */ public void addImages(int n) { nImages += n; } /** * retrieves character, link, and image count as a displayable string * @return pages statistics */ public String getNodeStats() { return "Page has "+nChars+" total text characters, "+nImages+" images, and "+nLinks+ " links."; }/** * retrieves the url as a string * @return url */ public String getUrlString() { return url.getProtocol()+"://"+url.getHost()+url.getPath(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -