コード例 #1
0
  protected String getRedirect(
      ActionRequest actionRequest, ActionResponse actionResponse, MBMessage message) {

    if (message == null) {
      String redirect = ParamUtil.getString(actionRequest, "redirect");

      return redirect;
    }

    int workflowAction =
        ParamUtil.getInteger(actionRequest, "workflowAction", WorkflowConstants.ACTION_PUBLISH);

    if (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT) {
      return getSaveAndContinueRedirect(actionRequest, actionResponse, message);
    } else if (message == null) {
      return ParamUtil.getString(actionRequest, "redirect");
    }

    ActionResponseImpl actionResponseImpl = (ActionResponseImpl) actionResponse;

    PortletURL portletURL = actionResponseImpl.createRenderURL();

    portletURL.setParameter("mvcRenderCommandName", "/message_boards/view_message");
    portletURL.setParameter("messageId", String.valueOf(message.getMessageId()));

    return portletURL.toString();
  }
コード例 #2
0
  protected String convertProcess(
      ActionRequest actionRequest, ActionResponse actionResponse, String cmd) throws Exception {

    ActionResponseImpl actionResponseImpl = (ActionResponseImpl) actionResponse;

    PortletSession portletSession = actionRequest.getPortletSession();

    String className = StringUtil.replaceFirst(cmd, "convertProcess.", StringPool.BLANK);

    ConvertProcess convertProcess = (ConvertProcess) InstancePool.get(className);

    String[] parameters = convertProcess.getParameterNames();

    if (parameters != null) {
      String[] values = new String[parameters.length];

      for (int i = 0; i < parameters.length; i++) {
        String parameter = className + StringPool.PERIOD + parameters[i];

        if (parameters[i].contains(StringPool.EQUAL)) {
          String[] parameterPair = StringUtil.split(parameters[i], CharPool.EQUAL);

          parameter = className + StringPool.PERIOD + parameterPair[0];
        }

        values[i] = ParamUtil.getString(actionRequest, parameter);
      }

      convertProcess.setParameterValues(values);
    }

    String path = convertProcess.getPath();

    if (path != null) {
      PortletURL portletURL = actionResponseImpl.createRenderURL();

      portletURL.setWindowState(WindowState.MAXIMIZED);

      portletURL.setParameter("struts_action", path);

      return portletURL.toString();
    } else {
      MaintenanceUtil.maintain(portletSession.getId(), className);

      MessageBusUtil.sendMessage(DestinationNames.CONVERT_PROCESS, className);

      return null;
    }
  }
コード例 #3
0
  protected void redirectActionURL(
      HttpServletRequest request,
      HttpServletResponse response,
      ActionResponseImpl actionResponseImpl,
      Portlet portlet)
      throws Exception {

    ActionRequestImpl actionRequestImpl =
        (ActionRequestImpl) request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);

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

    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);
    }

    response.sendRedirect(portletURL.toString());
  }
コード例 #4
0
  private Map _getRenderParameters(HttpServletRequest req, ActionResponseImpl res) {
    Map params = new HashMap();
    params.putAll(res.getRenderParameters());

    String[] plid = req.getParameterValues("p_l_id");
    params.put("p_l_id", plid);

    String[] portletName = req.getParameterValues("p_p_id");
    params.put("p_p_id", portletName);

    String[] action = {"0"};
    params.put("p_p_action", action);

    String[] windowState = req.getParameterValues("p_p_state");
    params.put("p_p_state", windowState);

    String[] portletMode = req.getParameterValues("p_p_mode");
    params.put("p_p_mode", portletMode);

    return params;
  }
