⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rawcommand.java

📁 用来为垂直搜索引擎抓取数据的采集系统
💻 JAVA
字号:
/*
 * *****************************************************
 * Copyright (c) 2005 IIM Lab. All  Rights Reserved.
 * Created by xuehao at 2005-10-12
 * Contact: zxuehao@mail.ustc.edu.cn
 * *****************************************************
 */
package org.indigo.commands;

import java.io.File;
import java.util.List;

import org.indigo.db.DBManager;
import org.indigo.db.Drop2DBGate;
import org.indigo.gui.Model;
import org.indigo.gui.TableView;
import org.indigo.log.FileLoggerParam;
import org.indigo.util.MainConfig;
import org.indigo.util.XmlFileUtil;
import org.indigo.xml.XmlView;

/**
 * 单任务模板对象
 * @author wbz
 *
 */
public class RawCommand extends Command
{
    private String itsXmlFile;
    /**
     * 单模板类构造函数。
     * @param file 任务对应的文件路径。
     * @param bTableView  是否再主界面中显示。
     * @param bXmlView    是否再xml中存储。
     */
    public RawCommand(String file, boolean bTableView, boolean bXmlView )
    {
        super(file);
        itsModel = new Model( itsPropertyFile );
        String str=null;
        str = "creating RawCommand "+file;
//        System.out.println( str );
        FileLoggerParam.getInstance().info( str );
        
        if( bTableView )
        {
	        if( itsView==null )
	            itsView = new TableView( file );
	        itsModel.addObserver( itsView );
        }
        if( bXmlView )
        {
//            System.out.println( "gui with xml........." );
            /*
            System.out.println( itsPropertyFile );
            
	        int i,j;
	        i = itsPropertyFile.lastIndexOf( "/" );
	        j = itsPropertyFile.lastIndexOf( "." );
	        itsXmlFile = "./data/" + itsPropertyFile.substring( i+1, j ) + ".xml";
	        */
            List dirs = XmlFileUtil.getPath( itsPropertyFile );
            str = "";
            for( int i=0; i<dirs.size(); i++ )
            {
                str = str + (String) dirs.get(i) + "/";
            }
            str = str.substring( 0, str.length()-1 );
            itsXmlFile = str;
            
            int k = 1;
            File theFile = new File( itsXmlFile );
            while( theFile.exists() )
            {
                str = itsXmlFile;
                int i = str.lastIndexOf( ".xml" );
                str = str.substring( 0, i );

                i = str.lastIndexOf( "(" );
                if( i==-1 )
                {
                }else
                {
                    str = str.substring( 0, i );
                }
                str += "(" + k + ").xml"; 

                k++;
                theFile = new File( str );
                itsXmlFile = str;
//                System.out.println( str );
            }

            System.out.println( itsXmlFile );
            
	        itsXmlView = new XmlView( itsPropertyFile, itsXmlFile );//构造一个xml显示对象。
	        itsModel.addObserver( (XmlView)itsXmlView );
	        
//	        System.out.println( "xmlfile=" + itsXmlFile );
	        
        }
    }
    public String getXmlFile()
    {
        return itsXmlFile;
    }
    /**
     * 单任务模式主要部分,此部分负责采集规则的执行。然后把采集结果存入xml和数据库。
     */
    public void execute()
    {
        itsModel.doStrategy();//采集,并把采集结果存到xml中。
        if( itsXmlView!=null )
        {
            itsXmlView.close();//xml文件如果没有关闭,则关闭。
//            System.out.println( "xml close!" );
        }
        String str;
        boolean  bDrop2DB=false;
        str = MainConfig.getInstance().getProperty( "Drop2DB" );//获取是否把采集的数据存入数据库参数。
        if( str==null || str.equals("") || str.equalsIgnoreCase("false") )
            bDrop2DB = false;
        else
            bDrop2DB = true;

        if( itsXmlView==null )
            bDrop2DB = false;
        
        if( bDrop2DB )//需要存入数据库
        {
            Drop2DBGate dropGate = DBManager.getInstance().getImpl();
        	dropGate.drop2DB( itsXmlView.getFileName() );//把数据从xml文件中读入,存入数据库中。
        }
    }

}

⌨️ 快捷键说明

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