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

📄 initsystemimpl.java

📁 java写的搜索引擎网络爬虫 java写的搜索引擎网络爬虫 java写的搜索引擎网络爬虫
💻 JAVA
字号:
/* 
 * FileName InitSystem.java
 * Create Time 2005-7-29 17:27:23
 * Author shiwei
 * Descript 初始化系统设置
 * Version 
 */
package com.snoics.reptile.system.init;

import java.util.ArrayList;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.snoics.base.interfaces.log.Log;
import com.snoics.base.pool.ObjectManager;
import com.snoics.base.util.StringClass;
import com.snoics.reptile.cache.Cache;
import com.snoics.reptile.regex.url.IUrlRegexMap;
import com.snoics.reptile.system.common.Common;
import com.snoics.reptile.system.common.CommonObject;
import com.snoics.reptile.system.conf.ConfigInfo;
import com.snoics.reptile.system.conf.ConfigParameterImpl;
import com.snoics.reptile.system.exception.ReptileSystemException;
import com.snoics.system.interfaces.InitSystem;
import com.snoics.useclass.SnoicsClass;
public class InitSystemImpl implements InitSystem{
	private static ConfigParameterImpl configParameter=new ConfigParameterImpl();
	private static CommonObject commonObject=new CommonObject();
	private static ObjectManager objectManager=ObjectManager.getInstance() ;
	private static Log log=null;
	
	public InitSystemImpl(){
		
	}
	
	/**
	 * 初始化系统
	 *
	 */
	public synchronized void initialize(){
		SnoicsClass snoicsClass=new SnoicsClass();
		log=snoicsClass.getLog();
		log.getLogger("com.snoics.reptile.initializing");
		objectManager.createPool(Common.REPTILE_OBJECTPOOL_NAME);
		
		log.info("------------------------reptile 系统初始化-------------------");
		
		if(checkConfig()){
			
			if(objectManager.getObject(Common.REPTILE_OBJECTPOOL_NAME,Common.COMMON_OBJECT_CONFIGINFO)==null){
				initAllConfigInfo();
				initSpringConfig();
			}
			
			if(objectManager.getObject(Common.REPTILE_OBJECTPOOL_NAME,Common.COMMON_OBJECT_CACHE)==null){
				initCache();
			}
			
			if(objectManager.getObject(Common.REPTILE_OBJECTPOOL_NAME,Common.COMMON_OBJECT_TEMPCACHE)==null){
				initTempCache();
			}
			
			if(objectManager.getObject(Common.REPTILE_OBJECTPOOL_NAME,Common.COMMON_OBJECT_UNRELINKTYPE)==null){
				initRelinkremotefiletype();
			}
			
			if(objectManager.getObject(Common.REPTILE_OBJECTPOOL_NAME,Common.COMMON_OBJECT_DOWNLOADFILETYPE)==null){
				initDownloadfiletype();
			}
			
			log.info("----------------------reptile 系统初始化完成------------------");
		}
	}
	
    /**
     * 初始化延迟加载的项
     *
     */
    public void initLazy(String objectName){
    	
    }
    
	/**
	 * 检查系统配置
	 * @return
	 */
	private boolean checkConfig(){
        if(((configParameter.getParameterValue(Common.CONFIGFILE_NODE_WEBSITENAME)).equals(""))||((configParameter.getParameterValue(Common.CONFIGFILE_NODE_WEBSITE)).equals(""))){
        	log.info("reptile 系统初始化失败");
        	log.info("1.系统配置文件中 '"+Common.CONFIGFILE_NODE_WEBSITENAME+"' 为必填项");
        	log.info("2.系统配置文件中 '"+Common.CONFIGFILE_NODE_WEBSITE+"' 为必填项");
        	return false;
        }
        return true;
	}
	
	/**
	 * 初始化Spring配制
	 *
	 */
	private void initSpringConfig(){
		String springConfigFile="";
		SnoicsClass snoicsClass=new SnoicsClass();
		springConfigFile=snoicsClass.getConfigFileName(Common.REPTILE_SPRING_CONFIG_FILE);
		ApplicationContext applicationContext=new FileSystemXmlApplicationContext(springConfigFile);
		IUrlRegexMap urlRegexMap=(IUrlRegexMap)applicationContext.getBean("urlRegexMap");
		ConfigInfo configInfo=commonObject.getConfigInfoObject();
		configInfo.setUrlRegexMap(urlRegexMap);
        commonObject.setConfigInfoObject(configInfo);
	}
	
