protected String getSaveAndContinueRedirect(
      PortletConfig portletConfig, ActionRequest actionRequest, DDMStructure structure)
      throws Exception {

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

    PortletURLImpl portletURL =
        new PortletURLImpl(
            actionRequest,
            portletConfig.getPortletName(),
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("struts_action", "/dynamic_data_mapping/copy_structure");

    long classNameId = PortalUtil.getClassNameId(DDMStructure.class);

    portletURL.setParameter("classNameId", String.valueOf(classNameId), false);

    portletURL.setParameter("classPK", String.valueOf(structure.getStructureId()), false);
    portletURL.setParameter(
        "copyFormTemplates", ParamUtil.getString(actionRequest, "copyFormTemplates"), false);
    portletURL.setParameter(
        "copyDisplayTemplates", ParamUtil.getString(actionRequest, "copyDisplayTemplates"), false);
    portletURL.setWindowState(actionRequest.getWindowState());

    return portletURL.toString();
  }
  protected String getSaveAndContinueRedirect(
      ActionRequest actionRequest, JournalArticle article, String redirect) throws Exception {

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

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

    PortletURLImpl portletURL =
        new PortletURLImpl(
            actionRequest,
            JournalPortletKeys.JOURNAL,
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcPath", "/edit_article.jsp");
    portletURL.setParameter("redirect", redirect, false);
    portletURL.setParameter("referringPortletResource", referringPortletResource, false);
    portletURL.setParameter("resourcePrimKey", String.valueOf(article.getResourcePrimKey()), false);
    portletURL.setParameter("groupId", String.valueOf(article.getGroupId()), false);
    portletURL.setParameter("folderId", String.valueOf(article.getFolderId()), false);
    portletURL.setParameter("articleId", article.getArticleId(), false);
    portletURL.setParameter("version", String.valueOf(article.getVersion()), false);
    portletURL.setWindowState(actionRequest.getWindowState());

    return portletURL.toString();
  }
  protected String getSaveAndContinueRedirect(
      ActionRequest actionRequest, BlogsEntry entry, String redirect) throws Exception {

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

    PortletConfig portletConfig =
        (PortletConfig) actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

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

    PortletURLImpl portletURL =
        new PortletURLImpl(
            actionRequest,
            portletConfig.getPortletName(),
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcRenderCommandName", "/blogs/edit_entry");

    portletURL.setParameter(Constants.CMD, Constants.UPDATE, false);
    portletURL.setParameter("redirect", redirect, false);
    portletURL.setParameter("backURL", backURL, false);
    portletURL.setParameter("groupId", String.valueOf(entry.getGroupId()), false);
    portletURL.setParameter("entryId", String.valueOf(entry.getEntryId()), false);
    portletURL.setWindowState(actionRequest.getWindowState());

    return portletURL.toString();
  }
  protected String getSaveAndContinueRedirect(
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      FileEntry fileEntry,
      String redirect)
      throws Exception {

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

    PortletURLImpl portletURL =
        new PortletURLImpl(
            actionRequest,
            portletConfig.getPortletName(),
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcRenderCommandName", "/document_library/edit_file_entry");
    portletURL.setParameter(Constants.CMD, Constants.UPDATE, false);
    portletURL.setParameter("redirect", redirect, false);
    portletURL.setParameter("groupId", String.valueOf(fileEntry.getGroupId()), false);
    portletURL.setParameter("fileEntryId", String.valueOf(fileEntry.getFileEntryId()), false);
    portletURL.setParameter("version", String.valueOf(fileEntry.getVersion()), false);
    portletURL.setWindowState(actionRequest.getWindowState());

    return portletURL.toString();
  }
  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);
    }
  }
  protected String getSaveAndContinueRedirect(
      PortletConfig portletConfig, ActionRequest actionRequest, BlogsEntry entry, String redirect)
      throws Exception {

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

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

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

    PortletURLImpl portletURL =
        new PortletURLImpl(
            actionRequest,
            portletConfig.getPortletName(),
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setWindowState(actionRequest.getWindowState());

    String portletName = portletConfig.getPortletName();

    if (portletName.equals(PortletKeys.BLOGS_ADMIN)) {
      portletURL.setParameter("struts_action", "/blogs_admin/edit_entry");
    } else {
      portletURL.setParameter("struts_action", "/blogs/edit_entry");
    }

    portletURL.setParameter(Constants.CMD, Constants.UPDATE, false);
    portletURL.setParameter("redirect", redirect, false);
    portletURL.setParameter("backURL", backURL, false);
    portletURL.setParameter("groupId", String.valueOf(entry.getGroupId()), false);
    portletURL.setParameter("entryId", String.valueOf(entry.getEntryId()), false);
    portletURL.setParameter("preview", String.valueOf(preview), false);

    return portletURL.toString();
  }
  protected void postProcessAuthFailure(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    LiferayPortletRequest liferayPortletRequest =
        PortalUtil.getLiferayPortletRequest(actionRequest);

    String portletName = liferayPortletRequest.getPortletName();

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

    PortletURL portletURL =
        new PortletURLImpl(
            actionRequest, portletName, layout.getPlid(), PortletRequest.RENDER_PHASE);

    portletURL.setParameter("saveLastPath", Boolean.FALSE.toString());

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

    if (Validator.isNotNull(redirect)) {
      portletURL.setParameter("redirect", redirect);
    }

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

    if (Validator.isNotNull(login)) {
      portletURL.setParameter("login", login);
    }

    if (portletName.equals(LoginPortletKeys.LOGIN)) {
      portletURL.setWindowState(WindowState.MAXIMIZED);
    } else {
      portletURL.setWindowState(actionRequest.getWindowState());
    }

    actionResponse.sendRedirect(portletURL.toString());
  }
  @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;
      }
    }
  }
Example #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);
    }
  }
  @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;
      }
    }
  }
  @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");
    }
  }