protected void deleteTempFileEntry(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    long folderId = ParamUtil.getLong(actionRequest, "folderId");
    String fileName = ParamUtil.getString(actionRequest, "fileName");

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    try {
      _dlAppService.deleteTempFileEntry(
          themeDisplay.getScopeGroupId(), folderId, TEMP_FOLDER_NAME, fileName);

      jsonObject.put("deleted", Boolean.TRUE);
    } catch (Exception e) {
      String errorMessage =
          themeDisplay.translate("an-unexpected-error-occurred-while-deleting-the-file");

      jsonObject.put("deleted", Boolean.FALSE);
      jsonObject.put("errorMessage", errorMessage);
    }

    JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
  }
Esempio n. 2
0
  protected void addTempAttachment(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
    String sourceFileName = uploadPortletRequest.getFileName("file");

    InputStream inputStream = null;

    try {
      inputStream = uploadPortletRequest.getFileAsStream("file");

      String mimeType = uploadPortletRequest.getContentType("file");

      String tempFileName = TempFileEntryUtil.getTempFileName(sourceFileName);

      FileEntry fileEntry =
          _wikiPageService.addTempFileEntry(
              nodeId, _TEMP_FOLDER_NAME, tempFileName, inputStream, mimeType);

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      jsonObject.put("groupId", fileEntry.getGroupId());
      jsonObject.put("name", fileEntry.getTitle());
      jsonObject.put("title", sourceFileName);
      jsonObject.put("uuid", fileEntry.getUuid());

      JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
    } finally {
      StreamUtil.cleanUp(inputStream);
    }
  }
Esempio n. 3
0
  @Override
  protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    PortletConfig portletConfig = getPortletConfig(actionRequest);

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

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

        throw new PortalException(uploadException.getCause());
      } else if (cmd.equals(Constants.ADD)) {
        addAttachment(actionRequest);
      } else if (cmd.equals(Constants.ADD_MULTIPLE)) {
        addMultipleFileEntries(portletConfig, actionRequest, actionResponse);
      } else if (cmd.equals(Constants.ADD_TEMP)) {
        addTempAttachment(actionRequest, actionResponse);
      } else if (cmd.equals(Constants.CHECK)) {
        JSONObject jsonObject = RestoreEntryUtil.checkEntry(actionRequest);

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);

        return;
      } else if (cmd.equals(Constants.DELETE)) {
        deleteAttachment(actionRequest, false);
      } else if (cmd.equals(Constants.DELETE_TEMP)) {
        deleteTempAttachment(actionRequest, actionResponse);
      } else if (cmd.equals(Constants.EMPTY_TRASH)) {
        emptyTrash(actionRequest);
      } else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
        deleteAttachment(actionRequest, true);
      } else if (cmd.equals(Constants.RENAME)) {
        restoreRename(actionRequest);
      } else if (cmd.equals(Constants.RESTORE)) {
        restoreEntries(actionRequest);
      } else if (cmd.equals(Constants.OVERRIDE)) {
        restoreOverride(actionRequest);
      }

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

        actionResponse.setRenderParameter("mvcPath", "/null.jsp");
      }
    } catch (NoSuchNodeException | NoSuchPageException | PrincipalException e) {

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

      actionResponse.setRenderParameter("mvcPath", "/wiki/error.jsp");
    } catch (Exception e) {
      handleUploadException(portletConfig, actionRequest, actionResponse, cmd, e);
    }
  }
  protected void writeJSON(
      PortletRequest portletRequest, ActionResponse actionResponse, Object json)
      throws IOException {

    JSONPortletResponseUtil.writeJSON(portletRequest, actionResponse, json);

    setForward(portletRequest, ActionConstants.COMMON_NULL);
  }
  protected void handleUploadException(
      PortletRequest portletRequest, PortletResponse portletResponse) throws PortalException {

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    jsonObject.put("success", Boolean.FALSE);

    try {
      JSONPortletResponseUtil.writeJSON(portletRequest, portletResponse, jsonObject);
    } catch (IOException ioe) {
      throw new SystemException(ioe);
    }
  }
