搜索引擎及搜索引擎优化(SEO)实验 - 图文(4)

2019-03-23 14:36

thefield.setForeground(Color.black); if(listener != null)

listener.validData(jComponent); return true; // if empty, just return true } else

if(input.length() == 0 && !blankOk) {

reportError(thefield,\ return false; // if empty, just return true } /*

* try to convert to an integer */ try{

number = Integer.parseInt(input); }

catch (NumberFormatException e) {

reportError(thefield,\ return false; } /*

* test if its in the range */

if(number < minValue || number > maxValue) {

reportError(thefield,\must enter a number between \\

return false; } /*

* report good data

16

and */

thefield.setForeground(Color.black);

thefield.setText(\ if(listener != null)

listener.validData(jComponent); return true; // valid input found } /**

* report error to the listener (if any) * @param thefield text field being checked * @param message error message to report */

private void reportError(JTextField thefield, String message) {

thefield.setForeground(Color.red); // paint the text red, return false invalid input if(listener != null)

listener.invalidData(message,thefield); } } /*

* Spider.java * */

import java.util.*; import java.io.*; import java.net.*; import javax.swing.*; import javax.swing.tree.*;

import javax.swing.text.html.parser.*;

import javax.swing.text.html.HTMLEditorKit.*; import javax.swing.text.html.*; import javax.swing.text.*; /**

17

* Object used to search the web (or a subset of given domains) for a list of keywords * @author Mark Pendergast */

public class Spider extends Thread{

/** site visit limit (stops search at some point) */ private int siteLimit = 100; /** search depth limit */ private int depthLimit = 100; /** keyword list for seach */ private String keywordList[]; /** ip type list */

private String ipDomainList[]; /** visited tree */

private JTree searchTree = null;

/** message JTextArea, place to post errors */ private JTextArea messageArea; /** place to put search statistics */ private JLabel statsLabel;

/** keep track of web sites searched */ private int sitesSearched = 0;

/** keep track of web sites found with matching criteria */ private int sitesFound = 0;

/** starting site for the search */ private String startSite;

/** flag used to stop search */ private boolean stopSearch = false; /**

* Creates a new instance of Spider

* @param atree JTree used to display the search space

* @param amessagearea JTextArea used to display error/warning messages * @param astatlabel JLabel to display number of searched sites and hits * @param akeywordlist list of keywords to search for

18

* @param aipdomainlist list of top level domains

* @param asitelimit maximum number of web pages to look at

* @param adepthlimit maximum number of levels down to search (controls recursion) * @param astartsite web site to use to start the search */

public Spider(JTree atree, JTextArea amessagearea,JLabel astatlabel, String astartsite, String[] akeywordlist, String[] aipdomainlist, int asitelimit, int adepthlimit) {

searchTree = atree; // place to display search tree

messageArea = amessagearea; // place to display error messages statsLabel = astatlabel; // place to put run statistics startSite = fixHref(astartsite);

keywordList = new String[akeywordlist.length]; for(int i = 0; i< akeywordlist.length; i++)

keywordList[i] = akeywordlist[i].toUpperCase(); // use all upper case for matching

ipDomainList = new String[aipdomainlist.length]; for(int i = 0; i< aipdomainlist.length; i++)

ipDomainList[i] = aipdomainlist[i].toUpperCase(); // use all upper case for matching

siteLimit = asitelimit; // max number of sites to look at depthLimit = adepthlimit; // max depth of recursion to use DefaultMutableTreeNode UrlTreeNode(\

DefaultTreeModel treeModel = new DefaultTreeModel(root); // create a tree model with a root

searchTree.setModel(treeModel);

searchTree.setCellRenderer(new UrlNodeRenderer()); // use a custom cell renderer } /**

* start running the search in a new thread */

root

=

new

DefaultMutableTreeNode(new

19

public void run() {

DefaultTreeModel treeModel = (DefaultTreeModel)searchTree.getModel(); // get our model

DefaultMutableTreeNode root = (DefaultMutableTreeNode)treeModel.getRoot(); String urllc = startSite.toLowerCase();

if(!urllc.startsWith(\ !urllc.startsWith(\ {

startSite = \ // note you must have 3 slashes ! }

else // http missing ? if(urllc.startsWith(\ {

startSite = \ }

startSite = startSite.replace('\\\\', '/'); // fix bad slashes

sitesFound = 0; sitesSearched = 0; updateStats();

searchWeb(root,startSite); // search the web messageArea.append(\ } /**

* search the url search tree to see if we've already visited the specified url * @param urlstring url to search for * @return true if the url is already in the tree */

public boolean urlHasBeenVisited(String urlstring) {

String teststring = fixHref(urlstring);

DefaultTreeModel treeModel = (DefaultTreeModel)searchTree.getModel(); // get our

20


搜索引擎及搜索引擎优化(SEO)实验 - 图文(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:小学数学第12册第一单元测试题

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: