Example usage for com.liferay.portal.kernel.util FastDateFormatFactoryUtil getDate

List of usage examples for com.liferay.portal.kernel.util FastDateFormatFactoryUtil getDate

Introduction

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

Prototype

public static Format getDate(int style, Locale locale, TimeZone timeZone) 

Source Link

Usage

From source file:com.liferay.announcements.web.internal.display.context.DefaultAnnouncementsDisplayContext.java

License:Open Source License

@Override
public Format getDateFormatDate() {
    ThemeDisplay themeDisplay = _announcementsRequestHelper.getThemeDisplay();

    return FastDateFormatFactoryUtil.getDate(DateFormat.FULL, themeDisplay.getLocale(),
            themeDisplay.getTimeZone());
}

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  w  ww .j av  a 2s  .c o  m*/

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

From source file:com.liferay.so.activities.hook.social.SOSocialActivityInterpreter.java

License:Open Source License

protected String getTitle(long activitySetId, long groupId, long userId, long displayDate,
        ServiceContext serviceContext) throws Exception {

    StringBundler sb = new StringBundler(8);

    sb.append("<div class=\"activity-header\">");
    sb.append("<div class=\"activity-user-name\">");

    String userName = getUserName(userId, serviceContext);

    int otherUsersCount = 0;

    if (activitySetId > 0) {
        List<Long> userIds = getActivitySetUserIds(activitySetId);

        otherUsersCount = userIds.size() - 1;
    }/*  w w w . j  a  v  a  2s . c  o  m*/

    if ((groupId != serviceContext.getScopeGroupId()) && (groupId > 0)) {
        String groupName = getGroupName(groupId, serviceContext);

        if (otherUsersCount > 0) {
            sb.append(serviceContext.translate("x-and-x-others-in-x",
                    new Object[] { userName, otherUsersCount, groupName }));
        } else {
            sb.append(serviceContext.translate("x-in-x", new Object[] { userName, groupName }));
        }
    } else if (otherUsersCount > 0) {
        sb.append(serviceContext.translate("x-and-x-others", new Object[] { userName, otherUsersCount }));
    } else {
        sb.append(userName);
    }

    sb.append("</div><div class=\"activity-time\" title=\"");

    Format dateFormatDate = FastDateFormatFactoryUtil.getDateTime(DateFormat.FULL, DateFormat.SHORT,
            serviceContext.getLocale(), serviceContext.getTimeZone());

    Date activityDate = new Date(displayDate);

    sb.append(dateFormatDate.format(activityDate));

    sb.append("\">");

    Format dateFormat = FastDateFormatFactoryUtil.getDate(DateFormat.FULL, serviceContext.getLocale(),
            serviceContext.getTimeZone());

    String relativeTimeDescription = Time.getRelativeTimeDescription(displayDate, serviceContext.getLocale(),
            serviceContext.getTimeZone(), dateFormat);

    sb.append(relativeTimeDescription);

    sb.append("</div></div>");

    return sb.toString();
}

From source file:com.liferay.so.activities.portlet.ActivitiesPortlet.java

License:Open Source License

protected JSONObject getJSONObject(long mbMessageIdOrMicroblogsEntryId, String body, Date modifiedDate,
        long userId, String userName, ThemeDisplay themeDisplay) throws Exception {

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    jsonObject.put("body", HtmlUtil.escape(body));

    if ((userId <= 0) || (userId != themeDisplay.getUserId())) {
        jsonObject.put("commentControlsClass", "hide");
    }// w w w . j  a  va2  s  . co  m

    jsonObject.put("mbMessageIdOrMicroblogsEntryId", mbMessageIdOrMicroblogsEntryId);

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

    jsonObject.put("modifiedDate", Time.getRelativeTimeDescription(modifiedDate.getTime(),
            themeDisplay.getLocale(), themeDisplay.getTimeZone(), dateFormat));

    User user = UserLocalServiceUtil.fetchUser(userId);

    if (user != null) {
        jsonObject.put("userDisplayURL", user.getDisplayURL(themeDisplay));
        jsonObject.put("userPortraitURL", HtmlUtil.escape(user.getPortraitURL(themeDisplay)));
    }

    jsonObject.put("userName", HtmlUtil.escape(userName));

    return jsonObject;
}