001: package com.icesoft.faces.env;
002:
003: import com.icesoft.jasper.Constants;
004:
005: import javax.portlet.PortalContext;
006: import javax.portlet.PortletMode;
007: import javax.portlet.PortletPreferences;
008: import javax.portlet.PortletSession;
009: import javax.portlet.RenderRequest;
010: import javax.portlet.WindowState;
011: import java.util.ArrayList;
012: import java.util.Collections;
013: import java.util.Enumeration;
014: import java.util.HashMap;
015: import java.util.Hashtable;
016: import java.util.LinkedList;
017: import java.util.List;
018: import java.util.Map;
019:
020: public class PortletEnvironmentRenderRequest extends
021: CommonEnvironmentRequest implements RenderRequest {
022: private RenderRequest request;
023:
024: private PortletMode portletMode;
025: private WindowState windowState;
026: private PortletPreferences portletPreferences;
027: private PortletSession portletSession;
028: private PortalContext portalContext;
029: private String responseContentType;
030: private ArrayList responseContentTypes;
031: private Map properties;
032:
033: public PortletEnvironmentRenderRequest(Object request) {
034: this .request = (RenderRequest) request;
035:
036: portletMode = this .request.getPortletMode();
037: windowState = this .request.getWindowState();
038: portletPreferences = this .request.getPreferences();
039: portletSession = this .request.getPortletSession();
040: portalContext = this .request.getPortalContext();
041: responseContentType = this .request.getResponseContentType();
042: responseContentTypes = Collections.list(this .request
043: .getResponseContentTypes());
044: authType = this .request.getAuthType();
045: remoteUser = this .request.getRemoteUser();
046: userPrincipal = this .request.getUserPrincipal();
047: requestedSessionId = this .request.getRequestedSessionId();
048: requestedSessionIdValid = this .request
049: .isRequestedSessionIdValid();
050: scheme = this .request.getScheme();
051: serverName = this .request.getServerName();
052: serverPort = this .request.getServerPort();
053: locale = this .request.getLocale();
054: locales = Collections.list(this .request.getLocales());
055: secure = this .request.isSecure();
056: contextPath = this .request.getContextPath();
057:
058: attributes = new Hashtable();
059: Enumeration attributeNames = this .request.getAttributeNames();
060: while (attributeNames.hasMoreElements()) {
061: String name = (String) attributeNames.nextElement();
062: Object attribute = this .request.getAttribute(name);
063: if ((null != name) && (null != attribute)) {
064: attributes.put(name, attribute);
065: }
066: }
067:
068: //Some portal containers do not add the javax.servlet.include.*
069: //attributes to the attribute names collection so they are not
070: //copied into our own collection. So we do that here if
071: //necessary:
072:
073: String[] incKeys = Constants.INC_CONSTANTS;
074: for (int index = 0; index < incKeys.length; index++) {
075: String incVal = (String) this .request
076: .getAttribute(incKeys[index]);
077: if (!attributes.containsKey(incKeys[index])
078: && incVal != null) {
079: attributes.put(incKeys[index], incVal);
080: }
081: }
082:
083: parameters = new HashMap();
084: Enumeration parameterNames = this .request.getParameterNames();
085: while (parameterNames.hasMoreElements()) {
086: String name = (String) parameterNames.nextElement();
087: parameters.put(name, this .request.getParameterValues(name));
088: }
089:
090: properties = new HashMap();
091: Enumeration propertyNames = this .request.getPropertyNames();
092: while (propertyNames.hasMoreElements()) {
093: String name = (String) propertyNames.nextElement();
094: Enumeration values = this .request.getProperties(name);
095: properties.put(name, Collections.list(values));
096: }
097: }
098:
099: public boolean isWindowStateAllowed(WindowState windowState) {
100: try {
101: return request.isWindowStateAllowed(windowState);
102: } catch (Exception e) {
103: return false;
104: }
105: }
106:
107: public boolean isPortletModeAllowed(PortletMode portletMode) {
108: try {
109: return request.isPortletModeAllowed(portletMode);
110: } catch (Exception e) {
111: return false;
112: }
113: }
114:
115: public PortletMode getPortletMode() {
116: return portletMode;
117: }
118:
119: public WindowState getWindowState() {
120: return windowState;
121: }
122:
123: public PortletPreferences getPreferences() {
124: return portletPreferences;
125: }
126:
127: public PortletSession getPortletSession() {
128: return portletSession;
129: }
130:
131: public PortletSession getPortletSession(boolean create) {
132: return portletSession;
133: }
134:
135: public String getProperty(String name) {
136: if (properties.containsKey(name)) {
137: List values = (LinkedList) properties.get(name);
138: return (String) values.get(0);
139: } else {
140: return null;
141: }
142: }
143:
144: public Enumeration getProperties(String name) {
145: if (properties.containsKey(name)) {
146: LinkedList values = (LinkedList) properties.get(name);
147: return Collections.enumeration(values);
148: } else {
149: return Collections.enumeration(Collections.EMPTY_LIST);
150: }
151: }
152:
153: public Enumeration getPropertyNames() {
154: return Collections.enumeration(properties.keySet());
155: }
156:
157: public PortalContext getPortalContext() {
158: return portalContext;
159: }
160:
161: public boolean isUserInRole(String string) {
162: return request.isUserInRole(string);
163: }
164:
165: public String getResponseContentType() {
166: return responseContentType;
167: }
168:
169: public Enumeration getResponseContentTypes() {
170: return Collections.enumeration(responseContentTypes);
171: }
172: }
|