001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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.GetterUtil;
021    import com.liferay.portal.kernel.util.HtmlUtil;
022    import com.liferay.portal.kernel.util.ObjectValuePair;
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.MBMessageDisplay;
041    import com.liferay.portlet.messageboards.model.MBThread;
042    import com.liferay.portlet.messageboards.model.MBThreadConstants;
043    import com.liferay.portlet.messageboards.service.base.MBMessageServiceBaseImpl;
044    import com.liferay.portlet.messageboards.service.permission.MBCategoryPermission;
045    import com.liferay.portlet.messageboards.service.permission.MBDiscussionPermission;
046    import com.liferay.portlet.messageboards.service.permission.MBMessagePermission;
047    import com.liferay.portlet.messageboards.util.comparator.MessageCreateDateComparator;
048    import com.liferay.util.RSSUtil;
049    
050    import com.sun.syndication.feed.synd.SyndContent;
051    import com.sun.syndication.feed.synd.SyndContentImpl;
052    import com.sun.syndication.feed.synd.SyndEntry;
053    import com.sun.syndication.feed.synd.SyndEntryImpl;
054    import com.sun.syndication.feed.synd.SyndFeed;
055    import com.sun.syndication.feed.synd.SyndFeedImpl;
056    import com.sun.syndication.io.FeedException;
057    
058    import java.io.InputStream;
059    
060    import java.util.ArrayList;
061    import java.util.Collections;
062    import java.util.Iterator;
063    import java.util.List;
064    
065    /**
066     * @author Brian Wing Shun Chan
067     * @author Mika Koivisto
068     * @author Shuyang Zhou
069     */
070    public class MBMessageServiceImpl extends MBMessageServiceBaseImpl {
071    
072            public MBMessage addDiscussionMessage(
073                            long groupId, String className, long classPK,
074                            String permissionClassName, long permissionClassPK,
075                            long permissionOwnerId, long threadId, long parentMessageId,
076                            String subject, String body, ServiceContext serviceContext)
077                    throws PortalException, SystemException {
078    
079                    User user = getGuestOrUser();
080    
081                    MBDiscussionPermission.check(
082                            getPermissionChecker(), user.getCompanyId(),
083                            serviceContext.getScopeGroupId(), permissionClassName,
084                            permissionClassPK, permissionOwnerId, ActionKeys.ADD_DISCUSSION);
085    
086                    return mbMessageLocalService.addDiscussionMessage(
087                            user.getUserId(), null, groupId, className, classPK, threadId,
088                            parentMessageId, subject, body, serviceContext);
089            }
090    
091            public MBMessage addMessage(
092                            long groupId, long categoryId, long threadId, long parentMessageId,
093                            String subject, String body, String format,
094                            List<ObjectValuePair<String, InputStream>> inputStreamOVPs,
095                            boolean anonymous, double priority, boolean allowPingbacks,
096                            ServiceContext serviceContext)
097                    throws PortalException, SystemException {
098    
099                    checkReplyToPermission(groupId, categoryId, parentMessageId);
100    
101                    if (lockLocalService.isLocked(MBThread.class.getName(), threadId)) {
102                            throw new LockedThreadException();
103                    }
104    
105                    if (!MBCategoryPermission.contains(
106                                    getPermissionChecker(), groupId, categoryId,
107                                    ActionKeys.ADD_FILE)) {
108    
109                            inputStreamOVPs = Collections.emptyList();
110                    }
111    
112                    boolean preview = GetterUtil.getBoolean(
113                            serviceContext.getAttribute("preview"));
114    
115                    int workFlowAction = serviceContext.getWorkflowAction();
116    
117                    if ((workFlowAction == WorkflowConstants.STATUS_DRAFT) && !preview) {
118                            MBMessagePermission.check(
119                                    getPermissionChecker(), parentMessageId, ActionKeys.UPDATE);
120                    }
121    
122                    if (!MBCategoryPermission.contains(
123                                    getPermissionChecker(), groupId, categoryId,
124                                    ActionKeys.UPDATE_THREAD_PRIORITY)) {
125    
126                            priority = MBThreadConstants.PRIORITY_NOT_GIVEN;
127                    }
128    
129                    return mbMessageLocalService.addMessage(
130                            getGuestOrUserId(), null, groupId, categoryId, threadId,
131                            parentMessageId, subject, body, format, inputStreamOVPs, anonymous,
132                            priority, allowPingbacks, serviceContext);
133            }
134    
135            public MBMessage addMessage(
136                            long groupId, long categoryId, String subject, String body,
137                            String format,
138                            List<ObjectValuePair<String, InputStream>> inputStreamOVPs,
139                            boolean anonymous, double priority, boolean allowPingbacks,
140                            ServiceContext serviceContext)
141                    throws PortalException, SystemException {
142    
143                    MBCategoryPermission.check(
144                            getPermissionChecker(), groupId, categoryId,
145                            ActionKeys.ADD_MESSAGE);
146    
147                    if (!MBCategoryPermission.contains(
148                                    getPermissionChecker(), groupId, categoryId,
149                                    ActionKeys.ADD_FILE)) {
150    
151                            inputStreamOVPs = Collections.emptyList();
152                    }
153    
154                    if (!MBCategoryPermission.contains(
155                                    getPermissionChecker(), groupId, categoryId,
156                                    ActionKeys.UPDATE_THREAD_PRIORITY)) {
157    
158                            priority = MBThreadConstants.PRIORITY_NOT_GIVEN;
159                    }
160    
161                    return mbMessageLocalService.addMessage(
162                            getGuestOrUserId(), null, groupId, categoryId, subject, body,
163                            format, inputStreamOVPs, anonymous, priority, allowPingbacks,
164                            serviceContext);
165            }
166    
167            public void deleteDiscussionMessage(
168                            long groupId, String className, long classPK,
169                            String permissionClassName, long permissionClassPK,
170                            long permissionOwnerId, long messageId)
171                    throws PortalException, SystemException {
172    
173                    User user = getUser();
174    
175                    MBDiscussionPermission.check(
176                            getPermissionChecker(), user.getCompanyId(), groupId,
177                            permissionClassName, permissionClassPK, messageId,
178                            permissionOwnerId, ActionKeys.DELETE_DISCUSSION);
179    
180                    mbMessageLocalService.deleteDiscussionMessage(messageId);
181            }
182    
183            public void deleteMessage(long messageId)
184                    throws PortalException, SystemException {
185    
186                    MBMessagePermission.check(
187                            getPermissionChecker(), messageId, ActionKeys.DELETE);
188    
189                    mbMessageLocalService.deleteMessage(messageId);
190            }
191    
192            public List<MBMessage> getCategoryMessages(
193                            long groupId, long categoryId, int status, int start, int end)
194                    throws PortalException, SystemException {
195    
196                    List<MBMessage> messages = new ArrayList<MBMessage>();
197    
198                    Iterator<MBMessage> itr = mbMessageLocalService.getCategoryMessages(
199                            groupId, categoryId, status, start, end).iterator();
200    
201                    while (itr.hasNext()) {
202                            MBMessage message = itr.next();
203    
204                            if (MBMessagePermission.contains(
205                                            getPermissionChecker(), message, ActionKeys.VIEW)) {
206    
207                                    messages.add(message);
208                            }
209                    }
210    
211                    return messages;
212            }
213    
214            public int getCategoryMessagesCount(
215                            long groupId, long categoryId, int status)
216                    throws SystemException {
217    
218                    return mbMessageLocalService.getCategoryMessagesCount(
219                            groupId, categoryId, status);
220            }
221    
222            public String getCategoryMessagesRSS(
223                            long groupId, long categoryId, int status, int max, String type,
224                            double version, String displayStyle, String feedURL,
225                            String entryURL, ThemeDisplay themeDisplay)
226                    throws PortalException, SystemException {
227    
228                    String name = StringPool.BLANK;
229                    String description = StringPool.BLANK;
230    
231                    try {
232                            MBCategory category = mbCategoryLocalService.getCategory(
233                                    categoryId);
234    
235                            groupId = category.getGroupId();
236                            name = category.getName();
237                            description = category.getDescription();
238                    }
239                    catch (NoSuchCategoryException nsce) {
240                            Group group = groupLocalService.getGroup(categoryId);
241    
242                            groupId = group.getGroupId();
243                            categoryId = MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID;
244                            name = group.getDescriptiveName();
245                            description = group.getDescription();
246                    }
247    
248                    List<MBMessage> messages = new ArrayList<MBMessage>();
249    
250                    int lastIntervalStart = 0;
251                    boolean listNotExhausted = true;
252                    MessageCreateDateComparator comparator =
253                            new MessageCreateDateComparator(false);
254    
255                    while ((messages.size() < max) && listNotExhausted) {
256                            List<MBMessage> messageList =
257                                    mbMessageLocalService.getCategoryMessages(
258                                            groupId, categoryId, status, lastIntervalStart,
259                                            lastIntervalStart + max, comparator);
260    
261                            Iterator<MBMessage> itr = messageList.iterator();
262    
263                            lastIntervalStart += max;
264                            listNotExhausted = (messageList.size() == max);
265    
266                            while (itr.hasNext() && (messages.size() < max)) {
267                                    MBMessage message = itr.next();
268    
269                                    if (MBMessagePermission.contains(
270                                                    getPermissionChecker(), message, ActionKeys.VIEW)) {
271    
272                                            messages.add(message);
273                                    }
274                            }
275                    }
276    
277                    return exportToRSS(
278                            name, description, type, version, displayStyle, feedURL, entryURL,
279                            messages, themeDisplay);
280            }
281    
282            public String getCompanyMessagesRSS(
283                            long companyId, int status, int max, String type, double version,
284                            String displayStyle, String feedURL, String entryURL,
285                            ThemeDisplay themeDisplay)
286                    throws PortalException, SystemException {
287    
288                    Company company = companyPersistence.findByPrimaryKey(companyId);
289    
290                    String name = company.getName();
291                    String description = company.getName();
292    
293                    List<MBMessage> messages = new ArrayList<MBMessage>();
294    
295                    int lastIntervalStart = 0;
296                    boolean listNotExhausted = true;
297                    MessageCreateDateComparator comparator =
298                            new MessageCreateDateComparator(false);
299    
300                    while ((messages.size() < max) && listNotExhausted) {
301                            List<MBMessage> messageList =
302                                    mbMessageLocalService.getCompanyMessages(
303                                            companyId, status, lastIntervalStart,
304                                            lastIntervalStart + max, comparator);
305    
306                            Iterator<MBMessage> itr = messageList.iterator();
307    
308                            lastIntervalStart += max;
309                            listNotExhausted = (messageList.size() == max);
310    
311                            while (itr.hasNext() && (messages.size() < max)) {
312                                    MBMessage message = itr.next();
313    
314                                    if (MBMessagePermission.contains(
315                                                    getPermissionChecker(), message, ActionKeys.VIEW)) {
316    
317                                            messages.add(message);
318                                    }
319                            }
320                    }
321    
322                    return exportToRSS(
323                            name, description, type, version, displayStyle, feedURL, entryURL,
324                            messages, themeDisplay);
325            }
326    
327            public int getGroupMessagesCount(long groupId, int status)
328                    throws SystemException {
329    
330                    if (status == WorkflowConstants.STATUS_ANY) {
331                            return mbMessagePersistence.filterCountByGroupId(groupId);
332                    }
333                    else {
334                            return mbMessagePersistence.filterCountByG_S(groupId, status);
335                    }
336            }
337    
338            public String getGroupMessagesRSS(
339                            long groupId, int status, int max, String type, double version,
340                            String displayStyle, String feedURL, String entryURL,
341                            ThemeDisplay themeDisplay)
342                    throws PortalException, SystemException {
343    
344                    String name = StringPool.BLANK;
345                    String description = StringPool.BLANK;
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.getGroupMessages(
357                                            groupId, status, lastIntervalStart, lastIntervalStart + max,
358                                            comparator);
359    
360                            Iterator<MBMessage> itr = messageList.iterator();
361    
362                            lastIntervalStart += max;
363                            listNotExhausted = (messageList.size() == max);
364    
365                            while (itr.hasNext() && (messages.size() < max)) {
366                                    MBMessage message = itr.next();
367    
368                                    if (MBMessagePermission.contains(
369                                                    getPermissionChecker(), message, ActionKeys.VIEW)) {
370    
371                                            messages.add(message);
372                                    }
373                            }
374                    }
375    
376                    if (messages.size() > 0) {
377                            MBMessage message = messages.get(messages.size() - 1);
378    
379                            name = message.getSubject();
380                            description = message.getSubject();
381                    }
382    
383                    return exportToRSS(
384                            name, description, type, version, displayStyle, feedURL, entryURL,
385                            messages, themeDisplay);
386            }
387    
388            public String getGroupMessagesRSS(
389                            long groupId, long userId, int status, int max, String type,
390                            double version, String displayStyle, String feedURL,
391                            String entryURL, ThemeDisplay themeDisplay)
392                    throws PortalException, SystemException {
393    
394                    String name = StringPool.BLANK;
395                    String description = StringPool.BLANK;
396    
397                    List<MBMessage> messages = new ArrayList<MBMessage>();
398    
399                    int lastIntervalStart = 0;
400                    boolean listNotExhausted = true;
401                    MessageCreateDateComparator comparator =
402                            new MessageCreateDateComparator(false);
403    
404                    while ((messages.size() < max) && listNotExhausted) {
405                            List<MBMessage> messageList =
406                                    mbMessageLocalService.getGroupMessages(
407                                            groupId, userId, status, lastIntervalStart,
408                                            lastIntervalStart + max, comparator);
409    
410                            Iterator<MBMessage> itr = messageList.iterator();
411    
412                            lastIntervalStart += max;
413                            listNotExhausted = (messageList.size() == max);
414    
415                            while (itr.hasNext() && (messages.size() < max)) {
416                                    MBMessage message = itr.next();
417    
418                                    if (MBMessagePermission.contains(
419                                                    getPermissionChecker(), message, ActionKeys.VIEW)) {
420    
421                                            messages.add(message);
422                                    }
423                            }
424                    }
425    
426                    if (messages.size() > 0) {
427                            MBMessage message = messages.get(messages.size() - 1);
428    
429                            name = message.getSubject();
430                            description = message.getSubject();
431                    }
432    
433                    return exportToRSS(
434                            name, description, type, version, displayStyle, feedURL, entryURL,
435                            messages, themeDisplay);
436            }
437    
438            public MBMessage getMessage(long messageId)
439                    throws PortalException, SystemException {
440    
441                    MBMessagePermission.check(
442                            getPermissionChecker(), messageId, ActionKeys.VIEW);
443    
444                    return mbMessageLocalService.getMessage(messageId);
445            }
446    
447            public MBMessageDisplay getMessageDisplay(
448                            long messageId, int status, String threadView,
449                            boolean includePrevAndNext)
450                    throws PortalException, SystemException {
451    
452                    MBMessagePermission.check(
453                            getPermissionChecker(), messageId, ActionKeys.VIEW);
454    
455                    return mbMessageLocalService.getMessageDisplay(
456                            getGuestOrUserId(), messageId, status, threadView,
457                            includePrevAndNext);
458            }
459    
460            public int getThreadAnswersCount(
461                            long groupId, long categoryId, long threadId)
462                    throws SystemException {
463    
464                    return mbMessagePersistence.filterCountByG_C_T_A(
465                            groupId, categoryId, threadId, true);
466            }
467    
468            public List<MBMessage> getThreadMessages(
469                            long groupId, long categoryId, long threadId, int status, int start,
470                            int end)
471                    throws SystemException {
472    
473                    if (status == WorkflowConstants.STATUS_ANY) {
474                            return mbMessagePersistence.filterFindByG_C_T(
475                                    groupId, categoryId, threadId, start, end);
476                    }
477                    else {
478                            return mbMessagePersistence.filterFindByG_C_T_S(
479                                    groupId, categoryId, threadId, status, start, end);
480                    }
481            }
482    
483            public int getThreadMessagesCount(
484                            long groupId, long categoryId, long threadId, int status)
485                    throws SystemException {
486    
487                    if (status == WorkflowConstants.STATUS_ANY) {
488                            return mbMessagePersistence.filterCountByG_C_T(
489                                    groupId, categoryId, threadId);
490                    }
491                    else {
492                            return mbMessagePersistence.filterCountByG_C_T_S(
493                                    groupId, categoryId, threadId, status);
494                    }
495            }
496    
497            public String getThreadMessagesRSS(
498                            long threadId, int status, int max, String type, double version,
499                            String displayStyle, String feedURL, String entryURL,
500                            ThemeDisplay themeDisplay)
501                    throws PortalException, SystemException {
502    
503                    String name = StringPool.BLANK;
504                    String description = StringPool.BLANK;
505    
506                    List<MBMessage> messages = new ArrayList<MBMessage>();
507    
508                    MBThread thread = mbThreadLocalService.getThread(threadId);
509    
510                    if (MBMessagePermission.contains(
511                                    getPermissionChecker(), thread.getRootMessageId(),
512                                    ActionKeys.VIEW)) {
513    
514                            MessageCreateDateComparator comparator =
515                                    new MessageCreateDateComparator(false);
516    
517                            Iterator<MBMessage> itr = mbMessageLocalService.getThreadMessages(
518                                    threadId, status, comparator).iterator();
519    
520                            while (itr.hasNext() && (messages.size() < max)) {
521                                    MBMessage message = itr.next();
522    
523                                    if (MBMessagePermission.contains(
524                                                    getPermissionChecker(), message, ActionKeys.VIEW)) {
525    
526                                            messages.add(message);
527                                    }
528                            }
529    
530                            if (messages.size() > 0) {
531                                    MBMessage message = messages.get(messages.size() - 1);
532    
533                                    name = message.getSubject();
534                                    description = message.getSubject();
535                            }
536                    }
537    
538                    return exportToRSS(
539                            name, description, type, version, displayStyle, feedURL, entryURL,
540                            messages, themeDisplay);
541            }
542    
543            public void subscribeMessage(long messageId)
544                    throws PortalException, SystemException {
545    
546                    MBMessagePermission.check(
547                            getPermissionChecker(), messageId, ActionKeys.SUBSCRIBE);
548    
549                    mbMessageLocalService.subscribeMessage(getUserId(), messageId);
550            }
551    
552            public void unsubscribeMessage(long messageId)
553                    throws PortalException, SystemException {
554    
555                    MBMessagePermission.check(
556                            getPermissionChecker(), messageId, ActionKeys.SUBSCRIBE);
557    
558                    mbMessageLocalService.unsubscribeMessage(getUserId(), messageId);
559            }
560    
561            public void updateAnswer(long messageId, boolean answer, boolean cascade)
562                    throws PortalException, SystemException {
563    
564                    mbMessageLocalService.updateAnswer(messageId, answer, cascade);
565            }
566    
567            public MBMessage updateDiscussionMessage(
568                            String className, long classPK, String permissionClassName,
569                            long permissionClassPK, long permissionOwnerId, long messageId,
570                            String subject, String body, ServiceContext serviceContext)
571                    throws PortalException, SystemException {
572    
573                    User user = getUser();
574    
575                    MBDiscussionPermission.check(
576                            getPermissionChecker(), user.getCompanyId(),
577                            serviceContext.getScopeGroupId(), permissionClassName,
578                            permissionClassPK, messageId, permissionOwnerId,
579                            ActionKeys.UPDATE_DISCUSSION);
580    
581                    return mbMessageLocalService.updateDiscussionMessage(
582                            getUserId(), messageId, className, classPK, subject, body,
583                            serviceContext);
584            }
585    
586            public MBMessage updateMessage(
587                            long messageId, String subject, String body,
588                            List<ObjectValuePair<String, InputStream>> inputStreamOVPs,
589                            List<String> existingFiles, double priority, boolean allowPingbacks,
590                            ServiceContext serviceContext)
591                    throws PortalException, SystemException {
592    
593                    MBMessage message = mbMessageLocalService.getMessage(messageId);
594    
595                    boolean preview = GetterUtil.getBoolean(
596                            serviceContext.getAttribute("preview"));
597    
598                    if (preview) {
599                            checkReplyToPermission(
600                                    message.getGroupId(), message.getCategoryId(),
601                                    message.getParentMessageId());
602                    }
603                    else {
604                            MBMessagePermission.check(
605                                    getPermissionChecker(), messageId, ActionKeys.UPDATE);
606                    }
607    
608                    if (lockLocalService.isLocked(
609                                    MBThread.class.getName(), message.getThreadId())) {
610    
611                            throw new LockedThreadException();
612                    }
613    
614                    if (!MBCategoryPermission.contains(
615                                    getPermissionChecker(), message.getGroupId(),
616                                    message.getCategoryId(), ActionKeys.ADD_FILE)) {
617    
618                            inputStreamOVPs = Collections.emptyList();
619                    }
620    
621                    if (!MBCategoryPermission.contains(
622                                    getPermissionChecker(), message.getGroupId(),
623                                    message.getCategoryId(), ActionKeys.UPDATE_THREAD_PRIORITY)) {
624    
625                            MBThread thread = mbThreadLocalService.getThread(
626                                    message.getThreadId());
627    
628                            priority = thread.getPriority();
629                    }
630    
631                    return mbMessageLocalService.updateMessage(
632                            getGuestOrUserId(), messageId, subject, body, inputStreamOVPs,
633                            existingFiles, priority, allowPingbacks, serviceContext);
634            }
635    
636            protected void checkReplyToPermission(
637                            long groupId, long categoryId, long parentMessageId)
638                    throws PortalException, SystemException {
639    
640                    if (parentMessageId > 0) {
641                            if (MBCategoryPermission.contains(
642                                            getPermissionChecker(), groupId, categoryId,
643                                            ActionKeys.ADD_MESSAGE)) {
644    
645                                    return;
646                            }
647    
648                            MBMessage parentMessage = mbMessagePersistence.fetchByPrimaryKey(
649                                    parentMessageId);
650    
651                            if ((parentMessage == null) ||
652                                    !MBCategoryPermission.contains(
653                                            getPermissionChecker(), groupId, categoryId,
654                                            ActionKeys.REPLY_TO_MESSAGE)) {
655    
656                                    throw new PrincipalException();
657                            }
658                    }
659                    else {
660                            MBCategoryPermission.check(
661                                    getPermissionChecker(), groupId, categoryId,
662                                    ActionKeys.ADD_MESSAGE);
663                    }
664            }
665    
666            protected String exportToRSS(
667                            String name, String description, String type, double version,
668                            String displayStyle, String feedURL, String entryURL,
669                            List<MBMessage> messages, ThemeDisplay themeDisplay)
670                    throws SystemException {
671    
672                    SyndFeed syndFeed = new SyndFeedImpl();
673    
674                    syndFeed.setFeedType(RSSUtil.getFeedType(type, version));
675                    syndFeed.setTitle(name);
676                    syndFeed.setLink(feedURL);
677                    syndFeed.setDescription(description);
678    
679                    List<SyndEntry> syndEntries = new ArrayList<SyndEntry>();
680    
681                    syndFeed.setEntries(syndEntries);
682    
683                    Iterator<MBMessage> itr = messages.iterator();
684    
685                    while (itr.hasNext()) {
686                            MBMessage message = itr.next();
687    
688                            String author = HtmlUtil.escape(
689                                    PortalUtil.getUserName(
690                                            message.getUserId(), message.getUserName()));
691    
692                            String value = null;
693    
694                            if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_ABSTRACT)) {
695                                    value = StringUtil.shorten(
696                                            HtmlUtil.extractText(message.getBody()),
697                                            PropsValues.MESSAGE_BOARDS_RSS_ABSTRACT_LENGTH,
698                                            StringPool.BLANK);
699                            }
700                            else if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) {
701                                    value = StringPool.BLANK;
702                            }
703                            else {
704                                    value = BBCodeTranslatorUtil.getHTML(message.getBody());
705    
706                                    value = StringUtil.replace(
707                                            value,
708                                            new String[] {
709                                                    "@theme_images_path@",
710                                                    "href=\"/",
711                                                    "src=\"/"
712                                            },
713                                            new String[] {
714                                                    themeDisplay.getURLPortal() +
715                                                            themeDisplay.getPathThemeImages(),
716                                                    "href=\"" + themeDisplay.getURLPortal() + "/",
717                                                    "src=\"" + themeDisplay.getURLPortal() + "/"
718                                            });
719                            }
720    
721                            SyndEntry syndEntry = new SyndEntryImpl();
722    
723                            if (!message.isAnonymous()) {
724                                    syndEntry.setAuthor(author);
725                            }
726    
727                            syndEntry.setTitle(message.getSubject());
728                            syndEntry.setLink(
729                                    entryURL + "&messageId=" + message.getMessageId());
730                            syndEntry.setUri(syndEntry.getLink());
731                            syndEntry.setPublishedDate(message.getCreateDate());
732                            syndEntry.setUpdatedDate(message.getModifiedDate());
733    
734                            SyndContent syndContent = new SyndContentImpl();
735    
736                            syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);
737                            syndContent.setValue(value);
738    
739                            syndEntry.setDescription(syndContent);
740    
741                            syndEntries.add(syndEntry);
742                    }
743    
744                    try {
745                            return RSSUtil.export(syndFeed);
746                    }
747                    catch (FeedException fe) {
748                            throw new SystemException(fe);
749                    }
750            }
751    
752    }