Example usage for com.liferay.portal.kernel.util Constants ADD_TEMP

List of usage examples for com.liferay.portal.kernel.util Constants ADD_TEMP

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util Constants ADD_TEMP.

Prototype

String ADD_TEMP

To view the source code for com.liferay.portal.kernel.util Constants ADD_TEMP.

Click Source Link

Usage

From source file:com.liferay.document.library.web.internal.portlet.action.EditFileEntryMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    FileEntry fileEntry = null;/*from   www . j  a va2  s  .  c o  m*/

    PortletConfig portletConfig = getPortletConfig(actionRequest);

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

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

            if (cmd.equals(Constants.ADD_TEMP)) {
                if (cause instanceof FileUploadBase.IOFileUploadException) {
                    if (_log.isInfoEnabled()) {
                        _log.info("Temporary upload was cancelled");
                    }
                }
            } else {
                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.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)) {
            SessionMessages.add(actionRequest,
                    _portal.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_FORCE_SEND_REDIRECT);

            hideDefaultSuccessMessage(actionRequest);

            actionResponse.setRenderParameter("mvcRenderCommandName", "/document_library/edit_file_entry");
        } 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 = _portal.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 = _portal.getPortletNamespace(portletId);

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

                        actionRequest.setAttribute(WebKeys.REDIRECT, redirect);
                    }
                }
            }
        }
    } catch (Exception e) {
        handleUploadException(portletConfig, actionRequest, actionResponse, cmd, e);
    }
}

From source file:com.liferay.document.library.web.internal.portlet.action.EditFileEntryMVCActionCommand.java

License:Open Source License

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 || e instanceof UploadRequestSizeException) {

        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());
            }/*w  w w  .ja va 2 s  . c o m*/

            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 || e instanceof UploadRequestSizeException) {

            HttpServletResponse response = _portal.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 FileEntryLockException.MustOwnLock
            || 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", "/document_library/error.jsp");
    } else {
        Throwable cause = e.getCause();

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

From source file:com.liferay.exportimport.web.internal.portlet.action.ExportImportMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    Portlet portlet = null;//ww w  .jav  a 2s. c o m

    try {
        portlet = ActionUtil.getPortlet(actionRequest);
    } catch (PrincipalException pe) {
        SessionErrors.add(actionRequest, pe.getClass());

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

        return;
    }

    actionRequest = ActionUtil.getWrappedActionRequest(actionRequest, null);

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

    if (Validator.isNull(cmd)) {
        SessionMessages.add(actionRequest,
                _portal.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_FORCE_SEND_REDIRECT);

        hideDefaultSuccessMessage(actionRequest);

        return;
    }

    try {
        if (cmd.equals(Constants.ADD_TEMP)) {
            _importLayoutsMVCActionCommand.addTempFileEntry(actionRequest,
                    ExportImportHelper.TEMP_FOLDER_NAME + portlet.getPortletId());

            validateFile(actionRequest, actionResponse,
                    ExportImportHelper.TEMP_FOLDER_NAME + portlet.getPortletId());

            hideDefaultSuccessMessage(actionRequest);
        } else if (cmd.equals(Constants.DELETE_TEMP)) {
            _importLayoutsMVCActionCommand.deleteTempFileEntry(actionRequest, actionResponse,
                    ExportImportHelper.TEMP_FOLDER_NAME + portlet.getPortletId());

            hideDefaultSuccessMessage(actionRequest);
        } else if (cmd.equals(Constants.EXPORT)) {
            hideDefaultSuccessMessage(actionRequest);

            exportData(actionRequest, portlet);

            sendRedirect(actionRequest, actionResponse);
        } else if (cmd.equals(Constants.IMPORT)) {
            hideDefaultSuccessMessage(actionRequest);

            importData(actionRequest, ExportImportHelper.TEMP_FOLDER_NAME + portlet.getPortletId());

            SessionMessages.add(actionRequest,
                    _portal.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_CLOSE_REFRESH_PORTLET,
                    portlet.getPortletId());

            sendRedirect(actionRequest, actionResponse);
        }
    } catch (Exception e) {
        if (cmd.equals(Constants.ADD_TEMP) || cmd.equals(Constants.DELETE_TEMP)) {

            hideDefaultSuccessMessage(actionRequest);

            _importLayoutsMVCActionCommand.handleUploadException(actionRequest, actionResponse,
                    ExportImportHelper.TEMP_FOLDER_NAME + portlet.getPortletId(), e);
        } else {
            if (e instanceof LARFileException || e instanceof LARFileNameException
                    || e instanceof LARFileSizeException || e instanceof LARTypeException
                    || e instanceof LocaleException || e instanceof NoSuchLayoutException
                    || e instanceof PortletIdException || e instanceof PrincipalException
                    || e instanceof StructureDuplicateStructureKeyException) {

                SessionErrors.add(actionRequest, e.getClass());
            } else {
                _log.error(e, e);

                SessionErrors.add(actionRequest, ExportImportMVCActionCommand.class.getName());
            }
        }
    }
}

