KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > portal > generic > GenericPortal


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution, if
19  * any, must include the following acknowlegement:
20  * "This product includes software developed by the
21  * Caucho Technology (http://www.caucho.com/)."
22  * Alternately, this acknowlegement may appear in the software itself,
23  * if and wherever such third-party acknowlegements normally appear.
24  *
25  * 4. The names "Hessian", "Resin", and "Caucho" must not be used to
26  * endorse or promote products derived from this software without prior
27  * written permission. For written permission, please contact
28  * info@caucho.com.
29  *
30  * 5. Products derived from this software may not be called "Resin"
31  * nor may "Resin" appear in their names without prior written
32  * permission of Caucho Technology.
33  *
34  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
35  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37  * DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
38  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
39  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
40  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
42  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
43  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
44  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45  *
46  * @author Sam
47  */

48
49 package com.caucho.portal.generic;
50
51 import javax.portlet.PortalContext;
52 import javax.portlet.PortletMode;
53 import javax.portlet.PortletRequest;
54 import javax.portlet.WindowState;
55 import java.util.Collections JavaDoc;
56 import java.util.Enumeration JavaDoc;
57 import java.util.LinkedHashMap JavaDoc;
58 import java.util.Map JavaDoc;
59 import java.util.Set JavaDoc;
60 import java.util.logging.Logger JavaDoc;
61
62 /**
63  * A Portal implementation with default values.
64  */

65 public class GenericPortal
66   implements Portal, PortalContext
67 {
68   static final public Logger JavaDoc log =
69     Logger.getLogger(GenericPortal.class.getName());
70
71   private String JavaDoc _portalInfo = "GenericPortal/1.0";
72   private String JavaDoc _reservedNamespace = "__";
73   private Map JavaDoc<String JavaDoc, String JavaDoc> _propertyMap;
74   private Set JavaDoc<WindowState> _supportedWindowStates;
75   private Set JavaDoc<PortletMode> _supportedPortletModes;
76
77   private Set JavaDoc<String JavaDoc> _userAttributeNames;
78
79   private PreferencesStore _preferencesStore;
80   private UserAttributeStore _userAttributeStore;
81
82   private Cache _cache;
83   private BufferFactory _bufferFactory;
84
85   private boolean _isInit;
86
87   public PortalContext getPortalContext()
88   {
89     return this;
90   }
91
92   /**
93    * Set the value to be returned by {@link #getPortalInfo}, the default
94    * is "GenericPortal/1.0".
95    */

96   public void setPortalInfo(String JavaDoc portalInfo)
97   {
98     _portalInfo = portalInfo;
99   }
100
101   /**
102    * {@inheritDoc}
103    */

104   public String JavaDoc getPortalInfo()
105   {
106     return _portalInfo;
107   }
108   /**
109    * Set the reserved namespace, the default is "__".
110    */

111   public void setReservedNamespace(String JavaDoc reservedNamespace)
112   {
113     _reservedNamespace = reservedNamespace;
114   }
115
116   /**
117    * {@inheritDoc}
118    */

119   public String JavaDoc getReservedNamespace()
120   {
121     return _reservedNamespace;
122   }
123
124   /**
125    * Set a portal property that is available with {@link #getProperty}.
126    */

127   public void setProperty(String JavaDoc name, String JavaDoc value)
128   {
129     if (_propertyMap == null)
130       _propertyMap = new LinkedHashMap JavaDoc<String JavaDoc, String JavaDoc>();
131
132     _propertyMap.put(name, value);
133   }
134
135   /**
136    * {@inheritDoc}
137    */

138   public String JavaDoc getProperty(String JavaDoc name)
139   {
140     if (_propertyMap == null)
141       return null;
142
143     return _propertyMap.get(name);
144   }
145
146   /**
147    * {@inheritDoc}
148    */

149   public Enumeration JavaDoc getPropertyNames()
150   {
151     if (_propertyMap == null)
152       return Collections.enumeration(Collections.EMPTY_LIST);
153     else
154       return Collections.enumeration(_propertyMap.keySet());
155   }
156
157   /**
158    * Set the supported portlet modes. If this method is not called then
159    * then {@link #isPortletModeAllowed} will always return true (all portlet
160    * modes are allowed) but {@link #getSupportedPortletModes} will return an
161    * empty enumeration.
162    */

163   public void setSupportedPortletModes(Set JavaDoc<PortletMode> portletModes)
164   {
165     _supportedPortletModes = portletModes;
166   }
167
168   /**
169    * {@inheritDoc}
170    */

171   public Enumeration JavaDoc getSupportedPortletModes()
172   {
173     if (_supportedPortletModes == null)
174       return Collections.enumeration(Collections.EMPTY_LIST);
175     else
176       return Collections.<PortletMode>enumeration(_supportedPortletModes);
177   }
178
179   /**
180    * {@inheritDoc}
181    */

182   public boolean isPortletModeAllowed(PortletRequest portletRequest,
183                                       PortletMode portletMode)
184   {
185     if (_supportedPortletModes == null)
186       return true;
187     else
188       return _supportedPortletModes.contains(portletMode);
189   }
190
191   /**
192    * Set the supported window states. If this method is never called
193    * and no window states are specified, then {@link #isWindowStateAllowed}
194    * will always return true (all window states are allowed) but
195    * {@link #getSupportedWindowStates} will return an empty enumeration.
196    */

197   public void setSupportedWindowStates(Set JavaDoc<WindowState> windowStates)
198   {
199     _supportedWindowStates = windowStates;
200   }
201
202   /**
203    * {@inheritDoc}
204    */

205   public Enumeration JavaDoc getSupportedWindowStates()
206   {
207
208     if (_supportedWindowStates == null)
209       return Collections.enumeration(Collections.EMPTY_LIST);
210     else
211       return Collections.enumeration(_supportedWindowStates);
212   }
213
214   /**
215    * {@inheritDoc}
216    */

217   public boolean isWindowStateAllowed(PortletRequest portletRequest,
218                                       WindowState windowState)
219   {
220     if (_supportedWindowStates == null)
221       return true;
222     else
223       return _supportedWindowStates.contains(windowState);
224   }
225
226   /**
227    * Set the {@link #PreferencesStore}, obtained once for each
228    * connection and then used to obtain a preferences store for each namespace
229    * as needed. The default is an instance of
230    * {@link #SessionPreferencesStore}.
231    */

232   public void setPreferencesStore(PreferencesStore preferencesStore)
233   {
234     _preferencesStore = preferencesStore;
235   }
236
237   /**
238    * {@inheritDoc}
239    */

240   public PreferencesStore getPreferencesStore()
241   {
242     if (_preferencesStore == null)
243       _preferencesStore = new SessionPreferencesStore();
244
245     return _preferencesStore;
246   }
247
248   /**
249    * Set the user attribute names that the portlet can use, the default
250    * is to allow all user attributes to be visible to the portlet.
251    */

252   public void setUserAttributeNames(Set JavaDoc<String JavaDoc> userAttributeNames)
253   {
254     if (_userAttributeNames != null)
255       throw new IllegalArgumentException JavaDoc("user-attribute-names already set");
256
257     _userAttributeNames = userAttributeNames;
258   }
259
260   /**
261    * {@inheritDoc}
262    */

263   public Set JavaDoc<String JavaDoc> getUserAttributeNames()
264   {
265     return _userAttributeNames;
266   }
267
268   /**
269    * Set the {@link #UserAttributeStore}, obtained once for each
270    * connection and then used to obtain user attributes
271    * as needed. The default is null, which means that no user attributes
272    * are available.
273    */

274   public void setUserAttributeStore(UserAttributeStore userAttributeStore)
275   {
276     _userAttributeStore = userAttributeStore;
277   }
278
279   /**
280    * {@inheritDoc}
281    */

282   public UserAttributeStore getUserAttributeStore()
283   {
284     return _userAttributeStore;
285   }
286
287   /**
288    * Caching is currently unimplemented, attempting to set this value will cause
289    * an exception to be thrown.
290    */

291   public void setCache(Cache cache)
292   {
293     _cache = cache;
294     throw new UnsupportedOperationException JavaDoc("cache not currently implemented");
295   }
296
297   /**
298    * {@inheritDoc}
299    */

300   public Cache getCache()
301   {
302     return _cache;
303   }
304
305   /**
306    * The default is an instance of BufferFactoryImpl.
307    */

308   public void setBufferFactory(BufferFactory bufferFactory)
309   {
310     _bufferFactory = bufferFactory;
311   }
312
313   /**
314    * @inheritDoc
315    */

316   public BufferFactory getBufferFactory()
317   {
318     if (_bufferFactory == null)
319       _bufferFactory = new BufferFactoryImpl();
320
321     return _bufferFactory;
322   }
323 }
324
325
Popular Tags