View Javadoc

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;
23  import java.util.HashMap;
24  import java.util.Vector;
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 info = null;
37  
38      /*** supported portlet modes by this portal */
39      private Vector modes;
40  
41      /*** supported window states by this portal */
42      private Vector states;
43  
44      /*** portal properties */
45      private HashMap properties = new HashMap();
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 getProperty(java.lang.String name)
61      {
62          if (name == null) {
63              throw new IllegalArgumentException("Property name == null");
64          }
65  
66          return(String) properties.get(name);
67      }
68  
69  
70      public java.util.Collection getPropertyNames()
71      {
72          return properties.keySet();
73      }
74  
75  
76      public java.util.Collection getSupportedPortletModes()
77      {
78          return modes;
79      }
80  
81  
82      public java.util.Collection getSupportedWindowStates()
83      {
84          return states;
85      }
86  
87  
88      public String getPortalInfo()
89      {
90          return info;
91      }
92  
93      // internal methods.
94  
95      private Vector getDefaultModes()
96      {
97  
98          Vector m = new Vector();
99  
100         String[] 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 getDefaultStates()
110     {
111         Vector s = new Vector();
112 
113         String[] 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 name, String value)
127     {
128         if (name == null) {
129             throw new IllegalArgumentException("Property name == null");
130         }
131 
132         properties.put(name, value);
133     }      
134 
135 
136     // expects enumeration of PortletMode objects
137     public void setSupportedPortletModes(Enumeration portletModes)
138     {
139         Vector v = new Vector();
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 windowStates)
148     {
149         Vector v = new Vector();
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 portalInfo)
165     {
166         info = new String(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 }