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

📄 compositecommand.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.ArrayList;
import java.util.List;

import org.indigo.log.FileLoggerParam;
import org.indigo.spider.Spider;
import org.indigo.spider.ThreadPool;
import org.indigo.util.*;

/**
 * 复合模板对象,此对象可包含RawCommand对象。
 * @author wbz
 *
 */
public class CompositeCommand extends Command
{
    private List itsCmds = new ArrayList();
    /**
     * 复合模板类构造函数。
     * @param file 任务对应的文件路径。
     * @param bTableView  是否再主界面中显示。
     * @param bXmlView    是否再xml中存储。
     */
    public CompositeCommand(String file, boolean bTableView, boolean bXmlView )
    {
        super(file);
        File theFile=null;
        String taskName=null,str=null;
        TaskProperties props = new TaskProperties();
        props.open( itsPropertyFile );//读取和任务对应的文件
        int taskCount,i;
        taskCount = Integer.parseInt( props.getProperty( "TaskCount" ) );//获取所包含的子任务数
        for( i=0; i<taskCount; i++ )//依次访问每个子任务。
        {
            taskName = props.getProperty( "Task"+(i+1) );
            theFile = new File( taskName );
            if( !theFile.exists() )
            {
                str = "TaskFile: " + taskName + " doesnot exists!";
                FileLoggerParam.getInstance().warning( str );
                continue ;
            }
            TaskProperties props2 = new TaskProperties();
            try
            {
                props2.open( taskName );
            }catch( Exception e )
            {
                System.out.println( "TaskFile error: " + file );
                System.out.println( "Task"+(i+1)+"="+taskName );
                
                FileLoggerParam.getInstance().warning( "TaskFile error: " + file );
                FileLoggerParam.getInstance().warning( "Task"+(i+1)+"="+taskName );
            }
            boolean bComp;
            String str2 = props2.getProperty( "Nested" );
            if( str2==null || str2.equals("") )
                bComp = false;
            else
                bComp = str2.equalsIgnoreCase("true");
            
            if( !bComp )//如果此子任务是单任务,则封装为RawCommand,否则封装为复合模板。
            {
                itsCmds.add( new RawCommand( taskName, bTableView, bXmlView ) );
            }else
            {
                itsCmds.add( new CompositeCommand( taskName, bTableView, bXmlView ) );
            }
        }        
    }

    /**
     * 针对复合模板,主要执行函数。
     * 思想是:首先把存放在复合模板对象中的每个子模板取出,然后执行。
     */
    public void execute()
    {
        while( !itsCmds.isEmpty() )
        {
            Command cmd = (Command) itsCmds.get(0);
            itsCmds.remove( 0 );
            String str = MainConfig.getInstance().getProperty( "SerialExecute");
            if( str==null || str.equals("false") )
                ThreadPool.getInstance().execute( new Spider(cmd) );
            else
                cmd.execute();
        }
    }

}

⌨️ 快捷键说明

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