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