Esempio n. 6
0
  /** TODO: Remove. This should extend from EditFileEntryAction once it is modularized. */
  protected void addMultipleFileEntries(
      PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    List<KeyValuePair> validFileNameKVPs = new ArrayList<>();
    List<KeyValuePair> invalidFileNameKVPs = new ArrayList<>();

    String[] selectedFileNames =
        ParamUtil.getParameterValues(actionRequest, "selectedFileName", new String[0], false);

    for (String selectedFileName : selectedFileNames) {
      addMultipleFileEntries(
          portletConfig,
          actionRequest,
          actionResponse,
          selectedFileName,
          validFileNameKVPs,
          invalidFileNameKVPs);
    }

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    for (KeyValuePair validFileNameKVP : validFileNameKVPs) {
      String fileName = validFileNameKVP.getKey();
      String originalFileName = validFileNameKVP.getValue();

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      jsonObject.put("added", Boolean.TRUE);
      jsonObject.put("fileName", fileName);
      jsonObject.put("originalFileName", originalFileName);

      jsonArray.put(jsonObject);
    }

    for (KeyValuePair invalidFileNameKVP : invalidFileNameKVPs) {
      String fileName = invalidFileNameKVP.getKey();
      String errorMessage = invalidFileNameKVP.getValue();

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      jsonObject.put("added", Boolean.FALSE);
      jsonObject.put("errorMessage", errorMessage);
      jsonObject.put("fileName", fileName);
      jsonObject.put("originalFileName", fileName);

      jsonArray.put(jsonObject);
    }

    JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonArray);
  }
  protected FileEntry updateFileEntry(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    long fileEntryId = ParamUtil.getLong(uploadPortletRequest, "fileEntryId");

    String sourceFileName = uploadPortletRequest.getFileName("imageEditorFileName");

    FileEntry fileEntry = _dlAppLocalService.getFileEntry(fileEntryId);

    InputStream inputStream = uploadPortletRequest.getFileAsStream("imageEditorFileName");
    String contentType = uploadPortletRequest.getContentType("imageEditorFileName");
    long size = uploadPortletRequest.getSize("imageEditorFileName");

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(DLFileEntry.class.getName(), uploadPortletRequest);

    fileEntry =
        _dlAppService.updateFileEntry(
            fileEntryId,
            sourceFileName,
            contentType,
            fileEntry.getTitle(),
            fileEntry.getDescription(),
            StringPool.BLANK,
            false,
            inputStream,
            size,
            serviceContext);

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    jsonObject.put("success", Boolean.TRUE);

    ResourceBundle resourceBundle =
        _resourceBundleLoader.loadResourceBundle(
            LanguageUtil.getLanguageId(themeDisplay.getLocale()));

    SessionMessages.add(
        actionRequest,
        "requestProcessed",
        LanguageUtil.get(resourceBundle, "the-image-was-edited-successfully"));

    JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);

    return fileEntry;
  }
