Example usage for com.liferay.portal.kernel.theme ThemeDisplay translate

List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay translate

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.theme ThemeDisplay translate.

Prototype

public String translate(String key) 

Source Link

Usage

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

License:Open Source License

protected String getAddMultipleFileEntriesErrorMessage(PortletConfig portletConfig, ActionRequest actionRequest,
        ActionResponse actionResponse, Exception e) throws Exception {

    String errorMessage = null;//from w  w w.j a va 2 s  . c  om

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

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

        errorMessage = themeDisplay.translate(ase.getMessageKey());
    } else if (e instanceof AssetCategoryException) {
        AssetCategoryException ace = (AssetCategoryException) e;

        AssetVocabulary assetVocabulary = ace.getVocabulary();

        String vocabularyTitle = StringPool.BLANK;

        if (assetVocabulary != null) {
            vocabularyTitle = assetVocabulary.getTitle(themeDisplay.getLocale());
        }

        if (ace.getType() == AssetCategoryException.AT_LEAST_ONE_CATEGORY) {
            errorMessage = themeDisplay.translate("please-select-at-least-one-category-for-x", vocabularyTitle);
        } else if (ace.getType() == AssetCategoryException.TOO_MANY_CATEGORIES) {

            errorMessage = themeDisplay.translate("you-cannot-select-more-than-one-category-for-x",
                    vocabularyTitle);
        }
    } else if (e instanceof DuplicateFileEntryException) {
        errorMessage = themeDisplay.translate("the-folder-you-selected-already-has-an-entry-with-this-"
                + "name.-please-select-a-different-folder");
    } else if (e instanceof FileExtensionException) {
        errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-extension-x",
                StringUtil.merge(getAllowedFileExtensions(portletConfig, actionRequest, actionResponse)));
    } else if (e instanceof FileNameException) {
        errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-name");
    } 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()));
    } else if (e instanceof InvalidFileEntryTypeException) {
        errorMessage = themeDisplay.translate("the-document-type-you-selected-is-not-valid-for-this-folder");
    } else if (e instanceof InvalidFileEntryTypeException) {
        errorMessage = themeDisplay.translate("the-document-type-you-selected-is-not-valid-for-this-folder");
    } else if (e instanceof QuotaExceededException) {
        ResourceBundle resourceBundle = ResourceBundleUtil.getBundle("content.Language",
                themeDisplay.getLocale(), getClass());

        errorMessage = ResourceBundleUtil.getString(resourceBundle, "quota-exceeded-error");
    } else {
        errorMessage = themeDisplay.translate("an-unexpected-error-occurred-while-saving-your-document");
    }

    return errorMessage;
}