bbstester.java

来自「用java实现的一个bbs的portal」· Java 代码 · 共 96 行

JAVA
96
字号
package BBSSpider;

import Classification.ArticleBatch;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.File;
import java.util.Properties;
import java.util.Vector;
import java.util.Hashtable;

/**
 * Created by IntelliJ IDEA.
 * User: ADMINISTRATOR
 * Date: 2003-7-22
 * Time: 17:17:08
 * To change this template use Options | File Templates.
 */
public class BBSTester {
    Vector bbsString = new Vector();
    Hashtable queryUserURL = new Hashtable();
    Hashtable queryUserMask = new Hashtable();
    private static BBSTester instance = null;

    public static BBSTester getInstance(){
        if (instance == null)
            instance = new BBSTester();
        return instance;
    }

    public BBSTester(){
        String BbsList[] =  getNewArticleList();
        for (int i=0;i<BbsList.length;i++){
            String bbsName = BbsList[i];
            BBSProper(bbsName);
        }
    }

    private static String[] getNewArticleList(){
        File MyDir = new File(ArticleBatch.PropertiesPath);
        return MyDir.list();
    }

    private void BBSProper(String theBBSString){
        bbsString.add(theBBSString);
        String propertiesFileName=ArticleBatch.PropertiesPath+theBBSString;
        FileInputStream is = null;
        try {
            is = new FileInputStream(propertiesFileName);
        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use Options | File Templates.
        }

        Properties catchProps = new Properties();
        try {
            catchProps.load(is);
        }
        catch (Exception e) {
            System.err.println(e.toString());
            return;
        }
        String queryURL = catchProps.getProperty("QueryUserURL");
        if (queryURL != null)
            queryUserURL.put(theBBSString,queryURL);
        else  queryUserURL.put(theBBSString,"NULL");
        String queryMask = catchProps.getProperty("QueryUserMask");
        if (queryMask != null)
            queryUserMask.put(theBBSString,BotTool.getChineseStr(queryMask));
        else  queryUserMask.put(theBBSString,"NULL");
    }

    public boolean isOnLine(String bbsname,String userName){
        System.out.println("BBSTester : "+bbsname+" "+userName);
        String listPage = "";
        try {
            listPage = BotTool.doGet(queryUserURL.get(bbsname+".properties")+userName);
        } catch (IOException e) {
            //To change body of catch statement use Options | File Templates.
            System.out.println("exception: " + e.toString());
            return false;
        }
        try {
            int index=listPage.indexOf((String)queryUserMask.get(bbsname+".properties"));
            return index!=-1;
        } catch (Exception e) {
            System.out.println("Exception is happend during query user:"+e.toString());
            return false;
        }
    }

    public static void main(String[] argv){
        boolean onLine=BBSTester.getInstance().isOnLine("bbs.tsinghua.edu.cn","coco");
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?