001
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.PortletLocalServiceUtil;
047 import com.liferay.portal.service.RoleLocalServiceUtil;
048 import com.liferay.portal.servlet.NamespaceServletRequest;
049 import com.liferay.portal.servlet.SharedSessionServletRequest;
050 import com.liferay.portal.theme.ThemeDisplay;
051 import com.liferay.portal.util.PortalUtil;
052 import com.liferay.portal.util.PropsValues;
053 import com.liferay.portal.util.WebKeys;
054 import com.liferay.portlet.portletconfiguration.util.PublicRenderParameterConfiguration;
055
056 import java.security.Principal;
057 import java.security.PrivilegedAction;
058
059 import java.util.ArrayList;
060 import java.util.Collections;
061 import java.util.Enumeration;
062 import java.util.HashMap;
063 import java.util.LinkedHashMap;
064 import java.util.List;
065 import java.util.Locale;
066 import java.util.Map;
067 import java.util.regex.Matcher;
068 import java.util.regex.Pattern;
069
070 import javax.ccpp.Profile;
071
072 import javax.portlet.PortalContext;
073 import javax.portlet.PortletConfig;
074 import javax.portlet.PortletContext;
075 import javax.portlet.PortletMode;
076 import javax.portlet.PortletPreferences;
077 import javax.portlet.PortletRequest;
078 import javax.portlet.PortletResponse;
079 import javax.portlet.PortletSession;
080 import javax.portlet.WindowState;
081 import javax.portlet.filter.PortletRequestWrapper;
082
083 import javax.servlet.ServletContext;
084 import javax.servlet.http.Cookie;
085 import javax.servlet.http.HttpServletRequest;
086 import javax.servlet.http.HttpSession;
087
088
094 public abstract class PortletRequestImpl implements LiferayPortletRequest {
095
096 public static PortletRequestImpl getPortletRequestImpl(
097 PortletRequest portletRequest) {
098
099 while (!(portletRequest instanceof PortletRequestImpl)) {
100 if (portletRequest instanceof DoPrivilegedBean) {
101 DoPrivilegedBean doPrivilegedBean =
102 (DoPrivilegedBean)portletRequest;
103
104 portletRequest =
105 (PortletRequest)doPrivilegedBean.getActualBean();
106 }
107 else if (portletRequest instanceof PortletRequestWrapper) {
108 PortletRequestWrapper portletRequestWrapper =
109 (PortletRequestWrapper)portletRequest;
110
111 portletRequest = portletRequestWrapper.getRequest();
112 }
113 else {
114 throw new RuntimeException(
115 "Unable to unwrap the portlet request from " +
116 portletRequest.getClass());
117 }
118 }
119
120 return (PortletRequestImpl)portletRequest;
121 }
122
123 public void cleanUp() {
124 _request.removeAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
125 _request.removeAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);
126 _request.removeAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);
127 _request.removeAttribute(PortletRequest.LIFECYCLE_PHASE);
128 _request.removeAttribute(WebKeys.PORTLET_ID);
129 _request.removeAttribute(WebKeys.PORTLET_CONTENT);
130 }
131
132 public void defineObjects(
133 PortletConfig portletConfig, PortletResponse portletResponse) {
134
135 LiferayPortletConfig liferayPortletConfig =
136 (LiferayPortletConfig)portletConfig;
137
138 setAttribute(WebKeys.PORTLET_ID, liferayPortletConfig.getPortletId());
139 setAttribute(JavaConstants.JAVAX_PORTLET_CONFIG, portletConfig);
140 setAttribute(JavaConstants.JAVAX_PORTLET_REQUEST, this);
141 setAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE, portletResponse);
142 setAttribute(PortletRequest.LIFECYCLE_PHASE, getLifecycle());
143 }
144
145 @Override
146 public Object getAttribute(String name) {
147 if (name == null) {
148 throw new IllegalArgumentException();
149 }
150
151 if (name.equals(PortletRequest.CCPP_PROFILE)) {
152 return getCCPPProfile();
153 }
154 else if (name.equals(PortletRequest.USER_INFO)) {
155 Object value = getUserInfo();
156
157 if (value != null) {
158 return value;
159 }
160 }
161
162 return _request.getAttribute(name);
163 }
164
165 @Override
166 public Enumeration<String> getAttributeNames() {
167 List<String> names = new ArrayList<String>();
168
169 Enumeration<String> enu = _request.getAttributeNames();
170
171 while (enu.hasMoreElements()) {
172 String name = enu.nextElement();
173
174 if (!name.equals(JavaConstants.JAVAX_SERVLET_INCLUDE_PATH_INFO)) {
175 names.add(name);
176 }
177 }
178
179 return Collections.enumeration(names);
180 }
181
182 @Override
183 public String getAuthType() {
184 return _request.getAuthType();
185 }
186
187 public Profile getCCPPProfile() {
188 if (_profile == null) {
189 _profile = PortalProfileFactory.getCCPPProfile(_request);
190 }
191
192 return _profile;
193 }
194
195 @Override
196 public String getContextPath() {
197 LiferayPortletContext liferayPortletContext =
198 (LiferayPortletContext)_portletContext;
199
200 ServletContext servletContext =
201 liferayPortletContext.getServletContext();
202
203 String servletContextName = servletContext.getServletContextName();
204
205 if (ServletContextPool.containsKey(servletContextName)) {
206 servletContext = ServletContextPool.get(servletContextName);
207
208 return ContextPathUtil.getContextPath(servletContext);
209 }
210
211 return StringPool.SLASH.concat(_portletContext.getPortletContextName());
212 }
213
214 @Override
215 public Cookie[] getCookies() {
216 return _request.getCookies();
217 }
218
219 public String getETag() {
220 return null;
221 }
222
223 @Override
224 public HttpServletRequest getHttpServletRequest() {
225 return _request;
226 }
227
228 public abstract String getLifecycle();
229
230 @Override
231 public Locale getLocale() {
232 Locale locale = _locale;
233
234 if (locale == null) {
235 locale = _request.getLocale();
236 }
237
238 if (locale == null) {
239 locale = LocaleUtil.getDefault();
240 }
241
242 return locale;
243 }
244
245 @Override
246 public Enumeration<Locale> getLocales() {
247 return _request.getLocales();
248 }
249
250 public String getMethod() {
251 return _request.getMethod();
252 }
253
254 public HttpServletRequest getOriginalHttpServletRequest() {
255 return _originalRequest;
256 }
257
258 @Override
259 public String getParameter(String name) {
260 if (name == null) {
261 throw new IllegalArgumentException();
262 }
263
264 if (_portletRequestDispatcherRequest != null) {
265 return _portletRequestDispatcherRequest.getParameter(name);
266 }
267
268 return _request.getParameter(name);
269 }
270
271 @Override
272 public Map<String, String[]> getParameterMap() {
273 if (_portletRequestDispatcherRequest != null) {
274 return Collections.unmodifiableMap(
275 _portletRequestDispatcherRequest.getParameterMap());
276 }
277
278 return Collections.unmodifiableMap(_request.getParameterMap());
279 }
280
281 @Override
282 public Enumeration<String> getParameterNames() {
283 if (_portletRequestDispatcherRequest != null) {
284 return _portletRequestDispatcherRequest.getParameterNames();
285 }
286
287 return _request.getParameterNames();
288 }
289
290 @Override
291 public String[] getParameterValues(String name) {
292 if (name == null) {
293 throw new IllegalArgumentException();
294 }
295
296 if (_portletRequestDispatcherRequest != null) {
297 return _portletRequestDispatcherRequest.getParameterValues(name);
298 }
299
300 return _request.getParameterValues(name);
301 }
302
303 @Override
304 public PortalContext getPortalContext() {
305 return _portalContext;
306 }
307
308 public Portlet getPortlet() {
309 return _portlet;
310 }
311
312 @Override
313 public long getPlid() {
314 return _plid;
315 }
316
317 public PortletContext getPortletContext() {
318 return _portletContext;
319 }
320
321 @Override
322 public PortletMode getPortletMode() {
323 return _portletMode;
324 }
325
326 @Override
327 public String getPortletName() {
328 return _portletName;
329 }
330
331 @Override
332 public PortletSession getPortletSession() {
333 return _session;
334 }
335
336 @Override
337 public PortletSession getPortletSession(boolean create) {
338
351
352
358
359 if (!create && _invalidSession) {
360 return null;
361 }
362
363 return _session;
364 }
365
366 @Override
367 public PortletPreferences getPreferences() {
368 String lifecycle = getLifecycle();
369
370 if (lifecycle.equals(PortletRequest.RENDER_PHASE) &&
371 PropsValues.PORTLET_PREFERENCES_STRICT_STORE) {
372
373 return DoPrivilegedUtil.wrap(
374 new PortletPreferencesPrivilegedAction());
375 }
376
377 return getPreferencesImpl();
378 }
379
380 public PortletPreferencesImpl getPreferencesImpl() {
381 return (PortletPreferencesImpl)_preferences;
382 }
383
384 @Override
385 public Map<String, String[]> getPrivateParameterMap() {
386 Map<String, String[]> parameterMap = null;
387
388 if (_portletRequestDispatcherRequest != null) {
389 parameterMap = _portletRequestDispatcherRequest.getParameterMap();
390 }
391 else {
392 parameterMap = _request.getParameterMap();
393 }
394
395 Map<String, String[]> privateParameterMap = null;
396
397 for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
398 String name = entry.getKey();
399
400 if (_portlet.getPublicRenderParameter(name) != null) {
401 continue;
402 }
403
404 if (privateParameterMap == null) {
405 privateParameterMap = new HashMap<String, String[]>(
406 parameterMap.size(), 1);
407 }
408
409 privateParameterMap.put(name, entry.getValue());
410 }
411
412 if (privateParameterMap == null) {
413 return Collections.emptyMap();
414 }
415
416 return Collections.unmodifiableMap(privateParameterMap);
417 }
418
419 @Override
420 public Enumeration<String> getProperties(String name) {
421 List<String> values = new ArrayList<String>();
422
423 String value = _portalContext.getProperty(name);
424
425 if (value != null) {
426 values.add(value);
427 }
428
429 return Collections.enumeration(values);
430 }
431
432 @Override
433 public String getProperty(String name) {
434 return _portalContext.getProperty(name);
435 }
436
437 @Override
438 public Enumeration<String> getPropertyNames() {
439 return _portalContext.getPropertyNames();
440 }
441
442 @Override
443 public Map<String, String[]> getPublicParameterMap() {
444 Map<String, String[]> parameterMap = null;
445
446 if (_portletRequestDispatcherRequest != null) {
447 parameterMap = _portletRequestDispatcherRequest.getParameterMap();
448 }
449 else {
450 parameterMap = _request.getParameterMap();
451 }
452
453 Map<String, String[]> publicParameterMap = null;
454
455 for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
456 String name = entry.getKey();
457
458 if (_portlet.getPublicRenderParameter(name) != null) {
459 if (publicParameterMap == null) {
460 publicParameterMap = new HashMap<String, String[]>(
461 parameterMap.size(), 1);
462 }
463
464 publicParameterMap.put(name, entry.getValue());
465 }
466 }
467
468 if (publicParameterMap == null) {
469 return Collections.emptyMap();
470 }
471 else {
472 return Collections.unmodifiableMap(publicParameterMap);
473 }
474 }
475
476 @Override
477 public String getRemoteUser() {
478 return _remoteUser;
479 }
480
481 @Override
482 public Map<String, String[]> getRenderParameters() {
483 return RenderParametersPool.get(_request, _plid, _portletName);
484 }
485
486 @Override
487 public String getRequestedSessionId() {
488 if (_session != null) {
489 return _session.getId();
490 }
491
492 HttpSession session = _request.getSession(false);
493
494 if (session == null) {
495 return StringPool.BLANK;
496 }
497 else {
498 return session.getId();
499 }
500 }
501
502 @Override
503 public String getResponseContentType() {
504 if (_wapTheme) {
505 return ContentTypes.XHTML_MP;
506 }
507 else {
508 return ContentTypes.TEXT_HTML;
509 }
510 }
511
512 @Override
513 public Enumeration<String> getResponseContentTypes() {
514 List<String> responseContentTypes = new ArrayList<String>();
515
516 responseContentTypes.add(getResponseContentType());
517
518 return Collections.enumeration(responseContentTypes);
519 }
520
521 @Override
522 public String getScheme() {
523 return _request.getScheme();
524 }
525
526 @Override
527 public String getServerName() {
528 return _request.getServerName();
529 }
530
531 @Override
532 public int getServerPort() {
533 return _request.getServerPort();
534 }
535
536 public LinkedHashMap<String, String> getUserInfo() {
537 return UserInfoFactory.getUserInfo(_remoteUserId, _portlet);
538 }
539
540 @Override
541 public Principal getUserPrincipal() {
542 return _userPrincipal;
543 }
544
545 @Override
546 public String getWindowID() {
547 return _portletName.concat(
548 LiferayPortletSession.LAYOUT_SEPARATOR).concat(
549 String.valueOf(_plid));
550 }
551
552 @Override
553 public WindowState getWindowState() {
554 return _windowState;
555 }
556
557 public void invalidateSession() {
558 _invalidSession = true;
559 }
560
561 public boolean isInvalidParameter(String name) {
562 if (Validator.isNull(name) ||
563 name.startsWith(PortletQName.PUBLIC_RENDER_PARAMETER_NAMESPACE) ||
564 name.startsWith(
565 PortletQName.REMOVE_PUBLIC_RENDER_PARAMETER_NAMESPACE) ||
566 PortalUtil.isReservedParameter(name)) {
567
568 return true;
569 }
570
571 if (_strutsPortlet) {
572 Matcher matcher = _strutsPortletIgnoredParamtersPattern.matcher(
573 name);
574
575 if (matcher.matches()) {
576 return true;
577 }
578 }
579
580 return false;
581 }
582
583 @Override
584 public boolean isPortletModeAllowed(PortletMode portletMode) {
585 if ((portletMode == null) || Validator.isNull(portletMode.toString())) {
586 return true;
587 }
588 else {
589 return _portlet.hasPortletMode(
590 getResponseContentType(), portletMode);
591 }
592 }
593
594 public boolean isPrivateRequestAttributes() {
595 return _portlet.isPrivateRequestAttributes();
596 }
597
598 @Override
599 public boolean isRequestedSessionIdValid() {
600 return _request.isRequestedSessionIdValid();
601 }
602
603 @Override
604 public boolean isSecure() {
605 return _request.isSecure();
606 }
607
608 public boolean isTriggeredByActionURL() {
609 return _triggeredByActionURL;
610 }
611
612 @Override
613 public boolean isUserInRole(String role) {
614 if (_remoteUserId <= 0) {
615 return false;
616 }
617
618 try {
619 long companyId = PortalUtil.getCompanyId(_request);
620
621 String roleLink = _portlet.getRoleMappers().get(role);
622
623 if (Validator.isNotNull(roleLink)) {
624 return RoleLocalServiceUtil.hasUserRole(
625 _remoteUserId, companyId, roleLink, true);
626 }
627 else {
628 return RoleLocalServiceUtil.hasUserRole(
629 _remoteUserId, companyId, role, true);
630 }
631 }
632 catch (Exception e) {
633 _log.error(e);
634 }
635
636 return _request.isUserInRole(role);
637 }
638
639 @Override
640 public boolean isWindowStateAllowed(WindowState windowState) {
641 return PortalContextImpl.isSupportedWindowState(windowState);
642 }
643
644 @Override
645 public void removeAttribute(String name) {
646 if (name == null) {
647 throw new IllegalArgumentException();
648 }
649
650 _request.removeAttribute(name);
651 }
652
653 @Override
654 public void setAttribute(String name, Object obj) {
655 if (name == null) {
656 throw new IllegalArgumentException();
657 }
658
659 if (obj == null) {
660 removeAttribute(name);
661 }
662 else {
663 _request.setAttribute(name, obj);
664 }
665 }
666
667 public void setPortletMode(PortletMode portletMode) {
668 _portletMode = portletMode;
669 }
670
671 public void setPortletRequestDispatcherRequest(HttpServletRequest request) {
672 _portletRequestDispatcherRequest = request;
673 }
674
675 public void setWindowState(WindowState windowState) {
676 _windowState = windowState;
677 }
678
679 protected void init(
680 HttpServletRequest request, Portlet portlet,
681 InvokerPortlet invokerPortlet, PortletContext portletContext,
682 WindowState windowState, PortletMode portletMode,
683 PortletPreferences preferences, long plid) {
684
685 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
686 WebKeys.THEME_DISPLAY);
687
688 _portlet = portlet;
689 _portletName = portlet.getPortletId();
690 _publicRenderParameters = PublicRenderParametersPool.get(request, plid);
691
692 if (invokerPortlet != null) {
693 if (invokerPortlet.isStrutsPortlet() ||
694 invokerPortlet.isStrutsBridgePortlet()) {
695
696 _strutsPortlet = true;
697 }
698 }
699
700 String portletNamespace = PortalUtil.getPortletNamespace(_portletName);
701
702 PortletApp portletApp = portlet.getPortletApp();
703
704 boolean warFile = portletApp.isWARFile();
705
706 if (!warFile) {
707 String portletResource = ParamUtil.getString(
708 request, portletNamespace.concat("portletResource"));
709
710 if (Validator.isNotNull(portletResource)) {
711 Portlet resourcePortlet = null;
712
713 try {
714 resourcePortlet = PortletLocalServiceUtil.getPortletById(
715 themeDisplay.getCompanyId(), portletResource);
716 }
717 catch (Exception e) {
718 }
719
720 if (resourcePortlet != null) {
721 PortletApp resourcePortletApp =
722 resourcePortlet.getPortletApp();
723
724 if (resourcePortletApp.isWARFile()) {
725 warFile = true;
726 }
727 }
728 }
729 }
730
731 if (warFile) {
732 request = new SharedSessionServletRequest(
733 request, !portlet.isPrivateSessionAttributes());
734 }
735
736 String dynamicQueryString = (String)request.getAttribute(
737 DynamicServletRequest.DYNAMIC_QUERY_STRING);
738
739 if (dynamicQueryString != null) {
740 request.removeAttribute(DynamicServletRequest.DYNAMIC_QUERY_STRING);
741
742 request = DynamicServletRequest.addQueryString(
743 request, dynamicQueryString, true);
744 }
745
746 DynamicServletRequest dynamicRequest = null;
747
748 if (portlet.isPrivateRequestAttributes()) {
749 dynamicRequest = new NamespaceServletRequest(
750 request, portletNamespace, portletNamespace, false);
751 }
752 else {
753 dynamicRequest = new DynamicServletRequest(request, false);
754 }
755
756 boolean portletFocus = false;
757
758 String ppid = ParamUtil.getString(request, "p_p_id");
759
760 boolean windowStateRestoreCurrentView = ParamUtil.getBoolean(
761 request, "p_p_state_rcv");
762
763 if (_portletName.equals(ppid) &&
764 !(windowStateRestoreCurrentView &&
765 portlet.isRestoreCurrentView())) {
766
767
768
769 if (themeDisplay.isLifecycleRender() ||
770 themeDisplay.isLifecycleResource()) {
771
772
773
774 portletFocus = true;
775 }
776 else if (themeDisplay.isLifecycleAction()) {
777 _triggeredByActionURL = true;
778
779 if (getLifecycle().equals(PortletRequest.ACTION_PHASE)) {
780
781
782
783
784 portletFocus = true;
785 }
786 }
787 }
788
789 if (portletFocus) {
790 Map<String, String[]> renderParameters =
791 new HashMap<String, String[]>();
792
793 if (getLifecycle().equals(PortletRequest.RENDER_PHASE) &&
794 !LiferayWindowState.isExclusive(request) &&
795 !LiferayWindowState.isPopUp(request)) {
796
797 RenderParametersPool.put(
798 request, plid, _portletName, renderParameters);
799 }
800
801 Map<String, String[]> parameters = request.getParameterMap();
802
803 for (Map.Entry<String, String[]> entry : parameters.entrySet()) {
804 String name = entry.getKey();
805
806 if (isInvalidParameter(name)) {
807 continue;
808 }
809
810 String[] values = entry.getValue();
811
812 if (themeDisplay.isLifecycleRender()) {
813 renderParameters.put(name, values);
814 }
815
816 if (values == null) {
817 continue;
818 }
819
820 if ((invokerPortlet != null) &&
821 invokerPortlet.isFacesPortlet()) {
822
823 if (name.startsWith(portletNamespace) ||
824 !portlet.isRequiresNamespacedParameters()) {
825
826 dynamicRequest.setParameterValues(name, values);
827 }
828 }
829 else {
830 String realName = removePortletNamespace(
831 portletNamespace, name);
832
833 if (!realName.equals(name) ||
834 !portlet.isRequiresNamespacedParameters()) {
835
836 dynamicRequest.setParameterValues(realName, values);
837 }
838 }
839 }
840 }
841 else {
842 Map<String, String[]> renderParameters = RenderParametersPool.get(
843 request, plid, _portletName);
844
845 for (Map.Entry<String, String[]> entry :
846 renderParameters.entrySet()) {
847
848 String name = entry.getKey();
849 String[] values = entry.getValue();
850
851 if ((invokerPortlet == null) ||
852 !invokerPortlet.isFacesPortlet()) {
853
854 name = removePortletNamespace(portletNamespace, name);
855 }
856
857 dynamicRequest.setParameterValues(name, values);
858 }
859 }
860
861 mergePublicRenderParameters(dynamicRequest, preferences, plid);
862
863 _request = dynamicRequest;
864 _originalRequest = request;
865 _wapTheme = BrowserSnifferUtil.isWap(_request);
866 _portlet = portlet;
867 _portalContext = new PortalContextImpl();
868 _portletContext = portletContext;
869 _windowState = windowState;
870 _portletMode = portletMode;
871 _preferences = preferences;
872 _session = new PortletSessionImpl(
873 _request.getSession(), _portletContext, _portletName, plid);
874
875 String remoteUser = request.getRemoteUser();
876
877 String userPrincipalStrategy = portlet.getUserPrincipalStrategy();
878
879 if (userPrincipalStrategy.equals(
880 PortletConstants.USER_PRINCIPAL_STRATEGY_SCREEN_NAME)) {
881
882 try {
883 User user = PortalUtil.getUser(request);
884
885 if (user != null) {
886 _remoteUser = user.getScreenName();
887 _remoteUserId = user.getUserId();
888 _userPrincipal = new ProtectedPrincipal(_remoteUser);
889 }
890 }
891 catch (Exception e) {
892 _log.error(e);
893 }
894 }
895 else {
896 long userId = PortalUtil.getUserId(request);
897
898 if ((userId > 0) && (remoteUser == null)) {
899 _remoteUser = String.valueOf(userId);
900 _remoteUserId = userId;
901 _userPrincipal = new ProtectedPrincipal(_remoteUser);
902 }
903 else {
904 _remoteUser = remoteUser;
905 _remoteUserId = GetterUtil.getLong(remoteUser);
906 _userPrincipal = request.getUserPrincipal();
907 }
908 }
909
910 _locale = themeDisplay.getLocale();
911 _plid = plid;
912 }
913
914 protected void mergePublicRenderParameters(
915 DynamicServletRequest dynamicRequest, PortletPreferences preferences,
916 long plid) {
917
918 Enumeration<PublicRenderParameter> publicRenderParameters =
919 Collections.enumeration(_portlet.getPublicRenderParameters());
920
921 while (publicRenderParameters.hasMoreElements()) {
922 PublicRenderParameter publicRenderParameter =
923 publicRenderParameters.nextElement();
924
925 String ignoreKey = PublicRenderParameterConfiguration.getIgnoreKey(
926 publicRenderParameter);
927
928 boolean ignoreValue = GetterUtil.getBoolean(
929 preferences.getValue(ignoreKey, null));
930
931 if (ignoreValue) {
932 continue;
933 }
934
935 String mappingKey =
936 PublicRenderParameterConfiguration.getMappingKey(
937 publicRenderParameter);
938
939 String mappingValue = GetterUtil.getString(
940 preferences.getValue(mappingKey, null));
941
942 HttpServletRequest request =
943 (HttpServletRequest)dynamicRequest.getRequest();
944
945 String[] newValues = request.getParameterValues(mappingValue);
946
947 if ((newValues != null) && (newValues.length != 0)) {
948 newValues = ArrayUtil.remove(newValues, StringPool.NULL);
949 }
950
951 String name = publicRenderParameter.getIdentifier();
952
953 if (ArrayUtil.isEmpty(newValues)) {
954 QName qName = publicRenderParameter.getQName();
955
956 String[] values = _publicRenderParameters.get(
957 PortletQNameUtil.getPublicRenderParameterName(qName));
958
959 if (ArrayUtil.isEmpty(values) || Validator.isNull(values[0])) {
960 continue;
961 }
962
963 if (dynamicRequest.getParameter(name) == null) {
964 dynamicRequest.setParameterValues(name, values);
965 }
966 }
967 else {
968 dynamicRequest.setParameterValues(name, newValues);
969 }
970 }
971 }
972
973 protected String removePortletNamespace(
974 String portletNamespace, String name) {
975
976 if (name.startsWith(portletNamespace)) {
977 name = name.substring(portletNamespace.length());
978 }
979
980 return name;
981 }
982
983 private static Log _log = LogFactoryUtil.getLog(PortletRequestImpl.class);
984
985 private static Pattern _strutsPortletIgnoredParamtersPattern =
986 Pattern.compile(PropsValues.STRUTS_PORTLET_IGNORED_PARAMETERS_REGEXP);
987
988 private boolean _invalidSession;
989 private Locale _locale;
990 private HttpServletRequest _originalRequest;
991 private long _plid;
992 private PortalContext _portalContext;
993 private Portlet _portlet;
994 private PortletContext _portletContext;
995 private PortletMode _portletMode;
996 private String _portletName;
997 private HttpServletRequest _portletRequestDispatcherRequest;
998 private PortletPreferences _preferences;
999 private Profile _profile;
1000 private Map<String, String[]> _publicRenderParameters;
1001 private String _remoteUser;
1002 private long _remoteUserId;
1003 private HttpServletRequest _request;
1004 private PortletSessionImpl _session;
1005 private boolean _strutsPortlet;
1006 private boolean _triggeredByActionURL;
1007 private Principal _userPrincipal;
1008 private boolean _wapTheme;
1009 private WindowState _windowState;
1010
1011 private class PortletPreferencesPrivilegedAction
1012 implements PrivilegedAction<PortletPreferences> {
1013
1014 @Override
1015 public PortletPreferences run() {
1016 return new PortletPreferencesWrapper(getPreferencesImpl());
1017 }
1018
1019 }
1020
1021 }