?? rawcommand.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 + -