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