public static HttpServletRequest setupOptionalRenderParameters(
      HttpServletRequest request,
      String renderPath,
      String columnId,
      Integer columnPos,
      Integer columnCount) {

    if ((_LAYOUT_PARALLEL_RENDER_ENABLE && ServerDetector.isTomcat())
        || _PORTLET_CONTAINER_RESTRICT) {

      RestrictPortletServletRequest restrictPortletServletRequest =
          new RestrictPortletServletRequest(request);

      if (renderPath != null) {
        restrictPortletServletRequest.setAttribute(WebKeys.RENDER_PATH, renderPath);
      }

      if (columnId != null) {
        restrictPortletServletRequest.setAttribute(WebKeys.RENDER_PORTLET_COLUMN_ID, columnId);
      }

      if (columnPos != null) {
        restrictPortletServletRequest.setAttribute(WebKeys.RENDER_PORTLET_COLUMN_POS, columnPos);
      }

      if (columnCount != null) {
        restrictPortletServletRequest.setAttribute(
            WebKeys.RENDER_PORTLET_COLUMN_COUNT, columnCount);
      }

      return restrictPortletServletRequest;
    }

    TempAttributesServletRequest tempAttributesServletRequest =
        new TempAttributesServletRequest(request);

    if (renderPath != null) {
      tempAttributesServletRequest.setTempAttribute(WebKeys.RENDER_PATH, renderPath);
    }

    if (columnId != null) {
      tempAttributesServletRequest.setTempAttribute(WebKeys.RENDER_PORTLET_COLUMN_ID, columnId);
    }

    if (columnPos != null) {
      tempAttributesServletRequest.setTempAttribute(WebKeys.RENDER_PORTLET_COLUMN_POS, columnPos);
    }

    if (columnCount != null) {
      tempAttributesServletRequest.setTempAttribute(
          WebKeys.RENDER_PORTLET_COLUMN_COUNT, columnCount);
    }

    return tempAttributesServletRequest;
  }
  protected HttpServletRequest getOwnerLayoutRequestWrapper(
      HttpServletRequest request, Portlet portlet) throws Exception {

    if (!PropsValues.PORTLET_EVENT_DISTRIBUTION_LAYOUT_SET) {
      return request;
    }

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

    Layout currentLayout = themeDisplay.getLayout();

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

    List<LayoutTypePortlet> layoutTypePortlets =
        PortletContainerUtil.getLayoutTypePortlets(requestLayout);

    Layout ownerLayout = null;
    LayoutTypePortlet ownerLayoutTypePortlet = null;

    for (LayoutTypePortlet layoutTypePortlet : layoutTypePortlets) {
      if (layoutTypePortlet.hasPortletId(portlet.getPortletId())) {
        ownerLayoutTypePortlet = layoutTypePortlet;

        ownerLayout = layoutTypePortlet.getLayout();

        break;
      }
    }

    if ((ownerLayout != null) && !currentLayout.equals(ownerLayout)) {
      ThemeDisplay themeDisplayClone = (ThemeDisplay) themeDisplay.clone();

      themeDisplayClone.setLayout(ownerLayout);
      themeDisplayClone.setLayoutTypePortlet(ownerLayoutTypePortlet);

      TempAttributesServletRequest tempAttributesServletRequest =
          new TempAttributesServletRequest(request);

      tempAttributesServletRequest.setTempAttribute(WebKeys.THEME_DISPLAY, themeDisplayClone);
      tempAttributesServletRequest.setTempAttribute(WebKeys.LAYOUT, ownerLayout);

      return tempAttributesServletRequest;
    }

    return request;
  }