Example usage for com.liferay.portal.kernel.util PrefsPropsUtil getLong

List of usage examples for com.liferay.portal.kernel.util PrefsPropsUtil getLong

Introduction

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

Prototype

public static long getLong(String name) 

Source Link

Usage

From source file:com.liferay.document.library.web.internal.display.context.DefaultDLEditFileEntryDisplayContext.java

License:Open Source License

@Override
public long getMaximumUploadRequestSize() {
    return PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE);
}

From source file:com.liferay.document.library.web.internal.display.context.DefaultDLEditFileEntryDisplayContext.java

License:Open Source License

@Override
public long getMaximumUploadSize() {
    long fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE);

    if (fileMaxSize == 0) {
        fileMaxSize = getMaximumUploadRequestSize();
    }/*from  ww  w. j a  va  2s  . c o m*/

    return fileMaxSize;
}

From source file:com.liferay.portlet.documentlibrary.util.DLImpl.java

License:Open Source License

@Override
public String getThumbnailStyle(boolean max, int margin) throws Exception {
    StringBundler sb = new StringBundler(5);

    if (max) {//www  . ja v a2  s  . c  om
        sb.append("max-height: ");
    } else {
        sb.append("height: ");
    }

    sb.append(PrefsPropsUtil.getLong(PropsKeys.DL_FILE_ENTRY_THUMBNAIL_MAX_HEIGHT) + 2 * margin);

    if (max) {
        sb.append("px; max-width: ");
    } else {
        sb.append("px; width: ");
    }

    sb.append(PrefsPropsUtil.getLong(PropsKeys.DL_FILE_ENTRY_THUMBNAIL_MAX_WIDTH) + 2 * margin);
    sb.append("px;");

    return sb.toString();
}

From source file:com.liferay.privatemessaging.portlet.PrivateMessagingPortlet.java

License:Open Source License

protected String getMessage(PortletRequest portletRequest, Exception key) throws Exception {

    String message = null;//  w  w w  .  j  av a  2 s . co m

    if (key instanceof FileExtensionException) {
        message = translate(portletRequest, "document-names-must-end-with-one-of-the-following-extensions");

        message += CharPool.SPACE + StringUtil.merge(
                PrefsPropsUtil.getStringArray(PropsKeys.DL_FILE_EXTENSIONS, StringPool.COMMA),
                StringPool.COMMA_AND_SPACE);
    } else if (key instanceof FileNameException) {
        message = translate(portletRequest, "please-enter-a-file-with-a-valid-file-name");
    } else if (key instanceof FileSizeException) {
        long fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE);

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

        fileMaxSize /= 1024;

        message = translate(portletRequest, "please-enter-a-file-with-a-valid-file-size-no-larger-than-x",
                fileMaxSize);
    } else if (key instanceof UserScreenNameException) {
        message = translate(portletRequest, "the-following-users-were-not-found");

        message += CharPool.SPACE + key.getMessage();
    } else {
        message = translate(portletRequest, "your-request-failed-to-complete");
    }

    return message;
}

From source file:com.liferay.privatemessaging.portlet.PrivateMessagingPortlet.java

License:Open Source License

protected void validateAttachment(String fileName, InputStream inputStream) throws Exception {

    if (inputStream instanceof ByteArrayFileInputStream) {
        ByteArrayFileInputStream byteArrayFileInputStream = (ByteArrayFileInputStream) inputStream;

        File file = byteArrayFileInputStream.getFile();

        if ((PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE) > 0)
                && ((file == null) || (file.length() > PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE)))) {

            throw new FileSizeException(fileName);
        }// www.  j  a va 2  s  .  c  o  m
    }

    if (!isValidName(fileName)) {
        throw new FileNameException(fileName);
    }

    String[] fileExtensions = PrefsPropsUtil.getStringArray(PropsKeys.DL_FILE_EXTENSIONS, StringPool.COMMA);

    boolean validFileExtension = false;

    for (String fileExtension : fileExtensions) {
        if (StringPool.STAR.equals(fileExtension) || StringUtil.endsWith(fileName, fileExtension)) {

            validFileExtension = true;

            break;
        }
    }

    if (!validFileExtension) {
        throw new FileExtensionException(fileName);
    }
}

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  w  w  . j  a v  a  2s.c om*/
 */
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

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

    String errorMessage = null;/* ww  w  .j a  v  a 2  s  .  c  o  m*/

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