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.Map;
016: import java.util.Collections;
017: import java.util.logging.Logger;
018:
019: import javax.servlet.http.HttpServletRequest;
020: import javax.servlet.http.HttpServletResponse;
021:
022: import javax.portlet.PortletContext;
023: import javax.portlet.PortalContext;
024: import javax.portlet.PortletMode;
025: import javax.portlet.WindowState;
026: import javax.portlet.RenderResponse;
027:
028: import com.sun.portal.portletappengine.PortletAppEngineUtils;
029:
030: import com.sun.portal.portletcontainercommon.PortletContainerRenderRequest;
031: import com.sun.portal.portletcontainercommon.PortletContainerRenderResponse;
032: import com.sun.portal.portletcontainercommon.descriptor.PortletDescriptor;
033:
034: /**
035: * This class provides implementation of the RenderRequest interface.
036: */
037: public class RenderRequestImpl extends PortletRequestImpl implements
038: javax.portlet.RenderRequest {
039: // Global variables
040: private PortletContainerRenderRequest _pContReq;
041: private PortletContainerRenderResponse _pContRes;
042:
043: /**
044: * Initialize the global variables.
045: * <P>
046: * @param req The <code>HttpServletRequest</code> of the PAE
047: * @param res The <code>HttpServletResponse</code> of the PAE
048: * @param pContReq The <code>PortletContainerRequest</code>
049: * @param logger The <code>Logger</code> object
050: */
051: void init(HttpServletRequest req, HttpServletResponse res,
052: PortletContainerRenderRequest pContReq,
053: PortletContainerRenderResponse pContRes,
054: PortletContext context, PortalContext portalContext,
055: PortletDescriptor pDescriptor, Logger logger) {
056:
057: _pContReq = pContReq;
058: _pContRes = pContRes;
059: super .init(req, res, pContReq, pContRes, context,
060: portalContext, pDescriptor, logger);
061:
062: }
063:
064: /**
065: * Clears the global variables.
066: */
067: void clear() {
068: _pContReq = null;
069: _pContRes = null;
070: super .clear();
071: }
072:
073: /**
074: * Returns a <code>Map</code> of the parameters of this request.
075: * Request parameters are extra information sent with the request.
076: * The returned parameters are "x-www-form-urlencoded" decoded.
077: * <p>
078: * The values in the returned <code>Map</code> are from type
079: * String array (<code>String[]</code>).
080: * <p>
081: * If no parameters exist this method returns <code>null</code>.
082: *
083: * @return an immutable java.util.Map containing parameter names as
084: * keys and parameter values as map values. The keys in the parameter
085: * map are of type String. The values in the parameter map are of type
086: * String array (<code>String[]</code>).
087: *
088: */
089: public java.util.Map getParameterMap() {
090: Map map = _pContReq.getRenderParameters();
091:
092: return Collections.unmodifiableMap(map);
093: }
094:
095: /**
096: * Returns the current mode of the portlet.
097: *
098: * @return the portlet mode
099: */
100: public PortletMode getPortletMode() {
101: return PortletAppEngineUtils.getPortletMode(_pContReq
102: .getChannelMode());
103: }
104:
105: /**
106: * Returns the current window state of the portlet.
107: *
108: * @return the window state
109: */
110:
111: public WindowState getWindowState() {
112: return PortletAppEngineUtils.getWindowState(_pContReq
113: .getWindowState());
114: }
115:
116: /**
117: *
118: * Returns the value of the specified client request property * as a <code>String</code>. If the request did not include a property
119: * of the specified name, this method returns <code>null</code>.
120: *
121: * A portlet can access portal/portlet-container specific properties
122: * through this method and, if available, the
123: * headers of the HTTP client request.
124: * <p>
125: * This method should only be used if the
126: * property has only one value. If the property might have
127: * more than one value, use {@link #getProperties}.
128: * <p>
129: * If this method is used with a multivalued
130: * parameter, the value returned is equal to the first value
131: * in the enumeration returned by <code>getProperties</code>.
132: *
133: * @param name a <code>String</code> specifying the
134: * property name
135: *
136: * @return a <code>String</code> containing the
137: * value of the requested
138: * property, or <code>null</code>
139: * if the request does not
140: * have a property of that name
141: * @exception java.lang.IllegalArgumentException
142: * if name is <code>null</code>.
143: */
144:
145: public String getProperty(String name) {
146: if (name == null) {
147: throw new IllegalArgumentException(
148: "Property name should not be null.");
149: }
150:
151: String retVal = null;
152:
153: if (name.equals(RenderResponse.EXPIRATION_CACHE)) {
154: if (_pContRes.getExpiration() != PortletDescriptor.EXPIRATION_CACHE_NOT_DEFINED) {
155: retVal = Integer.toString(_pContRes.getExpiration());
156: }
157: } else {
158: retVal = super.getProperty(name);
159: }
160: return retVal;
161:
162: }
163:
164: }
|