1 | /* |
2 | * Copyright 2003,2004 The Apache Software Foundation. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | package org.apache.pluto.driver.services.container; |
17 | |
18 | import java.util.Enumeration; |
19 | import java.util.HashMap; |
20 | import java.util.Vector; |
21 | |
22 | import javax.portlet.PortalContext; |
23 | import javax.portlet.PortletMode; |
24 | import javax.portlet.WindowState; |
25 | |
26 | import org.apache.pluto.driver.config.DriverConfiguration; |
27 | |
28 | /** |
29 | * <code>PortalContext</code> implementation for the Pluto Portal Driver. |
30 | */ |
31 | public class PortalContextImpl implements PortalContext { |
32 | |
33 | /** |
34 | * The <code>DriverConfigurationImpl</code> from which this |
35 | * <code>PortalContext</code> recieves it's configuration information. |
36 | */ |
37 | private DriverConfiguration config; |
38 | |
39 | /** |
40 | * Portal information. |
41 | */ |
42 | private String info = null; |
43 | |
44 | /** |
45 | * Portal Properties |
46 | */ |
47 | private HashMap properties = new HashMap(); |
48 | |
49 | /** |
50 | * Supported PortletModes. |
51 | */ |
52 | private Vector portletModes; |
53 | |
54 | /** |
55 | * Supported WindowStates. |
56 | */ |
57 | private Vector windowStates; |
58 | |
59 | |
60 | /** |
61 | * Default Constructor. |
62 | * @param config |
63 | */ |
64 | public PortalContextImpl(DriverConfiguration config) { |
65 | this.config = config; |
66 | reset(); |
67 | } |
68 | |
69 | /** |
70 | * Get a dynamic portal property. |
71 | * @param name |
72 | * @return the property value associated with the given key. |
73 | * @throws IllegalArgumentException if the specified name is null. |
74 | */ |
75 | public String getProperty(String name) { |
76 | if (name == null) { |
77 | throw new IllegalArgumentException("Property name == null"); |
78 | } |
79 | |
80 | return (String) properties.get(name); |
81 | } |
82 | |
83 | |
84 | /** |
85 | * Get an enumeration containing all names of the portal properties. |
86 | * @return an enumeration of all keys to which properties are bound. |
87 | */ |
88 | public Enumeration getPropertyNames() { |
89 | Vector names = new Vector(properties.keySet()); |
90 | return names.elements(); |
91 | } |
92 | |
93 | |
94 | /** |
95 | * Get an enumeration of all <code>PortletMode</code>s supported by this |
96 | * portal. |
97 | * @return enumeration of all supported portlet modes. |
98 | */ |
99 | public Enumeration getSupportedPortletModes() { |
100 | if (portletModes == null) { |
101 | portletModes = new Vector(); |
102 | Enumeration enumeration = new Vector(config.getSupportedPortletModes()).elements(); |
103 | while (enumeration.hasMoreElements()) { |
104 | portletModes.add( |
105 | new PortletMode(enumeration.nextElement().toString())); |
106 | } |
107 | } |
108 | return portletModes.elements(); |
109 | } |
110 | |
111 | /** |
112 | * Get an enumeration of all <code>WindowState</code>s supported by this |
113 | * portal. |
114 | * @return an enumeration of all supported window states. |
115 | */ |
116 | public Enumeration getSupportedWindowStates() { |
117 | if (windowStates == null) { |
118 | windowStates = new Vector(); |
119 | Enumeration enumeration = new Vector(config.getSupportedWindowStates()).elements(); |
120 | while (enumeration.hasMoreElements()) { |
121 | windowStates.add( |
122 | new WindowState(enumeration.nextElement().toString())); |
123 | } |
124 | } |
125 | return windowStates.elements(); |
126 | } |
127 | |
128 | /** |
129 | * Get the portal info for this portal. |
130 | * @return the portal information for this context. |
131 | */ |
132 | public String getPortalInfo() { |
133 | return info; |
134 | } |
135 | |
136 | |
137 | // additional methods. |
138 | // methods used container internally to set |
139 | |
140 | public void setProperty(String name, String value) { |
141 | if (name == null) { |
142 | throw new IllegalArgumentException("Property name == null"); |
143 | } |
144 | |
145 | properties.put(name, value); |
146 | } |
147 | |
148 | |
149 | /** |
150 | * reset all values to default portlet modes and window states; delete all |
151 | * properties and set the given portlet information as portlet info string. |
152 | */ |
153 | public void reset() { |
154 | info = config.getPortalName() + "/" + config.getPortalVersion(); |
155 | properties.clear(); |
156 | } |
157 | |
158 | public DriverConfiguration getDriverConfiguration() { |
159 | return config; |
160 | } |
161 | |
162 | } |