Example usage for com.liferay.portal.kernel.notifications UserNotificationFeedEntry getBody

List of usage examples for com.liferay.portal.kernel.notifications UserNotificationFeedEntry getBody

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.notifications UserNotificationFeedEntry getBody.

Prototype

public String getBody() 

Source Link

Usage

From source file:com.liferay.notifications.notifications.portlet.NotificationsPortlet.java

License:Open Source License

protected String renderEntry(ResourceRequest resourceRequest, ResourceResponse resourceResponse,
        UserNotificationEvent userNotificationEvent) throws Exception {

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

    UserNotificationFeedEntry userNotificationFeedEntry = UserNotificationManagerUtil.interpret(
            StringPool.BLANK, userNotificationEvent, ServiceContextFactory.getInstance(resourceRequest));

    if (userNotificationFeedEntry == null) {
        return null;
    }//from   www  .jav a2s.c om

    LiferayPortletResponse liferayPortletResponse = (LiferayPortletResponse) resourceResponse;

    PortletURL actionURL = liferayPortletResponse.createActionURL(PortletKeys.NOTIFICATIONS);

    actionURL.setParameter("userNotificationEventId",
            String.valueOf(userNotificationEvent.getUserNotificationEventId()));
    actionURL.setWindowState(WindowState.NORMAL);

    String actionDiv = StringPool.BLANK;
    String cssClass = StringPool.BLANK;
    String iconMenu = StringPool.BLANK;

    if (userNotificationEvent.isActionRequired()) {
        actionURL.setParameter("javax.portlet.action", "deleteUserNotificationEvent");

        actionDiv = StringUtil.replace(_DELETE_DIV, "[$DELETE_URL$]", actionURL.toString());
    } else {
        actionURL.setParameter("javax.portlet.action", "markAsRead");

        actionDiv = StringUtil.replace(_MARK_AS_READ_DIV, new String[] { "[$LINK$]", "[$MARK_AS_READ_URL$]" },
                new String[] { userNotificationFeedEntry.getLink(), actionURL.toString() });

        if (userNotificationEvent.isArchived()) {
            cssClass = "archived";
        }

        iconMenu = getIconMenu(userNotificationEvent, liferayPortletResponse, themeDisplay);
    }

    Portlet portlet = PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(),
            userNotificationEvent.getType());

    String portletName = portlet.getDisplayName();
    String portletIcon = portlet.getContextPath() + portlet.getIcon();

    JSONObject userNotificationEventJSONObject = JSONFactoryUtil
            .createJSONObject(userNotificationEvent.getPayload());

    long userId = userNotificationEventJSONObject.getLong("userId");

    String userFullName = HtmlUtil.escape(PortalUtil.getUserName(userId, StringPool.BLANK));

    String userPortraitURL = StringPool.BLANK;

    User user = UserLocalServiceUtil.fetchUserById(userId);

    if (user != null) {
        userPortraitURL = user.getPortraitURL(themeDisplay);
    }

    Format dateFormatDate = FastDateFormatFactoryUtil.getDate(DateFormat.FULL, themeDisplay.getLocale(),
            themeDisplay.getTimeZone());

    Format dateTimeFormat = FastDateFormatFactoryUtil.getDateTime(DateFormat.FULL, DateFormat.SHORT,
            themeDisplay.getLocale(), themeDisplay.getTimeZone());

    return StringUtil.replace(ContentUtil.get(PortletPropsValues.USER_NOTIFICATION_ENTRY),
            new String[] { "[$ACTION_DIV$]", "[$BODY$]", "[$CSS_CLASS$]", "[$ICON_MENU$]", "[$PORTLET_ICON$]",
                    "[$PORTLET_NAME$]", "[$TIMESTAMP$]", "[$TIMETITLE$]", "[$USER_FULL_NAME$]",
                    "[$USER_PORTRAIT_URL$]" },
            new String[] { actionDiv, userNotificationFeedEntry.getBody(), cssClass, iconMenu, portletIcon,
                    portletName,
                    Time.getRelativeTimeDescription(userNotificationEvent.getTimestamp(),
                            themeDisplay.getLocale(), themeDisplay.getTimeZone(), dateFormatDate),
                    dateTimeFormat.format(userNotificationEvent.getTimestamp()), userFullName,
                    userPortraitURL });
}