List of usage examples for com.liferay.portal.kernel.util FastDateFormatFactoryUtil getDateTime
public static Format getDateTime(int dateStyle, int timeStyle, Locale locale, TimeZone timeZone)
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 w w . ja v a 2s.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 }); }
From source file:com.liferay.privatemessaging.service.impl.UserThreadLocalServiceImpl.java
License:Open Source License
protected void sendEmail(long mbMessageId, ThemeDisplay themeDisplay) throws Exception { MBMessage mbMessage = MBMessageLocalServiceUtil.getMBMessage(mbMessageId); User sender = UserLocalServiceUtil.getUser(mbMessage.getUserId()); Company company = CompanyLocalServiceUtil.getCompany(sender.getCompanyId()); InternetAddress from = new InternetAddress(company.getEmailAddress()); String subject = StringUtil.read(PrivateMessagingPortlet.class .getResourceAsStream("dependencies/notification_message_subject.tmpl")); subject = StringUtil.replace(subject, new String[] { "[$COMPANY_NAME$]", "[$FROM_NAME$]" }, new String[] { company.getName(), sender.getFullName() }); String body = StringUtil.read( PrivateMessagingPortlet.class.getResourceAsStream("dependencies/notification_message_body.tmpl")); long portraitId = sender.getPortraitId(); String tokenId = WebServerServletTokenUtil.getToken(sender.getPortraitId()); String portraitURL = themeDisplay.getPortalURL() + themeDisplay.getPathImage() + "/user_" + (sender.isFemale() ? "female" : "male") + "_portrait?img_id=" + portraitId + "&t=" + tokenId; body = StringUtil.replace(body,//from ww w.j a va 2 s.com new String[] { "[$BODY$]", "[$COMPANY_NAME$]", "[$FROM_AVATAR$]", "[$FROM_NAME$]", "[$FROM_PROFILE_URL$]", "[$SUBJECT$]" }, new String[] { mbMessage.getBody(), company.getName(), portraitURL, sender.getFullName(), sender.getDisplayURL(themeDisplay), mbMessage.getSubject() }); List<UserThread> userThreads = UserThreadLocalServiceUtil.getMBThreadUserThreads(mbMessage.getThreadId()); for (UserThread userThread : userThreads) { if ((userThread.getUserId() == mbMessage.getUserId()) && UserNotificationManagerUtil.isDeliver( userThread.getUserId(), PortletKeys.PRIVATE_MESSAGING, PrivateMessagingConstants.NEW_MESSAGE, 0, UserNotificationDeliveryConstants.TYPE_EMAIL)) { continue; } User recipient = UserLocalServiceUtil.getUser(userThread.getUserId()); String threadURL = getThreadURL(recipient, mbMessage.getThreadId(), themeDisplay); if (Validator.isNull(threadURL)) { continue; } InternetAddress to = new InternetAddress(recipient.getEmailAddress()); Format dateFormatDateTime = FastDateFormatFactoryUtil.getDateTime(FastDateFormatConstants.LONG, FastDateFormatConstants.SHORT, recipient.getLocale(), recipient.getTimeZone()); String userThreadBody = StringUtil.replace(body, new String[] { "[$SENT_DATE$]", "[$THREAD_URL$]" }, new String[] { dateFormatDateTime.format(mbMessage.getCreateDate()), threadURL }); MailMessage mailMessage = new MailMessage(from, to, subject, userThreadBody, true); MailServiceUtil.sendEmail(mailMessage); } }
From source file:com.liferay.so.activities.hook.social.CalendarActivityInterpreter.java
License:Open Source License
protected String getBody(String className, long classPK, ServiceContext serviceContext) throws Exception { StringBundler sb = new StringBundler(15); sb.append("<div class=\"activity-body\"><div class=\"title\">"); sb.append(getPageTitle(className, classPK, serviceContext)); sb.append("</div><div class=\"date\"><strong>"); sb.append(serviceContext.translate("date")); sb.append(": </strong>"); Format dateFormatDate = FastDateFormatFactoryUtil.getDateTime(DateFormat.FULL, DateFormat.SHORT, serviceContext.getLocale(), serviceContext.getTimeZone()); CalendarBooking calendarBooking = CalendarBookingLocalServiceUtil.fetchCalendarBooking(classPK); sb.append(dateFormatDate.format(calendarBooking.getStartTime())); sb.append("</div><div class=\"location\"><strong>"); sb.append(serviceContext.translate("location")); sb.append(": </strong>"); sb.append(calendarBooking.getLocation()); sb.append("</div><div class=\"description\"><strong>"); sb.append(serviceContext.translate("description")); sb.append(": </strong>"); AssetRenderer assetRenderer = getAssetRenderer(className, classPK); sb.append(StringUtil.shorten(HtmlUtil.escape(assetRenderer.getSummary(), 200))); sb.append("</div></div>"); return sb.toString(); }
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 av a 2s.com*/ 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(); }