private List<Event> _doProcessEvent(
      HttpServletRequest request,
      HttpServletResponse response,
      Portlet portlet,
      Layout layout,
      Event event)
      throws Exception {

    ServletContext servletContext = (ServletContext) request.getAttribute(WebKeys.CTX);

    InvokerPortlet invokerPortlet = PortletInstanceFactoryUtil.create(portlet, servletContext);

    PortletConfig portletConfig = PortletConfigFactoryUtil.create(portlet, servletContext);
    PortletContext portletContext = portletConfig.getPortletContext();

    LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

    WindowState windowState = null;

    if (layoutTypePortlet.hasStateMaxPortletId(portlet.getPortletId())) {
      windowState = WindowState.MAXIMIZED;
    } else if (layoutTypePortlet.hasStateMinPortletId(portlet.getPortletId())) {

      windowState = WindowState.MINIMIZED;
    } else {
      windowState = WindowState.NORMAL;
    }

    PortletMode portletMode = null;

    if (layoutTypePortlet.hasModeAboutPortletId(portlet.getPortletId())) {
      portletMode = LiferayPortletMode.ABOUT;
    } else if (layoutTypePortlet.hasModeConfigPortletId(portlet.getPortletId())) {

      portletMode = LiferayPortletMode.CONFIG;
    } else if (layoutTypePortlet.hasModeEditPortletId(portlet.getPortletId())) {

      portletMode = PortletMode.EDIT;
    } else if (layoutTypePortlet.hasModeEditDefaultsPortletId(portlet.getPortletId())) {

      portletMode = LiferayPortletMode.EDIT_DEFAULTS;
    } else if (layoutTypePortlet.hasModeEditGuestPortletId(portlet.getPortletId())) {

      portletMode = LiferayPortletMode.EDIT_GUEST;
    } else if (layoutTypePortlet.hasModeHelpPortletId(portlet.getPortletId())) {

      portletMode = PortletMode.HELP;
    } else if (layoutTypePortlet.hasModePreviewPortletId(portlet.getPortletId())) {

      portletMode = LiferayPortletMode.PREVIEW;
    } else if (layoutTypePortlet.hasModePrintPortletId(portlet.getPortletId())) {

      portletMode = LiferayPortletMode.PRINT;
    } else {
      portletMode = PortletMode.VIEW;
    }

    long scopeGroupId = getScopeGroupId(request, layout, portlet.getPortletId());

    PortletPreferences portletPreferences =
        PortletPreferencesFactoryUtil.getPortletSetup(
            scopeGroupId, layout, portlet.getPortletId(), null);

    EventRequestImpl eventRequestImpl =
        EventRequestFactory.create(
            request,
            portlet,
            invokerPortlet,
            portletContext,
            windowState,
            portletMode,
            portletPreferences,
            layout.getPlid());

    eventRequestImpl.setEvent(serializeEvent(event, invokerPortlet.getPortletClassLoader()));

    User user = PortalUtil.getUser(request);
    Layout requestLayout = (Layout) request.getAttribute(WebKeys.LAYOUT);

    EventResponseImpl eventResponseImpl =
        EventResponseFactory.create(
            eventRequestImpl, response, portlet.getPortletId(), user, requestLayout);

    eventRequestImpl.defineObjects(portletConfig, eventResponseImpl);

    try {
      invokerPortlet.processEvent(eventRequestImpl, eventResponseImpl);

      if (eventResponseImpl.isCalledSetRenderParameter()) {
        Map<String, String[]> renderParameterMap = new HashMap<String, String[]>();

        renderParameterMap.putAll(eventResponseImpl.getRenderParameterMap());

        RenderParametersPool.put(
            request, requestLayout.getPlid(), portlet.getPortletId(), renderParameterMap);
      }

      return eventResponseImpl.getEvents();
    } finally {
      eventRequestImpl.cleanUp();
    }
  }
  private ActionResult _doProcessAction(
      HttpServletRequest request, HttpServletResponse response, Portlet portlet) throws Exception {

    HttpServletRequest ownerLayoutRequest = getOwnerLayoutRequestWrapper(request, portlet);

    Layout ownerLayout = (Layout) ownerLayoutRequest.getAttribute(WebKeys.LAYOUT);

    boolean allowAddPortletDefaultResource =
        PortalUtil.isAllowAddPortletDefaultResource(ownerLayoutRequest, portlet);

    if (!allowAddPortletDefaultResource) {
      String url = null;

      LastPath lastPath = (LastPath) request.getAttribute(WebKeys.LAST_PATH);

      if (lastPath != null) {
        StringBundler sb = new StringBundler(3);

        sb.append(PortalUtil.getPortalURL(request));
        sb.append(lastPath.getContextPath());
        sb.append(lastPath.getPath());

        url = sb.toString();
      } else {
        url = String.valueOf(request.getRequestURI());
      }

      _log.error("Reject processAction for " + url + " on " + portlet.getPortletId());

      return ActionResult.EMPTY_ACTION_RESULT;
    }

    Layout layout = (Layout) request.getAttribute(WebKeys.LAYOUT);

    WindowState windowState =
        WindowStateFactory.getWindowState(ParamUtil.getString(request, "p_p_state"));

    if (layout.isTypeControlPanel()
        && ((windowState == null)
            || windowState.equals(WindowState.NORMAL)
            || Validator.isNull(windowState.toString()))) {

      windowState = WindowState.MAXIMIZED;
    }

    PortletMode portletMode =
        PortletModeFactory.getPortletMode(ParamUtil.getString(request, "p_p_mode"));

    PortletPreferencesIds portletPreferencesIds =
        PortletPreferencesFactoryUtil.getPortletPreferencesIds(request, portlet.getPortletId());

    PortletPreferences portletPreferences =
        PortletPreferencesLocalServiceUtil.getPreferences(portletPreferencesIds);

    ServletContext servletContext = (ServletContext) request.getAttribute(WebKeys.CTX);

    InvokerPortlet invokerPortlet = PortletInstanceFactoryUtil.create(portlet, servletContext);

    PortletConfig portletConfig = PortletConfigFactoryUtil.create(portlet, servletContext);
    PortletContext portletContext = portletConfig.getPortletContext();

    String contentType = request.getHeader(HttpHeaders.CONTENT_TYPE);

    if (_log.isDebugEnabled()) {
      _log.debug("Content type " + contentType);
    }

    UploadServletRequest uploadServletRequest = null;

    try {
      if ((contentType != null) && contentType.startsWith(ContentTypes.MULTIPART_FORM_DATA)) {

        PortletConfigImpl invokerPortletConfigImpl =
            (PortletConfigImpl) invokerPortlet.getPortletConfig();

        if (invokerPortlet.isStrutsPortlet()
            || invokerPortletConfigImpl.isCopyRequestParameters()
            || !invokerPortletConfigImpl.isWARFile()) {

          uploadServletRequest = new UploadServletRequestImpl(request);

          request = uploadServletRequest;
        }
      }

      if (PropsValues.AUTH_TOKEN_CHECK_ENABLED && invokerPortlet.isCheckAuthToken()) {

        AuthTokenUtil.check(request);
      }

      ActionRequestImpl actionRequestImpl =
          ActionRequestFactory.create(
              request,
              portlet,
              invokerPortlet,
              portletContext,
              windowState,
              portletMode,
              portletPreferences,
              layout.getPlid());

      User user = PortalUtil.getUser(request);

      ActionResponseImpl actionResponseImpl =
          ActionResponseFactory.create(
              actionRequestImpl,
              response,
              portlet.getPortletId(),
              user,
              layout,
              windowState,
              portletMode);

      actionRequestImpl.defineObjects(portletConfig, actionResponseImpl);

      ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequestImpl);

      ServiceContextThreadLocal.pushServiceContext(serviceContext);

      PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

      long scopeGroupId = themeDisplay.getScopeGroupId();

      boolean access =
          PortletPermissionUtil.hasAccessPermission(
              permissionChecker, scopeGroupId, ownerLayout, portlet, portletMode);

      if (access) {
        invokerPortlet.processAction(actionRequestImpl, actionResponseImpl);

        actionResponseImpl.transferHeaders(response);
      }

      RenderParametersPool.put(
          request,
          layout.getPlid(),
          portlet.getPortletId(),
          actionResponseImpl.getRenderParameterMap());

      List<Event> events = actionResponseImpl.getEvents();

      String redirectLocation = actionResponseImpl.getRedirectLocation();

      if (Validator.isNull(redirectLocation) && portlet.isActionURLRedirect()) {

        PortletURL portletURL =
            new PortletURLImpl(
                actionRequestImpl,
                actionRequestImpl.getPortletName(),
                layout.getPlid(),
                PortletRequest.RENDER_PHASE);

        Map<String, String[]> renderParameters = actionResponseImpl.getRenderParameterMap();

        for (Map.Entry<String, String[]> entry : renderParameters.entrySet()) {

          String key = entry.getKey();
          String[] value = entry.getValue();

          portletURL.setParameter(key, value);
        }

        redirectLocation = portletURL.toString();
      }

      return new ActionResult(events, redirectLocation);
    } finally {
      if (uploadServletRequest != null) {
        uploadServletRequest.cleanUp();
      }

      ServiceContextThreadLocal.popServiceContext();
    }
  }
