PropertiesConfiguration.java
上传用户:qing5858
上传日期:2015-10-27
资源大小:6056k
文件大小:4k
源码类别:

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.core.util.config.properties;
  2. import net.javacoding.jspider.api.model.Site;
  3. import net.javacoding.jspider.core.util.config.*;
  4. import java.io.File;
  5. /**
  6.  * $Id: PropertiesConfiguration.java,v 1.14 2003/04/10 16:19:16 vanrogu Exp $
  7.  */
  8. public class PropertiesConfiguration implements JSpiderConfiguration {
  9.     protected String configuration;
  10.     protected String jspiderHome;
  11.     protected PropertySet jspiderProperties;
  12.     protected PropertySet pluginsProperties;
  13.     protected PropertySet websitesConfig;
  14.     protected File defaultOutputFolder;
  15.     public PropertiesConfiguration ( ) {
  16.         this ( ConfigurationFactory.CONFIG_DEFAULT );
  17.     }
  18.     public PropertiesConfiguration ( String configuration ) {
  19.         jspiderHome = System.getProperty("jspider.home");
  20.         if ( jspiderHome == null || "".equals(jspiderHome.trim()) || "null".equals(jspiderHome.trim())) {
  21.           jspiderHome = ".";
  22.         }
  23.         defaultOutputFolder = new File ( jspiderHome + File.separator + "output" );
  24.         System.err.println("[Engine] jspider.home=" + jspiderHome );
  25.         System.err.println("[Engine] default output folder=" + defaultOutputFolder );
  26.         System.err.println("[Engine] starting with configuration '" + configuration + "'");
  27.         this.configuration = configuration;
  28.         jspiderProperties = PropertiesFilePropertySet.getInstance ( jspiderHome, configuration, "jspider.properties" );
  29.         pluginsProperties = PropertiesFilePropertySet.getInstance ( jspiderHome, configuration, "plugin.properties" );
  30.         websitesConfig = PropertiesFilePropertySet.getInstance(jspiderHome, configuration, "sites.properties" );
  31.     }
  32.     public File getDefaultOutputFolder() {
  33.         return defaultOutputFolder;
  34.     }
  35.     public PropertySet getJSpiderConfiguration() {
  36.         return jspiderProperties;
  37.     }
  38.     public PropertySet getPluginsConfiguration() {
  39.         return pluginsProperties;
  40.     }
  41.     public PropertySet getPluginConfiguration(String pluginName) {
  42.         return PropertiesFilePropertySet.getInstance(jspiderHome, configuration, "plugins" + File.separator + pluginName + ".properties");
  43.     }
  44.     public File getPluginConfigurationFolder(String pluginName) {
  45.         File jspiderHomeFile = new File (jspiderHome);
  46.         File configFolder  = new File ( jspiderHomeFile,  "conf" );
  47.         File config = new File ( configFolder, configuration );
  48.         File plugins = new File ( config, "plugins" );
  49.         return new File ( plugins, pluginName );
  50.     }
  51.     public PropertySet getSiteConfiguration(Site site) {
  52.         if ( site.isBaseSite() ) {
  53.           return ConfigurationFactory.getConfiguration().getBaseSiteConfiguration();
  54.         } else {
  55.           return getSiteConfiguration(site.getHost(), site.getPort());
  56.         }
  57.     }
  58.     public PropertySet getSiteConfiguration(String host, int port) {
  59.         String matchString = host + ":" + port;
  60.         String configName = null;
  61.         if ( port > 0 ) {
  62.             configName = websitesConfig.getString(matchString, null);
  63.         }
  64.         if ( configName == null ) {
  65.             matchString = host;
  66.             configName = websitesConfig.getString(matchString, websitesConfig.getString(ConfigConstants.SITES_DEFAULT_SITE, "default") );
  67.         }
  68.         return PropertiesFilePropertySet.getInstance(jspiderHome, configuration, "sites" + File.separator + configName + ".properties" );
  69.     }
  70.     public PropertySet getDefaultSiteConfiguration() {
  71.         return PropertiesFilePropertySet.getInstance(jspiderHome, configuration, "sites" + File.separator + websitesConfig.getString(ConfigConstants.SITES_DEFAULT_SITE, "default" ) + ".properties" );
  72.     }
  73.     public PropertySet getBaseSiteConfiguration() {
  74.         return PropertiesFilePropertySet.getInstance(jspiderHome, configuration, "sites" + File.separator + websitesConfig.getString(ConfigConstants.SITES_BASE_SITE, "default" ) + ".properties" );
  75.     }
  76. }