001: /*
002: * Copyright 2002 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */
013: package com.sun.portal.portlet.impl;
014:
015: import java.util.ArrayList;
016: import java.util.Collections;
017: import java.util.Enumeration;
018: import java.util.List;
019: import java.util.Map;
020:
021: import javax.portlet.PortalContext;
022: import javax.portlet.PortletMode;
023: import javax.portlet.WindowState;
024:
025: /**
026: * The <code>PortalContextImpl</code> class provides a default
027: * implementation for the <code>PortalContext</code> interface.
028: *
029: */
030:
031: public class PortalContextImpl implements PortalContext {
032:
033: // constants
034: public static final String PORTAL_INFO =
035: // format: vendorname.majorversion.minorversion
036: "Sun Java System Portal Server/6.4";
037:
038: // static data members
039: private static List _supportedPortletModes = new ArrayList();
040: private static List _supportedWindowStates = new ArrayList();
041:
042: // static initializer
043: static {
044: _supportedPortletModes.add(PortletMode.VIEW);
045: _supportedPortletModes.add(PortletMode.EDIT);
046: _supportedPortletModes.add(PortletMode.HELP);
047: _supportedWindowStates.add(WindowState.NORMAL);
048: _supportedWindowStates.add(WindowState.MINIMIZED);
049: _supportedWindowStates.add(WindowState.MAXIMIZED);
050: }
051:
052: // data members
053: private Map properties;
054:
055: // default constructor
056: public PortalContextImpl() {
057: this .properties = Collections.EMPTY_MAP;
058: }
059:
060: // constructor with portal properties passed in
061: public PortalContextImpl(Map properties) {
062: this .properties = properties;
063: }
064:
065: /**
066: * Returns the portal property with the given name,
067: * or a <code>null</code> if there is
068: * no property by that name.
069: *
070: * @param name property name
071: *
072: * @return portal property with key <code>name</code>
073: *
074: * @exception java.lang.IllegalArgumentException
075: * if name is <code>null</code>.
076: */
077:
078: public String getProperty(java.lang.String name)
079: throws IllegalArgumentException {
080: if (name == null) {
081: throw new IllegalArgumentException(
082: "The given property name is null");
083: }
084:
085: return (String) properties.get(name);
086: }
087:
088: /**
089: * Returns all portal property names, or an empty
090: * <code>Enumeration</code> if there are no property names.
091: *
092: * @return All portal property names as an
093: * <code>Enumeration</code> of <code>String</code> objects
094: */
095: public Enumeration getPropertyNames() {
096:
097: return Collections.enumeration(properties.keySet());
098: }
099:
100: /**
101: * Returns all supported portlet modes by the portal
102: * as an enumertation of <code>PorltetMode</code> objects.
103: * <p>
104: * The portlet modes must at least include the
105: * standard portlet modes <code>EDIT, HELP, VIEW</code>.
106: *
107: * @return All supported portal modes by the portal
108: * as an enumertation of <code>PorltetMode</code> objects.
109: */
110:
111: public Enumeration getSupportedPortletModes() {
112:
113: return Collections.enumeration(_supportedPortletModes);
114:
115: }
116:
117: /**
118: * Returns all supported window states by the portal
119: * as an enumertation of <code>WindowState</code> objects.
120: * <p>
121: * The window states must at least include the
122: * standard window states <code> MINIMIZED, NORMAL, MAXIMIZED</code>.
123: *
124: * @return All supported window states by the portal
125: * as an enumertation of <code>WindowState</code> objects.
126: */
127:
128: public Enumeration getSupportedWindowStates() {
129:
130: return Collections.enumeration(_supportedWindowStates);
131: }
132:
133: /**
134: * Returns information about the portal like vendor, version, etc.
135: * <p>
136: * The form of the returned string is <I>servername/versionnumber</I>. For
137: * example, the reference implementation Pluto may return the string
138: * <CODE>Pluto/1.0</CODE>.
139: * <p>
140: * The portlet container may return other optional information after the
141: * primary string in parentheses, for example, <CODE>Pluto/1.0
142: * (JDK 1.3.1; Windows NT 4.0 x86)</CODE>.
143: *
144: * @return a <CODE>String</CODE> containing at least the portal name and version number
145: */
146:
147: public String getPortalInfo() {
148:
149: return PORTAL_INFO;
150: }
151: }
|