	/**
	 * 初始化系统配置
	 *
	 */
	private void initAllConfigInfo(){
		log.info("初始化系统配置..........");
        ConfigInfo configInfo=new ConfigInfo();
        try{
            commonObject.setConfigInfoObject(configInfo);
    		commonObject.setConfigInfo(Common.CONFIGFILE_NODE_WEBSITENAME,configParameter.getParameterValue(Common.CONFIGFILE_NODE_WEBSITENAME));
    		commonObject.setConfigInfo(Common.CONFIGFILE_NODE_WEBSITE,configParameter.getParameterValue(Common.CONFIGFILE_NODE_WEBSITE));
    		commonObject.setConfigInfo(Common.CONFIGFILE_NODE_STARTPAGE,configParameter.getParameterValue(Common.CONFIGFILE_NODE_STARTPAGE));
    		commonObject.setConfigInfo(Common.CONFIGFILE_NODE_URL,configParameter.getParameterValue(Common.CONFIGFILE_NODE_URL));
    		commonObject.setConfigInfo(Common.CONFIGFILE_NODE_REMOTEURLFLAG,configParameter.getParameterValue(Common.CONFIGFILE_NODE_REMOTEURLFLAG));
    		commonObject.setConfigInfo(Common.CONFIGFILE_FORBIDURL,configParameter.getParameterValue(Common.CONFIGFILE_FORBIDURL));
    		commonObject.setConfigInfo(Common.CONFIGFILE_NODE_CACHEFILE,configParameter.getParameterValue(Common.CONFIGFILE_NODE_CACHEFILE));
    		commonObject.setConfigInfo(Common.CONFIGFILE_NODE_FILEROOTPATH,configParameter.getParameterValue(Common.CONFIGFILE_NODE_FILEROOTPATH));
    		commonObject.setConfigInfo(Common.CONFIGFILE_NODE_INDEXPAGE,configParameter.getParameterValue(Common.CONFIGFILE_NODE_INDEXPAGE));
    		commonObject.setConfigInfo(Common.CONFIGFILE_NODE_FILENAMELENGTH,configParameter.getParameterValue(Common.CONFIGFILE_NODE_FILENAMELENGTH));
    		commonObject.setConfigInfo(Common.CONFIGFILE_NODE_CACHEUNITSIZE,configParameter.getParameterValue(Common.CONFIGFILE_NODE_CACHEUNITSIZE));	
    		commonObject.setConfigInfo(Common.CONFIGFILE_NODE_CHARSETNAME,configParameter.getParameterValue(Common.CONFIGFILE_NODE_CHARSETNAME));	
        }catch(Exception e){
        	throw new ReptileSystemException(e);
        }

	}
	
	/**
	 * 初始化站点缓存
	 *
	 */
	private void initCache(){
		log.info("初始化站点缓存..........");
		Cache cache=new Cache();
		cache.read();
		ArrayList reptilecache=cache.getCache();
		try{
			commonObject.setReptileCache(reptilecache);
		}catch(Exception e){
			throw new ReptileSystemException(e);
		}
	}
	
	/**
	 * 初始化临时缓存
	 *
	 */
	private void initTempCache(){
		log.info("初始化临时缓存.........");
		Cache cache=new Cache();
		cache.read();
		ArrayList reptilecache=cache.getCache();
		try{
			commonObject.setReptileTempCache(reptilecache);
		}catch(Exception e){
			throw new ReptileSystemException(e);
		}
	}
	
	/**
	 * 初始化文件类型
	 *
	 */
	private void initRelinkremotefiletype(){
		log.info("初始化文件类型..........");
		ConfigParameterImpl configParameterImpl=new ConfigParameterImpl();
		ArrayList arraylist=new ArrayList();
		try{
			arraylist=StringClass.getInterString(Common.STRING_SEPARATE_FLAG,configParameterImpl.getParameterValue(Common.DEFAULT_UNDOWNLOADFILETYPE).toUpperCase());
			commonObject.setRelinkremotefiletype(arraylist);
		}catch(Exception e){
			throw new ReptileSystemException(e);
		}
	}
	
	/**
	 * 初始化需要下载到本地的文件类型
	 *
	 */
	private void initDownloadfiletype(){
		log.info("初始化需要下载到本地的文件类型..........");
		ConfigParameterImpl configParameterImpl=new ConfigParameterImpl();
		ArrayList arraylist=new ArrayList();
		try{
			arraylist=StringClass.getInterString(Common.STRING_SEPARATE_FLAG,configParameterImpl.getParameterValue(Common.DEFAULT_DOWNLOADFILETYPE).toUpperCase());
			commonObject.setDownloadfiletype(arraylist);
		}catch(Exception e){
			throw new ReptileSystemException(e);
		}
	}
}

⌨️ 快捷键说明

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