private void printSupportedWindowStates(PortalContext context) {
   // -- supported window states by the portal server
   Enumeration<WindowState> windowStates = context.getSupportedWindowStates();
   while (windowStates.hasMoreElements()) {
     WindowState windowState = windowStates.nextElement();
     logger.info("Support window state " + windowState.toString());
   }
 }
  private void _doPreparePortlet(HttpServletRequest request, Portlet portlet) throws Exception {

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

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

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

    themeDisplay.setScopeGroupId(scopeGroupId);

    long siteGroupId = 0;

    if (layout.isTypeControlPanel()) {
      siteGroupId = PortalUtil.getSiteGroupId(scopeGroupId);
    } else {
      siteGroupId = PortalUtil.getSiteGroupId(layout.getGroupId());
    }

    themeDisplay.setSiteGroupId(siteGroupId);

    if (user != null) {
      HttpSession session = request.getSession();

      InvokerPortletImpl.clearResponse(
          session,
          layout.getPrimaryKey(),
          portlet.getPortletId(),
          LanguageUtil.getLanguageId(request));
    }

    processPublicRenderParameters(request, layout, portlet);

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

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

      PortalUtil.updateWindowState(portlet.getPortletId(), user, layout, windowState, request);

      PortalUtil.updatePortletMode(portlet.getPortletId(), user, layout, portletMode, request);
    }
  }
  protected void sendEditEntryRedirect(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

    WindowState windowState = actionRequest.getWindowState();

    if (!windowState.equals(LiferayWindowState.POP_UP)) {
      sendRedirect(actionRequest, actionResponse);
    } else if (Validator.isNotNull(redirect)) {
      actionResponse.sendRedirect(redirect);
    }
  }
  @Override
  protected String getURL(
      ThemeDisplay themeDisplay, long groupId, Document result, PortletURL portletURL) {

    long resourcePrimKey = GetterUtil.getLong(result.get(Field.ENTRY_CLASS_PK));
    int status = WorkflowConstants.STATUS_APPROVED;

    WindowState windowState = portletURL.getWindowState();

    return KnowledgeBaseUtil.getKBArticleURL(
        themeDisplay.getPlid(),
        resourcePrimKey,
        status,
        themeDisplay.getPortalURL(),
        windowState.equals(LiferayWindowState.MAXIMIZED));
  }
  public String buildPath(LiferayPortletURL liferayPortletURL) {
    StringBuilder sb = new StringBuilder();

    sb.append("/consumer");

    addPathElement(sb, liferayPortletURL.getPortletId());

    liferayPortletURL.addParameterIncludedInPath("p_p_id");

    WindowState windowState = liferayPortletURL.getWindowState();

    if (windowState != null) {
      addPathElement(sb, windowState.toString());
    } else {
      addPathElement(sb, null);
    }

    liferayPortletURL.addParameterIncludedInPath("p_p_state");

    PortletMode portletMode = liferayPortletURL.getPortletMode();

    if (portletMode != null) {
      addPathElement(sb, portletMode.toString());
    } else {
      addPathElement(sb, null);
    }

    liferayPortletURL.addParameterIncludedInPath("p_p_mode");

    addPathElement(sb, liferayPortletURL.getCacheability());

    liferayPortletURL.addParameterIncludedInPath("p_p_cacheability");

    Map<String, String[]> parameterMap = liferayPortletURL.getParameterMap();

    String[] navigationalState = parameterMap.get("wsrp-navigationalState");

    if ((navigationalState == null) || (navigationalState.length <= 0)) {
      navigationalState = new String[] {null};
    }

    addPathElement(sb, navigationalState[0]);

    liferayPortletURL.addParameterIncludedInPath("wsrp-navigationalState");

    return sb.toString();
  }
  @Override
  public void storePortletWindow(HttpServletRequest request, IPortletWindow portletWindow) {
    if (isDisablePersistentWindowStates(request)) {
      return;
    }

    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IPerson person = userInstance.getPerson();
    if (person.isGuest()) {
      // Never persist things for the guest user, just rely on in-memory storage
      return;
    }

    final IStylesheetDescriptor themeStylesheetDescriptor =
        this.getThemeStylesheetDescriptor(request);

    final WindowState windowState = portletWindow.getWindowState();

    final IPortletEntity portletEntity = portletWindow.getPortletEntity();
    final WindowState entityWindowState = portletEntity.getWindowState(themeStylesheetDescriptor);

    // If the window and entity states are different
    if (windowState != entityWindowState && !windowState.equals(entityWindowState)) {
      final WindowState defaultWindowState = this.getDefaultWindowState(themeStylesheetDescriptor);

      // If a window state is set and is one of the persistent states set it on the entity
      if (!defaultWindowState.equals(windowState) && persistentWindowStates.contains(windowState)) {
        portletEntity.setWindowState(themeStylesheetDescriptor, windowState);
      }
      // If not remove the state from the entity
      else if (entityWindowState != null) {
        portletEntity.setWindowState(themeStylesheetDescriptor, null);
      }

      // Persist the modified entity
      this.portletEntityRegistry.storePortletEntity(request, portletEntity);
    }
  }
  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();
    }
  }
  @Override
  protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    MBMessage message = null;

    try {
      UploadException uploadException =
          (UploadException) actionRequest.getAttribute(WebKeys.UPLOAD_EXCEPTION);

      if (uploadException != null) {
        Throwable cause = uploadException.getCause();

        if (uploadException.isExceededFileSizeLimit()) {
          throw new FileSizeException(cause);
        }

        if (uploadException.isExceededLiferayFileItemSizeLimit()) {
          throw new LiferayFileItemException(cause);
        }

        if (uploadException.isExceededUploadRequestSizeLimit()) {
          throw new UploadRequestSizeException(cause);
        }

        throw new PortalException(cause);
      } else if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {

        message = updateMessage(actionRequest, actionResponse);
      } else if (cmd.equals(Constants.ADD_ANSWER)) {
        addAnswer(actionRequest);
      } else if (cmd.equals(Constants.DELETE)) {
        deleteMessage(actionRequest);
      } else if (cmd.equals(Constants.DELETE_ANSWER)) {
        deleteAnswer(actionRequest);
      } else if (cmd.equals(Constants.LOCK)) {
        lockThreads(actionRequest);
      } else if (cmd.equals(Constants.SUBSCRIBE)) {
        subscribeMessage(actionRequest);
      } else if (cmd.equals(Constants.UNLOCK)) {
        unlockThreads(actionRequest);
      } else if (cmd.equals(Constants.UNSUBSCRIBE)) {
        unsubscribeMessage(actionRequest);
      }

      if (Validator.isNotNull(cmd)) {
        WindowState windowState = actionRequest.getWindowState();

        if (!windowState.equals(LiferayWindowState.POP_UP)) {
          String redirect = getRedirect(actionRequest, actionResponse, message);

          sendRedirect(actionRequest, actionResponse, redirect);
        } else {
          String redirect =
              PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

          if (Validator.isNotNull(redirect)) {
            actionResponse.sendRedirect(redirect);
          }
        }
      }
    } catch (NoSuchMessageException | PrincipalException | RequiredMessageException e) {

      SessionErrors.add(actionRequest, e.getClass());

      actionResponse.setRenderParameter("mvcPath", "/message_boards/error.jsp");
    } catch (AntivirusScannerException
        | CaptchaConfigurationException
        | CaptchaMaxChallengesException
        | CaptchaTextException
        | DuplicateFileEntryException
        | FileExtensionException
        | FileNameException
        | FileSizeException
        | LiferayFileItemException
        | LockedThreadException
        | MessageBodyException
        | MessageSubjectException
        | SanitizerException
        | UploadRequestSizeException e) {

      if (e instanceof AntivirusScannerException) {
        SessionErrors.add(actionRequest, e.getClass(), e);
      } else {
        SessionErrors.add(actionRequest, e.getClass());
      }
    } catch (AssetCategoryException | AssetTagException e) {
      SessionErrors.add(actionRequest, e.getClass(), e);
    } catch (Exception e) {
      Throwable cause = e.getCause();

      if (cause instanceof SanitizerException) {
        SessionErrors.add(actionRequest, SanitizerException.class);
      } else {
        throw e;
      }
    }
  }