From source file:com.liferay.exportimport.web.internal.portlet.action.ImportLayoutsMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    try {/*w ww.j a  va 2 s  .  c o m*/
        if (cmd.equals(Constants.ADD_TEMP)) {
            addTempFileEntry(actionRequest, ExportImportHelper.TEMP_FOLDER_NAME);

            validateFile(actionRequest, actionResponse, ExportImportHelper.TEMP_FOLDER_NAME);

            hideDefaultSuccessMessage(actionRequest);
        } else if (cmd.equals(Constants.DELETE_TEMP)) {
            deleteTempFileEntry(actionRequest, actionResponse, ExportImportHelper.TEMP_FOLDER_NAME);

            hideDefaultSuccessMessage(actionRequest);
        } else if (cmd.equals(Constants.IMPORT)) {
            hideDefaultSuccessMessage(actionRequest);

            importData(actionRequest, ExportImportHelper.TEMP_FOLDER_NAME);

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

            sendRedirect(actionRequest, actionResponse, redirect);
        }
    } catch (Exception e) {
        if (cmd.equals(Constants.ADD_TEMP) || cmd.equals(Constants.DELETE_TEMP)) {

            hideDefaultSuccessMessage(actionRequest);

            handleUploadException(actionRequest, actionResponse, ExportImportHelper.TEMP_FOLDER_NAME, e);
        } else {
            if (e instanceof LARFileException || e instanceof LARFileSizeException
                    || e instanceof LARTypeException) {

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

                SessionErrors.add(actionRequest, e.getClass(), e);
            } else {
                _log.error(e, e);

                SessionErrors.add(actionRequest, LayoutImportException.class.getName());
            }
        }
    }
}

From source file:com.liferay.image.uploader.web.internal.portlet.action.UploadImageMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    hideDefaultSuccessMessage(actionRequest);

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

    long maxFileSize = ParamUtil.getLong(actionRequest, "maxFileSize");

    try {/*from w w w.j a  v a  2s .  c  o m*/
        UploadException uploadException = (UploadException) actionRequest
                .getAttribute(WebKeys.UPLOAD_EXCEPTION);

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

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

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

            throw new PortalException(cause);
        } else if (cmd.equals(Constants.ADD_TEMP)) {
            FileEntry tempImageFileEntry = addTempImageFileEntry(actionRequest);

            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

            jsonObject.put("tempImageFileName", tempImageFileEntry.getTitle());

            JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
        } else {
            FileEntry fileEntry = null;

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

            if (imageUploaded) {
                fileEntry = saveTempImageFileEntry(actionRequest);

                if (fileEntry.getSize() > maxFileSize) {
                    throw new FileSizeException();
                }
            }

            SessionMessages.add(actionRequest, "imageUploaded", fileEntry);

            sendRedirect(actionRequest, actionResponse);
        }
    } catch (Exception e) {
        handleUploadException(actionRequest, actionResponse, cmd, maxFileSize, e);
    }
}

From source file:com.liferay.image.uploader.web.internal.portlet.action.UploadImageMVCActionCommand.java

License:Open Source License

protected void handleUploadException(ActionRequest actionRequest, ActionResponse actionResponse, String cmd,
        long maxFileSize, Exception e) throws Exception {

    if (e instanceof PrincipalException) {
        SessionErrors.add(actionRequest, e.getClass());

        actionResponse.setRenderParameter("mvcPath", "/error.jsp");
    } else if (e instanceof AntivirusScannerException || e instanceof FileExtensionException
            || e instanceof FileSizeException || e instanceof ImageTypeException
            || e instanceof NoSuchFileException || e instanceof UploadException
            || e instanceof UploadRequestSizeException) {

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

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

            String errorMessage = StringPool.BLANK;

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

                errorMessage = themeDisplay.translate(ase.getMessageKey());
            } else if (e instanceof FileExtensionException) {
                errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-extension-x",
                        StringUtil.merge(_dlConfiguration.fileExtensions()));
            } else if (e instanceof FileSizeException) {
                if (maxFileSize == 0) {
                    maxFileSize = _uploadServletRequestConfigurationHelper.getMaxSize();
                }// w ww. j av  a  2  s  .c  om

                errorMessage = themeDisplay.translate(
                        "please-enter-a-file-with-a-valid-file-size-no-" + "larger-than-x",
                        TextFormatter.formatStorageSize(maxFileSize, themeDisplay.getLocale()));
            } else if (e instanceof ImageTypeException) {
                errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-type");
            } else if (e instanceof NoSuchFileException || e instanceof UploadException) {

                errorMessage = themeDisplay
                        .translate("an-unexpected-error-occurred-while-uploading-your-" + "file");
            }

            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

            jsonObject.put("errorMessage", errorMessage);

            JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
        } else {
            SessionErrors.add(actionRequest, e.getClass(), e);
        }
    } else {
        throw e;
    }
}

