KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portalImpl > core > PortalContextProviderImpl


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 /*
17
18  */

19
20 package org.apache.pluto.portalImpl.core;
21
22 import java.util.Enumeration JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Vector JavaDoc;
25
26 import javax.portlet.PortletMode;
27 import javax.portlet.WindowState;
28
29 import org.apache.pluto.portalImpl.services.config.Config;
30 import org.apache.pluto.services.information.PortalContextProvider;
31
32 public class PortalContextProviderImpl implements PortalContextProvider {
33
34
35     /** Portal information */
36     private String JavaDoc info = null;
37
38     /** supported portlet modes by this portal */
39     private Vector JavaDoc modes;
40
41     /** supported window states by this portal */
42     private Vector JavaDoc states;
43
44     /** portal properties */
45     private HashMap JavaDoc properties = new HashMap JavaDoc();
46
47
48     public PortalContextProviderImpl()
49     {
50         // these are the minimum modes that the portal needs to support
51
modes = getDefaultModes();
52         // these are the minimum states that the portal needs to support
53
states = getDefaultStates();
54         // set info
55
info = Config.getParameters().getString("portaldriver.info");
56     }
57
58     // PortalContextProvider implementation.
59

60     public java.lang.String JavaDoc getProperty(java.lang.String JavaDoc name)
61     {
62         if (name == null) {
63             throw new IllegalArgumentException JavaDoc("Property name == null");
64         }
65
66         return(String JavaDoc) properties.get(name);
67     }
68
69
70     public java.util.Collection JavaDoc getPropertyNames()
71     {
72         return properties.keySet();
73     }
74
75
76     public java.util.Collection JavaDoc getSupportedPortletModes()
77     {
78         return modes;
79     }
80
81
82     public java.util.Collection JavaDoc getSupportedWindowStates()
83     {
84         return states;
85     }
86
87
88     public String JavaDoc getPortalInfo()
89     {
90         return info;
91     }
92
93     // internal methods.
94

95     private Vector JavaDoc getDefaultModes()
96     {
97
98         Vector JavaDoc m = new Vector JavaDoc();
99
100         String JavaDoc[] supportedModes = Config.getParameters().getStrings("supported.portletmode");
101
102         for (int i=0; i<supportedModes.length; i++) {
103             m.add(new PortletMode(supportedModes[i].toString().toLowerCase()));
104         }
105
106         return m;
107     }
108
109     private Vector JavaDoc getDefaultStates()
110     {
111         Vector JavaDoc s = new Vector JavaDoc();
112
113         String JavaDoc[] supportedStates = Config.getParameters().getStrings("supported.windowstate");
114
115         for (int i=0; i<supportedStates.length; i++) {
116             s.add(new WindowState(supportedStates[i].toString().toLowerCase()));
117         }
118
119         return s;
120     }
121
122     // additional methods.
123

124     // methods used container internally to set
125

126     public void setProperty(String JavaDoc name, String JavaDoc value)
127     {
128         if (name == null) {
129             throw new IllegalArgumentException JavaDoc("Property name == null");
130         }
131
132         properties.put(name, value);
133     }
134
135
136     // expects enumeration of PortletMode objects
137
public void setSupportedPortletModes(Enumeration JavaDoc portletModes)
138     {
139         Vector JavaDoc v = new Vector JavaDoc();
140         while (portletModes.hasMoreElements()) {
141             v.add(portletModes.nextElement());
142         }
143         modes = v;
144     }
145
146     // expects enumeration of WindowState objects
147
public void setSupportedWindowStates(Enumeration JavaDoc windowStates)
148     {
149         Vector JavaDoc v = new Vector JavaDoc();
150         while (windowStates.hasMoreElements()) {
151             v.add(windowStates.nextElement());
152         }
153         states = v;
154     }
155
156     /**
157      * reset all values to default portlet modes and window states;
158      * delete all properties and set the given portlet information
159      * as portlet info string.
160      *
161      * @param portalInfo portal information string that will be returned
162      * by the <code>getPortalInfo</code> call.
163      */

164     public void reset(String JavaDoc portalInfo)
165     {
166         info = new String JavaDoc(portalInfo);
167
168         // these are the minimum modes that the portal needs to support
169
modes = getDefaultModes();
170         // these are the minimum states that the portal needs to support
171
states = getDefaultStates();
172
173         properties.clear();
174     }
175
176
177
178 }
179
Popular Tags