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

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

Introduction

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

Prototype

public static long getLong(String name) 

Source Link

Usage

From source file:com.liferay.portlet.journal.service.impl.JournalTemplateLocalServiceImpl.java

License:Open Source License

protected void validate(Map<Locale, String> nameMap, String xsl, boolean smallImage, String smallImageURL,
        File smallImageFile, byte[] smallImageBytes) throws PortalException, SystemException {

    Locale locale = LocaleUtil.getDefault();

    if (nameMap.isEmpty() || Validator.isNull(nameMap.get(locale))) {
        throw new TemplateNameException();
    } else if (Validator.isNull(xsl)) {
        throw new TemplateXslException();
    }//from  w w  w.j  a va  2 s.  c o  m

    String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.JOURNAL_IMAGE_EXTENSIONS,
            StringPool.COMMA);

    if (smallImage && Validator.isNull(smallImageURL) && (smallImageFile != null)
            && (smallImageBytes != null)) {

        String smallImageName = smallImageFile.getName();

        if (smallImageName != null) {
            boolean validSmallImageExtension = false;

            for (int i = 0; i < imageExtensions.length; i++) {
                if (StringPool.STAR.equals(imageExtensions[i])
                        || StringUtil.endsWith(smallImageName, imageExtensions[i])) {

                    validSmallImageExtension = true;

                    break;
                }
            }

            if (!validSmallImageExtension) {
                throw new TemplateSmallImageNameException(smallImageName);
            }
        }

        long smallImageMaxSize = PrefsPropsUtil.getLong(PropsKeys.JOURNAL_IMAGE_SMALL_MAX_SIZE);

        if ((smallImageMaxSize > 0)
                && ((smallImageBytes == null) || (smallImageBytes.length > smallImageMaxSize))) {

            throw new TemplateSmallImageSizeException();
        }
    }
}

From source file:com.liferay.portlet.shopping.service.impl.ShoppingItemLocalServiceImpl.java

License:Open Source License

protected void validate(long companyId, long itemId, String sku, String name, boolean smallImage,
        String smallImageURL, File smallImageFile, byte[] smallImageBytes, boolean mediumImage,
        String mediumImageURL, File mediumImageFile, byte[] mediumImageBytes, boolean largeImage,
        String largeImageURL, File largeImageFile, byte[] largeImageBytes)
        throws PortalException, SystemException {

    if (Validator.isNull(sku)) {
        throw new ItemSKUException();
    }//from  w  w  w. j a  va2s  .  c om

    ShoppingItem item = shoppingItemPersistence.fetchByC_S(companyId, sku);

    if (item != null) {
        if (itemId > 0) {
            if (item.getItemId() != itemId) {
                throw new DuplicateItemSKUException();
            }
        } else {
            throw new DuplicateItemSKUException();
        }
    }

    if (Validator.isNull(name)) {
        throw new ItemNameException();
    }

    String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.SHOPPING_IMAGE_EXTENSIONS,
            StringPool.COMMA);

    // Small image

    if (smallImage && Validator.isNull(smallImageURL) && smallImageFile != null && smallImageBytes != null) {

        String smallImageName = smallImageFile.getName();

        if (smallImageName != null) {
            boolean validSmallImageExtension = false;

            for (int i = 0; i < imageExtensions.length; i++) {
                if (StringPool.STAR.equals(imageExtensions[i])
                        || StringUtil.endsWith(smallImageName, imageExtensions[i])) {

                    validSmallImageExtension = true;

                    break;
                }
            }

            if (!validSmallImageExtension) {
                throw new ItemSmallImageNameException(smallImageName);
            }
        }

        long smallImageMaxSize = PrefsPropsUtil.getLong(PropsKeys.SHOPPING_IMAGE_MEDIUM_MAX_SIZE);

        if ((smallImageMaxSize > 0)
                && ((smallImageBytes == null) || (smallImageBytes.length > smallImageMaxSize))) {

            throw new ItemSmallImageSizeException();
        }
    }

    // Medium image

    if (mediumImage && Validator.isNull(mediumImageURL) && mediumImageFile != null
            && mediumImageBytes != null) {

        String mediumImageName = mediumImageFile.getName();

        if (mediumImageName != null) {
            boolean validMediumImageExtension = false;

            for (int i = 0; i < imageExtensions.length; i++) {
                if (StringPool.STAR.equals(imageExtensions[i])
                        || StringUtil.endsWith(mediumImageName, imageExtensions[i])) {

                    validMediumImageExtension = true;

                    break;
                }
            }

            if (!validMediumImageExtension) {
                throw new ItemMediumImageNameException(mediumImageName);
            }
        }

        long mediumImageMaxSize = PrefsPropsUtil.getLong(PropsKeys.SHOPPING_IMAGE_MEDIUM_MAX_SIZE);

        if ((mediumImageMaxSize > 0)
                && ((mediumImageBytes == null) || (mediumImageBytes.length > mediumImageMaxSize))) {

            throw new ItemMediumImageSizeException();
        }
    }

    // Large image

    if (largeImage && Validator.isNull(largeImageURL) && largeImageFile != null && largeImageBytes != null) {

        String largeImageName = largeImageFile.getName();

        if (largeImageName != null) {
            boolean validLargeImageExtension = false;

            for (int i = 0; i < imageExtensions.length; i++) {
                if (StringPool.STAR.equals(imageExtensions[i])
                        || StringUtil.endsWith(largeImageName, imageExtensions[i])) {

                    validLargeImageExtension = true;

                    break;
                }
            }

            if (!validLargeImageExtension) {
                throw new ItemLargeImageNameException(largeImageName);
            }
        }

        long largeImageMaxSize = PrefsPropsUtil.getLong(PropsKeys.SHOPPING_IMAGE_LARGE_MAX_SIZE);

        if ((largeImageMaxSize > 0)
                && ((largeImageBytes == null) || (largeImageBytes.length > largeImageMaxSize))) {

            throw new ItemLargeImageSizeException();
        }
    }
}