com.liferay.portlet.blogs.util.BlogsUtil.java Source code

Java tutorial

Introduction

Here is the source code for com.liferay.portlet.blogs.util.BlogsUtil.java

Source

/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.liferay.portlet.blogs.util;

import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.LocalizationUtil;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portal.util.PropsUtil;
import com.liferay.portal.util.PropsValues;
import com.liferay.util.ContentUtil;

import java.util.Locale;
import java.util.Map;

import javax.portlet.PortletPreferences;

/**
 * @author Brian Wing Shun Chan
 * @author Thiago Moreira
 */
public class BlogsUtil {

    public static Map<Locale, String> getEmailEntryAddedBodyMap(PortletPreferences preferences) {

        Map<Locale, String> map = LocalizationUtil.getLocalizationMap(preferences, "emailEntryAddedBody");

        Locale defaultLocale = LocaleUtil.getDefault();

        String defaultValue = map.get(defaultLocale);

        if (Validator.isNotNull(defaultValue)) {
            return map;
        }

        map.put(defaultLocale, ContentUtil.get(PropsUtil.get(PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_BODY)));

        return map;
    }

    public static boolean getEmailEntryAddedEnabled(PortletPreferences preferences) {

        String emailEntryAddedEnabled = preferences.getValue("emailEntryAddedEnabled", StringPool.BLANK);

        if (Validator.isNotNull(emailEntryAddedEnabled)) {
            return GetterUtil.getBoolean(emailEntryAddedEnabled);
        } else {
            return GetterUtil.getBoolean(PropsUtil.get(PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_ENABLED));
        }
    }

    public static Map<Locale, String> getEmailEntryAddedSubjectMap(PortletPreferences preferences) {

        Map<Locale, String> map = LocalizationUtil.getLocalizationMap(preferences, "emailEntryAddedSubject");

        Locale defaultLocale = LocaleUtil.getDefault();

        String defaultValue = map.get(defaultLocale);

        if (Validator.isNotNull(defaultValue)) {
            return map;
        }

        map.put(defaultLocale, ContentUtil.get(PropsUtil.get(PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_SUBJECT)));

        return map;
    }

    public static Map<Locale, String> getEmailEntryUpdatedBodyMap(PortletPreferences preferences) {

        Map<Locale, String> map = LocalizationUtil.getLocalizationMap(preferences, "emailEntryUpdatedBody");

        Locale defaultLocale = LocaleUtil.getDefault();

        String defaultValue = map.get(defaultLocale);

        if (Validator.isNotNull(defaultValue)) {
            return map;
        }

        map.put(defaultLocale, ContentUtil.get(PropsUtil.get(PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_BODY)));

        return map;
    }

    public static boolean getEmailEntryUpdatedEnabled(PortletPreferences preferences) {

        String emailEntryUpdatedEnabled = preferences.getValue("emailEntryUpdatedEnabled", StringPool.BLANK);

        if (Validator.isNotNull(emailEntryUpdatedEnabled)) {
            return GetterUtil.getBoolean(emailEntryUpdatedEnabled);
        } else {
            return GetterUtil.getBoolean(PropsUtil.get(PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_ENABLED));
        }
    }

    public static Map<Locale, String> getEmailEntryUpdatedSubjectMap(PortletPreferences preferences) {

        Map<Locale, String> map = LocalizationUtil.getLocalizationMap(preferences, "emailEntryUpdatedSubject");

        Locale defaultLocale = LocaleUtil.getDefault();

        String defaultValue = map.get(defaultLocale);

        if (Validator.isNotNull(defaultValue)) {
            return map;
        }

        map.put(defaultLocale, ContentUtil.get(PropsUtil.get(PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_SUBJECT)));

        return map;
    }

    public static String getEmailFromAddress(PortletPreferences preferences, long companyId)
            throws SystemException {

        return PortalUtil.getEmailFromAddress(preferences, companyId, PropsValues.BLOGS_EMAIL_FROM_ADDRESS);
    }

    public static String getEmailFromName(PortletPreferences preferences, long companyId) throws SystemException {

        return PortalUtil.getEmailFromName(preferences, companyId, PropsValues.BLOGS_EMAIL_FROM_NAME);
    }

    public static String getUrlTitle(long entryId, String title) {
        title = title.trim().toLowerCase();

        if (Validator.isNull(title) || Validator.isNumber(title) || title.equals("rss")) {

            return String.valueOf(entryId);
        } else {
            return FriendlyURLNormalizerUtil.normalize(title, _URL_TITLE_REPLACE_CHARS);
        }
    }

    private static final char[] _URL_TITLE_REPLACE_CHARS = new char[] { '.', '/' };

}