Exemplo n.º 9
0
  @Override
  public void processAction(
      ActionMapping actionMapping,
      ActionForm actionForm,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {
      if (cmd.equals(Constants.DELETE) || cmd.equals(Constants.DELETE_VERSIONS)) {

        deleteEntries(actionRequest, false);
      } else if (cmd.equals(Constants.EXPIRE)) {
        expireEntries(actionRequest);
      } else if (cmd.equals(Constants.MOVE)) {
        moveEntries(actionRequest);
      } else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
        deleteEntries(actionRequest, true);
      }

      String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

      if (cmd.equals(Constants.DELETE_VERSIONS) && !ActionUtil.hasArticle(actionRequest)) {

        String referringPortletResource =
            ParamUtil.getString(actionRequest, "referringPortletResource");

        if (Validator.isNotNull(referringPortletResource)) {
          setForward(actionRequest, "portlet.journal.asset.add_asset_redirect");

          return;
        } else {
          ThemeDisplay themeDisplay =
              (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

          PortletURL portletURL =
              PortletURLFactoryUtil.create(
                  actionRequest,
                  portletConfig.getPortletName(),
                  themeDisplay.getPlid(),
                  PortletRequest.RENDER_PHASE);

          redirect = portletURL.toString();
        }
      }

      WindowState windowState = actionRequest.getWindowState();

      if (!windowState.equals(LiferayWindowState.POP_UP)) {
        sendRedirect(actionRequest, actionResponse);
      } else if (Validator.isNotNull(redirect)) {
        actionResponse.sendRedirect(redirect);
      }
    } catch (Exception e) {
      if (e instanceof NoSuchArticleException
          || e instanceof NoSuchFolderException
          || e instanceof PrincipalException) {

        SessionErrors.add(actionRequest, e.getClass());

        setForward(actionRequest, "portlet.journal.error");
      } else if (e instanceof DuplicateArticleIdException
          || e instanceof DuplicateFolderNameException
          || e instanceof NoSuchFolderException) {

        SessionErrors.add(actionRequest, e.getClass());
      } else if (e instanceof AssetCategoryException || e instanceof AssetTagException) {

        SessionErrors.add(actionRequest, e.getClass(), e);
      } else {
        throw e;
      }
    }
  }
  @Override
  protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {
      if (cmd.equals(Constants.CANCEL_CHECKOUT)) {
        cancelCheckedOutEntries(actionRequest);
      } else if (cmd.equals(Constants.CHECKIN)) {
        checkInEntries(actionRequest);
      } else if (cmd.equals(Constants.CHECKOUT)) {
        checkOutEntries(actionRequest);
      } else if (cmd.equals(Constants.DELETE)) {
        deleteEntries(actionRequest, false);
      } else if (cmd.equals(Constants.MOVE)) {
        moveEntries(actionRequest);
      } else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
        deleteEntries(actionRequest, true);
      } else if (cmd.equals(Constants.RESTORE)) {
        restoreTrashEntries(actionRequest);
      }

      WindowState windowState = actionRequest.getWindowState();

      if (windowState.equals(LiferayWindowState.POP_UP)) {
        String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

        if (Validator.isNotNull(redirect)) {
          sendRedirect(actionRequest, actionResponse, redirect);
        }
      }
    } catch (DuplicateLockException
        | NoSuchFileEntryException
        | NoSuchFolderException
        | PrincipalException e) {

      if (e instanceof DuplicateLockException) {
        DuplicateLockException dle = (DuplicateLockException) e;

        SessionErrors.add(actionRequest, dle.getClass(), dle.getLock());
      } else {
        SessionErrors.add(actionRequest, e.getClass());
      }

      actionResponse.setRenderParameter("mvcPath", "/document_library/error.jsp");
    } catch (DuplicateFileEntryException
        | DuplicateFolderNameException
        | SourceFileNameException e) {

      if (e instanceof DuplicateFileEntryException) {
        HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);

        response.setStatus(ServletResponseConstants.SC_DUPLICATE_FILE_EXCEPTION);
      }

      SessionErrors.add(actionRequest, e.getClass());
    } catch (AssetCategoryException | AssetTagException | InvalidFolderException e) {

      SessionErrors.add(actionRequest, e.getClass(), e);
    } catch (Exception e) {
      throw new PortletException(e);
    }
  }
  protected void sendEditArticleRedirect(
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      JournalArticle article,
      String oldUrlTitle)
      throws Exception {

    String actionName = ParamUtil.getString(actionRequest, ActionRequest.ACTION_NAME);

    String redirect = ParamUtil.getString(actionRequest, "redirect");

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

    String portletId = HttpUtil.getParameter(redirect, "p_p_id", false);

    String namespace = PortalUtil.getPortletNamespace(portletId);

    if (Validator.isNotNull(oldUrlTitle)) {
      String oldRedirectParam = namespace + "redirect";

      String oldRedirect = HttpUtil.getParameter(redirect, oldRedirectParam, false);

      if (Validator.isNotNull(oldRedirect)) {
        String newRedirect = HttpUtil.decodeURL(oldRedirect);

        newRedirect = StringUtil.replace(newRedirect, oldUrlTitle, article.getUrlTitle());
        newRedirect = StringUtil.replace(newRedirect, oldRedirectParam, "redirect");

        redirect = StringUtil.replace(redirect, oldRedirect, newRedirect);
      }
    }

    if ((actionName.equals("deleteArticle") || actionName.equals("deleteArticles"))
        && !ActionUtil.hasArticle(actionRequest)) {

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

      PortletURL portletURL =
          PortletURLFactoryUtil.create(
              actionRequest,
              themeDisplay.getPpid(),
              themeDisplay.getPlid(),
              PortletRequest.RENDER_PHASE);

      redirect = portletURL.toString();
    }

    if ((article != null) && (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT)) {

      redirect = getSaveAndContinueRedirect(actionRequest, article, redirect);

      if (actionName.equals("previewArticle")) {
        SessionMessages.add(actionRequest, "previewRequested");

        hideDefaultSuccessMessage(actionRequest);
      }
    } else {
      WindowState windowState = actionRequest.getWindowState();

      if (windowState.equals(LiferayWindowState.POP_UP)) {
        redirect = PortalUtil.escapeRedirect(redirect);

        if (Validator.isNotNull(redirect)) {
          if (actionName.equals("addArticle") && (article != null)) {
            redirect =
                HttpUtil.addParameter(
                    redirect, namespace + "className", JournalArticle.class.getName());
            redirect =
                HttpUtil.addParameter(
                    redirect,
                    namespace + "classPK",
                    JournalArticleAssetRenderer.getClassPK(article));
          }

          actionResponse.sendRedirect(redirect);
        }
      }
    }

    actionRequest.setAttribute(WebKeys.REDIRECT, redirect);
  }
  @Override
  protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    FileEntry fileEntry = null;

    PortletConfig portletConfig = getPortletConfig(actionRequest);

    try {
      UploadException uploadException =
          (UploadException) actionRequest.getAttribute(WebKeys.UPLOAD_EXCEPTION);

      if (uploadException != null) {
        if (uploadException.isExceededLiferayFileItemSizeLimit()) {
          throw new LiferayFileItemException();
        } else if (uploadException.isExceededSizeLimit()) {
          throw new FileSizeException(uploadException.getCause());
        }

        throw new PortalException(uploadException.getCause());
      } else if (cmd.equals(Constants.ADD)
          || cmd.equals(Constants.ADD_DYNAMIC)
          || cmd.equals(Constants.UPDATE)
          || cmd.equals(Constants.UPDATE_AND_CHECKIN)) {

        fileEntry = updateFileEntry(portletConfig, actionRequest, actionResponse);
      } else if (cmd.equals(Constants.ADD_MULTIPLE)) {
        addMultipleFileEntries(portletConfig, actionRequest, actionResponse);

        hideDefaultSuccessMessage(actionRequest);
      } else if (cmd.equals(Constants.ADD_TEMP)) {
        addTempFileEntry(actionRequest, actionResponse);
      } else if (cmd.equals(Constants.DELETE)) {
        deleteFileEntry(actionRequest, false);
      } else if (cmd.equals(Constants.DELETE_TEMP)) {
        deleteTempFileEntry(actionRequest, actionResponse);
      } else if (cmd.equals(Constants.CANCEL_CHECKOUT)) {
        cancelFileEntriesCheckOut(actionRequest);
      } else if (cmd.equals(Constants.CHECKIN)) {
        checkInFileEntries(actionRequest);
      } else if (cmd.equals(Constants.CHECKOUT)) {
        checkOutFileEntries(actionRequest);
      } else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
        deleteFileEntry(actionRequest, true);
      } else if (cmd.equals(Constants.RESTORE)) {
        restoreTrashEntries(actionRequest);
      } else if (cmd.equals(Constants.REVERT)) {
        revertFileEntry(actionRequest);
      }

      WindowState windowState = actionRequest.getWindowState();

      if (cmd.equals(Constants.ADD_TEMP) || cmd.equals(Constants.DELETE_TEMP)) {

        actionResponse.setRenderParameter("mvcPath", "/null.jsp");
      } else if (cmd.equals(Constants.PREVIEW)) {
      } else if (!windowState.equals(LiferayWindowState.POP_UP)) {
      } else {
        String redirect = ParamUtil.getString(actionRequest, "redirect");
        int workflowAction =
            ParamUtil.getInteger(
                actionRequest, "workflowAction", WorkflowConstants.ACTION_SAVE_DRAFT);

        if ((fileEntry != null) && (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT)) {

          redirect = getSaveAndContinueRedirect(portletConfig, actionRequest, fileEntry, redirect);

          sendRedirect(actionRequest, actionResponse, redirect);
        } else {
          if (windowState.equals(LiferayWindowState.POP_UP)) {
            redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

            if (Validator.isNotNull(redirect)) {
              if (cmd.equals(Constants.ADD) && (fileEntry != null)) {

                String portletId = HttpUtil.getParameter(redirect, "p_p_id", false);

                String namespace = PortalUtil.getPortletNamespace(portletId);

                redirect =
                    HttpUtil.addParameter(
                        redirect, namespace + "className", DLFileEntry.class.getName());
                redirect =
                    HttpUtil.addParameter(
                        redirect, namespace + "classPK", fileEntry.getFileEntryId());
              }

              sendRedirect(actionRequest, actionResponse, redirect);
            }
          }
        }
      }
    } catch (Exception e) {
      handleUploadException(portletConfig, actionRequest, actionResponse, cmd, e);
    }
  }
  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;
  }
