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 javax.servlet.http.HttpSession;
016: import javax.servlet.http.HttpServletRequest;
017: import javax.servlet.http.HttpServletResponse;
018:
019: import javax.portlet.PortletMode;
020: import javax.portlet.PortletPreferences;
021: import javax.portlet.PortletSession;
022: import javax.portlet.WindowState;
023: import javax.portlet.PortletContext;
024: import javax.portlet.PortalContext;
025:
026: import java.security.Principal;
027:
028: import java.util.Map;
029: import java.util.HashMap;
030: import java.util.List;
031: import java.util.ArrayList;
032: import java.util.Collections;
033: import java.util.Enumeration;
034:
035: import com.sun.portal.portletcontainercommon.PortletContainerRequest;
036: import com.sun.portal.portletcontainercommon.PortletContainerResponse;
037:
038: import com.sun.portal.portletcontainercommon.descriptor.PortletDescriptor;
039: import com.sun.portal.portletcontainercommon.descriptor.SecurityRoleRefDescriptor;
040:
041: import java.util.logging.Logger;
042:
043: /**
044: * This class provides implementation of the PortletRequest interface.
045: */
046: public class PortletRequestImpl implements javax.portlet.PortletRequest {
047:
048: // Global variables
049: private HttpServletRequest _req;
050:
051: private HttpServletResponse _res;
052:
053: private PortletContainerRequest _pContReq;
054:
055: private PortletContainerResponse _pContRes;
056:
057: private Map _attributes;
058:
059: private PortletContext _context;
060:
061: private PortalContext _portalContext;
062:
063: private PortletDescriptor _pDescriptor;
064:
065: private static Logger _logger;
066:
067: private static String PORTLET_SESSION_PREFIX = "javax.portlet.portlet_session";
068:
069: private static String HTTP_SESSION_ID = "javax.portlet.http_session_id";
070:
071: private static String CONTEXT_PATH_ATTRIBUTE = "javax.servlet.include.context_path";
072:
073: private static final String SESSION_INVALID = "javax.portlet.session_invalid";
074:
075: private static final String DEFAULT_CONTENT_TYPE = "text/html";
076:
077: /**
078: * Initialize the global variables.
079: * <P>
080: * @param req The <code>HttpServletRequest</code> of the PAE
081: * @param res The <code>HttpServletResponse</code> of the PAE
082: * @param pContReq The <code>PortletContainerRequest</code>
083: * @param pContRes The <code>PortletContainerResponse</code>
084: * @param context The <code>PortletContext</code>
085: * @param secRoleNames A <code>List</code> of security role names
086: * defined in Deployment Descriptor's security-role-ref
087: * @param pDescriptor The <code>PortletDescriptor</code> for the
088: * portlet
089: * @param logger The <code>Logger</code> object
090: */
091: void init(HttpServletRequest req, HttpServletResponse res,
092: PortletContainerRequest pContReq,
093: PortletContainerResponse pContRes, PortletContext context,
094: PortalContext portalContext, PortletDescriptor pDescriptor,
095: Logger logger) {
096:
097: _req = req;
098: _res = res;
099: _pContReq = pContReq;
100: _pContRes = pContRes;
101: _attributes = new HashMap();
102: _context = context;
103: _portalContext = portalContext;
104: _pDescriptor = pDescriptor;
105: _logger = logger;
106:
107: if (_pContReq.getUserInfo() != null) {
108: _attributes.put(USER_INFO, _pContReq.getUserInfo());
109: }
110: _attributes.put(PortletRequestConstants.SSO_TOKEN, _pContReq
111: .getSSOToken());
112:
113: // Sets entity ID in thread local
114: EntityIDThreadLocal.set(pContReq.getEntityID());
115:
116: //Sets the portlet name as an attribute on request
117: this .setAttribute(PortletRequestConstants.PORTLET_NAME,
118: pContReq.getPortletName());
119:
120: // Sets req and res in attributes
121: // Note: in the case of supporting distributed system, set the
122: // request violates the spec, since all objects should be
123: // serializable. The setAttribute() method may need to do some
124: // special checking.
125: this .setAttribute(PortletRequestConstants.HTTP_SERVLET_REQUEST,
126: _req);
127: this .setAttribute(
128: PortletRequestConstants.HTTP_SERVLET_RESPONSE, _res);
129:
130: }
131:
132: /**
133: * Clears the global variables.
134: */
135: void clear() {
136: _req = null;
137: _res = null;
138: _pContReq = null;
139: _pContRes = null;
140: _attributes = null;
141: _context = null;
142: _portalContext = null;
143: _pDescriptor = null;
144: _logger = null;
145: EntityIDThreadLocal.set(null);
146: }
147:
148: /**
149: * Returns the current mode of the portlet.
150: *
151: * @return the portlet mode
152: */
153: public PortletMode getPortletMode() {
154: // real implementation is in ActionRequestImpl and RenderRequestImpl
155: return null;
156: }
157:
158: /**
159: * Returns the current window state of the portlet.
160: *
161: * @return the window state
162: */
163:
164: public WindowState getWindowState() {
165: // real implementation is in ActionRequestImpl and RenderRequestImpl
166: return null;
167: }
168:
169: /**
170: * Returns true, if the given window state is valid
171: * to be set for this portlet in the context
172: * of the current request.
173: *
174: * @param state window state to check
175: *
176: * @return true, if it is valid for this portlet
177: * entity in this request to change to the
178: * given window state
179: *
180: * @see ActionRequest#setWindowState
181: */
182: public boolean isWindowStateAllowed(WindowState state) {
183:
184: boolean retVal = false;
185: com.sun.portal.container.WindowState newState = new com.sun.portal.container.WindowState(
186: state.toString());
187:
188: if (_pContReq.getAllowableWindowState().contains(newState)) {
189: retVal = true;
190: }
191:
192: return retVal;
193:
194: }
195:
196: /**
197: * Returns true, if the given portlet mode is a valid
198: * one to set for this portlet in the context
199: * of the current request.
200: *
201: * @param mode portlet mode to check
202: *
203: * @return true, if it is valid for this portlet
204: * entity in this request to change to the
205: * given portlet mode
206: *
207: * @see ActionRequest#setPortletMode
208: */
209:
210: public boolean isPortletModeAllowed(PortletMode portletMode) {
211:
212: boolean isAllowed = false;
213:
214: com.sun.portal.container.ChannelMode newMode = new com.sun.portal.container.ChannelMode(
215: portletMode.toString());
216:
217: // check if the new mode is allowed in the portal
218: if (_pContReq.getAllowableChannelMode().contains(newMode)) {
219: if (portletMode.equals(PortletMode.VIEW)) {
220: isAllowed = true;
221: }
222: // check if portlet mode is allowed in the container
223: else if (_pDescriptor != null) {
224:
225: String mimeType = getResponseContentType();
226: List supportedPortletModes = _pDescriptor
227: .getSupportedPortletModes(mimeType);
228:
229: if (supportedPortletModes != null) {
230: for (int i = 0; i < supportedPortletModes.size()
231: && !isAllowed; i++) {
232: String mode = (String) supportedPortletModes
233: .get(i);
234: if (portletMode.toString().equalsIgnoreCase(
235: mode)) {
236: isAllowed = true;
237: }
238: }
239: }
240: }
241: }
242:
243: return isAllowed;
244: }
245:
246: /**
247: * Returns the preferences object associated with the portlet.
248: * <p>
249: * @return the portlet preferences
250: */
251: public PortletPreferences getPreferences() {
252: return _pContReq.getPortletPreferences();
253: }
254:
255: /**
256: * Returns the current portlet session or, if there is no current session,
257: * creates one and returns the new session.
258: *
259: * Creating a new portlet session will result in creating
260: * a new <code>HttpSession</code> on which the portlet session is
261: * based on.
262: *
263: * @return the portlet session
264: */
265: public PortletSession getPortletSession() {
266: return getPortletSession(true);
267: }
268:
269: /**
270: * Returns the current portlet session or, if there is no current session
271: * and the given flag is <CODE>true</CODE>, it creates one and returns
272: * the new session.
273: *
274: * <P>
275: * If the given flag is <CODE>false</CODE> and there is no current
276: * portlet session, this method returns <CODE>null</CODE>.
277: *
278: * Creating a new portlet session will result in creating
279: * a new <code>HttpSession</code> on which the portlet session is based on.
280: *
281: * @param create
282: * <CODE>true</CODE> to create a news session, <BR>
283: * <CODE>false</CODE> to return <CODE>null</CODE> of there
284: * is no current session
285: * @return the portlet session
286: */
287: public PortletSession getPortletSession(boolean create) {
288: PortletSession portletSession = null;
289:
290: HttpSession session = null;
291: try {
292: session = _req.getSession(create);
293: } catch (IllegalStateException ise) {
294: //TBD: IllegalStateException should not be thrown here and
295: // there has been a S1AS bug #4812839 filed against this.
296: }
297:
298: if (session != null) {
299:
300: String session_id = (String) _req
301: .getAttribute(HTTP_SESSION_ID);
302: String sessionInvalid = (String) _req
303: .getAttribute(SESSION_INVALID);
304:
305: if (!session.getId().equals(session_id)
306: && sessionInvalid.equals("true")) {
307: // new user login, need to invalidate the existing
308: // HttpSession object and create a new one
309: session.invalidate();
310: session = _req.getSession(create);
311: }
312:
313: if (session != null) {
314: portletSession = new PortletSessionImpl(session,
315: _context);
316: }
317: }
318: return portletSession;
319: }
320:
321: /**
322: * Returns the name of the authentication scheme used to protect the
323: * connection between client and portal,
324: * for example, <code>BASIC_AUTH</code>, <code>CLIENT_CERT_AUTH</code>,
325: * a custom one or <code>null</code> if there was no authentication.
326: *
327: * @return one of the static members <code>BASIC_AUTH</code>,
328: * <code>FORM_AUTH</code>, <code>CLIENT_CERT_AUTH</code>,
329: * <code>DIGEST_AUTH</code> (suitable for == comparison)
330: * indicating the authentication scheme, a custom
331: * one, or
332: * <code>null</code> if the request was
333: * not authenticated.
334: */
335: public String getAuthType() {
336: return _req.getAuthType();
337: }
338:
339: /**
340: * Returns the login of the user making this request, if the user
341: * has been authenticated, or null if the user has not been authenticated.
342: *
343: * @return a <code>String</code> specifying the login
344: * of the user making this request, or <code>null</code
345: * if the user login is not known
346: *
347: */
348: public String getRemoteUser() {
349: return _pContReq.getUserID();
350: }
351:
352: /**
353: * Returns a java.security.Principal object containing the name of the
354: * current authenticated user.
355: *
356: * @return a <code>java.security.Principal</code> containing
357: * the name of the user making this request;
358: * <code>null</code> if the user has not been
359: * authenticated
360: */
361: public java.security.Principal getUserPrincipal() {
362: java.security.Principal retUserPrincipal = null;
363:
364: if (_req != null) {
365: retUserPrincipal = _req.getUserPrincipal();
366: /* Where _req equals HttpServletRequest */
367: }
368: return retUserPrincipal;
369: }
370:
371: /**
372: * Returns a boolean indicating whether the authenticated user is
373: * included in the specified logical "role". Roles and role
374: * membership
375: * can be defined using deployment descriptors. If the user has
376: * not been authenticated, the method returns <code>false</code>.
377: *
378: * @param role a <code>String</code> specifying the name
379: * of the role
380: *
381: * @return a <code>boolean</code> indicating whether
382: * the user making this request belongs to a given role;
383: * <code>false</code> if the user has not been
384: * authenticated
385: */
386: public boolean isUserInRole(String role) {
387: boolean isInRole = false;
388: List refDescriptors = _pDescriptor
389: .getSecurityRoleRefDescriptors();
390: List secRoleNames = _pContReq.getRoles();
391:
392: if (secRoleNames != null) {
393:
394: // Loop through security-role-refs for role names and links,
395: // and compare the role-link with the roles supported from
396: // the portal side.
397: for (int i = 0; i < refDescriptors.size() && !isInRole; i++) {
398: SecurityRoleRefDescriptor refDescriptor = (SecurityRoleRefDescriptor) refDescriptors
399: .get(i);
400:
401: String roleName = refDescriptor.getRoleName();
402: String roleLink = refDescriptor.getRoleLink();
403:
404: if (!role.equalsIgnoreCase(roleName)) {
405: continue;
406: }
407: for (int j = 0; j < secRoleNames.size() && !isInRole; j++) {
408: String secRoleName = (String) secRoleNames.get(j);
409:
410: if (roleLink != null) {
411: if (secRoleName.equalsIgnoreCase(roleLink)) {
412: isInRole = true;
413: }
414: } else if (secRoleName.equalsIgnoreCase(roleName)) {
415: isInRole = true;
416: }
417: }
418: }
419: }
420:
421: return isInRole;
422: }
423:
424: /**
425: *
426: * Returns the value of the named attribute as an <code>Object</code>,
427: * or <code>null</code> if no attribute of the given name exists.
428: *
429: *
430: * <p>Attribute names should follow the same conventions as package
431: * names. This specification reserves names matching <code>java.*</code>,
432: * and <code>javax.*</code>.
433: *
434: * In a distributed portlet web application the <code>Object</code>
435: * needs to be serializable.
436: *
437: * @param name a <code>String</code> specifying the name of
438: * the attribute
439: *
440: * @return an <code>Object</code> containing the value
441: * of the attribute, or <code>null</code> if
442: * the attribute does not exist
443: *
444: * @exception java.lang.IllegalArgumentException
445: * if name is <code>null</code>.
446: */
447: public Object getAttribute(String name) {
448: if (name == null) {
449: throw new IllegalArgumentException(
450: "Attribute name should not be null.");
451: }
452:
453: return _attributes.get(name);
454: }
455:
456: /**
457: * Returns an <code>Enumeration</code> containing the
458: * names of the attributes available to this request.
459: * This method returns an empty <code>Enumeration</code>
460: * if the request has no attributes available to it.
461: *
462: *
463: * @return an <code>Enumeration</code> of strings
464: * containing the names
465: * of the request's attributes, or an empty
466: * <code>Enumeration</code> if the request
467: * has no attributes available to it.
468: *
469: */
470: public Enumeration getAttributeNames() {
471:
472: return Collections.enumeration(_attributes.keySet());
473: }
474:
475: /**
476: * Returns the value of a request parameter as a <code>String</code>,
477: * or <code>null</code> if the parameter does not exist. Request parameters
478: * are extra information sent with the request. The returned parameter
479: * are "x-www-form-urlencoded" decoded.
480: * <p>
481: * Only parameters targeted to the current portlet are accessible.
482: *
483: * <p>This method should only be used when the
484: * parameter has only one value. If the parameter might have
485: * more than one value, use {@link #getParameterValues}.
486: *
487: * <p>If this method is used with a multivalued
488: * parameter, the value returned is equal to the first value
489: * in the array returned by <code>getParameterValues</code>.
490: *
491: *
492: * @param name a <code>String</code> specifying the
493: * name of the parameter
494: *
495: * @return a <code>String</code> representing the
496: * single value of the parameter
497: *
498: * @see #getParameterValues
499: *
500: * @exception java.lang.IllegalArgumentException
501: * if name is <code>null</code>.
502: *
503: */
504: public String getParameter(String name) {
505: Map map = getParameterMap();
506: String retVal = null;
507:
508: if (name == null) {
509: throw new IllegalArgumentException(
510: "Parameter name should not be null.");
511: }
512:
513: if (map != null) {
514: Object value = map.get(name);
515: if (value != null) {
516: if (value instanceof String) {
517: retVal = (String) value;
518: } else {
519: retVal = ((String[]) value)[0];
520: }
521: }
522: }
523:
524: return retVal;
525: }
526:
527: /**
528: *
529: * Returns an <code>Enumeration</code> of <code>String</code>
530: * objects containing the names of the parameters contained
531: * in this request. If the request has
532: * no parameters, the method returns an
533: * empty <code>Enumeration</code>.
534: *
535: * @return an <code>Enumeration</code> of <code>String</code>
536: * objects, each <code>String</code> containing
537: * the name of a request parameter; or an
538: * empty <code>Interator</code> if the
539: * request has no parameters
540: *
541: */
542: public Enumeration getParameterNames() {
543: Map map = getParameterMap();
544:
545: return Collections.enumeration(map.keySet());
546: }
547:
548: /**
549: * Returns an array of <code>String</code> objects containing
550: * all of the values the given request parameter has, or
551: * <code>null</code> if the parameter does not exist.
552: * The returned parameters are "x-www-form-urlencoded" decoded.
553: * <p>If the parameter has a single value, the array has a length
554: * of 1.
555: *
556: * @param name a <code>String</code> containing the name of
557: * the parameter whose value is requested
558: *
559: * @return an array of <code>String</code> objects
560: * containing the parameter's values
561: *
562: * @see #getParameter
563: *
564: * @exception java.lang.IllegalArgumentException
565: * if name is <code>null</code>.
566: */
567: public String[] getParameterValues(String name) {
568: Map map = getParameterMap();
569: String[] retVals = null;
570:
571: if (name == null) {
572: throw new IllegalArgumentException(
573: "Parameter name should not be null.");
574: }
575:
576: if (map != null) {
577: Object value = map.get(name);
578: if (value != null) {
579: if (value instanceof String) {
580: retVals = new String[] { ((String) value) };
581: } else {
582: retVals = ((String[]) value);
583: }
584: }
585: }
586:
587: return retVals;
588: }
589:
590: /**
591: * Returns a <code>Map</code> of the parameters of this request.
592: * Request parameters are extra information sent with the request.
593: * The returned parameters are "x-www-form-urlencoded" decoded.
594: * <p>
595: * The values in the returned <code>Map</code> are from type
596: * String array (<code>String[]</code>).
597: * <p>
598: * If no parameters exist this method returns an empty <code>Map</code>.
599: *
600: * @return an immutable java.util.Map containing parameter names as
601: * keys and parameter values as map values. The keys in the parameter
602: * map are of type String. The values in the parameter map are of type
603: * String array.
604: *
605: */
606: public java.util.Map getParameterMap() {
607: //real implmentation is in ActionRequestImpl and RenderRequestImpl
608: return Collections.EMPTY_MAP;
609: }
610:
611: /**
612: * Returns the preferred Locale in which the portal will accept content.
613: * The Locale may be based on the Accept-Language header of the client.
614: *
615: */
616: public java.util.Locale getLocale() {
617: return _pContReq.getLocale();
618: }
619:
620: /**
621: * Returns an Enumeration of Locale objects indicating, in decreasing
622: * order starting with the preferred locale in which the portal will
623: * accept content for this request.
624: * The Locales may be based on the Accept-Language header of the client.
625: *
626: * @return an Enumeration of Locales, in decreasing order, in which
627: * the portal will accept content for this request
628: */
629:
630: public java.util.Enumeration getLocales() {
631: List localeList = new ArrayList(1);
632: localeList.add(_pContReq.getLocale());
633:
634: return Collections.enumeration(localeList);
635: }
636:
637: /**
638: * Returns the name of the scheme used to make this request.
639: * For example, <code>http</code>, <code>https</code>, or <code>ftp</code>.
640: * Different schemes have different rules for constructing URLs,
641: * as noted in RFC 1738.
642: *
643: * @return a <code>String</code> containing the name
644: * of the scheme used to make this request
645: */
646:
647: public String getScheme() {
648: return _req.getScheme();
649: }
650:
651: /**
652: * Returns the host name of the server that received the request.
653: *
654: * @return a <code>String</code> containing the name
655: * of the server to which the request was sent
656: */
657:
658: public String getServerName() {
659: return _req.getServerName();
660: }
661:
662: /**
663: * Returns the port number on which this request was received.
664: *
665: * @return an integer specifying the port number
666: */
667:
668: public int getServerPort() {
669: return _req.getServerPort();
670: }
671:
672: /**
673: * Returns a boolean indicating whether this request was made
674: * using a secure channel between client and portal, such as HTTPS.
675: *
676: * @return true, if the request was made using a secure channel.
677: */
678: public boolean isSecure() {
679: return _req.isSecure();
680: }
681:
682: /**
683: *
684: * Stores an attribute in this request.
685: *
686: * <p>Attribute names should follow the same conventions as
687: * package names. Names beginning with <code>java.*</code>,
688: * <code>javax.*</code>, and <code>com.sun.*</code>, are
689: * reserved for use by Sun Microsystems.
690: * <br> If the value passed into this method is <code>null</code>,
691: * the effect is the same as calling {@link #removeAttribute}.
692: *
693: * @param name a <code>String</code> specifying
694: * the name of the attribute
695: *
696: * @param o the <code>Object</code> to be stored
697: *
698: * @exception java.lang.IllegalArgumentException
699: * if name is <code>null</code>.
700: */
701: public void setAttribute(String name, Object o) {
702: if (name == null) {
703: throw new IllegalArgumentException(
704: "Can not set attribue with null name.");
705: }
706:
707: if (o == null) {
708: _attributes.remove(name);
709: } else {
710: _attributes.put(name, o);
711: }
712:
713: }
714:
715: /**
716: *
717: * Removes an attribute from this request. This method is not
718: * generally needed as attributes only persist as long as the request
719: * is being handled.
720: *
721: * <p>Attribute names should follow the same conventions as
722: * package names. Names beginning with <code>java.*</code>,
723: * <code>javax.*</code>, and <code>com.sun.*</code>, are
724: * reserved for use by Sun Microsystems.
725: *
726: *
727: * @param name a <code>String</code> specifying
728: * the name of the attribute to remove
729: *
730: * @exception java.lang.IllegalArgumentException
731: * if name is <code>null</code>.
732: */
733: public void removeAttribute(String name) {
734: if (name == null) {
735: throw new IllegalArgumentException(
736: "Attribute name should not be null.");
737: }
738:
739: _attributes.remove(name);
740: }
741:
742: /**
743: * Returns the portal preferred content type of the response.
744: *
745: * The content type only includes the MIME type, not the
746: * character set.
747: * <p>
748: * Only content types that the portlet has defined in its
749: * deployment descriptor are valid return values for
750: * this method call. If the portlet has defined
751: * <code>'*'</code> or <code>'* / *'</code> as supported content
752: * types, these may also be valid return values.
753: *
754: * @return prefered MIME type of the response
755: */
756: public String getResponseContentType() {
757: String responseContentType = _pContReq.getResponseContentType();
758: if (responseContentType == null
759: || responseContentType.length() == 0) {
760: responseContentType = DEFAULT_CONTENT_TYPE;
761: }
762: return responseContentType;
763: }
764:
765: /**
766: * Gets a list of content types which the portal accepts for the response.
767: * This list is ordered with the most preferable types listed first.
768: * <p>
769: * The content type only includes the MIME type, not the
770: * character set.
771: * <p>
772: * Only content types that the portlet has defined in its
773: * deployment descriptor are valid return values for
774: * this method call. If the portlet has defined
775: * <code>'*'</code> or <code>'* / *'</code> as supported content
776: * types, these may also be valid return values.
777: *
778: * @return ordered list of MIME types for the response
779: */
780: public java.util.Enumeration getResponseContentTypes() {
781: List contentTypes = _pContReq.getAllowableContentType();
782: List mimeTypes = _pDescriptor.getSupportedMimeTypes();
783: List returnList = new ArrayList();
784: boolean stop = false;
785:
786: for (int i = 0; i < contentTypes.size() && !stop; i++) {
787: String contentType = ((String) contentTypes.get(i))
788: .toLowerCase();
789:
790: for (int j = 0; j < mimeTypes.size() && !stop; j++) {
791: String mimeType = ((String) mimeTypes.get(j))
792: .toLowerCase();
793:
794: if (mimeType.equals("*/*")) {
795: returnList = contentTypes;
796: stop = true;
797: } else if (contentType.equals(mimeType)) {
798: returnList.add(contentType);
799: } else if (mimeType.equals("text/*")
800: && contentType.startsWith("text/")) {
801: returnList.add(contentType);
802: }
803: }
804: }
805:
806: return Collections.enumeration(returnList);
807: }
808:
809: /**
810: *
811: * Returns the value of the specified client request property
812: * as a <code>String</code>. If the request did not include a property
813: * of the specified name, this method returns <code>null</code>.
814: *
815: * A portlet can access portal/portlet-container specific properties
816: * through this method and, if available, the
817: * headers of the HTTP client request.
818: * <p>
819: * This method should only be used if the
820: * property has only one value. If the property might have
821: * more than one value, use {@link #getProperties}.
822: * <p>
823: * If this method is used with a multivalued
824: * parameter, the value returned is equal to the first value
825: * in the enumeration returned by <code>getProperties</code>.
826: *
827: * @param name a <code>String</code> specifying the
828: * property name
829: *
830: * @return a <code>String</code> containing the
831: * value of the requested
832: * property, or <code>null</code>
833: * if the request does not
834: * have a property of that name
835: * @exception java.lang.IllegalArgumentException
836: * if name is <code>null</code>.
837: */
838:
839: public String getProperty(String name) {
840: if (name == null) {
841: throw new IllegalArgumentException(
842: "Property name should not be null.");
843: }
844:
845: return _req.getHeader(name);
846: }
847:
848: /**
849: *
850: * Returns all the values of the specified request property
851: * as a <code>Enumeration</code> of <code>String</code> objects.
852: *
853: * <p>If the request did not include any propertys
854: * of the specified name, this method returns an empty
855: * <code>Enumeration</code>.
856: * The property name is case insensitive. You can use
857: * this method with any request property.
858: *
859: * @param name a <code>String</code> specifying the
860: * property name
861: *
862: * @return a <code>Enumeration</code> containing
863: * the values of the requested property. If
864: * the request does not have any properties of
865: * that name return an empty Enumeration.
866: *
867: * @exception java.lang.IllegalArgumentException
868: * if name is <code>null</code>.
869: */
870: public Enumeration getProperties(String name) {
871: if (name == null) {
872: throw new IllegalArgumentException(
873: "Property name should not be null.");
874: }
875:
876: return _req.getHeaders(name);
877: }
878:
879: /**
880: *
881: * Returns a <code>Enumeration</code> of all the property names
882: * this request contains. If the request has no
883: * properties, this method returns an empty enumeration.
884: *
885: *
886: * @return an enumeration of all the
887: * property names sent with this
888: * request; if the request has
889: * no propertys, an empty enumeration
890: */
891: public Enumeration getPropertyNames() {
892: return _req.getHeaderNames();
893: }
894:
895: /**
896: * Returns the context of the calling portal.
897: *
898: * @return the context of the calling portal
899: */
900: public PortalContext getPortalContext() {
901: return _portalContext;
902: }
903:
904: /**
905: *
906: * Returns the context path which is the path prefix associated with the deployed
907: * portlet application. If the portlet application is rooted at the
908: * base of the web server URL namespace (also known as "default" context),
909: * this path must be an empty string. Otherwise, it must be the path the
910: * portlet application is rooted to, the path must start with a '/' and
911: * it must not end with a '/' character.
912: * <p>
913: * To encode a URL the {@link PortletResponse#encodeURL} method must be used.
914: *
915: * @return a <code>String</code> specifying the
916: * portion of the request URL that indicates the context
917: * of the request
918: *
919: * @see RenderResponse#encodeURL
920: */
921:
922: public String getContextPath() {
923: return (String) _req.getAttribute(CONTEXT_PATH_ATTRIBUTE);
924: }
925:
926: /**
927: *
928: * Returns the session ID indicated in the client request.
929: * This session ID may not be a valid one, it may be an old
930: * one that has expired or has been invalidated.
931: * If the client request
932: * did not specify a session ID, this method returns
933: * <code>null</code>.
934: *
935: * @return a <code>String</code> specifying the session
936: * ID, or <code>null</code> if the request did
937: * not specify a session ID
938: *
939: * @see #isRequestedSessionIdValid
940: *
941: */
942: public String getRequestedSessionId() {
943: return _req.getRequestedSessionId();
944: }
945:
946: /**
947: *
948: * Checks whether the requested session ID is still valid.
949: *
950: * @return <code>true</code> if this
951: * request has an id for a valid session
952: * in the current session context;
953: * <code>false</code> otherwise
954: *
955: * @see #getRequestedSessionId
956: * @see #getPortletSession
957: */
958: public boolean isRequestedSessionIdValid() {
959: return _req.isRequestedSessionIdValid();
960: }
961:
962: /*
963: * Implements <code>Pricipal</code> for a user.
964: */
965: class BasicPrincipal implements Principal {
966: private String user;
967:
968: BasicPrincipal(String user) {
969: this .user = user;
970: }
971:
972: public boolean equals(Object another) {
973: return (another instanceof Principal && ((Principal) another)
974: .getName().equals(user));
975: }
976:
977: public String getName() {
978: return user;
979: }
980:
981: public String toString() {
982: return getName();
983: }
984: }
985: }
|