001: /*
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: PortletRequestImpl.java 6437 2008-03-18 10:24:04Z wehrens $
004: */
005: package org.gridsphere.portlet.impl;
006:
007: import org.gridsphere.portlet.service.spi.PortletServiceFactory;
008: import org.gridsphere.portletcontainer.PortletPreferencesManager;
009: import org.gridsphere.services.core.portal.PortalConfigService;
010: import org.gridsphere.services.core.user.User;
011: import org.gridsphere.services.core.user.UserPrincipal;
012:
013: import javax.portlet.*;
014: import javax.servlet.ServletInputStream;
015: import javax.servlet.http.HttpServletRequest;
016: import javax.servlet.http.HttpServletRequestWrapper;
017: import javax.servlet.http.HttpSession;
018: import java.io.BufferedReader;
019: import java.io.File;
020: import java.io.IOException;
021: import java.io.UnsupportedEncodingException;
022: import java.util.*;
023:
024: /**
025: * The <CODE>PortletRequest</CODE> defines the base interface to provide client
026: * request information to a portlet. The portlet container uses two specialized
027: * versions of this interface when invoking a portlet, <CODE>ActionRequest</CODE>
028: * and <CODE>RenderRequest</CODE>. The portlet container creates these objects and
029: * passes them as arguments to the portlet's <CODE>processAction</CODE> and
030: * <CODE>render</CODE> methods.
031: *
032: * @see ActionRequest
033: * @see RenderRequest
034: */
035: public abstract class PortletRequestImpl extends
036: HttpServletRequestWrapper implements PortletRequest {
037:
038: protected PortletContext portletContext = null;
039: protected String contextPath = "/";
040: protected boolean hasReader = false;
041: protected boolean included = false;
042:
043: private PortletSession portletSession = null;
044: protected GridSphereParameters portalParameters = null;
045:
046: /**
047: * Constructor creates a proxy for a HttpServletRequest
048: * All PortletRequest objects come from request or session attributes
049: *
050: * @param req the HttpServletRequest
051: * @param portletContext the portlet context
052: */
053: public PortletRequestImpl(HttpServletRequest req,
054: PortletContext portletContext) {
055: super (req);
056: Map<String, String[]> origParams = new HashMap<String, String[]>();
057: this .portletContext = portletContext;
058: contextPath = this .portletContext.getRealPath("");
059: int l = contextPath.lastIndexOf(File.separator);
060: contextPath = contextPath.substring(l);
061: // handle windows file.separator "\" to "/"
062: if (contextPath.indexOf("\\") != -1) {
063: contextPath = contextPath.replace('\\', '/');
064: }
065:
066: Map<String, List> map = (Map<String, List>) getHttpServletRequest()
067: .getAttribute(SportletProperties.PORTAL_PROPERTIES);
068: if (map == null) {
069: map = new HashMap<String, List>();
070: getHttpServletRequest()
071: .setAttribute(SportletProperties.PORTAL_PROPERTIES,
072: new HashMap());
073: }
074:
075: Enumeration e = getHttpServletRequest().getHeaderNames();
076: while (e.hasMoreElements()) {
077: String name = (String) e.nextElement();
078: Enumeration headersEnum = getHttpServletRequest()
079: .getHeaders(name);
080: List<String> vals = new ArrayList<String>();
081: while (headersEnum.hasMoreElements()) {
082: String val = (String) headersEnum.nextElement();
083: vals.add(val);
084: }
085: map.put(name, vals);
086: }
087: getHttpServletRequest().setAttribute(
088: SportletProperties.PORTAL_PROPERTIES, map);
089:
090: for (Enumeration parameters = super .getParameterNames(); parameters
091: .hasMoreElements();) {
092: String paramName = (String) parameters.nextElement();
093: String[] paramValues = (String[]) super
094: .getParameterValues(paramName);
095: origParams.put(paramName, paramValues);
096: }
097:
098: portalParameters = new GridSphereParameters(origParams);
099:
100: /*
101: System.err.println("============================= PortletRequestImpl =====================================");
102: if (getAttribute(SportletProperties.PORTLET_ACTION_METHOD) != null) {
103: System.err.println("in action");
104: } else {
105: System.err.println("in render");
106: }
107: System.err.println("query string=" + super.getQueryString());
108:
109: System.err.println("Actual HTTP parameters");
110: Iterator it = origParams.keySet().iterator();
111: while (it.hasNext()) {
112:
113: String paramName = (String)it.next();
114: String[] paramValues = (String[])origParams.get(paramName);
115:
116: System.err.println("\nname=" + paramName + "\nvalues=");
117: for (int i = 0; i < paramValues.length; i++) {
118: System.err.print(" " + paramValues[i]);
119: }
120: }
121:
122: System.err.println("\n\nPortlet parameters for portlet " );
123: for (Enumeration parameters = getParameterNames(); parameters.hasMoreElements();) {
124: String paramName = (String)parameters.nextElement();
125: String[] paramValues = (String[])getParameterValues(paramName);
126: System.err.println("\nname=" + paramName + "\nvalues=");
127: for (int i = 0; i < paramValues.length; i++) {
128: System.err.print(" " + paramValues[i]);
129: }
130: }
131:
132: System.err.println("\n===================================================================");
133: */
134:
135: }
136:
137: public void setIncluded(boolean included) {
138: this .included = included;
139: }
140:
141: public boolean isIncluded() {
142: return included;
143: }
144:
145: public void addRenderParams(Map renderParams) {
146: portalParameters.addRenderParams(renderParams);
147: }
148:
149: /**
150: * Is this attribute name a reserved name (by the J2EE spec)?.
151: * Reserved names begin with "java." or "javax.".
152: *
153: * @param name the attribute name to test
154: * @return true if the supplied name is reserved
155: */
156: private boolean isNameReserved(String name) {
157: return name.startsWith("java.") || name.startsWith("javax.");
158: }
159:
160: /**
161: * Returns true, if the given window state is valid
162: * to be set for this portlet in the context
163: * of the current request.
164: *
165: * @param state window state to checked
166: * @return true, if it is valid for this portlet
167: * in this request to change to the
168: * given window state
169: */
170: public boolean isWindowStateAllowed(WindowState state) {
171: PortalContext context = (PortalContext) getAttribute(SportletProperties.PORTAL_CONTEXT);
172: Enumeration statesEnum = context.getSupportedWindowStates();
173: while (statesEnum.hasMoreElements()) {
174: WindowState s = (WindowState) statesEnum.nextElement();
175: if (s.equals(state))
176: return true;
177: }
178: return false;
179: }
180:
181: /**
182: * Returns true, if the given portlet mode is a valid
183: * one to set for this portlet in the context
184: * of the current request.
185: *
186: * @param mode portlet mode to check
187: * @return true, if it is valid for this portlet
188: * in this request to change to the
189: * given portlet mode
190: */
191: public boolean isPortletModeAllowed(PortletMode mode) {
192: Set modesAllowed = (Set) this .getHttpServletRequest()
193: .getAttribute(SportletProperties.ALLOWED_MODES);
194: if (modesAllowed.contains(mode.toString()))
195: return true;
196: return false;
197: }
198:
199: /**
200: * Returns the current portlet mode of the portlet.
201: *
202: * @return the portlet mode
203: */
204: public PortletMode getPortletMode() {
205: return (PortletMode) getAttribute(SportletProperties.PORTLET_MODE);
206: }
207:
208: /**
209: * Returns the current window state of the portlet.
210: *
211: * @return the window state
212: */
213: public WindowState getWindowState() {
214: return (WindowState) getAttribute(SportletProperties.PORTLET_WINDOW);
215: }
216:
217: /**
218: * Returns the preferences object associated with the portlet.
219: *
220: * @return the portlet preferences
221: */
222: public PortletPreferences getPreferences() {
223: PortletPreferencesManager prefsManager = (PortletPreferencesManager) getAttribute(SportletProperties.PORTLET_PREFERENCES_MANAGER);
224: return prefsManager.getPortletPreferences();
225: }
226:
227: /**
228: * Returns the current portlet session or, if there is no current session,
229: * creates one and returns the new session.
230: * <p/>
231: * Creating a new portlet session will result in creating
232: * a new <code>HttpSession</code> on which the portlet session is based on.
233: *
234: * @return the portlet session
235: */
236: public PortletSession getPortletSession() {
237: return getPortletSession(true);
238: }
239:
240: /**
241: * Returns the current portlet session or, if there is no current session
242: * and the given flag is <CODE>true</CODE>, creates one and returns
243: * the new session.
244: * <p/>
245: * If the given flag is <CODE>false</CODE> and there is no current
246: * portlet session, this method returns <CODE>null</CODE>.
247: * <p/>
248: * Creating a new portlet session will result in creating
249: * a new <code>HttpSession</code> on which the portlet session is based on.
250: *
251: * @param create <CODE>true</CODE> to create a new session, <BR>
252: * <CODE>false</CODE> to return <CODE>null</CODE> if there
253: * is no current session
254: * @return the portlet session
255: */
256: public PortletSession getPortletSession(boolean create) {
257: // check if the session was invalidated
258: HttpSession httpSession = this .getHttpServletRequest()
259: .getSession(false);
260:
261: if ((portletSession != null) && (httpSession == null)) {
262: portletSession = null;
263: } else if (httpSession != null) {
264: create = true;
265: }
266:
267: if (create && (portletSession == null)) {
268: httpSession = this .getHttpServletRequest().getSession(
269: create);
270: if (httpSession != null) {
271: portletSession = new PortletSessionImpl(this
272: .getHttpServletRequest(), httpSession,
273: portletContext);
274: }
275: }
276:
277: return portletSession;
278: }
279:
280: /**
281: * Returns the value of the specified request property
282: * as a <code>String</code>. If the request did not include a property
283: * of the specified name, this method returns <code>null</code>.
284: * <p/>
285: * A portlet can access portal/portlet-container specific properties
286: * through this method and, if available, the
287: * headers of the HTTP client request.
288: * <p/>
289: * This method should only be used if the
290: * property has only one value. If the property might have
291: * more than one value, use {@link #getProperties}.
292: * <p/>
293: * If this method is used with a multivalued
294: * parameter, the value returned is equal to the first value
295: * in the Enumeration returned by <code>getProperties</code>.
296: *
297: * @param name a <code>String</code> specifying the
298: * property name
299: * @return a <code>String</code> containing the
300: * value of the requested
301: * property, or <code>null</code>
302: * if the request does not
303: * have a property of that name.
304: * @throws IllegalArgumentException if name is <code>null</code>.
305: */
306: public String getProperty(String name) {
307: if (name == null)
308: throw new IllegalArgumentException("name is NULL");
309: Map props = (Map) getAttribute(SportletProperties.PORTAL_PROPERTIES);
310: Object o = props.get(name);
311: if (o instanceof String) {
312: return (String) o;
313: } else if (o instanceof List) {
314: List l = (List) o;
315: if (!l.isEmpty()) {
316: return (String) l.get(0);
317: }
318: }
319: return null;
320: }
321:
322: /**
323: * Returns all the values of the specified request property
324: * as a <code>Enumeration</code> of <code>String</code> objects.
325: * <p/>
326: * If the request did not include any propertys
327: * of the specified name, this method returns an empty
328: * <code>Enumeration</code>.
329: * The property name is case insensitive. You can use
330: * this method with any request property.
331: *
332: * @param name a <code>String</code> specifying the
333: * property name
334: * @return a <code>Enumeration</code> containing
335: * the values of the requested property. If
336: * the request does not have any properties of
337: * that name return an empty <code>Enumeration</code>.
338: * @throws IllegalArgumentException if name is <code>null</code>.
339: */
340: public java.util.Enumeration getProperties(String name) {
341: if (name == null)
342: throw new IllegalArgumentException("name is NULL");
343: Map props = (Map) getAttribute(SportletProperties.PORTAL_PROPERTIES);
344: Object o = props.get(name);
345: if (o instanceof List) {
346: List l = (List) o;
347: return new Enumerator(l.iterator());
348: }
349: return null;
350: }
351:
352: /**
353: * Returns a <code>Enumeration</code> of all the property names
354: * this request contains. If the request has no
355: * properties, this method returns an empty <code>Enumeration</code>.
356: *
357: * @return an <code>Enumeration</code> of all the
358: * property names sent with this
359: * request; if the request has
360: * no properties, an empty <code>Enumeration</code>.
361: */
362: public java.util.Enumeration getPropertyNames() {
363: Map props = (Map) getAttribute(SportletProperties.PORTAL_PROPERTIES);
364: return new Enumerator(props.keySet().iterator());
365: }
366:
367: /**
368: * Returns the context of the calling portal.
369: *
370: * @return the context of the calling portal
371: */
372: public PortalContext getPortalContext() {
373: return (PortalContext) getAttribute(SportletProperties.PORTAL_CONTEXT);
374: }
375:
376: /**
377: * Returns the name of the authentication scheme used for the
378: * connection between client and portal,
379: * for example, <code>BASIC_AUTH</code>, <code>CLIENT_CERT_AUTH</code>,
380: * a custom one or <code>null</code> if there was no authentication.
381: *
382: * @return one of the static members <code>BASIC_AUTH</code>,
383: * <code>FORM_AUTH</code>, <code>CLIENT_CERT_AUTH</code>,
384: * <code>DIGEST_AUTH</code> (suitable for == comparison)
385: * indicating the authentication scheme,
386: * a custom one, or
387: * <code>null</code> if the request was
388: * not authenticated.
389: */
390: public String getAuthType() {
391: return this .getHttpServletRequest().getAuthType();
392: }
393:
394: /**
395: * Returns the context path which is the path prefix associated with the deployed
396: * portlet application. If the portlet application is rooted at the
397: * base of the web server URL namespace (also known as "default" context),
398: * this path must be an empty string. Otherwise, it must be the path the
399: * portlet application is rooted to, the path must start with a '/' and
400: * it must not end with a '/' character.
401: * <p/>
402: * To encode a URL the {@link PortletResponse#encodeURL} method must be used.
403: *
404: * @return a <code>String</code> specifying the
405: * portion of the request URL that indicates the context
406: * of the request
407: * @see PortletResponse#encodeURL
408: */
409: public String getContextPath() {
410: return contextPath;
411: //return this.getHttpServletRequest().getContextPath();
412: }
413:
414: /**
415: * Returns the login of the user making this request, if the user
416: * has been authenticated, or null if the user has not been authenticated.
417: *
418: * @return a <code>String</code> specifying the login
419: * of the user making this request, or <code>null</code>
420: * if the user login is not known.
421: */
422: public String getRemoteUser() {
423: UserPrincipal userPrincipal = (UserPrincipal) getAttribute(SportletProperties.PORTLET_USER_PRINCIPAL);
424: return (userPrincipal != null) ? userPrincipal.getName() : this
425: .getHttpServletRequest().getRemoteUser();
426: }
427:
428: /**
429: * Returns a java.security.Principal object containing the name of the
430: * current authenticated user.
431: *
432: * @return a <code>java.security.Principal</code> containing
433: * the name of the user making this request, or
434: * <code>null</code> if the user has not been
435: * authenticated.
436: */
437: public java.security.Principal getUserPrincipal() {
438: UserPrincipal userPrincipal = (UserPrincipal) getAttribute(SportletProperties.PORTLET_USER_PRINCIPAL);
439: return (userPrincipal != null) ? userPrincipal : this
440: .getHttpServletRequest().getUserPrincipal();
441: }
442:
443: /**
444: * Returns a boolean indicating whether the authenticated user is
445: * included in the specified logical "role". Roles and role membership can be
446: * defined using deployment descriptors. If the user has not been
447: * authenticated, the method returns <code>false</code>.
448: *
449: * @param role a <code>String</code> specifying the name
450: * of the role
451: * @return a <code>boolean</code> indicating whether
452: * the user making this request belongs to a given role;
453: * <code>false</code> if the user has not been
454: * authenticated.
455: */
456: public boolean isUserInRole(String role) {
457: // TODO
458: // As specified in PLT-20-3, the <security-role-ref> mapping in portlet.xml must be used.
459: if (role.equals(""))
460: return true;
461: List roles = (List) getAttribute(SportletProperties.PORTLET_ROLE);
462: return (roles != null)
463: && (roles.contains(role) || (getUserPrincipal() != null)
464: && this .getHttpServletRequest().isUserInRole(
465: role));
466: }
467:
468: /**
469: * Returns the value of the named attribute as an <code>Object</code>,
470: * or <code>null</code> if no attribute of the given name exists.
471: * <p/>
472: * Attribute names should follow the same conventions as package
473: * names. This specification reserves names matching <code>java.*</code>,
474: * and <code>javax.*</code>.
475: * <p/>
476: * In a distributed portlet web application the <code>Object</code>
477: * needs to be serializable.
478: *
479: * @param name a <code>String</code> specifying the name of
480: * the attribute
481: * @return an <code>Object</code> containing the value
482: * of the attribute, or <code>null</code> if
483: * the attribute does not exist.
484: * @throws IllegalArgumentException if name is <code>null</code>.
485: */
486: public Object getAttribute(String name) {
487: if (name == null)
488: throw new IllegalArgumentException("name is NULL");
489: return this .getHttpServletRequest().getAttribute(name);
490: }
491:
492: /**
493: * Returns an <code>Enumeration</code> containing the
494: * names of the attributes available to this request.
495: * This method returns an empty <code>Enumeration</code>
496: * if the request has no attributes available to it.
497: *
498: * @return an <code>Enumeration</code> of strings
499: * containing the names
500: * of the request attributes, or an empty
501: * <code>Enumeration</code> if the request
502: * has no attributes available to it.
503: */
504: public java.util.Enumeration getAttributeNames() {
505: return this .getHttpServletRequest().getAttributeNames();
506: }
507:
508: /**
509: * Returns the value of a request parameter as a <code>String</code>,
510: * or <code>null</code> if the parameter does not exist. Request parameters
511: * are extra information sent with the request. The returned parameter
512: * are "x-www-form-urlencoded" decoded.
513: * <p/>
514: * Only parameters targeted to the current portlet are accessible.
515: * <p/>
516: * This method should only be used if the
517: * parameter has only one value. If the parameter might have
518: * more than one value, use {@link #getParameterValues}.
519: * <p/>
520: * If this method is used with a multivalued
521: * parameter, the value returned is equal to the first value
522: * in the array returned by <code>getParameterValues</code>.
523: *
524: * @param name a <code>String</code> specifying the
525: * name of the parameter
526: * @return a <code>String</code> representing the
527: * single value of the parameter
528: * @throws IllegalArgumentException if name is <code>null</code>.
529: * @see #getParameterValues
530: */
531: public String getParameter(String name) {
532: if (name == null)
533: throw new IllegalArgumentException("name is NULL");
534: hasReader = true;
535: Map map = this .getParameterMap();
536: Object val = map.get(name);
537: if (val != null) {
538: if (val instanceof String)
539: return (String) val;
540: if (val instanceof String[]) {
541: String[] s = (String[]) val;
542: return s[0];
543: }
544: return (String) val;
545: }
546: return null;
547: }
548:
549: /**
550: * Returns an <code>Enumeration</code> of <code>String</code>
551: * objects containing the names of the parameters contained
552: * in this request. If the request has
553: * no parameters, the method returns an
554: * empty <code>Enumeration</code>.
555: * <p/>
556: * Only parameters targeted to the current portlet are returned.
557: *
558: * @return an <code>Enumeration</code> of <code>String</code>
559: * objects, each <code>String</code> containing
560: * the name of a request parameter; or an
561: * empty <code>Enumeration</code> if the
562: * request has no parameters.
563: */
564: public java.util.Enumeration getParameterNames() {
565: hasReader = true;
566: return Collections.enumeration(this .getParameterMap().keySet());
567: }
568:
569: /**
570: * Returns an array of <code>String</code> objects containing
571: * all of the values the given request parameter has, or
572: * <code>null</code> if the parameter does not exist.
573: * The returned parameters are "x-www-form-urlencoded" decoded.
574: * <p/>
575: * If the parameter has a single value, the array has a length
576: * of 1.
577: *
578: * @param name a <code>String</code> containing the name of
579: * the parameter the value of which is requested
580: * @return an array of <code>String</code> objects
581: * containing the parameter values.
582: * @throws IllegalArgumentException if name is <code>null</code>.
583: * @see #getParameter
584: */
585: public String[] getParameterValues(String name) {
586: if (name == null)
587: throw new IllegalArgumentException("name is NULL");
588: hasReader = true;
589: Map map = this .getParameterMap();
590: return (String[]) map.get(name);
591: }
592:
593: /**
594: * Returns a <code>Map</code> of the parameters of this request.
595: * Request parameters are extra information sent with the request.
596: * The returned parameters are "x-www-form-urlencoded" decoded.
597: * <p/>
598: * The values in the returned <code>Map</code> are from type
599: * String array (<code>String[]</code>).
600: * <p/>
601: * If no parameters exist this method returns an empty <code>Map</code>.
602: *
603: * @return an immutable <code>Map</code> containing parameter names as
604: * keys and parameter values as map values, or an empty <code>Map</code>
605: * if no parameters exist. The keys in the parameter
606: * map are of type String. The values in the parameter map are of type
607: * String array (<code>String[]</code>).
608: */
609: public java.util.Map getParameterMap() {
610: hasReader = true;
611: return portalParameters.getParameterMap(
612: getHttpServletRequest(), getQueryString());
613: }
614:
615: /**
616: * Returns a boolean indicating whether this request was made
617: * using a secure channel between client and the portal, such as HTTPS.
618: *
619: * @return true, if the request was made using a secure channel.
620: */
621: public boolean isSecure() {
622: return this .getHttpServletRequest().isSecure();
623: }
624:
625: /**
626: * Stores an attribute in this request.
627: * <p/>
628: * <p>Attribute names should follow the same conventions as
629: * package names. Names beginning with <code>java.*</code>,
630: * <code>javax.*</code>, and <code>com.sun.*</code> are
631: * reserved for use by Sun Microsystems.
632: * <br> If the value passed into this method is <code>null</code>,
633: * the effect is the same as calling {@link #removeAttribute}.
634: *
635: * @param name a <code>String</code> specifying
636: * the name of the attribute
637: * @param o the <code>Object</code> to be stored
638: * @throws IllegalArgumentException if name is <code>null</code>.
639: */
640: public void setAttribute(String name, Object o) {
641: if (name == null)
642: throw new IllegalArgumentException("name is NULL");
643: if (o == null) {
644: this .removeAttribute(name);
645: } else {
646: this .getHttpServletRequest().setAttribute(name, o);
647: }
648: }
649:
650: /**
651: * Removes an attribute from this request. This method is not
652: * generally needed, as attributes only persist as long as the request
653: * is being handled.
654: * <p/>
655: * <p>Attribute names should follow the same conventions as
656: * package names. Names beginning with <code>java.*</code>,
657: * <code>javax.*</code>, and <code>com.sun.*</code> are
658: * reserved for use by Sun Microsystems.
659: *
660: * @param name a <code>String</code> specifying
661: * the name of the attribute to be removed
662: * @throws IllegalArgumentException if name is <code>null</code>.
663: */
664: public void removeAttribute(String name) {
665: if (name == null)
666: throw new IllegalArgumentException("name is NULL");
667: this .getHttpServletRequest().removeAttribute(name);
668: }
669:
670: /**
671: * Returns the session ID indicated in the client request.
672: * This session ID may not be a valid one, it may be an old
673: * one that has expired or has been invalidated.
674: * If the client request
675: * did not specify a session ID, this method returns
676: * <code>null</code>.
677: *
678: * @return a <code>String</code> specifying the session
679: * ID, or <code>null</code> if the request did
680: * not specify a session ID
681: * @see #isRequestedSessionIdValid
682: */
683: public String getRequestedSessionId() {
684: return this .getHttpServletRequest().getRequestedSessionId();
685: }
686:
687: /**
688: * Checks whether the requested session ID is still valid.
689: *
690: * @return <code>true</code> if this
691: * request has an id for a valid session
692: * in the current session context;
693: * <code>false</code> otherwise
694: * @see #getRequestedSessionId
695: * @see #getPortletSession
696: */
697: public boolean isRequestedSessionIdValid() {
698: return this .getHttpServletRequest().isRequestedSessionIdValid();
699: }
700:
701: /**
702: * Returns the portal preferred content type for the response.
703: * <p/>
704: * The content type only includes the MIME type, not the
705: * character set.
706: * <p/>
707: * Only content types that the portlet has defined in its
708: * deployment descriptor are valid return values for
709: * this method call. If the portlet has defined
710: * <code>'*'</code> or <code>'* / *'</code> as supported content
711: * types, these may also be valid return values.
712: *
713: * @return preferred MIME type of the response
714: */
715: public String getResponseContentType() {
716: SortedSet types = (SortedSet) getAttribute(SportletProperties.PORTLET_MIMETYPES);
717: if ((types == null) || (types.isEmpty()))
718: return null;
719: return (String) types.first();
720: }
721:
722: /**
723: * Gets a list of content types which the portal accepts for the response.
724: * This list is ordered with the most preferable types listed first.
725: * <p/>
726: * The content type only includes the MIME type, not the
727: * character set.
728: * <p/>
729: * Only content types that the portlet has defined in its
730: * deployment descriptor are valid return values for
731: * this method call. If the portlet has defined
732: * <code>'*'</code> or <code>'* / *'</code> as supported content
733: * types, these may also be valid return values.
734: *
735: * @return ordered list of MIME types for the response
736: */
737: public java.util.Enumeration getResponseContentTypes() {
738: SortedSet types = (SortedSet) getAttribute(SportletProperties.PORTLET_MIMETYPES);
739: if (types == null)
740: types = new TreeSet();
741: return new Enumerator(types);
742: }
743:
744: /**
745: * Returns the preferred Locale in which the portal will accept content.
746: * The Locale may be based on the Accept-Language header of the client.
747: *
748: * @return the prefered Locale in which the portal will accept content.
749: */
750: public java.util.Locale getLocale() {
751: Locale locale = (Locale) this .getPortletSession(true)
752: .getAttribute(User.LOCALE,
753: PortletSession.APPLICATION_SCOPE);
754: if (locale != null)
755: return locale;
756: User user = (User) this .getHttpServletRequest().getAttribute(
757: SportletProperties.PORTLET_USER);
758: if (user != null) {
759: String loc = (String) user.getAttribute(User.LOCALE);
760: if (loc != null) {
761: locale = new Locale(loc, "", "");
762: this .getPortletSession(true).setAttribute(User.LOCALE,
763: locale, PortletSession.APPLICATION_SCOPE);
764: return locale;
765: }
766: }
767: PortalConfigService portalConfigService = (PortalConfigService) PortletServiceFactory
768: .createPortletService(PortalConfigService.class, true);
769: if (portalConfigService
770: .getProperty(PortalConfigService.DEFAULT_LANGUAGE_OVERRIDE) != null
771: && portalConfigService.getProperty(
772: PortalConfigService.DEFAULT_LANGUAGE_OVERRIDE)
773: .equals(Boolean.TRUE.toString())) {
774: // we do want to have another locale then the browser language as default if nothing is set in the
775: // user profile (mostly for guest)
776: String defaultLocale = portalConfigService
777: .getProperty(PortalConfigService.DEFAULT_LANGUAGE_SELECTION);
778: if (defaultLocale != null
779: && defaultLocale != PortalConfigService.DEFAULT_LANGUAGE_SELECTION)
780: locale = new Locale(defaultLocale);
781: return locale;
782: }
783:
784: locale = this .getHttpServletRequest().getLocale();
785: if (locale != null)
786: return locale;
787: return Locale.ENGLISH;
788: }
789:
790: /**
791: * Returns an Enumeration of Locale objects indicating, in decreasing
792: * order starting with the preferred locale in which the portal will
793: * accept content for this request.
794: * The Locales may be based on the Accept-Language header of the client.
795: *
796: * @return an Enumeration of Locales, in decreasing order, in which
797: * the portal will accept content for this request
798: */
799: public java.util.Enumeration getLocales() {
800: return this .getHttpServletRequest().getLocales();
801: }
802:
803: /**
804: * Returns the name of the scheme used to make this request.
805: * For example, <code>http</code>, <code>https</code>, or <code>ftp</code>.
806: * Different schemes have different rules for constructing URLs,
807: * as noted in RFC 1738.
808: *
809: * @return a <code>String</code> containing the name
810: * of the scheme used to make this request
811: */
812: public String getScheme() {
813: return this .getHttpServletRequest().getScheme();
814: }
815:
816: /**
817: * Returns the host name of the server that received the request.
818: *
819: * @return a <code>String</code> containing the name
820: * of the server to which the request was sent
821: */
822: public String getServerName() {
823: return this .getHttpServletRequest().getServerName();
824: }
825:
826: /**
827: * Returns the port number on which this request was received.
828: *
829: * @return an integer specifying the port number
830: */
831: public int getServerPort() {
832: return this .getHttpServletRequest().getServerPort();
833: }
834:
835: public int getContentLength() {
836: if (included)
837: return 0;
838: return this .getHttpServletRequest().getContentLength();
839: }
840:
841: public String getProtocol() {
842: return null;
843: }
844:
845: public String getRemoteAddr() {
846: return null;
847: }
848:
849: public String getRemoteHost() {
850: return null;
851: }
852:
853: public String getRealPath(String s) {
854: return null;
855: }
856:
857: public StringBuffer getRequestURL() {
858: return null;
859: }
860:
861: public String getCharacterEncoding() {
862: return null;
863: }
864:
865: public void setCharacterEncoding(String s)
866: throws UnsupportedEncodingException {
867: // do nothing
868: }
869:
870: public String getContentType() {
871: if (included)
872: return null;
873: return this .getHttpServletRequest().getContentType();
874: }
875:
876: public String getQueryString() {
877: if (included) {
878: return (String) super
879: .getAttribute("javax.servlet.include.query_string");
880: }
881: return super .getQueryString();
882: }
883:
884: public String getPathInfo() {
885: String cmd = (String) getAttribute("org.gridsphere.tomcat_hack");
886: if (cmd != null)
887: return cmd;
888: if (included) {
889: return (String) super
890: .getAttribute("javax.servlet.include.path_info");
891: }
892: return super .getPathInfo();
893: }
894:
895: public String getRequestURI() {
896: if (included)
897: return (String) super
898: .getAttribute("javax.servlet.include.request_uri");
899: //return (attr != null) ? attr : super.getRequestURI();
900: return super .getRequestURI();
901: }
902:
903: public String getServletPath() {
904: if (included)
905: return (String) super
906: .getAttribute("javax.servlet.include.servlet_path");
907: //return (attr != null) ? attr : super.getServletPath();
908: return super .getServletPath();
909: }
910:
911: public String getPathTranslated() {
912: return super .getPathTranslated();
913: }
914:
915: public ServletInputStream getInputStream() throws IOException {
916: if (included)
917: return null;
918: ServletInputStream stream = getHttpServletRequest()
919: .getInputStream();
920: hasReader = true;
921: return stream;
922:
923: }
924:
925: public BufferedReader getReader() throws IOException {
926: if (included)
927: return null;
928: hasReader = true;
929: return getHttpServletRequest().getReader();
930: }
931:
932: private HttpServletRequest getHttpServletRequest() {
933: return (HttpServletRequest) super.getRequest();
934: }
935:
936: }
|