001: package net.javacoding.jspider.core.util.config.properties;
002:
003: import net.javacoding.jspider.api.model.Site;
004: import net.javacoding.jspider.core.util.config.*;
005:
006: import java.io.File;
007:
008: /**
009: * $Id: PropertiesConfiguration.java,v 1.14 2003/04/10 16:19:16 vanrogu Exp $
010: */
011: public class PropertiesConfiguration implements JSpiderConfiguration {
012:
013: protected String configuration;
014: protected String jspiderHome;
015: protected PropertySet jspiderProperties;
016: protected PropertySet pluginsProperties;
017: protected PropertySet websitesConfig;
018: protected File defaultOutputFolder;
019:
020: public PropertiesConfiguration() {
021: this (ConfigurationFactory.CONFIG_DEFAULT);
022: }
023:
024: public PropertiesConfiguration(String configuration) {
025:
026: jspiderHome = System.getProperty("jspider.home");
027: if (jspiderHome == null || "".equals(jspiderHome.trim())
028: || "null".equals(jspiderHome.trim())) {
029: jspiderHome = ".";
030: }
031: defaultOutputFolder = new File(jspiderHome + File.separator
032: + "output");
033: System.err.println("[Engine] jspider.home=" + jspiderHome);
034: System.err.println("[Engine] default output folder="
035: + defaultOutputFolder);
036: System.err.println("[Engine] starting with configuration '"
037: + configuration + "'");
038:
039: this .configuration = configuration;
040:
041: jspiderProperties = PropertiesFilePropertySet.getInstance(
042: jspiderHome, configuration, "jspider.properties");
043: pluginsProperties = PropertiesFilePropertySet.getInstance(
044: jspiderHome, configuration, "plugin.properties");
045: websitesConfig = PropertiesFilePropertySet.getInstance(
046: jspiderHome, configuration, "sites.properties");
047: }
048:
049: public File getDefaultOutputFolder() {
050: return defaultOutputFolder;
051: }
052:
053: public PropertySet getJSpiderConfiguration() {
054: return jspiderProperties;
055: }
056:
057: public PropertySet getPluginsConfiguration() {
058: return pluginsProperties;
059: }
060:
061: public PropertySet getPluginConfiguration(String pluginName) {
062: return PropertiesFilePropertySet.getInstance(jspiderHome,
063: configuration, "plugins" + File.separator + pluginName
064: + ".properties");
065: }
066:
067: public File getPluginConfigurationFolder(String pluginName) {
068: File jspiderHomeFile = new File(jspiderHome);
069: File configFolder = new File(jspiderHomeFile, "conf");
070: File config = new File(configFolder, configuration);
071: File plugins = new File(config, "plugins");
072: return new File(plugins, pluginName);
073: }
074:
075: public PropertySet getSiteConfiguration(Site site) {
076: if (site.isBaseSite()) {
077: return ConfigurationFactory.getConfiguration()
078: .getBaseSiteConfiguration();
079: } else {
080: return getSiteConfiguration(site.getHost(), site.getPort());
081: }
082: }
083:
084: public PropertySet getSiteConfiguration(String host, int port) {
085: String matchString = host + ":" + port;
086: String configName = null;
087: if (port > 0) {
088: configName = websitesConfig.getString(matchString, null);
089: }
090: if (configName == null) {
091: matchString = host;
092: configName = websitesConfig.getString(matchString,
093: websitesConfig.getString(
094: ConfigConstants.SITES_DEFAULT_SITE,
095: "default"));
096: }
097: return PropertiesFilePropertySet.getInstance(jspiderHome,
098: configuration, "sites" + File.separator + configName
099: + ".properties");
100: }
101:
102: public PropertySet getDefaultSiteConfiguration() {
103: return PropertiesFilePropertySet.getInstance(jspiderHome,
104: configuration, "sites"
105: + File.separator
106: + websitesConfig.getString(
107: ConfigConstants.SITES_DEFAULT_SITE,
108: "default") + ".properties");
109: }
110:
111: public PropertySet getBaseSiteConfiguration() {
112: return PropertiesFilePropertySet.getInstance(jspiderHome,
113: configuration, "sites"
114: + File.separator
115: + websitesConfig.getString(
116: ConfigConstants.SITES_BASE_SITE,
117: "default") + ".properties");
118: }
119:
120: }
|