コード例 #5
0
  protected Portlet processPortletRequest(
      HttpServletRequest request, HttpServletResponse response, String lifecycle) throws Exception {

    HttpSession session = request.getSession();

    long companyId = PortalUtil.getCompanyId(request);
    User user = PortalUtil.getUser(request);
    Layout layout = (Layout) request.getAttribute(WebKeys.LAYOUT);

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

    if (Validator.isNull(portletId)) {
      return null;
    }

    Portlet portlet = PortletLocalServiceUtil.getPortletById(companyId, portletId);

    if (portlet == null) {
      return null;
    }

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

    themeDisplay.setScopeGroupId(PortalUtil.getScopeGroupId(request, portletId));

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

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

    if (user != null) {
      InvokerPortletImpl.clearResponse(
          session, layout.getPrimaryKey(), portletId, LanguageUtil.getLanguageId(request));
    }

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

    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, portletId);

    PortletPreferences portletPreferences =
        PortletPreferencesLocalServiceUtil.getPreferences(portletPreferencesIds);

    processPublicRenderParameters(request, layout, portlet);

    if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
      String contentType = request.getHeader(HttpHeaders.CONTENT_TYPE);

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

      UploadServletRequest uploadRequest = null;

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

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

          if (invokerPortlet.isStrutsPortlet()
              || ((invokerPortletConfigImpl != null) && (!invokerPortletConfigImpl.isWARFile()))) {

            uploadRequest = new UploadServletRequestImpl(request);

            request = uploadRequest;
          }
        }

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

          AuthTokenUtil.check(request);
        }

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

        ActionResponseImpl actionResponseImpl =
            ActionResponseFactory.create(
                actionRequestImpl, response, portletId, 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(), portletId, actionResponseImpl.getRenderParameterMap());

        List<LayoutTypePortlet> layoutTypePortlets = null;

        if (!actionResponseImpl.getEvents().isEmpty()) {
          if (PropsValues.PORTLET_EVENT_DISTRIBUTION_LAYOUT_SET) {
            layoutTypePortlets =
                getLayoutTypePortlets(layout.getGroupId(), layout.isPrivateLayout());
          } else {
            if (layout.isTypePortlet()) {
              LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

              layoutTypePortlets = new ArrayList<LayoutTypePortlet>();

              layoutTypePortlets.add(layoutTypePortlet);
            }
          }

          processEvents(actionRequestImpl, actionResponseImpl, layoutTypePortlets);

          actionRequestImpl.defineObjects(portletConfig, actionResponseImpl);
        }
      } finally {
        if (uploadRequest != null) {
          uploadRequest.cleanUp();
        }

        ServiceContextThreadLocal.popServiceContext();
      }
    } else if (lifecycle.equals(PortletRequest.RENDER_PHASE)
        || lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {

      PortalUtil.updateWindowState(portletId, user, layout, windowState, request);

      PortalUtil.updatePortletMode(portletId, user, layout, portletMode, request);
    }

    if (lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {
      PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

      String portletPrimaryKey = PortletPermissionUtil.getPrimaryKey(layout.getPlid(), portletId);

      portletDisplay.setId(portletId);
      portletDisplay.setRootPortletId(portlet.getRootPortletId());
      portletDisplay.setInstanceId(portlet.getInstanceId());
      portletDisplay.setResourcePK(portletPrimaryKey);
      portletDisplay.setPortletName(portletConfig.getPortletName());
      portletDisplay.setNamespace(PortalUtil.getPortletNamespace(portletId));

      ResourceRequestImpl resourceRequestImpl =
          ResourceRequestFactory.create(
              request,
              portlet,
              invokerPortlet,
              portletContext,
              windowState,
              portletMode,
              portletPreferences,
              layout.getPlid());

      ResourceResponseImpl resourceResponseImpl =
          ResourceResponseFactory.create(resourceRequestImpl, response, portletId, companyId);

      resourceRequestImpl.defineObjects(portletConfig, resourceResponseImpl);

      try {
        ServiceContext serviceContext = ServiceContextFactory.getInstance(resourceRequestImpl);

        ServiceContextThreadLocal.pushServiceContext(serviceContext);

        invokerPortlet.serveResource(resourceRequestImpl, resourceResponseImpl);
      } finally {
        ServiceContextThreadLocal.popServiceContext();
      }
    }

    return portlet;
  }
コード例 #6
0
  protected ActionForward processLayout(
      ActionMapping mapping, HttpServletRequest request, HttpServletResponse response, long plid)
      throws Exception {

    HttpSession session = request.getSession();

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

    try {
      Layout layout = themeDisplay.getLayout();

      boolean resetLayout =
          ParamUtil.getBoolean(request, "p_l_reset", PropsValues.LAYOUT_DEFAULT_P_L_RESET);

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

      Layout previousLayout = (Layout) session.getAttribute(WebKeys.PREVIOUS_LAYOUT);

      if ((previousLayout == null) || (layout.getPlid() != previousLayout.getPlid())) {

        session.setAttribute(WebKeys.PREVIOUS_LAYOUT, layout);

        if (themeDisplay.isSignedIn()
            && PropsValues.AUDIT_MESSAGE_COM_LIFERAY_PORTAL_MODEL_LAYOUT_VIEW
            && MessageBusUtil.hasMessageListener(DestinationNames.AUDIT)) {

          User user = themeDisplay.getUser();

          AuditMessage auditMessage =
              new AuditMessage(
                  ActionKeys.VIEW,
                  user.getCompanyId(),
                  user.getUserId(),
                  user.getFullName(),
                  Layout.class.getName(),
                  String.valueOf(layout.getPlid()));

          AuditRouterUtil.route(auditMessage);
        }
      }

      if (!PropsValues.TCK_URL
          && resetLayout
          && (Validator.isNull(portletId)
              || ((previousLayout != null) && (layout.getPlid() != previousLayout.getPlid())))) {

        // Always clear render parameters on a layout url, but do not
        // clear on portlet urls invoked on the same layout

        RenderParametersPool.clear(request, plid);
      }

      if (themeDisplay.isLifecycleAction()) {
        Portlet portlet = processPortletRequest(request, response, PortletRequest.ACTION_PHASE);

        if (portlet != null) {
          ActionResponseImpl actionResponseImpl =
              (ActionResponseImpl) request.getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);

          String redirectLocation = actionResponseImpl.getRedirectLocation();

          if (Validator.isNotNull(redirectLocation)) {
            response.sendRedirect(redirectLocation);

            return null;
          }

          if (portlet.isActionURLRedirect()) {
            redirectActionURL(request, response, actionResponseImpl, portlet);

            return null;
          }
        }
      } else if (themeDisplay.isLifecycleRender()) {
        processPortletRequest(request, response, PortletRequest.RENDER_PHASE);
      }

      if (themeDisplay.isLifecycleResource()) {
        processPortletRequest(request, response, PortletRequest.RESOURCE_PHASE);

        return null;
      } else {
        if (response.isCommitted()) {
          return null;
        }

        if (layout != null) {

          // Include layout content before the page loads because
          // portlets on the page can set the page title and page
          // subtitle

          includeLayoutContent(request, response, themeDisplay, layout);

          if (themeDisplay.isStateExclusive()) {
            renderExclusive(request, response, themeDisplay);

            return null;
          }
        }

        return mapping.findForward("portal.layout");
      }
    } catch (Exception e) {
      PortalUtil.sendError(e, request, response);

      return null;
    } finally {
      if (!ServerDetector.isResin()) {
        PortletRequest portletRequest =
            (PortletRequest) request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);

        if (portletRequest != null) {
          PortletRequestImpl portletRequestImpl = (PortletRequestImpl) portletRequest;

          portletRequestImpl.cleanUp();
        }
      }
    }
  }