From source file:com.liferay.portlet.wiki.action.EditPageAttachmentAction.java

License:Open Source License

@Override
public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    try {/*from   w w w  .jav a  2 s . c om*/
        if (Validator.isNull(cmd)) {
            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(actionRequest, actionResponse);
        } else if (cmd.equals(Constants.ADD_TEMP)) {
            addTempAttachment(actionRequest);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteAttachment(actionRequest);
        } else if (cmd.equals(Constants.DELETE_TEMP)) {
            deleteTempAttachment(actionRequest, actionResponse);
        }

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

            setForward(actionRequest, ActionConstants.COMMON_NULL);
        } else {
            sendRedirect(actionRequest, actionResponse);
        }
    } catch (Exception e) {
        if (e instanceof DuplicateFileException || e instanceof NoSuchNodeException
                || e instanceof NoSuchPageException || e instanceof PrincipalException) {

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

            setForward(actionRequest, "portlet.wiki.error");
        } else if (e instanceof FileSizeException) {
            SessionErrors.add(actionRequest, e.getClass().getName());
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.wiki.web.internal.portlet.action.EditPageAttachmentsMVCActionCommand.java

License:Open Source License

/**
 * TODO: Remove. This should extend from EditFileEntryAction once it is
 * modularized./*from w  ww. j a v  a 2s .  c  o  m*/
 */
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 || e instanceof UploadRequestSizeException) {

        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 || e instanceof UploadRequestSizeException) {

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

From source file:org.lsug.quota.web.internal.portlet.action.documentlibrary.QuotaUploadMultipleFileEntriesMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    PortletConfig portletConfig = getPortletConfig(actionRequest);

    try {// w w w  .  ja  va 2  s  . com
        UploadException uploadException = (UploadException) actionRequest
                .getAttribute(WebKeys.UPLOAD_EXCEPTION);

        if (uploadException != null) {
            mvcActionCommand.processAction(actionRequest, actionResponse);
            return;
        } else if (cmd.equals(Constants.ADD_MULTIPLE)) {
            addMultipleFileEntries(portletConfig, actionRequest, actionResponse);

            hideDefaultSuccessMessage(actionRequest);
        } else if (cmd.equals(Constants.ADD_TEMP)) {
            addTempFileEntry(actionRequest, actionResponse);
            actionResponse.setRenderParameter("mvcPath", "/null.jsp");
        } else {
            mvcActionCommand.processAction(actionRequest, actionResponse);
            return;
        }

        WindowState windowState = actionRequest.getWindowState();

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

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

                if (Validator.isNotNull(redirect)) {
                    actionRequest.setAttribute(WebKeys.REDIRECT, redirect);
                }
            }
        }
    } catch (Exception e) {
        handleUploadException(portletConfig, actionRequest, actionResponse, cmd, e);
    }
}

From source file:org.lsug.quota.web.internal.portlet.action.documentlibrary.QuotaUploadMultipleFileEntriesMVCActionCommand.java

License:Open Source License

protected void handleUploadException(PortletConfig portletConfig, ActionRequest actionRequest,
        ActionResponse actionResponse, String cmd, Exception e) throws Exception {

    if (e instanceof QuotaExceededException) {

        if (cmd.equals(Constants.ADD_TEMP)) {
            hideDefaultErrorMessage(actionRequest);
        }// w  ww  . j a  v  a 2 s .c  om

        HttpServletResponse response = _portal.getHttpServletResponse(actionResponse);

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

        String errorMessage = StringPool.BLANK;
        int errorType = PortletKeys.SC_QUOTA_EXCEEDED_ERROR_TYPE;

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

        ResourceBundle resourceBundle = ResourceBundleUtil.getBundle("content.Language",
                themeDisplay.getLocale(), getClass());

        errorMessage = ResourceBundleUtil.getString(resourceBundle, "quota-exceeded-error");

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

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

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);

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

    } else {
        throw e;
    }
}