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