View Javadoc

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      {
52          this.portalContext = portalContext;
53          
54          modes = getDefaultModes();
55  
56          // these are the minimum states that the portal needs to support
57  
58          states = getDefaultStates(); 
59  
60          // set info
61          portalName = this.portalContext.getConfiguration().getString("portal.name");
62          portalVersion = this.portalContext.getConfiguration().getString("portal.version");         
63          info = portalName + "/" + portalVersion;   
64          
65      }
66      
67      /* (non-Javadoc)
68       * @see org.apache.pluto.services.information.PortalContextProvider#getPortalContext()
69       */
70      public PortalContext getPortalContext() 
71      {
72          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          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          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          Iterator itr = portalContext.getConfiguration().getKeys();
113          ArrayList names = new ArrayList();
114          while(itr.hasNext())
115          {
116              names.add(itr.next());
117          }
118          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         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         return states;
145     }
146 
147     private Vector getDefaultModes()
148     {  
149         Vector m = new Vector();
150         Enumeration supportedPortletModes = portalContext.getSupportedPortletModes();
151         while(supportedPortletModes.hasMoreElements()) 
152         {
153             m.add(supportedPortletModes.nextElement());
154         }
155 
156         return m;
157     }
158 
159     private Vector getDefaultStates()
160     {
161         Vector s = new Vector();
162         Enumeration supportedWindowStates = portalContext.getSupportedWindowStates();
163         while(supportedWindowStates.hasMoreElements()) 
164         {
165             s.add(supportedWindowStates.nextElement());
166         }
167 
168         return s;
169     }
170 
171     public void setProperty(String name, String value)
172     {
173         if (name == null) 
174         {
175             throw new IllegalArgumentException("Property name == null");
176         }
177         portalContext.getConfiguration().setString(name, value);
178     }      
179 
180     // expects enumeration of PortletMode objects
181 
182     public void setSupportedPortletModes(Enumeration portletModes)
183     {
184         Vector v = new Vector();
185 
186         while (portletModes.hasMoreElements()) 
187         {
188             v.add(portletModes.nextElement());
189         }
190 
191         modes = v;
192     }
193 
194 
195 
196     // expects enumeration of WindowState objects
197 
198     public void setSupportedWindowStates(Enumeration windowStates)
199     {
200         Vector v = new Vector();
201         while (windowStates.hasMoreElements()) 
202         {
203             v.add(windowStates.nextElement());
204         }
205 
206         states = v;
207     }
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         info = new String(portalInfo);
224 
225         // these are the minimum modes that the portal needs to support
226         modes = getDefaultModes();
227 
228         // these are the minimum states that the portal needs to support
229         states = getDefaultStates();    
230 
231         //properties.clear();
232     }
233 
234 }