001: /*
002: * The Apache Software License, Version 1.1
003: *
004: * Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution, if
019: * any, must include the following acknowlegement:
020: * "This product includes software developed by the
021: * Caucho Technology (http://www.caucho.com/)."
022: * Alternately, this acknowlegement may appear in the software itself,
023: * if and wherever such third-party acknowlegements normally appear.
024: *
025: * 4. The names "Hessian", "Resin", and "Caucho" must not be used to
026: * endorse or promote products derived from this software without prior
027: * written permission. For written permission, please contact
028: * info@caucho.com.
029: *
030: * 5. Products derived from this software may not be called "Resin"
031: * nor may "Resin" appear in their names without prior written
032: * permission of Caucho Technology.
033: *
034: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037: * DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
038: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
039: * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
040: * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
041: * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
042: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
043: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
044: * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
045: *
046: * @author Sam
047: */
048:
049: package com.caucho.portal.generic;
050:
051: import javax.portlet.PortalContext;
052: import javax.portlet.PortletMode;
053: import javax.portlet.PortletRequest;
054: import javax.portlet.WindowState;
055: import java.util.Collections;
056: import java.util.Enumeration;
057: import java.util.LinkedHashMap;
058: import java.util.Map;
059: import java.util.Set;
060: import java.util.logging.Logger;
061:
062: /**
063: * A Portal implementation with default values.
064: */
065: public class GenericPortal implements Portal, PortalContext {
066: static final public Logger log = Logger
067: .getLogger(GenericPortal.class.getName());
068:
069: private String _portalInfo = "GenericPortal/1.0";
070: private String _reservedNamespace = "__";
071: private Map<String, String> _propertyMap;
072: private Set<WindowState> _supportedWindowStates;
073: private Set<PortletMode> _supportedPortletModes;
074:
075: private Set<String> _userAttributeNames;
076:
077: private PreferencesStore _preferencesStore;
078: private UserAttributeStore _userAttributeStore;
079:
080: private Cache _cache;
081: private BufferFactory _bufferFactory;
082:
083: private boolean _isInit;
084:
085: public PortalContext getPortalContext() {
086: return this ;
087: }
088:
089: /**
090: * Set the value to be returned by {@link #getPortalInfo}, the default
091: * is "GenericPortal/1.0".
092: */
093: public void setPortalInfo(String portalInfo) {
094: _portalInfo = portalInfo;
095: }
096:
097: /**
098: * {@inheritDoc}
099: */
100: public String getPortalInfo() {
101: return _portalInfo;
102: }
103:
104: /**
105: * Set the reserved namespace, the default is "__".
106: */
107: public void setReservedNamespace(String reservedNamespace) {
108: _reservedNamespace = reservedNamespace;
109: }
110:
111: /**
112: * {@inheritDoc}
113: */
114: public String getReservedNamespace() {
115: return _reservedNamespace;
116: }
117:
118: /**
119: * Set a portal property that is available with {@link #getProperty}.
120: */
121: public void setProperty(String name, String value) {
122: if (_propertyMap == null)
123: _propertyMap = new LinkedHashMap<String, String>();
124:
125: _propertyMap.put(name, value);
126: }
127:
128: /**
129: * {@inheritDoc}
130: */
131: public String getProperty(String name) {
132: if (_propertyMap == null)
133: return null;
134:
135: return _propertyMap.get(name);
136: }
137:
138: /**
139: * {@inheritDoc}
140: */
141: public Enumeration getPropertyNames() {
142: if (_propertyMap == null)
143: return Collections.enumeration(Collections.EMPTY_LIST);
144: else
145: return Collections.enumeration(_propertyMap.keySet());
146: }
147:
148: /**
149: * Set the supported portlet modes. If this method is not called then
150: * then {@link #isPortletModeAllowed} will always return true (all portlet
151: * modes are allowed) but {@link #getSupportedPortletModes} will return an
152: * empty enumeration.
153: */
154: public void setSupportedPortletModes(Set<PortletMode> portletModes) {
155: _supportedPortletModes = portletModes;
156: }
157:
158: /**
159: * {@inheritDoc}
160: */
161: public Enumeration getSupportedPortletModes() {
162: if (_supportedPortletModes == null)
163: return Collections.enumeration(Collections.EMPTY_LIST);
164: else
165: return Collections
166: .<PortletMode> enumeration(_supportedPortletModes);
167: }
168:
169: /**
170: * {@inheritDoc}
171: */
172: public boolean isPortletModeAllowed(PortletRequest portletRequest,
173: PortletMode portletMode) {
174: if (_supportedPortletModes == null)
175: return true;
176: else
177: return _supportedPortletModes.contains(portletMode);
178: }
179:
180: /**
181: * Set the supported window states. If this method is never called
182: * and no window states are specified, then {@link #isWindowStateAllowed}
183: * will always return true (all window states are allowed) but
184: * {@link #getSupportedWindowStates} will return an empty enumeration.
185: */
186: public void setSupportedWindowStates(Set<WindowState> windowStates) {
187: _supportedWindowStates = windowStates;
188: }
189:
190: /**
191: * {@inheritDoc}
192: */
193: public Enumeration getSupportedWindowStates() {
194:
195: if (_supportedWindowStates == null)
196: return Collections.enumeration(Collections.EMPTY_LIST);
197: else
198: return Collections.enumeration(_supportedWindowStates);
199: }
200:
201: /**
202: * {@inheritDoc}
203: */
204: public boolean isWindowStateAllowed(PortletRequest portletRequest,
205: WindowState windowState) {
206: if (_supportedWindowStates == null)
207: return true;
208: else
209: return _supportedWindowStates.contains(windowState);
210: }
211:
212: /**
213: * Set the {@link #PreferencesStore}, obtained once for each
214: * connection and then used to obtain a preferences store for each namespace
215: * as needed. The default is an instance of
216: * {@link #SessionPreferencesStore}.
217: */
218: public void setPreferencesStore(PreferencesStore preferencesStore) {
219: _preferencesStore = preferencesStore;
220: }
221:
222: /**
223: * {@inheritDoc}
224: */
225: public PreferencesStore getPreferencesStore() {
226: if (_preferencesStore == null)
227: _preferencesStore = new SessionPreferencesStore();
228:
229: return _preferencesStore;
230: }
231:
232: /**
233: * Set the user attribute names that the portlet can use, the default
234: * is to allow all user attributes to be visible to the portlet.
235: */
236: public void setUserAttributeNames(Set<String> userAttributeNames) {
237: if (_userAttributeNames != null)
238: throw new IllegalArgumentException(
239: "user-attribute-names already set");
240:
241: _userAttributeNames = userAttributeNames;
242: }
243:
244: /**
245: * {@inheritDoc}
246: */
247: public Set<String> getUserAttributeNames() {
248: return _userAttributeNames;
249: }
250:
251: /**
252: * Set the {@link #UserAttributeStore}, obtained once for each
253: * connection and then used to obtain user attributes
254: * as needed. The default is null, which means that no user attributes
255: * are available.
256: */
257: public void setUserAttributeStore(
258: UserAttributeStore userAttributeStore) {
259: _userAttributeStore = userAttributeStore;
260: }
261:
262: /**
263: * {@inheritDoc}
264: */
265: public UserAttributeStore getUserAttributeStore() {
266: return _userAttributeStore;
267: }
268:
269: /**
270: * Caching is currently unimplemented, attempting to set this value will cause
271: * an exception to be thrown.
272: */
273: public void setCache(Cache cache) {
274: _cache = cache;
275: throw new UnsupportedOperationException(
276: "cache not currently implemented");
277: }
278:
279: /**
280: * {@inheritDoc}
281: */
282: public Cache getCache() {
283: return _cache;
284: }
285:
286: /**
287: * The default is an instance of BufferFactoryImpl.
288: */
289: public void setBufferFactory(BufferFactory bufferFactory) {
290: _bufferFactory = bufferFactory;
291: }
292:
293: /**
294: * @inheritDoc
295: */
296: public BufferFactory getBufferFactory() {
297: if (_bufferFactory == null)
298: _bufferFactory = new BufferFactoryImpl();
299:
300: return _bufferFactory;
301: }
302: }
|