001
014
015 package com.liferay.portlet.messageboards.service.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.parsers.bbcode.BBCodeTranslatorUtil;
020 import com.liferay.portal.kernel.util.HtmlUtil;
021 import com.liferay.portal.kernel.util.ObjectValuePair;
022 import com.liferay.portal.kernel.util.ParamUtil;
023 import com.liferay.portal.kernel.util.StringPool;
024 import com.liferay.portal.kernel.util.StringUtil;
025 import com.liferay.portal.kernel.workflow.WorkflowConstants;
026 import com.liferay.portal.model.Company;
027 import com.liferay.portal.model.Group;
028 import com.liferay.portal.model.User;
029 import com.liferay.portal.security.auth.PrincipalException;
030 import com.liferay.portal.security.permission.ActionKeys;
031 import com.liferay.portal.service.ServiceContext;
032 import com.liferay.portal.theme.ThemeDisplay;
033 import com.liferay.portal.util.PortalUtil;
034 import com.liferay.portal.util.PropsValues;
035 import com.liferay.portlet.messageboards.LockedThreadException;
036 import com.liferay.portlet.messageboards.NoSuchCategoryException;
037 import com.liferay.portlet.messageboards.model.MBCategory;
038 import com.liferay.portlet.messageboards.model.MBCategoryConstants;
039 import com.liferay.portlet.messageboards.model.MBMessage;
040 import com.liferay.portlet.messageboards.model.MBMessageConstants;
041 import com.liferay.portlet.messageboards.model.MBMessageDisplay;
042 import com.liferay.portlet.messageboards.model.MBThread;
043 import com.liferay.portlet.messageboards.model.MBThreadConstants;
044 import com.liferay.portlet.messageboards.service.base.MBMessageServiceBaseImpl;
045 import com.liferay.portlet.messageboards.service.permission.MBCategoryPermission;
046 import com.liferay.portlet.messageboards.service.permission.MBDiscussionPermission;
047 import com.liferay.portlet.messageboards.service.permission.MBMessagePermission;
048 import com.liferay.portlet.messageboards.util.MBUtil;
049 import com.liferay.portlet.messageboards.util.comparator.MessageCreateDateComparator;
050 import com.liferay.util.RSSUtil;
051
052 import com.sun.syndication.feed.synd.SyndContent;
053 import com.sun.syndication.feed.synd.SyndContentImpl;
054 import com.sun.syndication.feed.synd.SyndEntry;
055 import com.sun.syndication.feed.synd.SyndEntryImpl;
056 import com.sun.syndication.feed.synd.SyndFeed;
057 import com.sun.syndication.feed.synd.SyndFeedImpl;
058 import com.sun.syndication.feed.synd.SyndLink;
059 import com.sun.syndication.feed.synd.SyndLinkImpl;
060 import com.sun.syndication.io.FeedException;
061
062 import java.io.InputStream;
063
064 import java.util.ArrayList;
065 import java.util.Collections;
066 import java.util.Date;
067 import java.util.List;
068
069
074 public class MBMessageServiceImpl extends MBMessageServiceBaseImpl {
075
076 public MBMessage addDiscussionMessage(
077 long groupId, String className, long classPK,
078 String permissionClassName, long permissionClassPK,
079 long permissionOwnerId, long threadId, long parentMessageId,
080 String subject, String body, ServiceContext serviceContext)
081 throws PortalException, SystemException {
082
083 User user = getGuestOrUser();
084
085 MBDiscussionPermission.check(
086 getPermissionChecker(), user.getCompanyId(),
087 serviceContext.getScopeGroupId(), permissionClassName,
088 permissionClassPK, permissionOwnerId, ActionKeys.ADD_DISCUSSION);
089
090 return mbMessageLocalService.addDiscussionMessage(
091 user.getUserId(), null, groupId, className, classPK, threadId,
092 parentMessageId, subject, body, serviceContext);
093 }
094
095
100 public MBMessage addMessage(
101 long groupId, long categoryId, long threadId, long parentMessageId,
102 String subject, String body, String format,
103 List<ObjectValuePair<String, InputStream>> inputStreamOVPs,
104 boolean anonymous, double priority, boolean allowPingbacks,
105 ServiceContext serviceContext)
106 throws PortalException, SystemException {
107
108 return addMessage(
109 parentMessageId, subject, body, format, inputStreamOVPs, anonymous,
110 priority, allowPingbacks, serviceContext);
111 }
112
113 public MBMessage addMessage(
114 long groupId, long categoryId, String subject, String body,
115 String format,
116 List<ObjectValuePair<String, InputStream>> inputStreamOVPs,
117 boolean anonymous, double priority, boolean allowPingbacks,
118 ServiceContext serviceContext)
119 throws PortalException, SystemException {
120
121 MBCategoryPermission.check(
122 getPermissionChecker(), groupId, categoryId,
123 ActionKeys.ADD_MESSAGE);
124
125 if (!MBCategoryPermission.contains(
126 getPermissionChecker(), groupId, categoryId,
127 ActionKeys.ADD_FILE)) {
128
129 inputStreamOVPs = Collections.emptyList();
130 }
131
132 if (!MBCategoryPermission.contains(
133 getPermissionChecker(), groupId, categoryId,
134 ActionKeys.UPDATE_THREAD_PRIORITY)) {
135
136 priority = MBThreadConstants.PRIORITY_NOT_GIVEN;
137 }
138
139 return mbMessageLocalService.addMessage(
140 getGuestOrUserId(), null, groupId, categoryId, subject, body,
141 format, inputStreamOVPs, anonymous, priority, allowPingbacks,
142 serviceContext);
143 }
144
145 public MBMessage addMessage(
146 long categoryId, String subject, String body,
147 ServiceContext serviceContext)
148 throws PortalException, SystemException {
149
150 MBCategory category = mbCategoryPersistence.findByPrimaryKey(
151 categoryId);
152
153 List<ObjectValuePair<String, InputStream>> inputStreamOVPs =
154 Collections.emptyList();
155
156 return addMessage(
157 category.getGroupId(), categoryId, subject, body,
158 MBMessageConstants.DEFAULT_FORMAT, inputStreamOVPs, false, 0.0,
159 false, serviceContext);
160 }
161
162 public MBMessage addMessage(
163 long parentMessageId, String subject, String body, String format,
164 List<ObjectValuePair<String, InputStream>> inputStreamOVPs,
165 boolean anonymous, double priority, boolean allowPingbacks,
166 ServiceContext serviceContext)
167 throws PortalException, SystemException {
168
169 MBMessage parentMessage = mbMessagePersistence.findByPrimaryKey(
170 parentMessageId);
171
172 checkReplyToPermission(
173 parentMessage.getGroupId(), parentMessage.getCategoryId(),
174 parentMessageId);
175
176 boolean preview = ParamUtil.getBoolean(serviceContext, "preview");
177
178 int workFlowAction = serviceContext.getWorkflowAction();
179
180 if ((workFlowAction == WorkflowConstants.STATUS_DRAFT) && !preview) {
181 MBMessagePermission.check(
182 getPermissionChecker(), parentMessageId, ActionKeys.UPDATE);
183 }
184
185 if (lockLocalService.isLocked(
186 MBThread.class.getName(), parentMessage.getThreadId())) {
187
188 throw new LockedThreadException();
189 }
190
191 if (!MBCategoryPermission.contains(
192 getPermissionChecker(), parentMessage.getGroupId(),
193 parentMessage.getCategoryId(), ActionKeys.ADD_FILE)) {
194
195 inputStreamOVPs = Collections.emptyList();
196 }
197
198 if (!MBCategoryPermission.contains(
199 getPermissionChecker(), parentMessage.getGroupId(),
200 parentMessage.getCategoryId(),
201 ActionKeys.UPDATE_THREAD_PRIORITY)) {
202
203 priority = MBThreadConstants.PRIORITY_NOT_GIVEN;
204 }
205
206 return mbMessageLocalService.addMessage(
207 getGuestOrUserId(), null, parentMessage.getGroupId(),
208 parentMessage.getCategoryId(), parentMessage.getThreadId(),
209 parentMessageId, subject, body, format, inputStreamOVPs, anonymous,
210 priority, allowPingbacks, serviceContext);
211 }
212
213 public void deleteDiscussionMessage(
214 long groupId, String className, long classPK,
215 String permissionClassName, long permissionClassPK,
216 long permissionOwnerId, long messageId)
217 throws PortalException, SystemException {
218
219 User user = getUser();
220
221 MBDiscussionPermission.check(
222 getPermissionChecker(), user.getCompanyId(), groupId,
223 permissionClassName, permissionClassPK, messageId,
224 permissionOwnerId, ActionKeys.DELETE_DISCUSSION);
225
226 mbMessageLocalService.deleteDiscussionMessage(messageId);
227 }
228
229 public void deleteMessage(long messageId)
230 throws PortalException, SystemException {
231
232 MBMessagePermission.check(
233 getPermissionChecker(), messageId, ActionKeys.DELETE);
234
235 mbMessageLocalService.deleteMessage(messageId);
236 }
237
238 public void deleteMessageAttachments(long messageId)
239 throws PortalException, SystemException {
240
241 MBMessagePermission.check(
242 getPermissionChecker(), messageId, ActionKeys.DELETE);
243
244 mbMessageLocalService.deleteMessageAttachments(messageId);
245 }
246
247 public List<MBMessage> getCategoryMessages(
248 long groupId, long categoryId, int status, int start, int end)
249 throws PortalException, SystemException {
250
251 List<MBMessage> messages = new ArrayList<MBMessage>();
252
253 List<MBMessage> categoryMessages =
254 mbMessageLocalService.getCategoryMessages(
255 groupId, categoryId, status, start, end);
256
257 for (MBMessage message : categoryMessages) {
258 if (MBMessagePermission.contains(
259 getPermissionChecker(), message, ActionKeys.VIEW)) {
260
261 messages.add(message);
262 }
263 }
264
265 return messages;
266 }
267
268 public int getCategoryMessagesCount(
269 long groupId, long categoryId, int status)
270 throws SystemException {
271
272 return mbMessageLocalService.getCategoryMessagesCount(
273 groupId, categoryId, status);
274 }
275
276 public String getCategoryMessagesRSS(
277 long groupId, long categoryId, int status, int max, String type,
278 double version, String displayStyle, String feedURL,
279 String entryURL, ThemeDisplay themeDisplay)
280 throws PortalException, SystemException {
281
282 String name = StringPool.BLANK;
283 String description = StringPool.BLANK;
284
285 try {
286 MBCategory category = mbCategoryLocalService.getCategory(
287 categoryId);
288
289 groupId = category.getGroupId();
290 name = category.getName();
291 description = category.getDescription();
292 }
293 catch (NoSuchCategoryException nsce) {
294 Group group = groupLocalService.getGroup(categoryId);
295
296 groupId = group.getGroupId();
297 categoryId = MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID;
298 name = group.getDescriptiveName();
299 description = group.getDescription();
300 }
301
302 List<MBMessage> messages = new ArrayList<MBMessage>();
303
304 int lastIntervalStart = 0;
305 boolean listNotExhausted = true;
306 MessageCreateDateComparator comparator =
307 new MessageCreateDateComparator(false);
308
309 while ((messages.size() < max) && listNotExhausted) {
310 List<MBMessage> messageList =
311 mbMessageLocalService.getCategoryMessages(
312 groupId, categoryId, status, lastIntervalStart,
313 lastIntervalStart + max, comparator);
314
315 lastIntervalStart += max;
316 listNotExhausted = (messageList.size() == max);
317
318 for (MBMessage message : messageList) {
319 if (messages.size() >= max) {
320 break;
321 }
322
323 if (MBMessagePermission.contains(
324 getPermissionChecker(), message, ActionKeys.VIEW)) {
325
326 messages.add(message);
327 }
328 }
329 }
330
331 return exportToRSS(
332 name, description, type, version, displayStyle, feedURL, entryURL,
333 messages, themeDisplay);
334 }
335
336 public String getCompanyMessagesRSS(
337 long companyId, int status, int max, String type, double version,
338 String displayStyle, String feedURL, String entryURL,
339 ThemeDisplay themeDisplay)
340 throws PortalException, SystemException {
341
342 Company company = companyPersistence.findByPrimaryKey(companyId);
343
344 String name = company.getName();
345 String description = company.getName();
346
347 List<MBMessage> messages = new ArrayList<MBMessage>();
348
349 int lastIntervalStart = 0;
350 boolean listNotExhausted = true;
351 MessageCreateDateComparator comparator =
352 new MessageCreateDateComparator(false);
353
354 while ((messages.size() < max) && listNotExhausted) {
355 List<MBMessage> messageList =
356 mbMessageLocalService.getCompanyMessages(
357 companyId, status, lastIntervalStart,
358 lastIntervalStart + max, comparator);
359
360 lastIntervalStart += max;
361 listNotExhausted = (messageList.size() == max);
362
363 for (MBMessage message : messageList) {
364 if (messages.size() >= max) {
365 break;
366 }
367
368 if (MBMessagePermission.contains(
369 getPermissionChecker(), message, ActionKeys.VIEW)) {
370
371 messages.add(message);
372 }
373 }
374 }
375
376 return exportToRSS(
377 name, description, type, version, displayStyle, feedURL, entryURL,
378 messages, themeDisplay);
379 }
380
381 public int getGroupMessagesCount(long groupId, int status)
382 throws SystemException {
383
384 if (status == WorkflowConstants.STATUS_ANY) {
385 return mbMessagePersistence.filterCountByGroupId(groupId);
386 }
387 else {
388 return mbMessagePersistence.filterCountByG_S(groupId, status);
389 }
390 }
391
392 public String getGroupMessagesRSS(
393 long groupId, int status, int max, String type, double version,
394 String displayStyle, String feedURL, String entryURL,
395 ThemeDisplay themeDisplay)
396 throws PortalException, SystemException {
397
398 String name = StringPool.BLANK;
399 String description = StringPool.BLANK;
400
401 List<MBMessage> messages = new ArrayList<MBMessage>();
402
403 int lastIntervalStart = 0;
404 boolean listNotExhausted = true;
405 MessageCreateDateComparator comparator =
406 new MessageCreateDateComparator(false);
407
408 while ((messages.size() < max) && listNotExhausted) {
409 List<MBMessage> messageList =
410 mbMessageLocalService.getGroupMessages(
411 groupId, status, lastIntervalStart, lastIntervalStart + max,
412 comparator);
413
414 lastIntervalStart += max;
415 listNotExhausted = (messageList.size() == max);
416
417 for (MBMessage message : messageList) {
418 if (messages.size() >= max) {
419 break;
420 }
421
422 if (MBMessagePermission.contains(
423 getPermissionChecker(), message, ActionKeys.VIEW)) {
424
425 messages.add(message);
426 }
427 }
428 }
429
430 if (messages.size() > 0) {
431 MBMessage message = messages.get(messages.size() - 1);
432
433 name = message.getSubject();
434 description = message.getSubject();
435 }
436
437 return exportToRSS(
438 name, description, type, version, displayStyle, feedURL, entryURL,
439 messages, themeDisplay);
440 }
441
442 public String getGroupMessagesRSS(
443 long groupId, long userId, int status, int max, String type,
444 double version, String displayStyle, String feedURL,
445 String entryURL, ThemeDisplay themeDisplay)
446 throws PortalException, SystemException {
447
448 String name = StringPool.BLANK;
449 String description = StringPool.BLANK;
450
451 List<MBMessage> messages = new ArrayList<MBMessage>();
452
453 int lastIntervalStart = 0;
454 boolean listNotExhausted = true;
455 MessageCreateDateComparator comparator =
456 new MessageCreateDateComparator(false);
457
458 while ((messages.size() < max) && listNotExhausted) {
459 List<MBMessage> messageList =
460 mbMessageLocalService.getGroupMessages(
461 groupId, userId, status, lastIntervalStart,
462 lastIntervalStart + max, comparator);
463
464 lastIntervalStart += max;
465 listNotExhausted = (messageList.size() == max);
466
467 for (MBMessage message : messageList) {
468 if (messages.size() >= max) {
469 break;
470 }
471
472 if (MBMessagePermission.contains(
473 getPermissionChecker(), message, ActionKeys.VIEW)) {
474
475 messages.add(message);
476 }
477 }
478 }
479
480 if (messages.size() > 0) {
481 MBMessage message = messages.get(messages.size() - 1);
482
483 name = message.getSubject();
484 description = message.getSubject();
485 }
486
487 return exportToRSS(
488 name, description, type, version, displayStyle, feedURL, entryURL,
489 messages, themeDisplay);
490 }
491
492 public MBMessage getMessage(long messageId)
493 throws PortalException, SystemException {
494
495 MBMessagePermission.check(
496 getPermissionChecker(), messageId, ActionKeys.VIEW);
497
498 return mbMessageLocalService.getMessage(messageId);
499 }
500
501 public MBMessageDisplay getMessageDisplay(
502 long messageId, int status, String threadView,
503 boolean includePrevAndNext)
504 throws PortalException, SystemException {
505
506 MBMessagePermission.check(
507 getPermissionChecker(), messageId, ActionKeys.VIEW);
508
509 return mbMessageLocalService.getMessageDisplay(
510 getGuestOrUserId(), messageId, status, threadView,
511 includePrevAndNext);
512 }
513
514 public int getThreadAnswersCount(
515 long groupId, long categoryId, long threadId)
516 throws SystemException {
517
518 return mbMessagePersistence.filterCountByG_C_T_A(
519 groupId, categoryId, threadId, true);
520 }
521
522 public List<MBMessage> getThreadMessages(
523 long groupId, long categoryId, long threadId, int status, int start,
524 int end)
525 throws SystemException {
526
527 if (status == WorkflowConstants.STATUS_ANY) {
528 return mbMessagePersistence.filterFindByG_C_T(
529 groupId, categoryId, threadId, start, end);
530 }
531 else {
532 return mbMessagePersistence.filterFindByG_C_T_S(
533 groupId, categoryId, threadId, status, start, end);
534 }
535 }
536
537 public int getThreadMessagesCount(
538 long groupId, long categoryId, long threadId, int status)
539 throws SystemException {
540
541 if (status == WorkflowConstants.STATUS_ANY) {
542 return mbMessagePersistence.filterCountByG_C_T(
543 groupId, categoryId, threadId);
544 }
545 else {
546 return mbMessagePersistence.filterCountByG_C_T_S(
547 groupId, categoryId, threadId, status);
548 }
549 }
550
551 public String getThreadMessagesRSS(
552 long threadId, int status, int max, String type, double version,
553 String displayStyle, String feedURL, String entryURL,
554 ThemeDisplay themeDisplay)
555 throws PortalException, SystemException {
556
557 String name = StringPool.BLANK;
558 String description = StringPool.BLANK;
559
560 List<MBMessage> messages = new ArrayList<MBMessage>();
561
562 MBThread thread = mbThreadLocalService.getThread(threadId);
563
564 if (MBMessagePermission.contains(
565 getPermissionChecker(), thread.getRootMessageId(),
566 ActionKeys.VIEW)) {
567
568 MessageCreateDateComparator comparator =
569 new MessageCreateDateComparator(false);
570
571 List<MBMessage> threadMessages =
572 mbMessageLocalService.getThreadMessages(
573 threadId, status, comparator);
574
575 for (MBMessage message : threadMessages) {
576 if (messages.size() >= max) {
577 break;
578 }
579
580 if (MBMessagePermission.contains(
581 getPermissionChecker(), message, ActionKeys.VIEW)) {
582
583 messages.add(message);
584 }
585 }
586
587 if (messages.size() > 0) {
588 MBMessage message = messages.get(messages.size() - 1);
589
590 name = message.getSubject();
591 description = message.getSubject();
592 }
593 }
594
595 return exportToRSS(
596 name, description, type, version, displayStyle, feedURL, entryURL,
597 messages, themeDisplay);
598 }
599
600 public void restoreMessageAttachmentFromTrash(
601 long messageId, String fileName)
602 throws PortalException, SystemException {
603
604 MBMessagePermission.check(
605 getPermissionChecker(), messageId, ActionKeys.ADD_FILE);
606
607 mbMessageLocalService.restoreMessageAttachmentFromTrash(
608 getUserId(), messageId, fileName);
609 }
610
611 public void subscribeMessage(long messageId)
612 throws PortalException, SystemException {
613
614 MBMessagePermission.check(
615 getPermissionChecker(), messageId, ActionKeys.SUBSCRIBE);
616
617 mbMessageLocalService.subscribeMessage(getUserId(), messageId);
618 }
619
620 public void unsubscribeMessage(long messageId)
621 throws PortalException, SystemException {
622
623 MBMessagePermission.check(
624 getPermissionChecker(), messageId, ActionKeys.SUBSCRIBE);
625
626 mbMessageLocalService.unsubscribeMessage(getUserId(), messageId);
627 }
628
629 public void updateAnswer(long messageId, boolean answer, boolean cascade)
630 throws PortalException, SystemException {
631
632 mbMessageLocalService.updateAnswer(messageId, answer, cascade);
633 }
634
635 public MBMessage updateDiscussionMessage(
636 String className, long classPK, String permissionClassName,
637 long permissionClassPK, long permissionOwnerId, long messageId,
638 String subject, String body, ServiceContext serviceContext)
639 throws PortalException, SystemException {
640
641 User user = getUser();
642
643 MBDiscussionPermission.check(
644 getPermissionChecker(), user.getCompanyId(),
645 serviceContext.getScopeGroupId(), permissionClassName,
646 permissionClassPK, messageId, permissionOwnerId,
647 ActionKeys.UPDATE_DISCUSSION);
648
649 return mbMessageLocalService.updateDiscussionMessage(
650 getUserId(), messageId, className, classPK, subject, body,
651 serviceContext);
652 }
653
654 public MBMessage updateMessage(
655 long messageId, String subject, String body,
656 List<ObjectValuePair<String, InputStream>> inputStreamOVPs,
657 List<String> existingFiles, double priority, boolean allowPingbacks,
658 ServiceContext serviceContext)
659 throws PortalException, SystemException {
660
661 MBMessage message = mbMessagePersistence.findByPrimaryKey(messageId);
662
663 boolean preview = ParamUtil.getBoolean(serviceContext, "preview");
664
665 if (preview &&
666 MBMessagePermission.contains(
667 getPermissionChecker(), message, ActionKeys.UPDATE)) {
668
669 checkReplyToPermission(
670 message.getGroupId(), message.getCategoryId(),
671 message.getParentMessageId());
672 }
673 else {
674 MBMessagePermission.check(
675 getPermissionChecker(), messageId, ActionKeys.UPDATE);
676 }
677
678 if (lockLocalService.isLocked(
679 MBThread.class.getName(), message.getThreadId())) {
680
681 throw new LockedThreadException();
682 }
683
684 if (!MBCategoryPermission.contains(
685 getPermissionChecker(), message.getGroupId(),
686 message.getCategoryId(), ActionKeys.ADD_FILE)) {
687
688 inputStreamOVPs = Collections.emptyList();
689 }
690
691 if (!MBCategoryPermission.contains(
692 getPermissionChecker(), message.getGroupId(),
693 message.getCategoryId(), ActionKeys.UPDATE_THREAD_PRIORITY)) {
694
695 MBThread thread = mbThreadLocalService.getThread(
696 message.getThreadId());
697
698 priority = thread.getPriority();
699 }
700
701 return mbMessageLocalService.updateMessage(
702 getGuestOrUserId(), messageId, subject, body, inputStreamOVPs,
703 existingFiles, priority, allowPingbacks, serviceContext);
704 }
705
706 protected void checkReplyToPermission(
707 long groupId, long categoryId, long parentMessageId)
708 throws PortalException, SystemException {
709
710 if (parentMessageId > 0) {
711 if (MBCategoryPermission.contains(
712 getPermissionChecker(), groupId, categoryId,
713 ActionKeys.ADD_MESSAGE)) {
714
715 return;
716 }
717
718 if (!MBCategoryPermission.contains(
719 getPermissionChecker(), groupId, categoryId,
720 ActionKeys.REPLY_TO_MESSAGE)) {
721
722 throw new PrincipalException();
723 }
724 }
725 else {
726 MBCategoryPermission.check(
727 getPermissionChecker(), groupId, categoryId,
728 ActionKeys.ADD_MESSAGE);
729 }
730 }
731
732 protected String exportToRSS(
733 String name, String description, String type, double version,
734 String displayStyle, String feedURL, String entryURL,
735 List<MBMessage> messages, ThemeDisplay themeDisplay)
736 throws SystemException {
737
738 SyndFeed syndFeed = new SyndFeedImpl();
739
740 syndFeed.setDescription(description);
741
742 List<SyndEntry> syndEntries = new ArrayList<SyndEntry>();
743
744 syndFeed.setEntries(syndEntries);
745
746 for (MBMessage message : messages) {
747 SyndEntry syndEntry = new SyndEntryImpl();
748
749 if (!message.isAnonymous()) {
750 String author = PortalUtil.getUserName(message);
751
752 syndEntry.setAuthor(author);
753 }
754
755 SyndContent syndContent = new SyndContentImpl();
756
757 syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);
758
759 String value = null;
760
761 if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_ABSTRACT)) {
762 value = StringUtil.shorten(
763 HtmlUtil.extractText(message.getBody()),
764 PropsValues.MESSAGE_BOARDS_RSS_ABSTRACT_LENGTH,
765 StringPool.BLANK);
766 }
767 else if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) {
768 value = StringPool.BLANK;
769 }
770 else if (message.isFormatBBCode()) {
771 value = BBCodeTranslatorUtil.getHTML(message.getBody());
772
773 value = MBUtil.replaceMessageBodyPaths(themeDisplay, value);
774 }
775 else {
776 value = message.getBody();
777 }
778
779 syndContent.setValue(value);
780
781 syndEntry.setDescription(syndContent);
782
783 syndEntry.setLink(
784 entryURL + "&messageId=" + message.getMessageId());
785 syndEntry.setPublishedDate(message.getCreateDate());
786 syndEntry.setTitle(message.getSubject());
787 syndEntry.setUpdatedDate(message.getModifiedDate());
788 syndEntry.setUri(syndEntry.getLink());
789
790 syndEntries.add(syndEntry);
791 }
792
793 syndFeed.setFeedType(RSSUtil.getFeedType(type, version));
794
795 List<SyndLink> syndLinks = new ArrayList<SyndLink>();
796
797 syndFeed.setLinks(syndLinks);
798
799 SyndLink selfSyndLink = new SyndLinkImpl();
800
801 syndLinks.add(selfSyndLink);
802
803 selfSyndLink.setHref(feedURL);
804 selfSyndLink.setRel("self");
805
806 syndFeed.setPublishedDate(new Date());
807 syndFeed.setTitle(name);
808 syndFeed.setUri(feedURL);
809
810 try {
811 return RSSUtil.export(syndFeed);
812 }
813 catch (FeedException fe) {
814 throw new SystemException(fe);
815 }
816 }
817
818 }