%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.engine.core.PortalContextProviderImpl |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | package org.apache.jetspeed.engine.core; |
|
18 | ||
19 | import java.util.ArrayList; |
|
20 | import java.util.Collection; |
|
21 | import java.util.Enumeration; |
|
22 | import java.util.Iterator; |
|
23 | import java.util.Vector; |
|
24 | ||
25 | import org.apache.jetspeed.PortalContext; |
|
26 | import org.apache.pluto.services.information.PortalContextProvider; |
|
27 | ||
28 | /** |
|
29 | * Provide information about the calling portal. |
|
30 | * |
|
31 | * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a> |
|
32 | * @version $Id: PortalContextProviderImpl.java 553375 2007-07-05 05:37:00Z taylor $ |
|
33 | */ |
|
34 | public class PortalContextProviderImpl |
|
35 | implements PortalContextProvider |
|
36 | { |
|
37 | private final PortalContext portalContext; |
|
38 | /** Portal information */ |
|
39 | ||
40 | private String info; |
|
41 | private final String portalName; |
|
42 | private final String portalVersion; |
|
43 | ||
44 | /** supported portlet modes by this portal */ |
|
45 | private Vector modes; |
|
46 | ||
47 | /** supported window states by this portal */ |
|
48 | private Vector states; |
|
49 | ||
50 | public PortalContextProviderImpl(PortalContext portalContext) |
|
51 | 0 | { |
52 | 0 | this.portalContext = portalContext; |
53 | ||
54 | 0 | modes = getDefaultModes(); |
55 | ||
56 | // these are the minimum states that the portal needs to support |
|
57 | ||
58 | 0 | states = getDefaultStates(); |
59 | ||
60 | // set info |
|
61 | 0 | portalName = this.portalContext.getConfiguration().getString("portal.name"); |
62 | 0 | portalVersion = this.portalContext.getConfiguration().getString("portal.version"); |
63 | 0 | info = portalName + "/" + portalVersion; |
64 | ||
65 | 0 | } |
66 | ||
67 | /* (non-Javadoc) |
|
68 | * @see org.apache.pluto.services.information.PortalContextProvider#getPortalContext() |
|
69 | */ |
|
70 | public PortalContext getPortalContext() |
|
71 | { |
|
72 | 0 | return portalContext; |
73 | } |
|
74 | ||
75 | /** |
|
76 | * <p> |
|
77 | * getPortalInfo |
|
78 | * </p> |
|
79 | * |
|
80 | * @see org.apache.pluto.services.information.PortalContextProvider#getPortalInfo() |
|
81 | * @return |
|
82 | */ |
|
83 | public String getPortalInfo() |
|
84 | { |
|
85 | 0 | return info; |
86 | } |
|
87 | ||
88 | /** |
|
89 | * <p> |
|
90 | * getProperty |
|
91 | * </p> |
|
92 | * |
|
93 | * @see org.apache.pluto.services.information.PortalContextProvider#getProperty(java.lang.String) |
|
94 | * @param name |
|
95 | * @return |
|
96 | */ |
|
97 | public String getProperty(String name) |
|
98 | { |
|
99 | 0 | return portalContext.getProperty(name); |
100 | } |
|
101 | ||
102 | /** |
|
103 | * <p> |
|
104 | * getPropertyNames |
|
105 | * </p> |
|
106 | * |
|
107 | * @see org.apache.pluto.services.information.PortalContextProvider#getPropertyNames() |
|
108 | * @return |
|
109 | */ |
|
110 | public Collection getPropertyNames() |
|
111 | { |
|
112 | 0 | Iterator itr = portalContext.getConfiguration().getKeys(); |
113 | 0 | ArrayList names = new ArrayList(); |
114 | 0 | while(itr.hasNext()) |
115 | { |
|
116 | 0 | names.add(itr.next()); |
117 | } |
|
118 | 0 | return names; |
119 | } |
|
120 | ||
121 | /** |
|
122 | * <p> |
|
123 | * getSupportedPortletModes |
|
124 | * </p> |
|
125 | * |
|
126 | * @see org.apache.pluto.services.information.PortalContextProvider#getSupportedPortletModes() |
|
127 | * @return |
|
128 | */ |
|
129 | public Collection getSupportedPortletModes() |
|
130 | { |
|
131 | 0 | return modes; |
132 | } |
|
133 | ||
134 | /** |
|
135 | * <p> |
|
136 | * getSupportedWindowStates |
|
137 | * </p> |
|
138 | * |
|
139 | * @see org.apache.pluto.services.information.PortalContextProvider#getSupportedWindowStates() |
|
140 | * @return |
|
141 | */ |
|
142 | public Collection getSupportedWindowStates() |
|
143 | { |
|
144 | 0 | return states; |
145 | } |
|
146 | ||
147 | private Vector getDefaultModes() |
|
148 | { |
|
149 | 0 | Vector m = new Vector(); |
150 | 0 | Enumeration supportedPortletModes = portalContext.getSupportedPortletModes(); |
151 | 0 | while(supportedPortletModes.hasMoreElements()) |
152 | { |
|
153 | 0 | m.add(supportedPortletModes.nextElement()); |
154 | } |
|
155 | ||
156 | 0 | return m; |
157 | } |
|
158 | ||
159 | private Vector getDefaultStates() |
|
160 | { |
|
161 | 0 | Vector s = new Vector(); |
162 | 0 | Enumeration supportedWindowStates = portalContext.getSupportedWindowStates(); |
163 | 0 | while(supportedWindowStates.hasMoreElements()) |
164 | { |
|
165 | 0 | s.add(supportedWindowStates.nextElement()); |
166 | } |
|
167 | ||
168 | 0 | return s; |
169 | } |
|
170 | ||
171 | public void setProperty(String name, String value) |
|
172 | { |
|
173 | 0 | if (name == null) |
174 | { |
|
175 | 0 | throw new IllegalArgumentException("Property name == null"); |
176 | } |
|
177 | 0 | portalContext.getConfiguration().setString(name, value); |
178 | 0 | } |
179 | ||
180 | // expects enumeration of PortletMode objects |
|
181 | ||
182 | public void setSupportedPortletModes(Enumeration portletModes) |
|
183 | { |
|
184 | 0 | Vector v = new Vector(); |
185 | ||
186 | 0 | while (portletModes.hasMoreElements()) |
187 | { |
|
188 | 0 | v.add(portletModes.nextElement()); |
189 | } |
|
190 | ||
191 | 0 | modes = v; |
192 | 0 | } |
193 | ||
194 | ||
195 | ||
196 | // expects enumeration of WindowState objects |
|
197 | ||
198 | public void setSupportedWindowStates(Enumeration windowStates) |
|
199 | { |
|
200 | 0 | Vector v = new Vector(); |
201 | 0 | while (windowStates.hasMoreElements()) |
202 | { |
|
203 | 0 | v.add(windowStates.nextElement()); |
204 | } |
|
205 | ||
206 | 0 | states = v; |
207 | 0 | } |
208 | ||
209 | ||
210 | ||
211 | /** |
|
212 | * reset all values to default portlet modes and window states; |
|
213 | * delete all properties and set the given portlet information |
|
214 | * as portlet info string. |
|
215 | * |
|
216 | * @param |
|
217 | * @param portalInfo portal information string that will be returned |
|
218 | * by the <code>getPortalInfo</code> call. |
|
219 | */ |
|
220 | public void reset(String portalInfo) |
|
221 | ||
222 | { |
|
223 | 0 | info = new String(portalInfo); |
224 | ||
225 | // these are the minimum modes that the portal needs to support |
|
226 | 0 | modes = getDefaultModes(); |
227 | ||
228 | // these are the minimum states that the portal needs to support |
|
229 | 0 | states = getDefaultStates(); |
230 | ||
231 | //properties.clear(); |
|
232 | 0 | } |
233 | ||
234 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |