001: /*
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: PortalContextImpl.java 6385 2007-10-25 14:02:26Z wehrens $
004: */
005: package org.gridsphere.portlet.impl;
006:
007: import org.gridsphere.portletcontainer.impl.descriptor.CustomPortletMode;
008: import org.gridsphere.portletcontainer.impl.descriptor.CustomWindowState;
009: import org.gridsphere.portletcontainer.impl.descriptor.PortletApp;
010:
011: import javax.portlet.PortalContext;
012: import javax.portlet.PortletMode;
013: import javax.portlet.WindowState;
014: import java.util.ArrayList;
015: import java.util.HashMap;
016: import java.util.List;
017: import java.util.Map;
018:
019: /**
020: * The <CODE>PortalContext</CODE> interface gives the portlet
021: * the ability to retrieve information about the portal calling this portlet.
022: * <p/>
023: * The portlet can only read the <CODE>PortalContext</CODE> data.
024: */
025: public class PortalContextImpl implements PortalContext {
026:
027: private Map props = new HashMap();
028: private List windowStates = null;
029: private List portletModes = null;
030:
031: public PortalContextImpl(PortletApp portletApp) {
032: windowStates = new ArrayList();
033: windowStates.add(WindowState.MAXIMIZED);
034: windowStates.add(WindowState.NORMAL);
035: windowStates.add(WindowState.MINIMIZED);
036: CustomWindowState[] customStates = portletApp
037: .getCustomWindowState();
038:
039: for (int i = 0; i < customStates.length; i++) {
040: CustomWindowState state = customStates[i];
041: // GPF-460
042: windowStates.add(new WindowState(state.getWindowState()
043: .getContent()));
044: }
045: portletModes = new ArrayList();
046: portletModes.add(PortletMode.EDIT);
047: portletModes.add(PortletMode.VIEW);
048: portletModes.add(PortletMode.HELP);
049: CustomPortletMode[] customModes = portletApp
050: .getCustomPortletMode();
051: for (int i = 0; i < customModes.length; i++) {
052: CustomPortletMode mode = customModes[i];
053: portletModes.add(mode.getPortletMode());
054: }
055: }
056:
057: /**
058: * Returns the portal property with the given name,
059: * or a <code>null</code> if there is
060: * no property by that name.
061: *
062: * @param name property name
063: * @return portal property with key <code>name</code>
064: * @exception IllegalArgumentException if name is <code>null</code>.
065: */
066: public String getProperty(String name) {
067: if (name == null)
068: throw new IllegalArgumentException("name is NULL");
069: return (String) props.get(name);
070: }
071:
072: /**
073: * Returns all portal property names, or an empty
074: * <code>Enumeration</code> if there are no property names.
075: *
076: * @return All portal property names as an
077: * <code>Enumeration</code> of <code>String</code> objects
078: */
079: public java.util.Enumeration getPropertyNames() {
080: return new Enumerator(props.keySet());
081: }
082:
083: /**
084: * Returns all supported portlet modes by the portal
085: * as an enumertation of <code>PortletMode</code> objects.
086: * <p/>
087: * The portlet modes must at least include the
088: * standard portlet modes <code>EDIT, HELP, VIEW</code>.
089: *
090: * @return All supported portal modes by the portal
091: * as an enumertation of <code>PortletMode</code> objects.
092: */
093: public java.util.Enumeration getSupportedPortletModes() {
094: return new Enumerator(portletModes);
095: }
096:
097: /**
098: * Returns all supported window states by the portal
099: * as an enumertation of <code>WindowState</code> objects.
100: * <p/>
101: * The window states must at least include the
102: * standard window states <code> MINIMIZED, NORMAL, MAXIMIZED</code>.
103: *
104: * @return All supported window states by the portal
105: * as an enumertation of <code>WindowState</code> objects.
106: */
107: public java.util.Enumeration getSupportedWindowStates() {
108: return new Enumerator(windowStates);
109: }
110:
111: /**
112: * Returns information about the portal like vendor, version, etc.
113: * <p/>
114: * The form of the returned string is <I>servername/versionnumber</I>.
115: * <p/>
116: * The portlet container may return other optional information after the
117: * primary string in parentheses, for example, <CODE>GridSphere/1.0
118: * (JDK 1.3.1; Windows NT 4.0 x86)</CODE>.
119: *
120: * @return a <CODE>String</CODE> containing at least the portal name and version number
121: */
122: public String getPortalInfo() {
123: return SportletProperties.getInstance().getProperty(
124: "gridsphere.release");
125: }
126: }
|