001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet;
016    
017    import com.liferay.portal.ccpp.PortalProfileFactory;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.kernel.portlet.LiferayPortletConfig;
021    import com.liferay.portal.kernel.portlet.LiferayPortletContext;
022    import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
023    import com.liferay.portal.kernel.portlet.LiferayPortletSession;
024    import com.liferay.portal.kernel.portlet.LiferayWindowState;
025    import com.liferay.portal.kernel.servlet.BrowserSnifferUtil;
026    import com.liferay.portal.kernel.servlet.DynamicServletRequest;
027    import com.liferay.portal.kernel.servlet.ProtectedPrincipal;
028    import com.liferay.portal.kernel.servlet.ServletContextPool;
029    import com.liferay.portal.kernel.util.ArrayUtil;
030    import com.liferay.portal.kernel.util.ContentTypes;
031    import com.liferay.portal.kernel.util.ContextPathUtil;
032    import com.liferay.portal.kernel.util.GetterUtil;
033    import com.liferay.portal.kernel.util.JavaConstants;
034    import com.liferay.portal.kernel.util.LocaleUtil;
035    import com.liferay.portal.kernel.util.ParamUtil;
036    import com.liferay.portal.kernel.util.StringPool;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.xml.QName;
039    import com.liferay.portal.model.Portlet;
040    import com.liferay.portal.model.PortletApp;
041    import com.liferay.portal.model.PortletConstants;
042    import com.liferay.portal.model.PublicRenderParameter;
043    import com.liferay.portal.model.User;
044    import com.liferay.portal.security.lang.DoPrivilegedBean;
045    import com.liferay.portal.security.lang.DoPrivilegedUtil;
046    import com.liferay.portal.service.RoleLocalServiceUtil;
047    import com.liferay.portal.servlet.NamespaceServletRequest;
048    import com.liferay.portal.servlet.SharedSessionServletRequest;
049    import com.liferay.portal.theme.ThemeDisplay;
050    import com.liferay.portal.util.PortalUtil;
051    import com.liferay.portal.util.WebKeys;
052    import com.liferay.portlet.portletconfiguration.util.PublicRenderParameterConfiguration;
053    
054    import java.security.Principal;
055    import java.security.PrivilegedAction;
056    
057    import java.util.ArrayList;
058    import java.util.Collections;
059    import java.util.Enumeration;
060    import java.util.HashMap;
061    import java.util.LinkedHashMap;
062    import java.util.List;
063    import java.util.Locale;
064    import java.util.Map;
065    
066    import javax.ccpp.Profile;
067    
068    import javax.portlet.PortalContext;
069    import javax.portlet.PortletConfig;
070    import javax.portlet.PortletContext;
071    import javax.portlet.PortletMode;
072    import javax.portlet.PortletPreferences;
073    import javax.portlet.PortletRequest;
074    import javax.portlet.PortletResponse;
075    import javax.portlet.PortletSession;
076    import javax.portlet.WindowState;
077    import javax.portlet.filter.PortletRequestWrapper;
078    
079    import javax.servlet.ServletContext;
080    import javax.servlet.http.Cookie;
081    import javax.servlet.http.HttpServletRequest;
082    import javax.servlet.http.HttpSession;
083    
084    /**
085     * @author Brian Wing Shun Chan
086     * @author Brian Myunghun Kim
087     * @author Sergey Ponomarev
088     * @author Raymond Augé
089     */
090    public abstract class PortletRequestImpl implements LiferayPortletRequest {
091    
092            public static PortletRequestImpl getPortletRequestImpl(
093                    PortletRequest portletRequest) {
094    
095                    while (!(portletRequest instanceof PortletRequestImpl)) {
096                            if (portletRequest instanceof DoPrivilegedBean) {
097                                    DoPrivilegedBean doPrivilegedBean =
098                                            (DoPrivilegedBean)portletRequest;
099    
100                                    portletRequest =
101                                            (PortletRequest)doPrivilegedBean.getActualBean();
102                            }
103                            else if (portletRequest instanceof PortletRequestWrapper) {
104                                    PortletRequestWrapper portletRequestWrapper =
105                                            (PortletRequestWrapper)portletRequest;
106    
107                                    portletRequest = portletRequestWrapper.getRequest();
108                            }
109                            else {
110                                    throw new RuntimeException(
111                                            "Unable to unwrap the portlet request from " +
112                                                    portletRequest.getClass());
113                            }
114                    }
115    
116                    return (PortletRequestImpl)portletRequest;
117            }
118    
119            public void cleanUp() {
120                    _request.removeAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
121                    _request.removeAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);
122                    _request.removeAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);
123                    _request.removeAttribute(PortletRequest.LIFECYCLE_PHASE);
124                    _request.removeAttribute(WebKeys.PORTLET_ID);
125                    _request.removeAttribute(WebKeys.PORTLET_CONTENT);
126            }
127    
128            public void defineObjects(
129                    PortletConfig portletConfig, PortletResponse portletResponse) {
130    
131                    LiferayPortletConfig liferayPortletConfig =
132                            (LiferayPortletConfig)portletConfig;
133    
134                    setAttribute(WebKeys.PORTLET_ID, liferayPortletConfig.getPortletId());
135                    setAttribute(JavaConstants.JAVAX_PORTLET_CONFIG, portletConfig);
136                    setAttribute(JavaConstants.JAVAX_PORTLET_REQUEST, this);
137                    setAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE, portletResponse);
138                    setAttribute(PortletRequest.LIFECYCLE_PHASE, getLifecycle());
139            }
140    
141            public Object getAttribute(String name) {
142                    if (name == null) {
143                            throw new IllegalArgumentException();
144                    }
145    
146                    if (name.equals(PortletRequest.CCPP_PROFILE)) {
147                            return getCCPPProfile();
148                    }
149                    else if (name.equals(PortletRequest.USER_INFO)) {
150                            Object value = getUserInfo();
151    
152                            if (value != null) {
153                                    return value;
154                            }
155                    }
156    
157                    return _request.getAttribute(name);
158            }
159    
160            public Enumeration<String> getAttributeNames() {
161                    List<String> names = new ArrayList<String>();
162    
163                    Enumeration<String> enu = _request.getAttributeNames();
164    
165                    while (enu.hasMoreElements()) {
166                            String name = enu.nextElement();
167    
168                            if (!name.equals(JavaConstants.JAVAX_SERVLET_INCLUDE_PATH_INFO)) {
169                                    names.add(name);
170                            }
171                    }
172    
173                    return Collections.enumeration(names);
174            }
175    
176            public String getAuthType() {
177                    return _request.getAuthType();
178            }
179    
180            public Profile getCCPPProfile() {
181                    if (_profile == null) {
182                            _profile = PortalProfileFactory.getCCPPProfile(_request);
183                    }
184    
185                    return _profile;
186            }
187    
188            public String getContextPath() {
189                    LiferayPortletContext liferayPortletContext =
190                            (LiferayPortletContext)_portletContext;
191    
192                    ServletContext servletContext =
193                            liferayPortletContext.getServletContext();
194    
195                    String servletContextName = servletContext.getServletContextName();
196    
197                    if (ServletContextPool.containsKey(servletContextName)) {
198                            servletContext = ServletContextPool.get(servletContextName);
199    
200                            return ContextPathUtil.getContextPath(servletContext);
201                    }
202    
203                    return StringPool.SLASH.concat(_portletContext.getPortletContextName());
204            }
205    
206            public Cookie[] getCookies() {
207                    return _request.getCookies();
208            }
209    
210            public String getETag() {
211                    return null;
212            }
213    
214            public HttpServletRequest getHttpServletRequest() {
215                    return _request;
216            }
217    
218            public abstract String getLifecycle();
219    
220            public Locale getLocale() {
221                    Locale locale = _locale;
222    
223                    if (locale == null) {
224                            locale = _request.getLocale();
225                    }
226    
227                    if (locale == null) {
228                            locale = LocaleUtil.getDefault();
229                    }
230    
231                    return locale;
232            }
233    
234            public Enumeration<Locale> getLocales() {
235                    return _request.getLocales();
236            }
237    
238            public String getMethod() {
239                    return _request.getMethod();
240            }
241    
242            public HttpServletRequest getOriginalHttpServletRequest() {
243                    return _originalRequest;
244            }
245    
246            public String getParameter(String name) {
247                    if (name == null) {
248                            throw new IllegalArgumentException();
249                    }
250    
251                    if (_portletRequestDispatcherRequest != null) {
252                            return _portletRequestDispatcherRequest.getParameter(name);
253                    }
254    
255                    return _request.getParameter(name);
256            }
257    
258            public Map<String, String[]> getParameterMap() {
259                    if (_portletRequestDispatcherRequest != null) {
260                            return Collections.unmodifiableMap(
261                                    _portletRequestDispatcherRequest.getParameterMap());
262                    }
263    
264                    return Collections.unmodifiableMap(_request.getParameterMap());
265            }
266    
267            public Enumeration<String> getParameterNames() {
268                    if (_portletRequestDispatcherRequest != null) {
269                            return _portletRequestDispatcherRequest.getParameterNames();
270                    }
271    
272                    return _request.getParameterNames();
273            }
274    
275            public String[] getParameterValues(String name) {
276                    if (name == null) {
277                            throw new IllegalArgumentException();
278                    }
279    
280                    if (_portletRequestDispatcherRequest != null) {
281                            return _portletRequestDispatcherRequest.getParameterValues(name);
282                    }
283    
284                    return _request.getParameterValues(name);
285            }
286    
287            public PortalContext getPortalContext() {
288                    return _portalContext;
289            }
290    
291            public Portlet getPortlet() {
292                    return _portlet;
293            }
294    
295            public PortletContext getPortletContext() {
296                    return _portletContext;
297            }
298    
299            public PortletMode getPortletMode() {
300                    return _portletMode;
301            }
302    
303            public String getPortletName() {
304                    return _portletName;
305            }
306    
307            public PortletSession getPortletSession() {
308                    return _session;
309            }
310    
311            public PortletSession getPortletSession(boolean create) {
312                    /*HttpSession httpSes = _req.getSession(create);
313    
314                    if (httpSes == null) {
315                            return null;
316                    }
317                    else {
318                            if (create) {
319                                    _session = new PortletSessionImpl(
320                                            _req.getSession(), _portletContext, _portletName, _plid);
321                            }
322    
323                            return _ses;
324                    }*/
325    
326                    /*if ((_session == null) && create) {
327                            _req.getSession(create);
328    
329                            _session = new PortletSessionImpl(
330                                    _req.getSession(), _portletContext, _portletName, _plid);
331                    }*/
332    
333                    if (!create && _invalidSession) {
334                            return null;
335                    }
336    
337                    return _session;
338            }
339    
340            public PortletPreferences getPreferences() {
341                    return DoPrivilegedUtil.wrap(new PortletPreferencesPrivilegedAction());
342            }
343    
344            public PortletPreferencesImpl getPreferencesImpl() {
345                    return (PortletPreferencesImpl)_preferences;
346            }
347    
348            public Map<String, String[]> getPrivateParameterMap() {
349                    Map<String, String[]> parameterMap = null;
350    
351                    if (_portletRequestDispatcherRequest != null) {
352                            parameterMap = _portletRequestDispatcherRequest.getParameterMap();
353                    }
354                    else {
355                            parameterMap = _request.getParameterMap();
356                    }
357    
358                    Map<String, String[]> privateParameterMap = null;
359    
360                    for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
361                            String name = entry.getKey();
362    
363                            if (_portlet.getPublicRenderParameter(name) != null) {
364                                    continue;
365                            }
366    
367                            if (privateParameterMap == null) {
368                                    privateParameterMap = new HashMap<String, String[]>(
369                                            parameterMap.size(), 1);
370                            }
371    
372                            privateParameterMap.put(name, entry.getValue());
373                    }
374    
375                    if (privateParameterMap == null) {
376                            return Collections.emptyMap();
377                    }
378    
379                    return Collections.unmodifiableMap(privateParameterMap);
380            }
381    
382            public Enumeration<String> getProperties(String name) {
383                    List<String> values = new ArrayList<String>();
384    
385                    String value = _portalContext.getProperty(name);
386    
387                    if (value != null) {
388                            values.add(value);
389                    }
390    
391                    return Collections.enumeration(values);
392            }
393    
394            public String getProperty(String name) {
395                    return _portalContext.getProperty(name);
396            }
397    
398            public Enumeration<String> getPropertyNames() {
399                    return _portalContext.getPropertyNames();
400            }
401    
402            public Map<String, String[]> getPublicParameterMap() {
403                    Map<String, String[]> parameterMap = null;
404    
405                    if (_portletRequestDispatcherRequest != null) {
406                            parameterMap = _portletRequestDispatcherRequest.getParameterMap();
407                    }
408                    else {
409                            parameterMap = _request.getParameterMap();
410                    }
411    
412                    Map<String, String[]> publicParameterMap = null;
413    
414                    for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
415                            String name = entry.getKey();
416    
417                            if (_portlet.getPublicRenderParameter(name) != null) {
418    
419                                    if (publicParameterMap == null) {
420                                            publicParameterMap = new HashMap<String, String[]>(
421                                                    parameterMap.size(), 1);
422                                    }
423    
424                                    publicParameterMap.put(name, entry.getValue());
425                            }
426                    }
427    
428                    if (publicParameterMap == null) {
429                            return Collections.emptyMap();
430                    }
431                    else {
432                            return Collections.unmodifiableMap(publicParameterMap);
433                    }
434            }
435    
436            public String getRemoteUser() {
437                    return _remoteUser;
438            }
439    
440            public Map<String, String[]> getRenderParameters() {
441                    return RenderParametersPool.get(_request, _plid, _portletName);
442            }
443    
444            public String getRequestedSessionId() {
445                    if (_session != null) {
446                            return _session.getId();
447                    }
448                    else {
449                            HttpSession session = _request.getSession(false);
450    
451                            if (session == null) {
452                                    return StringPool.BLANK;
453                            }
454                            else {
455                                    return session.getId();
456                            }
457                    }
458            }
459    
460            public String getResponseContentType() {
461                    if (_wapTheme) {
462                            return ContentTypes.XHTML_MP;
463                    }
464                    else {
465                            return ContentTypes.TEXT_HTML;
466                    }
467            }
468    
469            public Enumeration<String> getResponseContentTypes() {
470                    List<String> responseContentTypes = new ArrayList<String>();
471    
472                    responseContentTypes.add(getResponseContentType());
473    
474                    return Collections.enumeration(responseContentTypes);
475            }
476    
477            public String getScheme() {
478                    return _request.getScheme();
479            }
480    
481            public String getServerName() {
482                    return _request.getServerName();
483            }
484    
485            public int getServerPort() {
486                    return _request.getServerPort();
487            }
488    
489            public LinkedHashMap<String, String> getUserInfo() {
490                    return UserInfoFactory.getUserInfo(_remoteUserId, _portlet);
491            }
492    
493            public Principal getUserPrincipal() {
494                    return _userPrincipal;
495            }
496    
497            public String getWindowID() {
498                    return _portletName.concat(
499                            LiferayPortletSession.LAYOUT_SEPARATOR).concat(
500                                    String.valueOf(_plid));
501            }
502    
503            public WindowState getWindowState() {
504                    return _windowState;
505            }
506    
507            public void invalidateSession() {
508                    _invalidSession = true;
509            }
510    
511            public boolean isInvalidParameter(String name) {
512                    if (Validator.isNull(name) ||
513                            name.startsWith(PortletQName.PUBLIC_RENDER_PARAMETER_NAMESPACE) ||
514                            name.startsWith(
515                                    PortletQName.REMOVE_PUBLIC_RENDER_PARAMETER_NAMESPACE) ||
516                            PortalUtil.isReservedParameter(name)) {
517    
518                            return true;
519                    }
520                    else {
521                            return false;
522                    }
523            }
524    
525            public boolean isPortletModeAllowed(PortletMode portletMode) {
526                    if ((portletMode == null) || Validator.isNull(portletMode.toString())) {
527                            return true;
528                    }
529                    else {
530                            return _portlet.hasPortletMode(
531                                    getResponseContentType(), portletMode);
532                    }
533            }
534    
535            public boolean isPrivateRequestAttributes() {
536                    return _portlet.isPrivateRequestAttributes();
537            }
538    
539            public boolean isRequestedSessionIdValid() {
540                    return _request.isRequestedSessionIdValid();
541            }
542    
543            public boolean isSecure() {
544                    return _request.isSecure();
545            }
546    
547            public boolean isTriggeredByActionURL() {
548                    return _triggeredByActionURL;
549            }
550    
551            public boolean isUserInRole(String role) {
552                    if (_remoteUserId <= 0) {
553                            return false;
554                    }
555                    else {
556                            try {
557                                    long companyId = PortalUtil.getCompanyId(_request);
558    
559                                    String roleLink = _portlet.getRoleMappers().get(role);
560    
561                                    if (Validator.isNotNull(roleLink)) {
562                                            return RoleLocalServiceUtil.hasUserRole(
563                                                    _remoteUserId, companyId, roleLink, true);
564                                    }
565                                    else {
566                                            return RoleLocalServiceUtil.hasUserRole(
567                                                    _remoteUserId, companyId, role, true);
568                                    }
569                            }
570                            catch (Exception e) {
571                                    _log.error(e);
572                            }
573    
574                            return _request.isUserInRole(role);
575                    }
576            }
577    
578            public boolean isWindowStateAllowed(WindowState windowState) {
579                    return PortalContextImpl.isSupportedWindowState(windowState);
580            }
581    
582            public void removeAttribute(String name) {
583                    if (name == null) {
584                            throw new IllegalArgumentException();
585                    }
586    
587                    _request.removeAttribute(name);
588            }
589    
590            public void setAttribute(String name, Object obj) {
591                    if (name == null) {
592                            throw new IllegalArgumentException();
593                    }
594    
595                    if (obj == null) {
596                            removeAttribute(name);
597                    }
598                    else {
599                            _request.setAttribute(name, obj);
600                    }
601            }
602    
603            public void setPortletMode(PortletMode portletMode) {
604                    _portletMode = portletMode;
605            }
606    
607            public void setPortletRequestDispatcherRequest(HttpServletRequest request) {
608                    _portletRequestDispatcherRequest = request;
609            }
610    
611            public void setWindowState(WindowState windowState) {
612                    _windowState = windowState;
613            }
614    
615            protected void init(
616                    HttpServletRequest request, Portlet portlet,
617                    InvokerPortlet invokerPortlet, PortletContext portletContext,
618                    WindowState windowState, PortletMode portletMode,
619                    PortletPreferences preferences, long plid) {
620    
621                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
622                            WebKeys.THEME_DISPLAY);
623    
624                    _portlet = portlet;
625                    _portletName = portlet.getPortletId();
626                    _publicRenderParameters = PublicRenderParametersPool.get(request, plid);
627    
628                    String portletNamespace = PortalUtil.getPortletNamespace(_portletName);
629    
630                    boolean portalSessionShared = false;
631    
632                    PortletApp portletApp = portlet.getPortletApp();
633    
634                    if (portletApp.isWARFile() && !portlet.isPrivateSessionAttributes()) {
635                            portalSessionShared = true;
636                    }
637    
638                    request = new SharedSessionServletRequest(request, portalSessionShared);
639    
640                    DynamicServletRequest dynamicRequest = null;
641    
642                    if (portlet.isPrivateRequestAttributes()) {
643                            dynamicRequest = new NamespaceServletRequest(
644                                    request, portletNamespace, portletNamespace, false);
645                    }
646                    else {
647                            dynamicRequest = new DynamicServletRequest(request, false);
648                    }
649    
650                    boolean portletFocus = false;
651    
652                    String ppid = ParamUtil.getString(request, "p_p_id");
653    
654                    boolean windowStateRestoreCurrentView = ParamUtil.getBoolean(
655                            request, "p_p_state_rcv");
656    
657                    if (_portletName.equals(ppid) &&
658                            !(windowStateRestoreCurrentView &&
659                              portlet.isRestoreCurrentView())) {
660    
661                            // Request was targeted to this portlet
662    
663                            if (themeDisplay.isLifecycleRender() ||
664                                    themeDisplay.isLifecycleResource()) {
665    
666                                    // Request was triggered by a render or resource URL
667    
668                                    portletFocus = true;
669                            }
670                            else if (themeDisplay.isLifecycleAction()) {
671                                    _triggeredByActionURL = true;
672    
673                                    if (getLifecycle().equals(PortletRequest.ACTION_PHASE)) {
674    
675                                            // Request was triggered by an action URL and is being
676                                            // processed by com.liferay.portlet.ActionRequestImpl
677    
678                                            portletFocus = true;
679                                    }
680                            }
681                    }
682    
683                    if (portletFocus) {
684                            Map<String, String[]> renderParameters =
685                                    new HashMap<String, String[]>();
686    
687                            if (getLifecycle().equals(PortletRequest.RENDER_PHASE) &&
688                                    !LiferayWindowState.isExclusive(request) &&
689                                    !LiferayWindowState.isPopUp(request)) {
690    
691                                    RenderParametersPool.put(
692                                            request, plid, _portletName, renderParameters);
693                            }
694    
695                            Map<String, String[]> parameters = request.getParameterMap();
696    
697                            for (Map.Entry<String, String[]> entry : parameters.entrySet()) {
698                                    String name = entry.getKey();
699    
700                                    if (isInvalidParameter(name)) {
701                                            continue;
702                                    }
703    
704                                    String[] values = entry.getValue();
705    
706                                    if (themeDisplay.isLifecycleRender()) {
707                                            renderParameters.put(name, values);
708                                    }
709    
710                                    if (values == null) {
711                                            continue;
712                                    }
713    
714                                    name = removePortletNamespace(
715                                            invokerPortlet, portletNamespace, name);
716    
717                                    dynamicRequest.setParameterValues(name, values);
718                            }
719                    }
720                    else {
721                            Map<String, String[]> renderParameters = RenderParametersPool.get(
722                                    request, plid, _portletName);
723    
724                            for (Map.Entry<String, String[]> entry :
725                                            renderParameters.entrySet()) {
726    
727                                    String name = entry.getKey();
728                                    String[] values = entry.getValue();
729    
730                                    name = removePortletNamespace(
731                                            invokerPortlet, portletNamespace, name);
732    
733                                    dynamicRequest.setParameterValues(name, values);
734                            }
735                    }
736    
737                    mergePublicRenderParameters(dynamicRequest, preferences, plid);
738    
739                    _request = dynamicRequest;
740                    _originalRequest = request;
741                    _wapTheme = BrowserSnifferUtil.isWap(_request);
742                    _portlet = portlet;
743                    _portalContext = new PortalContextImpl();
744                    _portletContext = portletContext;
745                    _windowState = windowState;
746                    _portletMode = portletMode;
747                    _preferences = preferences;
748                    _session = new PortletSessionImpl(
749                            _request.getSession(), _portletContext, _portletName, plid);
750    
751                    String remoteUser = request.getRemoteUser();
752    
753                    String userPrincipalStrategy = portlet.getUserPrincipalStrategy();
754    
755                    if (userPrincipalStrategy.equals(
756                                    PortletConstants.USER_PRINCIPAL_STRATEGY_SCREEN_NAME)) {
757    
758                            try {
759                                    User user = PortalUtil.getUser(request);
760    
761                                    if (user != null) {
762                                            _remoteUser = user.getScreenName();
763                                            _remoteUserId = user.getUserId();
764                                            _userPrincipal = new ProtectedPrincipal(_remoteUser);
765                                    }
766                            }
767                            catch (Exception e) {
768                                    _log.error(e);
769                            }
770                    }
771                    else {
772                            long userId = PortalUtil.getUserId(request);
773    
774                            if ((userId > 0) && (remoteUser == null)) {
775                                    _remoteUser = String.valueOf(userId);
776                                    _remoteUserId = userId;
777                                    _userPrincipal = new ProtectedPrincipal(_remoteUser);
778                            }
779                            else {
780                                    _remoteUser = remoteUser;
781                                    _remoteUserId = GetterUtil.getLong(remoteUser);
782                                    _userPrincipal = request.getUserPrincipal();
783                            }
784                    }
785    
786                    _locale = themeDisplay.getLocale();
787                    _plid = plid;
788            }
789    
790            protected void mergePublicRenderParameters(
791                    DynamicServletRequest dynamicRequest, PortletPreferences preferences,
792                    long plid) {
793    
794                    Enumeration<PublicRenderParameter> publicRenderParameters =
795                            Collections.enumeration(_portlet.getPublicRenderParameters());
796    
797                    while (publicRenderParameters.hasMoreElements()) {
798                            PublicRenderParameter publicRenderParameter =
799                                    publicRenderParameters.nextElement();
800    
801                            String ignoreKey = PublicRenderParameterConfiguration.getIgnoreKey(
802                                    publicRenderParameter);
803    
804                            boolean ignoreValue = GetterUtil.getBoolean(
805                                    preferences.getValue(ignoreKey, null));
806    
807                            if (ignoreValue) {
808                                    continue;
809                            }
810    
811                            String mappingKey =
812                                    PublicRenderParameterConfiguration.getMappingKey(
813                                            publicRenderParameter);
814    
815                            String mappingValue = GetterUtil.getString(
816                                    preferences.getValue(mappingKey, null));
817    
818                            HttpServletRequest request =
819                                    (HttpServletRequest)dynamicRequest.getRequest();
820    
821                            String[] newValues = request.getParameterValues(mappingValue);
822    
823                            if ((newValues != null) && (newValues.length != 0)) {
824                                    newValues = ArrayUtil.remove(newValues, StringPool.NULL);
825                            }
826    
827                            String name = publicRenderParameter.getIdentifier();
828    
829                            if ((newValues == null) || (newValues.length == 0)) {
830                                    QName qName = publicRenderParameter.getQName();
831    
832                                    String[] values = _publicRenderParameters.get(
833                                            PortletQNameUtil.getPublicRenderParameterName(qName));
834    
835                                    if ((values == null) || (values.length == 0) ||
836                                            Validator.isNull(values[0])) {
837    
838                                            continue;
839                                    }
840    
841                                    if (dynamicRequest.getParameter(name) == null) {
842                                            dynamicRequest.setParameterValues(name, values);
843                                    }
844                            }
845                            else {
846                                    dynamicRequest.setParameterValues(name, newValues);
847                            }
848                    }
849            }
850    
851            protected String removePortletNamespace(
852                    InvokerPortlet invokerPortlet, String portletNamespace, String name) {
853    
854                    if (name.startsWith(portletNamespace) &&
855                            ((invokerPortlet == null) || !invokerPortlet.isFacesPortlet())) {
856    
857                            name = name.substring(portletNamespace.length());
858                    }
859    
860                    return name;
861            }
862    
863            private static Log _log = LogFactoryUtil.getLog(PortletRequestImpl.class);
864    
865            private boolean _invalidSession;
866            private Locale _locale;
867            private HttpServletRequest _originalRequest;
868            private long _plid;
869            private PortalContext _portalContext;
870            private Portlet _portlet;
871            private PortletContext _portletContext;
872            private PortletMode _portletMode;
873            private String _portletName;
874            private HttpServletRequest _portletRequestDispatcherRequest;
875            private PortletPreferences _preferences;
876            private Profile _profile;
877            private Map<String, String[]> _publicRenderParameters;
878            private String _remoteUser;
879            private long _remoteUserId;
880            private HttpServletRequest _request;
881            private PortletSessionImpl _session;
882            private boolean _triggeredByActionURL;
883            private Principal _userPrincipal;
884            private boolean _wapTheme;
885            private WindowState _windowState;
886    
887            private class PortletPreferencesPrivilegedAction
888                    implements PrivilegedAction<PortletPreferences> {
889    
890                    public PortletPreferences run() {
891                            return new PortletPreferencesWrapper(
892                                    getPreferencesImpl(), getLifecycle());
893                    }
894    
895            }
896    
897    }