Ejemplo n.º 3
0
 public Map<String, String[]> getRenderParameters() {
   return RenderParametersPool.get(_request, _plid, _portletName);
 }
Ejemplo n.º 4
0
  protected void init(
      HttpServletRequest request,
      Portlet portlet,
      InvokerPortlet invokerPortlet,
      PortletContext portletContext,
      WindowState windowState,
      PortletMode portletMode,
      PortletPreferences preferences,
      long plid) {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    _portlet = portlet;
    _portletName = portlet.getPortletId();
    _publicRenderParameters = PublicRenderParametersPool.get(request, plid);

    String portletNamespace = PortalUtil.getPortletNamespace(_portletName);

    boolean portalSessionShared = false;

    PortletApp portletApp = portlet.getPortletApp();

    if (portletApp.isWARFile() && !portlet.isPrivateSessionAttributes()) {
      portalSessionShared = true;
    }

    request = new SharedSessionServletRequest(request, portalSessionShared);

    DynamicServletRequest dynamicRequest = null;

    if (portlet.isPrivateRequestAttributes()) {
      dynamicRequest =
          new NamespaceServletRequest(request, portletNamespace, portletNamespace, false);
    } else {
      dynamicRequest = new DynamicServletRequest(request, false);
    }

    boolean portletFocus = false;

    String ppid = ParamUtil.getString(request, "p_p_id");

    boolean windowStateRestoreCurrentView = ParamUtil.getBoolean(request, "p_p_state_rcv");

    if (_portletName.equals(ppid)
        && !(windowStateRestoreCurrentView && portlet.isRestoreCurrentView())) {

      // Request was targeted to this portlet

      if (themeDisplay.isLifecycleRender() || themeDisplay.isLifecycleResource()) {

        // Request was triggered by a render or resource URL

        portletFocus = true;
      } else if (themeDisplay.isLifecycleAction()) {
        _triggeredByActionURL = true;

        if (getLifecycle().equals(PortletRequest.ACTION_PHASE)) {

          // Request was triggered by an action URL and is being
          // processed by com.liferay.portlet.ActionRequestImpl

          portletFocus = true;
        }
      }
    }

    Map<String, String[]> renderParameters = RenderParametersPool.get(request, plid, _portletName);

    if (portletFocus) {
      renderParameters = new HashMap<String, String[]>();

      if (getLifecycle().equals(PortletRequest.RENDER_PHASE)
          && !LiferayWindowState.isExclusive(request)
          && !LiferayWindowState.isPopUp(request)) {

        RenderParametersPool.put(request, plid, _portletName, renderParameters);
      }

      Map<String, String[]> parameters = request.getParameterMap();

      for (Map.Entry<String, String[]> entry : parameters.entrySet()) {
        String name = entry.getKey();

        if (isInvalidParameter(name)) {
          continue;
        }

        String[] values = entry.getValue();

        if (themeDisplay.isLifecycleRender()) {
          renderParameters.put(name, values);
        }

        if (values == null) {
          continue;
        }

        name = removePortletNamespace(invokerPortlet, portletNamespace, name);

        dynamicRequest.setParameterValues(name, values);
      }
    } else {
      for (Map.Entry<String, String[]> entry : renderParameters.entrySet()) {

        String name = entry.getKey();
        String[] values = entry.getValue();

        name = removePortletNamespace(invokerPortlet, portletNamespace, name);

        dynamicRequest.setParameterValues(name, values);
      }
    }

    mergePublicRenderParameters(dynamicRequest, preferences, plid);

    _request = dynamicRequest;
    _originalRequest = request;
    _wapTheme = BrowserSnifferUtil.isWap(_request);
    _portlet = portlet;
    _portalContext = new PortalContextImpl();
    _portletContext = portletContext;
    _windowState = windowState;
    _portletMode = portletMode;
    _preferences = preferences;
    _portalSessionId = _request.getRequestedSessionId();
    _session =
        new PortletSessionImpl(_request, _portletName, _portletContext, _portalSessionId, plid);

    String remoteUser = request.getRemoteUser();

    String userPrincipalStrategy = portlet.getUserPrincipalStrategy();

    if (userPrincipalStrategy.equals(PortletConstants.USER_PRINCIPAL_STRATEGY_SCREEN_NAME)) {

      try {
        User user = PortalUtil.getUser(request);

        if (user != null) {
          _remoteUser = user.getScreenName();
          _remoteUserId = user.getUserId();
          _userPrincipal = new ProtectedPrincipal(_remoteUser);
        }
      } catch (Exception e) {
        _log.error(e);
      }
    } else {
      long userId = PortalUtil.getUserId(request);

      if ((userId > 0) && (remoteUser == null)) {
        _remoteUser = String.valueOf(userId);
        _remoteUserId = userId;
        _userPrincipal = new ProtectedPrincipal(_remoteUser);
      } else {
        _remoteUser = remoteUser;
        _remoteUserId = GetterUtil.getLong(remoteUser);
        _userPrincipal = request.getUserPrincipal();
      }
    }

    _locale = themeDisplay.getLocale();
    _plid = plid;
  }
