KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > javacoding > jspider > core > util > config > properties > PropertiesConfiguration


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 JavaDoc;
7
8 /**
9  * $Id: PropertiesConfiguration.java,v 1.14 2003/04/10 16:19:16 vanrogu Exp $
10  */

11 public class PropertiesConfiguration implements JSpiderConfiguration {
12
13     protected String JavaDoc configuration;
14     protected String JavaDoc jspiderHome;
15     protected PropertySet jspiderProperties;
16     protected PropertySet pluginsProperties;
17     protected PropertySet websitesConfig;
18     protected File JavaDoc defaultOutputFolder;
19
20     public PropertiesConfiguration ( ) {
21         this ( ConfigurationFactory.CONFIG_DEFAULT );
22     }
23
24     public PropertiesConfiguration ( String JavaDoc 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 JavaDoc ( 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 JavaDoc 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 JavaDoc pluginName) {
55         return PropertiesFilePropertySet.getInstance(jspiderHome, configuration, "plugins" + File.separator + pluginName + ".properties");
56     }
57
58     public File JavaDoc getPluginConfigurationFolder(String JavaDoc pluginName) {
59         File JavaDoc jspiderHomeFile = new File JavaDoc (jspiderHome);
60         File JavaDoc configFolder = new File JavaDoc ( jspiderHomeFile, "conf" );
61         File JavaDoc config = new File JavaDoc ( configFolder, configuration );
62         File JavaDoc plugins = new File JavaDoc ( config, "plugins" );
63         return new File JavaDoc ( 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 JavaDoc host, int port) {
75         String JavaDoc matchString = host + ":" + port;
76         String JavaDoc 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