Esempio n. 8
0
  /** TODO: Remove. This should extend from EditFileEntryAction once it is modularized. */
  protected void handleUploadException(
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      String cmd,
      Exception e)
      throws Exception {

    if (e instanceof AssetCategoryException || e instanceof AssetTagException) {

      SessionErrors.add(actionRequest, e.getClass(), e);
    } else if (e instanceof AntivirusScannerException
        || e instanceof DuplicateFileEntryException
        || e instanceof DuplicateFolderNameException
        || e instanceof FileExtensionException
        || e instanceof FileMimeTypeException
        || e instanceof FileNameException
        || e instanceof FileSizeException
        || e instanceof LiferayFileItemException
        || e instanceof NoSuchFolderException
        || e instanceof SourceFileNameException
        || e instanceof StorageFieldRequiredException) {

      if (!cmd.equals(Constants.ADD_DYNAMIC)
          && !cmd.equals(Constants.ADD_MULTIPLE)
          && !cmd.equals(Constants.ADD_TEMP)) {

        if (e instanceof AntivirusScannerException) {
          SessionErrors.add(actionRequest, e.getClass(), e);
        } else {
          SessionErrors.add(actionRequest, e.getClass());
        }

        return;
      } else if (cmd.equals(Constants.ADD_TEMP)) {
        hideDefaultErrorMessage(actionRequest);
      }

      if (e instanceof AntivirusScannerException
          || e instanceof DuplicateFileEntryException
          || e instanceof FileExtensionException
          || e instanceof FileNameException
          || e instanceof FileSizeException) {

        HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);

        response.setContentType(ContentTypes.TEXT_HTML);
        response.setStatus(HttpServletResponse.SC_OK);

        String errorMessage = StringPool.BLANK;
        int errorType = 0;

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

        if (e instanceof AntivirusScannerException) {
          AntivirusScannerException ase = (AntivirusScannerException) e;

          errorMessage = themeDisplay.translate(ase.getMessageKey());
          errorType = ServletResponseConstants.SC_FILE_ANTIVIRUS_EXCEPTION;
        }

        if (e instanceof DuplicateFileEntryException) {
          errorMessage = themeDisplay.translate("please-enter-a-unique-document-name");
          errorType = ServletResponseConstants.SC_DUPLICATE_FILE_EXCEPTION;
        } else if (e instanceof FileExtensionException) {
          errorMessage =
              themeDisplay.translate(
                  "please-enter-a-file-with-a-valid-extension-x",
                  StringUtil.merge(
                      getAllowedFileExtensions(portletConfig, actionRequest, actionResponse)));
          errorType = ServletResponseConstants.SC_FILE_EXTENSION_EXCEPTION;
        } else if (e instanceof FileNameException) {
          errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-name");
          errorType = ServletResponseConstants.SC_FILE_NAME_EXCEPTION;
        } else if (e instanceof FileSizeException) {
          long fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE);

          if (fileMaxSize == 0) {
            fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE);
          }

          errorMessage =
              themeDisplay.translate(
                  "please-enter-a-file-with-a-valid-file-size-no-larger" + "-than-x",
                  TextFormatter.formatStorageSize(fileMaxSize, themeDisplay.getLocale()));

          errorType = ServletResponseConstants.SC_FILE_SIZE_EXCEPTION;
        }

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        jsonObject.put("message", errorMessage);
        jsonObject.put("status", errorType);

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
      }

      if (e instanceof AntivirusScannerException) {
        SessionErrors.add(actionRequest, e.getClass(), e);
      } else {
        SessionErrors.add(actionRequest, e.getClass());
      }
    } else if (e instanceof DuplicateLockException
        || e instanceof InvalidFileVersionException
        || e instanceof NoSuchFileEntryException
        || e instanceof PrincipalException) {

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

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

      actionResponse.setRenderParameter("mvcPath", "/html/porltet/document_library/error.jsp");
    } else {
      Throwable cause = e.getCause();

      if (cause instanceof DuplicateFileEntryException) {
        SessionErrors.add(actionRequest, DuplicateFileEntryException.class);
      } else {
        throw e;
      }
    }
  }
  @Override
  protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    Company company = themeDisplay.getCompany();

    if (!company.isStrangers()) {
      throw new PrincipalException.MustBeEnabled(
          company.getCompanyId(), PropsKeys.COMPANY_SECURITY_STRANGERS);
    }

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

    String portletName = portletConfig.getPortletName();

    if (!portletName.equals(LoginPortletKeys.FAST_LOGIN)) {
      throw new PrincipalException("Unable to create anonymous account");
    }

    if (actionRequest.getRemoteUser() != null) {
      actionResponse.sendRedirect(themeDisplay.getPathMain());

      return;
    }

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

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

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

    portletURL.setParameter("mvcRenderCommandName", "/login/login_redirect");
    portletURL.setParameter("emailAddress", emailAddress);
    portletURL.setParameter("anonymousUser", Boolean.TRUE.toString());
    portletURL.setWindowState(LiferayWindowState.POP_UP);

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    try {
      if (cmd.equals(Constants.ADD)) {
        addAnonymousUser(actionRequest, actionResponse);

        sendRedirect(actionRequest, actionResponse, portletURL.toString());
      } else if (cmd.equals(Constants.UPDATE)) {
        jsonObject = updateIncompleteUser(actionRequest, actionResponse);

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
      }
    } catch (Exception e) {
      if (cmd.equals(Constants.UPDATE)) {
        jsonObject.putException(e);

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
      } else if (e instanceof UserEmailAddressException.MustNotBeDuplicate) {

        User user =
            _userLocalService.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);

        if (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE) {
          SessionErrors.add(actionRequest, e.getClass());
        } else {
          sendRedirect(actionRequest, actionResponse, portletURL.toString());
        }
      } else if (e instanceof CaptchaConfigurationException
          || e instanceof CaptchaTextException
          || e instanceof CompanyMaxUsersException
          || e instanceof ContactNameException
          || e instanceof EmailAddressException
          || e instanceof GroupFriendlyURLException
          || e instanceof UserEmailAddressException) {

        SessionErrors.add(actionRequest, e.getClass(), e);
      } else {
        _log.error("Unable to create anonymous account", e);

        PortalUtil.sendError(e, actionRequest, actionResponse);
      }
    }
  }
  protected FileEntry updateFileEntry(
      PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

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

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

    long fileEntryId = ParamUtil.getLong(uploadPortletRequest, "fileEntryId");

    long repositoryId = ParamUtil.getLong(uploadPortletRequest, "repositoryId");
    long folderId = ParamUtil.getLong(uploadPortletRequest, "folderId");
    String sourceFileName = uploadPortletRequest.getFileName("file");
    String title = ParamUtil.getString(uploadPortletRequest, "title");
    String description = ParamUtil.getString(uploadPortletRequest, "description");
    String changeLog = ParamUtil.getString(uploadPortletRequest, "changeLog");
    boolean majorVersion = ParamUtil.getBoolean(uploadPortletRequest, "majorVersion");

    if (folderId > 0) {
      Folder folder = _dlAppService.getFolder(folderId);

      if (folder.getGroupId() != themeDisplay.getScopeGroupId()) {
        throw new NoSuchFolderException("{folderId=" + folderId + "}");
      }
    }

    InputStream inputStream = null;

    try {
      String contentType = uploadPortletRequest.getContentType("file");
      long size = uploadPortletRequest.getSize("file");

      if ((cmd.equals(Constants.ADD) || cmd.equals(Constants.ADD_DYNAMIC)) && (size == 0)) {

        contentType = MimeTypesUtil.getContentType(title);
      }

      if (cmd.equals(Constants.ADD) || cmd.equals(Constants.ADD_DYNAMIC) || (size > 0)) {

        String portletName = portletConfig.getPortletName();

        if (portletName.equals(DLPortletKeys.MEDIA_GALLERY_DISPLAY)) {
          PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

          DLPortletInstanceSettings dlPortletInstanceSettings =
              DLPortletInstanceSettings.getInstance(
                  themeDisplay.getLayout(), portletDisplay.getId());

          String[] mimeTypes = dlPortletInstanceSettings.getMimeTypes();

          if (Arrays.binarySearch(mimeTypes, contentType) < 0) {
            throw new FileMimeTypeException(contentType);
          }
        }
      }

      inputStream = uploadPortletRequest.getFileAsStream("file");

      ServiceContext serviceContext =
          ServiceContextFactory.getInstance(DLFileEntry.class.getName(), uploadPortletRequest);

      FileEntry fileEntry = null;

      if (cmd.equals(Constants.ADD) || cmd.equals(Constants.ADD_DYNAMIC)) {

        // Add file entry

        fileEntry =
            _dlAppService.addFileEntry(
                repositoryId,
                folderId,
                sourceFileName,
                contentType,
                title,
                description,
                changeLog,
                inputStream,
                size,
                serviceContext);

        if (cmd.equals(Constants.ADD_DYNAMIC)) {
          JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

          jsonObject.put("fileEntryId", fileEntry.getFileEntryId());

          JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
        }
      } else if (cmd.equals(Constants.UPDATE_AND_CHECKIN)) {

        // Update file entry and checkin

        fileEntry =
            _dlAppService.updateFileEntryAndCheckIn(
                fileEntryId,
                sourceFileName,
                contentType,
                title,
                description,
                changeLog,
                majorVersion,
                inputStream,
                size,
                serviceContext);
      } else {

        // Update file entry

        fileEntry =
            _dlAppService.updateFileEntry(
                fileEntryId,
                sourceFileName,
                contentType,
                title,
                description,
                changeLog,
                majorVersion,
                inputStream,
                size,
                serviceContext);
      }

      return fileEntry;
    } catch (Exception e) {
      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 e;
    } finally {
      StreamUtil.cleanUp(inputStream);
    }
  }
  protected void addTempFileEntry(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

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

    long folderId = ParamUtil.getLong(uploadPortletRequest, "folderId");
    String sourceFileName = uploadPortletRequest.getFileName("file");

    StringBundler sb = new StringBundler(5);

    sb.append(FileUtil.stripExtension(sourceFileName));
    sb.append(DL.TEMP_RANDOM_SUFFIX);
    sb.append(StringUtil.randomString());

    String extension = FileUtil.getExtension(sourceFileName);

    if (Validator.isNotNull(extension)) {
      sb.append(StringPool.PERIOD);
      sb.append(extension);
    }

    InputStream inputStream = null;

    try {
      inputStream = uploadPortletRequest.getFileAsStream("file");

      String contentType = uploadPortletRequest.getContentType("file");

      FileEntry fileEntry =
          _dlAppService.addTempFileEntry(
              themeDisplay.getScopeGroupId(),
              folderId,
              TEMP_FOLDER_NAME,
              sb.toString(),
              inputStream,
              contentType);

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      jsonObject.put("groupId", fileEntry.getGroupId());
      jsonObject.put("name", fileEntry.getTitle());
      jsonObject.put("title", sourceFileName);
      jsonObject.put("uuid", fileEntry.getUuid());

      JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
    } catch (Exception e) {
      UploadException uploadException =
          (UploadException) actionRequest.getAttribute(WebKeys.UPLOAD_EXCEPTION);

      if ((uploadException != null)
          && (uploadException.getCause() instanceof FileUploadBase.IOFileUploadException)) {

        // Cancelled a temporary upload

      } else if ((uploadException != null) && uploadException.isExceededSizeLimit()) {

        throw new FileSizeException(uploadException.getCause());
      } else {
        throw e;
      }
    } finally {
      StreamUtil.cleanUp(inputStream);
    }
  }
Esempio n. 12
0
  protected void writeJSON(PortletRequest portletRequest, MimeResponse mimeResponse, Object json)
      throws IOException {

    JSONPortletResponseUtil.writeJSON(portletRequest, mimeResponse, json);
  }
  @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");
    }
  }