Exemplo n.º 14
0
  @Override
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {
      BlogsEntry entry = null;
      String oldUrlTitle = StringPool.BLANK;

      if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
        Object[] returnValue = updateEntry(actionRequest);

        entry = (BlogsEntry) returnValue[0];
        oldUrlTitle = ((String) returnValue[1]);
      } else if (cmd.equals(Constants.DELETE)) {
        deleteEntries(actionRequest);
      } else if (cmd.equals(Constants.SUBSCRIBE)) {
        subscribe(actionRequest);
      } else if (cmd.equals(Constants.UNSUBSCRIBE)) {
        unsubscribe(actionRequest);
      }

      String redirect = ParamUtil.getString(actionRequest, "redirect");
      boolean updateRedirect = false;

      if (redirect.contains("/blogs/" + oldUrlTitle + "/maximized")) {
        oldUrlTitle += "/maximized";
      }

      if ((entry != null)
          && (Validator.isNotNull(oldUrlTitle))
          && (redirect.endsWith("/blogs/" + oldUrlTitle)
              || redirect.contains("/blogs/" + oldUrlTitle + "?")
              || redirect.contains("/blog/" + oldUrlTitle + "?"))) {

        int pos = redirect.indexOf("?");

        if (pos == -1) {
          pos = redirect.length();
        }

        String newRedirect = redirect.substring(0, pos - oldUrlTitle.length());

        newRedirect += entry.getUrlTitle();

        if (oldUrlTitle.indexOf("/maximized") != -1) {
          newRedirect += "/maximized";
        }

        if (pos < redirect.length()) {
          newRedirect += "?" + redirect.substring(pos + 1);
        }

        redirect = newRedirect;
        updateRedirect = true;
      }

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

      boolean ajax = ParamUtil.getBoolean(actionRequest, "ajax");

      if (ajax) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        jsonObject.put("entryId", entry.getEntryId());
        jsonObject.put("redirect", redirect);
        jsonObject.put("updateRedirect", updateRedirect);

        writeJSON(actionRequest, actionResponse, jsonObject);

        return;
      }

      if ((entry != null) && (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT)) {

        redirect = getSaveAndContinueRedirect(portletConfig, actionRequest, entry, redirect);

        sendRedirect(actionRequest, actionResponse, redirect);
      } else {
        WindowState windowState = actionRequest.getWindowState();

        if (!windowState.equals(LiferayWindowState.POP_UP)) {
          sendRedirect(actionRequest, actionResponse, redirect);
        } else {
          redirect = PortalUtil.escapeRedirect(redirect);

          if (Validator.isNotNull(redirect)) {
            actionResponse.sendRedirect(redirect);
          }
        }
      }
    } catch (Exception e) {
      if (e instanceof NoSuchEntryException || e instanceof PrincipalException) {

        SessionErrors.add(actionRequest, e.getClass().getName());

        setForward(actionRequest, "portlet.blogs.error");
      } else if (e instanceof EntryContentException
          || e instanceof EntryDisplayDateException
          || e instanceof EntrySmallImageNameException
          || e instanceof EntrySmallImageSizeException
          || e instanceof EntryTitleException) {

        SessionErrors.add(actionRequest, e.getClass().getName());
      } else if (e instanceof AssetCategoryException || e instanceof AssetTagException) {

        SessionErrors.add(actionRequest, e.getClass().getName(), e);
      } else {
        throw e;
      }
    }
  }
