01: /*
02: * Created on Mar 31, 2003
03: */
04: package net.sf.jportlet.impl;
05:
06: import java.util.ArrayList;
07: import java.util.Collections;
08: import java.util.Enumeration;
09: import java.util.Properties;
10:
11: import javax.servlet.ServletConfig;
12:
13: import net.sf.jportlet.portlet.application.PortletApplication;
14: import net.sf.jportlet.service.PortletServiceConfig;
15: import net.sf.jportlet.service.PortletServiceContext;
16:
17: /**
18: * Implementation of {@link PortletServiceConfig}
19: *
20: * @author <a href="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
21: */
22: public class PortletServiceConfigImpl implements PortletServiceConfig {
23: //~ Instance fields --------------------------------------------------------
24:
25: private PortletApplication _application;
26: private String _prefix;
27: private Properties _serviceConfig;
28: private PortletServiceContext _serviceContext;
29: private ServletConfig _servletConfig;
30:
31: //~ Constructors -----------------------------------------------------------
32:
33: public PortletServiceConfigImpl(String prefix,
34: Properties serviceConfig, ServletConfig servletConfig,
35: PortletApplication application) {
36: _prefix = prefix;
37: _serviceConfig = serviceConfig;
38: _servletConfig = servletConfig;
39: _application = application;
40: _serviceContext = new PortletServiceContextImpl(application);
41: }
42:
43: //~ Methods ----------------------------------------------------------------
44:
45: /**
46: * @see net.sf.jportlet.service.PortletServiceConfig#getInitParameter(java.lang.String)
47: */
48: public String getInitParameter(String name) {
49: return _serviceConfig.getProperty(_prefix + "." + name);
50: }
51:
52: /**
53: * @see net.sf.jportlet.service.PortletServiceConfig#getInitParameterNames()
54: */
55: public Enumeration getInitParameterNames() {
56: Enumeration all = _serviceConfig.keys();
57: ArrayList names = new ArrayList();
58: String prefix = _prefix + ".";
59:
60: while (all.hasMoreElements()) {
61: String name = all.nextElement().toString();
62: if (name.startsWith(prefix)) {
63: names.add(name.substring(prefix.length()));
64: }
65: }
66:
67: return Collections.enumeration(names);
68: }
69:
70: /**
71: * @see net.sf.jportlet.service.PortletServiceConfig#getServiceContext()
72: */
73: public PortletServiceContext getServiceContext() {
74: return _serviceContext;
75: }
76:
77: /**
78: * @see net.sf.jportlet.service.PortletServiceConfig#getServletConfig()
79: */
80: public ServletConfig getServletConfig() {
81: return _servletConfig;
82: }
83: }
|