01: /**
02: * @author <a href="mailto:kisg@mailbox.hu">Gergely Kis</a>
03: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
04: * @version $Id: PortalConfigServiceImpl.java 6407 2008-01-16 15:20:21Z wehrens $
05: */package org.gridsphere.services.core.portal.impl;
06:
07: import org.apache.commons.logging.Log;
08: import org.apache.commons.logging.LogFactory;
09: import org.gridsphere.layout.PortletPageFactory;
10: import org.gridsphere.portlet.service.PortletServiceUnavailableException;
11: import org.gridsphere.portlet.service.spi.PortletServiceConfig;
12: import org.gridsphere.portlet.service.spi.PortletServiceFactory;
13: import org.gridsphere.portlet.service.spi.PortletServiceProvider;
14: import org.gridsphere.services.core.customization.SettingsService;
15: import org.gridsphere.services.core.portal.PortalConfigService;
16:
17: import javax.servlet.ServletContext;
18: import java.io.*;
19: import java.util.Properties;
20:
21: /**
22: * Portal configuration service is used to manage portal administrative settings
23: */
24: public class PortalConfigServiceImpl implements PortletServiceProvider,
25: PortalConfigService {
26:
27: private Log log = LogFactory.getLog(PortalConfigServiceImpl.class);
28:
29: protected Properties props = new Properties();
30: protected ServletContext ctx = null;
31: private SettingsService settingsService = null;
32:
33: public void init(PortletServiceConfig config)
34: throws PortletServiceUnavailableException {
35: ctx = config.getServletContext();
36: settingsService = (SettingsService) PortletServiceFactory
37: .createPortletService(SettingsService.class, true);
38: try {
39: File propFile = new File(
40: settingsService
41: .getRealSettingsPath("portal/gridsphere.properties"));
42: props.load(new FileInputStream(propFile));
43:
44: // init config params here, just make sure we do have a theme set
45: String theme = getProperty(PortalConfigService.DEFAULT_THEME);
46: if (theme == null)
47: setProperty(PortalConfigService.DEFAULT_THEME,
48: PortletPageFactory.DEFAULT_THEME);
49: props.store(new FileOutputStream(propFile),
50: "GridSphere Portal Properties");
51: } catch (FileNotFoundException e) {
52: log.error("Unable to find gridsphere.properties", e);
53: } catch (IOException e) {
54: log.error("Unable to load gridsphere.properties", e);
55: }
56: }
57:
58: public void destroy() {
59:
60: }
61:
62: public String getProperty(String key) {
63: if (key == null)
64: throw new IllegalArgumentException(
65: "property key cannot be null!");
66: return props.getProperty(key);
67: }
68:
69: public void setProperty(String key, String value) {
70: if (key == null)
71: throw new IllegalArgumentException(
72: "property key cannot be null!");
73: if (value == null)
74: throw new IllegalArgumentException(
75: "property value cannot be null!");
76: props.setProperty(key, value);
77: }
78:
79: public void storeProperties() throws IOException {
80: FileOutputStream propertiesOutputStream = new FileOutputStream(
81: settingsService
82: .getRealSettingsPath("portal/gridsphere.properties"));
83: props.store(propertiesOutputStream,
84: "GridSphere Portal Properties");
85: }
86:
87: }
|