Ejemplo n.º 5
0
  private ActionResult _doProcessAction(
      HttpServletRequest request, HttpServletResponse response, Portlet portlet) throws Exception {

    Layout layout = (Layout) request.getAttribute(WebKeys.LAYOUT);

    WindowState windowState =
        WindowStateFactory.getWindowState(ParamUtil.getString(request, "p_p_state"));

    if (layout.isTypeControlPanel()
        && ((windowState == null)
            || windowState.equals(WindowState.NORMAL)
            || Validator.isNull(windowState.toString()))) {

      windowState = WindowState.MAXIMIZED;
    }

    PortletMode portletMode =
        PortletModeFactory.getPortletMode(ParamUtil.getString(request, "p_p_mode"));

    PortletPreferencesIds portletPreferencesIds =
        PortletPreferencesFactoryUtil.getPortletPreferencesIds(request, portlet.getPortletId());

    PortletPreferences portletPreferences =
        PortletPreferencesLocalServiceUtil.getStrictPreferences(portletPreferencesIds);

    ServletContext servletContext = (ServletContext) request.getAttribute(WebKeys.CTX);

    InvokerPortlet invokerPortlet = PortletInstanceFactoryUtil.create(portlet, servletContext);

    PortletConfig portletConfig = PortletConfigFactoryUtil.create(portlet, servletContext);
    PortletContext portletContext = portletConfig.getPortletContext();

    String contentType = request.getHeader(HttpHeaders.CONTENT_TYPE);

    if (_log.isDebugEnabled()) {
      _log.debug("Content type " + contentType);
    }

    UploadServletRequest uploadServletRequest = null;

    try {
      if ((contentType != null) && contentType.startsWith(ContentTypes.MULTIPART_FORM_DATA)) {

        LiferayPortletConfig liferayPortletConfig =
            (LiferayPortletConfig) invokerPortlet.getPortletConfig();

        if (invokerPortlet.isStrutsPortlet()
            || liferayPortletConfig.isCopyRequestParameters()
            || !liferayPortletConfig.isWARFile()) {

          uploadServletRequest = PortalUtil.getUploadServletRequest(request);

          request = uploadServletRequest;
        }
      }

      ActionRequestImpl actionRequestImpl =
          ActionRequestFactory.create(
              request,
              portlet,
              invokerPortlet,
              portletContext,
              windowState,
              portletMode,
              portletPreferences,
              layout.getPlid());

      User user = PortalUtil.getUser(request);

      ActionResponseImpl actionResponseImpl =
          ActionResponseFactory.create(
              actionRequestImpl,
              response,
              portlet.getPortletId(),
              user,
              layout,
              windowState,
              portletMode);

      actionRequestImpl.defineObjects(portletConfig, actionResponseImpl);

      ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequestImpl);

      ServiceContextThreadLocal.pushServiceContext(serviceContext);

      invokerPortlet.processAction(actionRequestImpl, actionResponseImpl);

      actionResponseImpl.transferHeaders(response);

      RenderParametersPool.put(
          request,
          layout.getPlid(),
          portlet.getPortletId(),
          actionResponseImpl.getRenderParameterMap());

      List<Event> events = actionResponseImpl.getEvents();

      String redirectLocation = actionResponseImpl.getRedirectLocation();

      if (Validator.isNull(redirectLocation) && portlet.isActionURLRedirect()) {

        PortletURL portletURL =
            new PortletURLImpl(
                actionRequestImpl,
                actionRequestImpl.getPortletName(),
                layout.getPlid(),
                PortletRequest.RENDER_PHASE);

        Map<String, String[]> renderParameters = actionResponseImpl.getRenderParameterMap();

        for (Map.Entry<String, String[]> entry : renderParameters.entrySet()) {

          String key = entry.getKey();
          String[] value = entry.getValue();

          portletURL.setParameter(key, value);
        }

        redirectLocation = portletURL.toString();
      }

      return new ActionResult(events, redirectLocation);
    } finally {
      if (uploadServletRequest != null) {
        uploadServletRequest.cleanUp();
      }

      ServiceContextThreadLocal.popServiceContext();
    }
  }