Exemplo n.º 15
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();
    }
  }
  @Override
  protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {
      BlogsEntry entry = null;
      String oldUrlTitle = StringPool.BLANK;
      List<BlogsEntryAttachmentFileEntryReference> blogsEntryAttachmentFileEntryReferences = null;

      UploadException uploadException =
          (UploadException) actionRequest.getAttribute(WebKeys.UPLOAD_EXCEPTION);

      if (uploadException != null) {
        if (uploadException.isExceededLiferayFileItemSizeLimit()) {
          throw new LiferayFileItemException();
        } else if (uploadException.isExceededSizeLimit()) {
          throw new FileSizeException(uploadException.getCause());
        }

        throw new PortalException(uploadException.getCause());
      } else if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {

        Callable<Object[]> updateEntryCallable = new UpdateEntryCallable(actionRequest);

        Object[] returnValue =
            TransactionInvokerUtil.invoke(_transactionAttribute, updateEntryCallable);

        entry = (BlogsEntry) returnValue[0];
        oldUrlTitle = ((String) returnValue[1]);
        blogsEntryAttachmentFileEntryReferences =
            ((List<BlogsEntryAttachmentFileEntryReference>) returnValue[2]);
      } else if (cmd.equals(Constants.DELETE)) {
        deleteEntries(actionRequest, false);
      } else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
        deleteEntries(actionRequest, true);
      } else if (cmd.equals(Constants.RESTORE)) {
        restoreTrashEntries(actionRequest);
      } else if (cmd.equals(Constants.SUBSCRIBE)) {
        subscribe(actionRequest);
      } else if (cmd.equals(Constants.UNSUBSCRIBE)) {
        unsubscribe(actionRequest);
      }

      String redirect = ParamUtil.getString(actionRequest, "redirect");
      boolean updateRedirect = false;

      String portletId = HttpUtil.getParameter(redirect, "p_p_id", false);

      if (Validator.isNotNull(oldUrlTitle)) {
        String oldRedirectParam = PortalUtil.getPortletNamespace(portletId) + "redirect";

        String oldRedirect = HttpUtil.getParameter(redirect, oldRedirectParam, false);

        if (Validator.isNotNull(oldRedirect)) {
          String newRedirect = HttpUtil.decodeURL(oldRedirect);

          newRedirect = StringUtil.replace(newRedirect, oldUrlTitle, entry.getUrlTitle());
          newRedirect = StringUtil.replace(newRedirect, oldRedirectParam, "redirect");

          redirect = StringUtil.replace(redirect, oldRedirect, newRedirect);
        } else if (redirect.endsWith("/blogs/" + oldUrlTitle)
            || redirect.contains("/blogs/" + oldUrlTitle + "?")
            || redirect.contains("/blog/" + oldUrlTitle + "?")) {

          redirect = StringUtil.replace(redirect, oldUrlTitle, entry.getUrlTitle());
        }

        updateRedirect = true;
      }

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

      boolean ajax = ParamUtil.getBoolean(actionRequest, "ajax");

      if (ajax) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

        for (BlogsEntryAttachmentFileEntryReference blogsEntryAttachmentFileEntryReference :
            blogsEntryAttachmentFileEntryReferences) {

          JSONObject blogsEntryFileEntryReferencesJSONObject = JSONFactoryUtil.createJSONObject();

          blogsEntryFileEntryReferencesJSONObject.put(
              "attributeDataImageId", EditorConstants.ATTRIBUTE_DATA_IMAGE_ID);
          blogsEntryFileEntryReferencesJSONObject.put(
              "fileEntryId",
              String.valueOf(
                  blogsEntryAttachmentFileEntryReference.getTempBlogsEntryAttachmentFileEntryId()));
          blogsEntryFileEntryReferencesJSONObject.put(
              "fileEntryUrl",
              PortletFileRepositoryUtil.getPortletFileEntryURL(
                  null,
                  blogsEntryAttachmentFileEntryReference.getBlogsEntryAttachmentFileEntry(),
                  StringPool.BLANK));

          jsonArray.put(blogsEntryFileEntryReferencesJSONObject);
        }

        jsonObject.put("blogsEntryAttachmentReferences", jsonArray);

        jsonObject.put("entryId", entry.getEntryId());
        jsonObject.put("redirect", redirect);
        jsonObject.put("updateRedirect", updateRedirect);

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);

        return;
      }

      if ((entry != null) && (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT)) {

        redirect = getSaveAndContinueRedirect(actionRequest, entry, redirect);

        sendRedirect(actionRequest, actionResponse, redirect);
      } else {
        WindowState windowState = actionRequest.getWindowState();

        if (!windowState.equals(LiferayWindowState.POP_UP)) {
          sendRedirect(actionRequest, actionResponse, redirect);
        } else {
          redirect = PortalUtil.escapeRedirect(redirect);

          if (Validator.isNotNull(redirect)) {
            if (cmd.equals(Constants.ADD) && (entry != null)) {
              String namespace = PortalUtil.getPortletNamespace(portletId);

              redirect =
                  HttpUtil.addParameter(
                      redirect, namespace + "className", BlogsEntry.class.getName());
              redirect = HttpUtil.addParameter(redirect, namespace + "classPK", entry.getEntryId());
            }

            sendRedirect(actionRequest, actionResponse, redirect);
          }
        }
      }
    } catch (Exception e) {
      String mvcPath = "/blogs/edit_entry.jsp";

      if (e instanceof NoSuchEntryException || e instanceof PrincipalException) {

        SessionErrors.add(actionRequest, e.getClass());

        mvcPath = "/blogs/error.jsp";
      } else if (e instanceof EntryContentException
          || e instanceof EntryCoverImageCropException
          || e instanceof EntryDescriptionException
          || e instanceof EntryDisplayDateException
          || e instanceof EntrySmallImageNameException
          || e instanceof EntrySmallImageScaleException
          || e instanceof EntryTitleException
          || e instanceof FileSizeException
          || e instanceof LiferayFileItemException
          || e instanceof SanitizerException) {

        SessionErrors.add(actionRequest, e.getClass());
      } else if (e instanceof AssetCategoryException || e instanceof AssetTagException) {

        SessionErrors.add(actionRequest, e.getClass(), e);
      } else {
        Throwable cause = e.getCause();

        if (cause instanceof SanitizerException) {
          SessionErrors.add(actionRequest, SanitizerException.class);
        } else {
          throw e;
        }
      }

      actionResponse.setRenderParameter("mvcPath", mvcPath);
    } catch (Throwable t) {
      _log.error(t, t);

      actionResponse.setRenderParameter("mvcPath", "/blogs/error.jsp");
    }
  }