01: package net.sourceforge.cruisecontrol.dashboard.service;
02:
03: import net.sourceforge.cruisecontrol.dashboard.exception.ConfigurationException;
04: import org.apache.commons.lang.StringUtils;
05: import org.apache.log4j.Logger;
06: import org.springframework.web.context.ServletContextAware;
07:
08: import javax.servlet.ServletContext;
09:
10: public class ServletContextConfigService implements
11: ServletContextAware, DashboardConfigService {
12: private static final String WARNING_MESSAGE = "Configure dashboard via web.xml is deprecated. Use system properties or dashboard-config.xml instead.";
13:
14: private static final Logger LOGGER = Logger
15: .getLogger(ServletContextConfigService.class);
16:
17: public static final String CONTEXT_CC_CONFIG_FILE = "cruisecontrol.config.file";
18:
19: public static final String CONTEXT_CC_CONFIG_EDITABLE = "cruisecontrol.config.editable";
20:
21: public static final String CONTEXT_CC_CONFIG_FORCEBUILD_ENABLED = "cruisecontrol.config.forcebuild";
22:
23: public static final String CONTEXT_CC_CONFIG_LOG_DIR = "cruisecontrol.logdir";
24:
25: public static final String CONTEXT_CC_CONFIG_ARTIFACTS_DIR = "cruisecontrol.artifacts";
26:
27: public static final String CONTEXT_CC_CONFIG_PROJECTS_DIR = "cruisecontrol.projects";
28:
29: private ServletContext servletContext;
30:
31: public void setServletContext(ServletContext servletContext) {
32: this .servletContext = servletContext;
33: }
34:
35: public String getArtifactsDir() throws ConfigurationException {
36: return getValueAndwarnDeprecated(CONTEXT_CC_CONFIG_ARTIFACTS_DIR);
37: }
38:
39: public String getLogsDir() throws ConfigurationException {
40: return getValueAndwarnDeprecated(CONTEXT_CC_CONFIG_LOG_DIR);
41: }
42:
43: public String isForceBuildEnabled() {
44: return getValueAndwarnDeprecated(CONTEXT_CC_CONFIG_FORCEBUILD_ENABLED);
45: }
46:
47: private String getValueAndwarnDeprecated(final String parameter) {
48: String value = StringUtils.defaultString(servletContext
49: .getInitParameter(parameter));
50: if (!StringUtils.isEmpty(value)) {
51: LOGGER.warn(WARNING_MESSAGE);
52: }
53: return value;
54: }
55: }
|