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 public PortletContext getPortletContext() {
313 return _portletContext;
314 }
315
316 @Override
317 public PortletMode getPortletMode() {
318 return _portletMode;
319 }
320
321 public String getPortletName() {
322 return _portletName;
323 }
324
325 @Override
326 public PortletSession getPortletSession() {
327 return _session;
328 }
329
330 @Override
331 public PortletSession getPortletSession(boolean create) {
332
345
346
352
353 if (!create && _invalidSession) {
354 return null;
355 }
356
357 return _session;
358 }
359
360 @Override
361 public PortletPreferences getPreferences() {
362 String lifecycle = getLifecycle();
363
364 if (lifecycle.equals(PortletRequest.RENDER_PHASE) &&
365 PropsValues.PORTLET_PREFERENCES_STRICT_STORE) {
366
367 return DoPrivilegedUtil.wrap(
368 new PortletPreferencesPrivilegedAction());
369 }
370
371 return getPreferencesImpl();
372 }
373
374 public PortletPreferencesImpl getPreferencesImpl() {
375 return (PortletPreferencesImpl)_preferences;
376 }
377
378 @Override
379 public Map<String, String[]> getPrivateParameterMap() {
380 Map<String, String[]> parameterMap = null;
381
382 if (_portletRequestDispatcherRequest != null) {
383 parameterMap = _portletRequestDispatcherRequest.getParameterMap();
384 }
385 else {
386 parameterMap = _request.getParameterMap();
387 }
388
389 Map<String, String[]> privateParameterMap = null;
390
391 for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
392 String name = entry.getKey();
393
394 if (_portlet.getPublicRenderParameter(name) != null) {
395 continue;
396 }
397
398 if (privateParameterMap == null) {
399 privateParameterMap = new HashMap<String, String[]>(
400 parameterMap.size(), 1);
401 }
402
403 privateParameterMap.put(name, entry.getValue());
404 }
405
406 if (privateParameterMap == null) {
407 return Collections.emptyMap();
408 }
409
410 return Collections.unmodifiableMap(privateParameterMap);
411 }
412
413 @Override
414 public Enumeration<String> getProperties(String name) {
415 List<String> values = new ArrayList<String>();
416
417 String value = _portalContext.getProperty(name);
418
419 if (value != null) {
420 values.add(value);
421 }
422
423 return Collections.enumeration(values);
424 }
425
426 @Override
427 public String getProperty(String name) {
428 return _portalContext.getProperty(name);
429 }
430
431 @Override
432 public Enumeration<String> getPropertyNames() {
433 return _portalContext.getPropertyNames();
434 }
435
436 @Override
437 public Map<String, String[]> getPublicParameterMap() {
438 Map<String, String[]> parameterMap = null;
439
440 if (_portletRequestDispatcherRequest != null) {
441 parameterMap = _portletRequestDispatcherRequest.getParameterMap();
442 }
443 else {
444 parameterMap = _request.getParameterMap();
445 }
446
447 Map<String, String[]> publicParameterMap = null;
448
449 for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
450 String name = entry.getKey();
451
452 if (_portlet.getPublicRenderParameter(name) != null) {
453 if (publicParameterMap == null) {
454 publicParameterMap = new HashMap<String, String[]>(
455 parameterMap.size(), 1);
456 }
457
458 publicParameterMap.put(name, entry.getValue());
459 }
460 }
461
462 if (publicParameterMap == null) {
463 return Collections.emptyMap();
464 }
465 else {
466 return Collections.unmodifiableMap(publicParameterMap);
467 }
468 }
469
470 @Override
471 public String getRemoteUser() {
472 return _remoteUser;
473 }
474
475 @Override
476 public Map<String, String[]> getRenderParameters() {
477 return RenderParametersPool.get(_request, _plid, _portletName);
478 }
479
480 @Override
481 public String getRequestedSessionId() {
482 if (_session != null) {
483 return _session.getId();
484 }
485
486 HttpSession session = _request.getSession(false);
487
488 if (session == null) {
489 return StringPool.BLANK;
490 }
491 else {
492 return session.getId();
493 }
494 }
495
496 @Override
497 public String getResponseContentType() {
498 if (_wapTheme) {
499 return ContentTypes.XHTML_MP;
500 }
501 else {
502 return ContentTypes.TEXT_HTML;
503 }
504 }
505
506 @Override
507 public Enumeration<String> getResponseContentTypes() {
508 List<String> responseContentTypes = new ArrayList<String>();
509
510 responseContentTypes.add(getResponseContentType());
511
512 return Collections.enumeration(responseContentTypes);
513 }
514
515 @Override
516 public String getScheme() {
517 return _request.getScheme();
518 }
519
520 @Override
521 public String getServerName() {
522 return _request.getServerName();
523 }
524
525 @Override
526 public int getServerPort() {
527 return _request.getServerPort();
528 }
529
530 public LinkedHashMap<String, String> getUserInfo() {
531 return UserInfoFactory.getUserInfo(_remoteUserId, _portlet);
532 }
533
534 @Override
535 public Principal getUserPrincipal() {
536 return _userPrincipal;
537 }
538
539 @Override
540 public String getWindowID() {
541 return _portletName.concat(
542 LiferayPortletSession.LAYOUT_SEPARATOR).concat(
543 String.valueOf(_plid));
544 }
545
546 @Override
547 public WindowState getWindowState() {
548 return _windowState;
549 }
550
551 public void invalidateSession() {
552 _invalidSession = true;
553 }
554
555 public boolean isInvalidParameter(String name) {
556 if (Validator.isNull(name) ||
557 name.startsWith(PortletQName.PUBLIC_RENDER_PARAMETER_NAMESPACE) ||
558 name.startsWith(
559 PortletQName.REMOVE_PUBLIC_RENDER_PARAMETER_NAMESPACE) ||
560 PortalUtil.isReservedParameter(name)) {
561
562 return true;
563 }
564
565 if (_strutsPortlet) {
566 Matcher matcher = _strutsPortletIgnoredParamtersPattern.matcher(
567 name);
568
569 if (matcher.matches()) {
570 return true;
571 }
572 }
573
574 return false;
575 }
576
577 @Override
578 public boolean isPortletModeAllowed(PortletMode portletMode) {
579 if ((portletMode == null) || Validator.isNull(portletMode.toString())) {
580 return true;
581 }
582 else {
583 return _portlet.hasPortletMode(
584 getResponseContentType(), portletMode);
585 }
586 }
587
588 public boolean isPrivateRequestAttributes() {
589 return _portlet.isPrivateRequestAttributes();
590 }
591
592 @Override
593 public boolean isRequestedSessionIdValid() {
594 return _request.isRequestedSessionIdValid();
595 }
596
597 @Override
598 public boolean isSecure() {
599 return _request.isSecure();
600 }
601
602 public boolean isTriggeredByActionURL() {
603 return _triggeredByActionURL;
604 }
605
606 @Override
607 public boolean isUserInRole(String role) {
608 if (_remoteUserId <= 0) {
609 return false;
610 }
611
612 try {
613 long companyId = PortalUtil.getCompanyId(_request);
614
615 String roleLink = _portlet.getRoleMappers().get(role);
616
617 if (Validator.isNotNull(roleLink)) {
618 return RoleLocalServiceUtil.hasUserRole(
619 _remoteUserId, companyId, roleLink, true);
620 }
621 else {
622 return RoleLocalServiceUtil.hasUserRole(
623 _remoteUserId, companyId, role, true);
624 }
625 }
626 catch (Exception e) {
627 _log.error(e);
628 }
629
630 return _request.isUserInRole(role);
631 }
632
633 @Override
634 public boolean isWindowStateAllowed(WindowState windowState) {
635 return PortalContextImpl.isSupportedWindowState(windowState);
636 }
637
638 @Override
639 public void removeAttribute(String name) {
640 if (name == null) {
641 throw new IllegalArgumentException();
642 }
643
644 _request.removeAttribute(name);
645 }
646
647 @Override
648 public void setAttribute(String name, Object obj) {
649 if (name == null) {
650 throw new IllegalArgumentException();
651 }
652
653 if (obj == null) {
654 removeAttribute(name);
655 }
656 else {
657 _request.setAttribute(name, obj);
658 }
659 }
660
661 public void setPortletMode(PortletMode portletMode) {
662 _portletMode = portletMode;
663 }
664
665 public void setPortletRequestDispatcherRequest(HttpServletRequest request) {
666 _portletRequestDispatcherRequest = request;
667 }
668
669 public void setWindowState(WindowState windowState) {
670 _windowState = windowState;
671 }
672
673 protected void init(
674 HttpServletRequest request, Portlet portlet,
675 InvokerPortlet invokerPortlet, PortletContext portletContext,
676 WindowState windowState, PortletMode portletMode,
677 PortletPreferences preferences, long plid) {
678
679 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
680 WebKeys.THEME_DISPLAY);
681
682 _portlet = portlet;
683 _portletName = portlet.getPortletId();
684 _publicRenderParameters = PublicRenderParametersPool.get(request, plid);
685
686 if (invokerPortlet != null) {
687 if (invokerPortlet.isStrutsPortlet() ||
688 invokerPortlet.isStrutsBridgePortlet()) {
689
690 _strutsPortlet = true;
691 }
692 }
693
694 String portletNamespace = PortalUtil.getPortletNamespace(_portletName);
695
696 PortletApp portletApp = portlet.getPortletApp();
697
698 boolean warFile = portletApp.isWARFile();
699
700 if (!warFile) {
701 String portletResource = ParamUtil.getString(
702 request, portletNamespace.concat("portletResource"));
703
704 if (Validator.isNotNull(portletResource)) {
705 Portlet resourcePortlet = null;
706
707 try {
708 resourcePortlet = PortletLocalServiceUtil.getPortletById(
709 themeDisplay.getCompanyId(), portletResource);
710 }
711 catch (Exception e) {
712 }
713
714 if (resourcePortlet != null) {
715 PortletApp resourcePortletApp =
716 resourcePortlet.getPortletApp();
717
718 if (resourcePortletApp.isWARFile()) {
719 warFile = true;
720 }
721 }
722 }
723 }
724
725 if (warFile) {
726 request = new SharedSessionServletRequest(
727 request, !portlet.isPrivateSessionAttributes());
728 }
729
730 String dynamicQueryString = (String)request.getAttribute(
731 DynamicServletRequest.DYNAMIC_QUERY_STRING);
732
733 if (dynamicQueryString != null) {
734 request.removeAttribute(DynamicServletRequest.DYNAMIC_QUERY_STRING);
735
736 request = DynamicServletRequest.addQueryString(
737 request, dynamicQueryString, true);
738 }
739
740 DynamicServletRequest dynamicRequest = null;
741
742 if (portlet.isPrivateRequestAttributes()) {
743 dynamicRequest = new NamespaceServletRequest(
744 request, portletNamespace, portletNamespace, false);
745 }
746 else {
747 dynamicRequest = new DynamicServletRequest(request, false);
748 }
749
750 boolean portletFocus = false;
751
752 String ppid = ParamUtil.getString(request, "p_p_id");
753
754 boolean windowStateRestoreCurrentView = ParamUtil.getBoolean(
755 request, "p_p_state_rcv");
756
757 if (_portletName.equals(ppid) &&
758 !(windowStateRestoreCurrentView &&
759 portlet.isRestoreCurrentView())) {
760
761
762
763 if (themeDisplay.isLifecycleRender() ||
764 themeDisplay.isLifecycleResource()) {
765
766
767
768 portletFocus = true;
769 }
770 else if (themeDisplay.isLifecycleAction()) {
771 _triggeredByActionURL = true;
772
773 if (getLifecycle().equals(PortletRequest.ACTION_PHASE)) {
774
775
776
777
778 portletFocus = true;
779 }
780 }
781 }
782
783 if (portletFocus) {
784 Map<String, String[]> renderParameters =
785 new HashMap<String, String[]>();
786
787 if (getLifecycle().equals(PortletRequest.RENDER_PHASE) &&
788 !LiferayWindowState.isExclusive(request) &&
789 !LiferayWindowState.isPopUp(request)) {
790
791 RenderParametersPool.put(
792 request, plid, _portletName, renderParameters);
793 }
794
795 Map<String, String[]> parameters = request.getParameterMap();
796
797 for (Map.Entry<String, String[]> entry : parameters.entrySet()) {
798 String name = entry.getKey();
799
800 if (isInvalidParameter(name)) {
801 continue;
802 }
803
804 String[] values = entry.getValue();
805
806 if (themeDisplay.isLifecycleRender()) {
807 renderParameters.put(name, values);
808 }
809
810 if (values == null) {
811 continue;
812 }
813
814 if ((invokerPortlet != null) &&
815 invokerPortlet.isFacesPortlet()) {
816
817 if (name.startsWith(portletNamespace) ||
818 !portlet.isRequiresNamespacedParameters()) {
819
820 dynamicRequest.setParameterValues(name, values);
821 }
822 }
823 else {
824 String realName = removePortletNamespace(
825 portletNamespace, name);
826
827 if (!realName.equals(name) ||
828 !portlet.isRequiresNamespacedParameters()) {
829
830 dynamicRequest.setParameterValues(realName, values);
831 }
832 }
833 }
834 }
835 else {
836 Map<String, String[]> renderParameters = RenderParametersPool.get(
837 request, plid, _portletName);
838
839 for (Map.Entry<String, String[]> entry :
840 renderParameters.entrySet()) {
841
842 String name = entry.getKey();
843 String[] values = entry.getValue();
844
845 if ((invokerPortlet == null) ||
846 !invokerPortlet.isFacesPortlet()) {
847
848 name = removePortletNamespace(portletNamespace, name);
849 }
850
851 dynamicRequest.setParameterValues(name, values);
852 }
853 }
854
855 mergePublicRenderParameters(dynamicRequest, preferences, plid);
856
857 _request = dynamicRequest;
858 _originalRequest = request;
859 _wapTheme = BrowserSnifferUtil.isWap(_request);
860 _portlet = portlet;
861 _portalContext = new PortalContextImpl();
862 _portletContext = portletContext;
863 _windowState = windowState;
864 _portletMode = portletMode;
865 _preferences = preferences;
866 _session = new PortletSessionImpl(
867 _request.getSession(), _portletContext, _portletName, plid);
868
869 String remoteUser = request.getRemoteUser();
870
871 String userPrincipalStrategy = portlet.getUserPrincipalStrategy();
872
873 if (userPrincipalStrategy.equals(
874 PortletConstants.USER_PRINCIPAL_STRATEGY_SCREEN_NAME)) {
875
876 try {
877 User user = PortalUtil.getUser(request);
878
879 if (user != null) {
880 _remoteUser = user.getScreenName();
881 _remoteUserId = user.getUserId();
882 _userPrincipal = new ProtectedPrincipal(_remoteUser);
883 }
884 }
885 catch (Exception e) {
886 _log.error(e);
887 }
888 }
889 else {
890 long userId = PortalUtil.getUserId(request);
891
892 if ((userId > 0) && (remoteUser == null)) {
893 _remoteUser = String.valueOf(userId);
894 _remoteUserId = userId;
895 _userPrincipal = new ProtectedPrincipal(_remoteUser);
896 }
897 else {
898 _remoteUser = remoteUser;
899 _remoteUserId = GetterUtil.getLong(remoteUser);
900 _userPrincipal = request.getUserPrincipal();
901 }
902 }
903
904 _locale = themeDisplay.getLocale();
905 _plid = plid;
906 }
907
908 protected void mergePublicRenderParameters(
909 DynamicServletRequest dynamicRequest, PortletPreferences preferences,
910 long plid) {
911
912 Enumeration<PublicRenderParameter> publicRenderParameters =
913 Collections.enumeration(_portlet.getPublicRenderParameters());
914
915 while (publicRenderParameters.hasMoreElements()) {
916 PublicRenderParameter publicRenderParameter =
917 publicRenderParameters.nextElement();
918
919 String ignoreKey = PublicRenderParameterConfiguration.getIgnoreKey(
920 publicRenderParameter);
921
922 boolean ignoreValue = GetterUtil.getBoolean(
923 preferences.getValue(ignoreKey, null));
924
925 if (ignoreValue) {
926 continue;
927 }
928
929 String mappingKey =
930 PublicRenderParameterConfiguration.getMappingKey(
931 publicRenderParameter);
932
933 String mappingValue = GetterUtil.getString(
934 preferences.getValue(mappingKey, null));
935
936 HttpServletRequest request =
937 (HttpServletRequest)dynamicRequest.getRequest();
938
939 String[] newValues = request.getParameterValues(mappingValue);
940
941 if ((newValues != null) && (newValues.length != 0)) {
942 newValues = ArrayUtil.remove(newValues, StringPool.NULL);
943 }
944
945 String name = publicRenderParameter.getIdentifier();
946
947 if (ArrayUtil.isEmpty(newValues)) {
948 QName qName = publicRenderParameter.getQName();
949
950 String[] values = _publicRenderParameters.get(
951 PortletQNameUtil.getPublicRenderParameterName(qName));
952
953 if (ArrayUtil.isEmpty(values) || Validator.isNull(values[0])) {
954 continue;
955 }
956
957 if (dynamicRequest.getParameter(name) == null) {
958 dynamicRequest.setParameterValues(name, values);
959 }
960 }
961 else {
962 dynamicRequest.setParameterValues(name, newValues);
963 }
964 }
965 }
966
967 protected String removePortletNamespace(
968 String portletNamespace, String name) {
969
970 if (name.startsWith(portletNamespace)) {
971 name = name.substring(portletNamespace.length());
972 }
973
974 return name;
975 }
976
977 private static Log _log = LogFactoryUtil.getLog(PortletRequestImpl.class);
978
979 private static Pattern _strutsPortletIgnoredParamtersPattern =
980 Pattern.compile(PropsValues.STRUTS_PORTLET_IGNORED_PARAMETERS_REGEXP);
981
982 private boolean _invalidSession;
983 private Locale _locale;
984 private HttpServletRequest _originalRequest;
985 private long _plid;
986 private PortalContext _portalContext;
987 private Portlet _portlet;
988 private PortletContext _portletContext;
989 private PortletMode _portletMode;
990 private String _portletName;
991 private HttpServletRequest _portletRequestDispatcherRequest;
992 private PortletPreferences _preferences;
993 private Profile _profile;
994 private Map<String, String[]> _publicRenderParameters;
995 private String _remoteUser;
996 private long _remoteUserId;
997 private HttpServletRequest _request;
998 private PortletSessionImpl _session;
999 private boolean _strutsPortlet;
1000 private boolean _triggeredByActionURL;
1001 private Principal _userPrincipal;
1002 private boolean _wapTheme;
1003 private WindowState _windowState;
1004
1005 private class PortletPreferencesPrivilegedAction
1006 implements PrivilegedAction<PortletPreferences> {
1007
1008 @Override
1009 public PortletPreferences run() {
1010 return new PortletPreferencesWrapper(getPreferencesImpl());
1011 }
1012
1013 }
1014
1015 }