001    /**
002     * Copyright (c) 2000-2013 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.wiki.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.language.LanguageUtil;
020    import com.liferay.portal.kernel.util.CalendarFactoryUtil;
021    import com.liferay.portal.kernel.util.HtmlUtil;
022    import com.liferay.portal.kernel.util.HttpUtil;
023    import com.liferay.portal.kernel.util.ObjectValuePair;
024    import com.liferay.portal.kernel.util.OrderByComparator;
025    import com.liferay.portal.kernel.util.StringBundler;
026    import com.liferay.portal.kernel.util.StringPool;
027    import com.liferay.portal.kernel.util.StringUtil;
028    import com.liferay.portal.kernel.workflow.WorkflowConstants;
029    import com.liferay.portal.security.permission.ActionKeys;
030    import com.liferay.portal.service.ServiceContext;
031    import com.liferay.portal.util.PortalUtil;
032    import com.liferay.portal.util.PortletKeys;
033    import com.liferay.portal.util.PropsValues;
034    import com.liferay.portlet.wiki.NoSuchPageException;
035    import com.liferay.portlet.wiki.model.WikiNode;
036    import com.liferay.portlet.wiki.model.WikiPage;
037    import com.liferay.portlet.wiki.model.WikiPageConstants;
038    import com.liferay.portlet.wiki.service.base.WikiPageServiceBaseImpl;
039    import com.liferay.portlet.wiki.service.permission.WikiNodePermission;
040    import com.liferay.portlet.wiki.service.permission.WikiPagePermission;
041    import com.liferay.portlet.wiki.util.WikiUtil;
042    import com.liferay.portlet.wiki.util.comparator.PageCreateDateComparator;
043    import com.liferay.util.RSSUtil;
044    
045    import com.sun.syndication.feed.synd.SyndContent;
046    import com.sun.syndication.feed.synd.SyndContentImpl;
047    import com.sun.syndication.feed.synd.SyndEntry;
048    import com.sun.syndication.feed.synd.SyndEntryImpl;
049    import com.sun.syndication.feed.synd.SyndFeed;
050    import com.sun.syndication.feed.synd.SyndFeedImpl;
051    import com.sun.syndication.feed.synd.SyndLink;
052    import com.sun.syndication.feed.synd.SyndLinkImpl;
053    import com.sun.syndication.io.FeedException;
054    
055    import java.io.File;
056    import java.io.InputStream;
057    
058    import java.util.ArrayList;
059    import java.util.Calendar;
060    import java.util.Date;
061    import java.util.List;
062    import java.util.Locale;
063    
064    /**
065     * Provides the remote service for accessing, adding, deleting, moving,
066     * subscription handling of, trash handling of, and updating wiki pages and wiki
067     * page attachments. Its methods include permission checks.
068     *
069     * @author Brian Wing Shun Chan
070     * @author Jorge Ferrer
071     * @author Raymond Augé
072     */
073    public class WikiPageServiceImpl extends WikiPageServiceBaseImpl {
074    
075            public WikiPage addPage(
076                            long nodeId, String title, String content, String summary,
077                            boolean minorEdit, ServiceContext serviceContext)
078                    throws PortalException, SystemException {
079    
080                    WikiNodePermission.check(
081                            getPermissionChecker(), nodeId, ActionKeys.ADD_PAGE);
082    
083                    return wikiPageLocalService.addPage(
084                            getUserId(), nodeId, title, content, summary, minorEdit,
085                            serviceContext);
086            }
087    
088            public WikiPage addPage(
089                            long nodeId, String title, String content, String summary,
090                            boolean minorEdit, String format, String parentTitle,
091                            String redirectTitle, ServiceContext serviceContext)
092                    throws PortalException, SystemException {
093    
094                    WikiNodePermission.check(
095                            getPermissionChecker(), nodeId, ActionKeys.ADD_PAGE);
096    
097                    return wikiPageLocalService.addPage(
098                            getUserId(), nodeId, title, WikiPageConstants.VERSION_DEFAULT,
099                            content, summary, minorEdit, format, true, parentTitle,
100                            redirectTitle, serviceContext);
101            }
102    
103            public void addPageAttachment(
104                            long nodeId, String title, String fileName, File file,
105                            String mimeType)
106                    throws PortalException, SystemException {
107    
108                    WikiNodePermission.check(
109                            getPermissionChecker(), nodeId, ActionKeys.ADD_ATTACHMENT);
110    
111                    wikiPageLocalService.addPageAttachment(
112                            getUserId(), nodeId, title, fileName, file, mimeType);
113            }
114    
115            public void addPageAttachment(
116                            long nodeId, String title, String fileName, InputStream inputStream,
117                            String mimeType)
118                    throws PortalException, SystemException {
119    
120                    WikiNodePermission.check(
121                            getPermissionChecker(), nodeId, ActionKeys.ADD_ATTACHMENT);
122    
123                    wikiPageLocalService.addPageAttachment(
124                            getUserId(), nodeId, title, fileName, inputStream, mimeType);
125            }
126    
127            public void addPageAttachments(
128                            long nodeId, String title,
129                            List<ObjectValuePair<String, InputStream>> inputStreamOVPs)
130                    throws PortalException, SystemException {
131    
132                    WikiNodePermission.check(
133                            getPermissionChecker(), nodeId, ActionKeys.ADD_ATTACHMENT);
134    
135                    wikiPageLocalService.addPageAttachments(
136                            getUserId(), nodeId, title, inputStreamOVPs);
137            }
138    
139            public void addTempPageAttachment(
140                            long nodeId, String fileName, String tempFolderName,
141                            InputStream inputStream, String mimeType)
142                    throws PortalException, SystemException {
143    
144                    WikiNode node = wikiNodeLocalService.getNode(nodeId);
145    
146                    WikiNodePermission.check(
147                            getPermissionChecker(), node, ActionKeys.ADD_ATTACHMENT);
148    
149                    wikiPageLocalService.addTempPageAttachment(
150                            node.getGroupId(), getUserId(), fileName, tempFolderName,
151                            inputStream, mimeType);
152            }
153    
154            public void changeParent(
155                            long nodeId, String title, String newParentTitle,
156                            ServiceContext serviceContext)
157                    throws PortalException, SystemException {
158    
159                    WikiPagePermission.check(
160                            getPermissionChecker(), nodeId, title, ActionKeys.DELETE);
161    
162                    WikiNodePermission.check(
163                            getPermissionChecker(), nodeId, ActionKeys.ADD_PAGE);
164    
165                    wikiPageLocalService.changeParent(
166                            getUserId(), nodeId, title, newParentTitle, serviceContext);
167            }
168    
169            public void deletePage(long nodeId, String title)
170                    throws PortalException, SystemException {
171    
172                    WikiPagePermission.check(
173                            getPermissionChecker(), nodeId, title, ActionKeys.DELETE);
174    
175                    wikiPageLocalService.deletePage(nodeId, title);
176            }
177    
178            /**
179             * @deprecated As of 6.2.0 replaced by {@link #discardDraft(long, String,
180             *             double)}
181             */
182            public void deletePage(long nodeId, String title, double version)
183                    throws PortalException, SystemException {
184    
185                    discardDraft(nodeId, title, version);
186            }
187    
188            public void deletePageAttachment(long nodeId, String title, String fileName)
189                    throws PortalException, SystemException {
190    
191                    WikiPagePermission.check(
192                            getPermissionChecker(), nodeId, title, ActionKeys.DELETE);
193    
194                    wikiPageLocalService.deletePageAttachment(nodeId, title, fileName);
195            }
196    
197            public void deletePageAttachments(long nodeId, String title)
198                    throws PortalException, SystemException {
199    
200                    WikiPagePermission.check(
201                            getPermissionChecker(), nodeId, title, ActionKeys.DELETE);
202    
203                    wikiPageLocalService.deletePageAttachments(nodeId, title);
204            }
205    
206            public void deleteTempPageAttachment(
207                            long nodeId, String fileName, String tempFolderName)
208                    throws PortalException, SystemException {
209    
210                    WikiNode node = wikiNodeLocalService.getNode(nodeId);
211    
212                    WikiNodePermission.check(
213                            getPermissionChecker(), node, ActionKeys.ADD_ATTACHMENT);
214    
215                    wikiPageLocalService.deleteTempPageAttachment(
216                            node.getGroupId(), getUserId(), fileName, tempFolderName);
217            }
218    
219            public void deleteTrashPageAttachments(long nodeId, String title)
220                    throws PortalException, SystemException {
221    
222                    WikiPagePermission.check(
223                            getPermissionChecker(), nodeId, title, ActionKeys.DELETE);
224    
225                    wikiPageLocalService.deleteTrashPageAttachments(nodeId, title);
226            }
227    
228            public void discardDraft(long nodeId, String title, double version)
229                    throws PortalException, SystemException {
230    
231                    WikiPagePermission.check(
232                            getPermissionChecker(), nodeId, title, version, ActionKeys.DELETE);
233    
234                    wikiPageLocalService.discardDraft(nodeId, title, version);
235            }
236    
237            public List<WikiPage> getChildren(
238                            long groupId, long nodeId, boolean head, String parentTitle)
239                    throws PortalException, SystemException {
240    
241                    WikiNodePermission.check(
242                            getPermissionChecker(), nodeId, ActionKeys.VIEW);
243    
244                    return wikiPagePersistence.filterFindByG_N_H_P_S(
245                            groupId, nodeId, head, parentTitle,
246                            WorkflowConstants.STATUS_APPROVED);
247            }
248    
249            public WikiPage getDraftPage(long nodeId, String title)
250                    throws PortalException, SystemException {
251    
252                    WikiPagePermission.check(
253                            getPermissionChecker(), nodeId, title, ActionKeys.VIEW);
254    
255                    return wikiPageLocalService.getDraftPage(nodeId, title);
256            }
257    
258            public List<WikiPage> getNodePages(long nodeId, int max)
259                    throws PortalException, SystemException {
260    
261                    List<WikiPage> pages = new ArrayList<WikiPage>();
262    
263                    int lastIntervalStart = 0;
264                    boolean listNotExhausted = true;
265    
266                    while ((pages.size() < max) && listNotExhausted) {
267                            List<WikiPage> pageList = wikiPageLocalService.getPages(
268                                    nodeId, true, lastIntervalStart, lastIntervalStart + max);
269    
270                            lastIntervalStart += max;
271                            listNotExhausted = (pageList.size() == max);
272    
273                            for (WikiPage page : pageList) {
274                                    if (pages.size() >= max) {
275                                            break;
276                                    }
277    
278                                    if (WikiPagePermission.contains(
279                                                    getPermissionChecker(), page, ActionKeys.VIEW)) {
280    
281                                            pages.add(page);
282                                    }
283                            }
284                    }
285    
286                    return pages;
287            }
288    
289            /**
290             * @deprecated As of 6.2.0, replaced by {@link #getNodePagesRSS(long, int,
291             *             String, double, String, String, String, String)}
292             */
293            public String getNodePagesRSS(
294                            long nodeId, int max, String type, double version,
295                            String displayStyle, String feedURL, String entryURL)
296                    throws PortalException, SystemException {
297    
298                    return getNodePagesRSS(
299                            nodeId, max, type, version, displayStyle, feedURL, entryURL, null);
300            }
301    
302            public String getNodePagesRSS(
303                            long nodeId, int max, String type, double version,
304                            String displayStyle, String feedURL, String entryURL,
305                            String attachmentURLPrefix)
306                    throws PortalException, SystemException {
307    
308                    WikiNodePermission.check(
309                            getPermissionChecker(), nodeId, ActionKeys.VIEW);
310    
311                    WikiNode node = wikiNodePersistence.findByPrimaryKey(nodeId);
312    
313                    List<WikiPage> pages = getNodePages(nodeId, max);
314    
315                    return exportToRSS(
316                            node.getCompanyId(), node.getName(), node.getDescription(), type,
317                            version, displayStyle, feedURL, entryURL, attachmentURLPrefix,
318                            pages, false, null);
319            }
320    
321            public List<WikiPage> getOrphans(long groupId, long nodeId)
322                    throws PortalException, SystemException {
323    
324                    WikiNodePermission.check(
325                            getPermissionChecker(), nodeId, ActionKeys.VIEW);
326    
327                    List<WikiPage> pages = wikiPagePersistence.filterFindByG_N_H_S(
328                            groupId, nodeId, true, WorkflowConstants.STATUS_APPROVED);
329    
330                    return WikiUtil.filterOrphans(pages);
331            }
332    
333            public WikiPage getPage(long groupId, long nodeId, String title)
334                    throws PortalException, SystemException {
335    
336                    List<WikiPage> pages = wikiPagePersistence.filterFindByG_N_T_H(
337                            groupId, nodeId, title, true, 0, 1);
338    
339                    if (!pages.isEmpty()) {
340                            return pages.get(0);
341                    }
342                    else {
343                            throw new NoSuchPageException();
344                    }
345            }
346    
347            public WikiPage getPage(long nodeId, String title)
348                    throws PortalException, SystemException {
349    
350                    WikiPagePermission.check(
351                            getPermissionChecker(), nodeId, title, ActionKeys.VIEW);
352    
353                    return wikiPageLocalService.getPage(nodeId, title);
354            }
355    
356            public WikiPage getPage(long nodeId, String title, Boolean head)
357                    throws PortalException, SystemException {
358    
359                    WikiPagePermission.check(
360                            getPermissionChecker(), nodeId, title, ActionKeys.VIEW);
361    
362                    return wikiPageLocalService.getPage(nodeId, title, head);
363            }
364    
365            public WikiPage getPage(long nodeId, String title, double version)
366                    throws PortalException, SystemException {
367    
368                    WikiPagePermission.check(
369                            getPermissionChecker(), nodeId, title, ActionKeys.VIEW);
370    
371                    return wikiPageLocalService.getPage(nodeId, title, version);
372            }
373    
374            public List<WikiPage> getPages(
375                            long groupId, long nodeId, boolean head, int status, int start,
376                            int end, OrderByComparator obc)
377                    throws PortalException, SystemException {
378    
379                    WikiNodePermission.check(
380                            getPermissionChecker(), nodeId, ActionKeys.VIEW);
381    
382                    if (status == WorkflowConstants.STATUS_ANY) {
383                            return wikiPagePersistence.filterFindByG_N_H(
384                                    groupId, nodeId, head, start, end, obc);
385                    }
386                    else {
387                            return wikiPagePersistence.filterFindByG_N_H_S(
388                                    groupId, nodeId, head, status, start, end, obc);
389                    }
390            }
391    
392            public List<WikiPage> getPages(
393                            long groupId, long userId, long nodeId, int status, int start,
394                            int end)
395                    throws PortalException, SystemException {
396    
397                    WikiNodePermission.check(
398                            getPermissionChecker(), nodeId, ActionKeys.VIEW);
399    
400                    if (userId > 0) {
401                            return wikiPagePersistence.filterFindByG_U_N_S(
402                                    groupId, userId, nodeId, status, start, end,
403                                    new PageCreateDateComparator(false));
404                    }
405                    else {
406                            return wikiPagePersistence.filterFindByG_N_S(
407                                    groupId, nodeId, status, start, end,
408                                    new PageCreateDateComparator(false));
409                    }
410            }
411    
412            public int getPagesCount(long groupId, long nodeId, boolean head)
413                    throws PortalException, SystemException {
414    
415                    WikiNodePermission.check(
416                            getPermissionChecker(), nodeId, ActionKeys.VIEW);
417    
418                    return wikiPagePersistence.filterCountByG_N_H_S(
419                            groupId, nodeId, head, WorkflowConstants.STATUS_APPROVED);
420            }
421    
422            public int getPagesCount(long groupId, long userId, long nodeId, int status)
423                    throws PortalException, SystemException {
424    
425                    WikiNodePermission.check(
426                            getPermissionChecker(), nodeId, ActionKeys.VIEW);
427    
428                    if (userId > 0) {
429                            return wikiPagePersistence.filterCountByG_U_N_S(
430                                    groupId, userId, nodeId, status);
431                    }
432                    else {
433                            return wikiPagePersistence.filterCountByG_N_S(
434                                    groupId, nodeId, status);
435                    }
436            }
437    
438            /**
439             * @deprecated As of 6.2.0, replaced by {@link #getPagesRSS(long, long,
440             *             String, int, String, double, String, String, String, String,
441             *             java.util.Locale)}
442             */
443            public String getPagesRSS(
444                            long companyId, long nodeId, String title, int max, String type,
445                            double version, String displayStyle, String feedURL,
446                            String entryURL, Locale locale)
447                    throws PortalException, SystemException {
448    
449                    return getPagesRSS(
450                            companyId, nodeId, title, max, type, version, displayStyle, feedURL,
451                            entryURL, null, locale);
452            }
453    
454            public String getPagesRSS(
455                            long companyId, long nodeId, String title, int max, String type,
456                            double version, String displayStyle, String feedURL,
457                            String entryURL, String attachmentURLPrefix, Locale locale)
458                    throws PortalException, SystemException {
459    
460                    WikiPagePermission.check(
461                            getPermissionChecker(), nodeId, title, ActionKeys.VIEW);
462    
463                    List<WikiPage> pages = wikiPageLocalService.getPages(
464                            nodeId, title, 0, max, new PageCreateDateComparator(true));
465    
466                    return exportToRSS(
467                            companyId, title, title, type, version, displayStyle, feedURL,
468                            entryURL, attachmentURLPrefix, pages, true, locale);
469            }
470    
471            public List<WikiPage> getRecentChanges(
472                            long groupId, long nodeId, int start, int end)
473                    throws PortalException, SystemException {
474    
475                    WikiNodePermission.check(
476                            getPermissionChecker(), nodeId, ActionKeys.VIEW);
477    
478                    Calendar calendar = CalendarFactoryUtil.getCalendar();
479    
480                    calendar.add(Calendar.WEEK_OF_YEAR, -1);
481    
482                    return wikiPageFinder.filterFindByCreateDate(
483                            groupId, nodeId, calendar.getTime(), false, start, end);
484            }
485    
486            public int getRecentChangesCount(long groupId, long nodeId)
487                    throws PortalException, SystemException {
488    
489                    WikiNodePermission.check(
490                            getPermissionChecker(), nodeId, ActionKeys.VIEW);
491    
492                    Calendar calendar = CalendarFactoryUtil.getCalendar();
493    
494                    calendar.add(Calendar.WEEK_OF_YEAR, -1);
495    
496                    return wikiPageFinder.filterCountByCreateDate(
497                            groupId, nodeId, calendar.getTime(), false);
498            }
499    
500            public String[] getTempPageAttachmentNames(
501                            long nodeId, String tempFolderName)
502                    throws PortalException, SystemException {
503    
504                    WikiNode node = wikiNodeLocalService.getNode(nodeId);
505    
506                    WikiNodePermission.check(
507                            getPermissionChecker(), node, ActionKeys.ADD_ATTACHMENT);
508    
509                    return wikiPageLocalService.getTempPageAttachmentNames(
510                            node.getGroupId(), getUserId(), tempFolderName);
511            }
512    
513            public void movePage(
514                            long nodeId, String title, String newTitle,
515                            ServiceContext serviceContext)
516                    throws PortalException, SystemException {
517    
518                    WikiPagePermission.check(
519                            getPermissionChecker(), nodeId, title, ActionKeys.DELETE);
520    
521                    WikiNodePermission.check(
522                            getPermissionChecker(), nodeId, ActionKeys.ADD_PAGE);
523    
524                    wikiPageLocalService.movePage(
525                            getUserId(), nodeId, title, newTitle, serviceContext);
526            }
527    
528            public long movePageAttachmentToTrash(
529                            long nodeId, String title, String fileName)
530                    throws PortalException, SystemException {
531    
532                    WikiPagePermission.check(
533                            getPermissionChecker(), nodeId, title, ActionKeys.DELETE);
534    
535                    return wikiPageLocalService.movePageAttachmentToTrash(
536                            getUserId(), nodeId, title, fileName);
537            }
538    
539            public void movePageToTrash(long nodeId, String title)
540                    throws PortalException, SystemException {
541    
542                    WikiPagePermission.check(
543                            getPermissionChecker(), nodeId, title, ActionKeys.DELETE);
544    
545                    wikiPageLocalService.movePageToTrash(getUserId(), nodeId, title);
546            }
547    
548            public void movePageToTrash(long nodeId, String title, double version)
549                    throws PortalException, SystemException {
550    
551                    WikiPagePermission.check(
552                            getPermissionChecker(), nodeId, title, version, ActionKeys.DELETE);
553    
554                    wikiPageLocalService.movePageToTrash(
555                            getUserId(), nodeId, title, version);
556            }
557    
558            public void restorePageAttachmentFromTrash(
559                            long nodeId, String title, String fileName)
560                    throws PortalException, SystemException {
561    
562                    WikiNodePermission.check(
563                            getPermissionChecker(), nodeId, ActionKeys.ADD_ATTACHMENT);
564    
565                    wikiPageLocalService.restorePageAttachmentFromTrash(
566                            getUserId(), nodeId, title, fileName);
567            }
568    
569            public void restorePageFromTrash(long resourcePrimKey)
570                    throws PortalException, SystemException {
571    
572                    WikiPage page = wikiPageLocalService.getPage(resourcePrimKey);
573    
574                    WikiPagePermission.check(
575                            getPermissionChecker(), page, ActionKeys.DELETE);
576    
577                    wikiPageLocalService.restorePageFromTrash(getUserId(), page);
578            }
579    
580            public WikiPage revertPage(
581                            long nodeId, String title, double version,
582                            ServiceContext serviceContext)
583                    throws PortalException, SystemException {
584    
585                    WikiPagePermission.check(
586                            getPermissionChecker(), nodeId, title, ActionKeys.UPDATE);
587    
588                    return wikiPageLocalService.revertPage(
589                            getUserId(), nodeId, title, version, serviceContext);
590            }
591    
592            public void subscribePage(long nodeId, String title)
593                    throws PortalException, SystemException {
594    
595                    WikiPagePermission.check(
596                            getPermissionChecker(), nodeId, title, ActionKeys.SUBSCRIBE);
597    
598                    wikiPageLocalService.subscribePage(getUserId(), nodeId, title);
599            }
600    
601            public void unsubscribePage(long nodeId, String title)
602                    throws PortalException, SystemException {
603    
604                    WikiPagePermission.check(
605                            getPermissionChecker(), nodeId, title, ActionKeys.SUBSCRIBE);
606    
607                    wikiPageLocalService.unsubscribePage(getUserId(), nodeId, title);
608            }
609    
610            public WikiPage updatePage(
611                            long nodeId, String title, double version, String content,
612                            String summary, boolean minorEdit, String format,
613                            String parentTitle, String redirectTitle,
614                            ServiceContext serviceContext)
615                    throws PortalException, SystemException {
616    
617                    WikiPagePermission.check(
618                            getPermissionChecker(), nodeId, title, ActionKeys.UPDATE);
619    
620                    return wikiPageLocalService.updatePage(
621                            getUserId(), nodeId, title, version, content, summary, minorEdit,
622                            format, parentTitle, redirectTitle, serviceContext);
623            }
624    
625            protected String exportToRSS(
626                            long companyId, String name, String description, String type,
627                            double version, String displayStyle, String feedURL,
628                            String entryURL, String attachmentURLPrefix, List<WikiPage> pages,
629                            boolean diff, Locale locale)
630                    throws PortalException, SystemException {
631    
632                    SyndFeed syndFeed = new SyndFeedImpl();
633    
634                    syndFeed.setDescription(description);
635    
636                    List<SyndEntry> syndEntries = new ArrayList<SyndEntry>();
637    
638                    syndFeed.setEntries(syndEntries);
639    
640                    WikiPage latestPage = null;
641    
642                    StringBundler sb = new StringBundler(6);
643    
644                    for (WikiPage page : pages) {
645                            SyndEntry syndEntry = new SyndEntryImpl();
646    
647                            String author = PortalUtil.getUserName(page);
648    
649                            syndEntry.setAuthor(author);
650    
651                            SyndContent syndContent = new SyndContentImpl();
652    
653                            syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);
654    
655                            sb.setIndex(0);
656    
657                            sb.append(entryURL);
658    
659                            if (entryURL.endsWith(StringPool.SLASH)) {
660                                    sb.append(HttpUtil.encodeURL(page.getTitle()));
661                            }
662    
663                            if (diff) {
664                                    if ((latestPage != null) || (pages.size() == 1)) {
665                                            sb.append(StringPool.QUESTION);
666                                            sb.append(PortalUtil.getPortletNamespace(PortletKeys.WIKI));
667                                            sb.append("version=");
668                                            sb.append(page.getVersion());
669    
670                                            String value = null;
671    
672                                            if (latestPage == null) {
673                                                    value = WikiUtil.convert(
674                                                            page, null, null, attachmentURLPrefix);
675                                            }
676                                            else {
677                                                    try {
678                                                            value = WikiUtil.diffHtml(
679                                                                    latestPage, page, null, null,
680                                                                    attachmentURLPrefix);
681                                                    }
682                                                    catch (PortalException pe) {
683                                                            throw pe;
684                                                    }
685                                                    catch (SystemException se) {
686                                                            throw se;
687                                                    }
688                                                    catch (Exception e) {
689                                                            throw new SystemException(e);
690                                                    }
691                                            }
692    
693                                            syndContent.setValue(value);
694    
695                                            syndEntry.setDescription(syndContent);
696    
697                                            syndEntries.add(syndEntry);
698                                    }
699                            }
700                            else {
701                                    String value = null;
702    
703                                    if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_ABSTRACT)) {
704                                            value = StringUtil.shorten(
705                                                    HtmlUtil.extractText(page.getContent()),
706                                                    PropsValues.WIKI_RSS_ABSTRACT_LENGTH, StringPool.BLANK);
707                                    }
708                                    else if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) {
709                                            value = StringPool.BLANK;
710                                    }
711                                    else {
712                                            value = WikiUtil.convert(
713                                                    page, null, null, attachmentURLPrefix);
714                                    }
715    
716                                    syndContent.setValue(value);
717    
718                                    syndEntry.setDescription(syndContent);
719    
720                                    syndEntries.add(syndEntry);
721                            }
722    
723                            syndEntry.setLink(sb.toString());
724                            syndEntry.setPublishedDate(page.getCreateDate());
725    
726                            String title =
727                                    page.getTitle() + StringPool.SPACE + page.getVersion();
728    
729                            if (page.isMinorEdit()) {
730                                    title +=
731                                            StringPool.SPACE + StringPool.OPEN_PARENTHESIS +
732                                                    LanguageUtil.get(locale, "minor-edit") +
733                                                            StringPool.CLOSE_PARENTHESIS;
734                            }
735    
736                            syndEntry.setTitle(title);
737    
738                            syndEntry.setUpdatedDate(page.getModifiedDate());
739                            syndEntry.setUri(sb.toString());
740    
741                            latestPage = page;
742                    }
743    
744                    syndFeed.setFeedType(RSSUtil.getFeedType(type, version));
745    
746                    List<SyndLink> syndLinks = new ArrayList<SyndLink>();
747    
748                    syndFeed.setLinks(syndLinks);
749    
750                    SyndLink syndLinkSelf = new SyndLinkImpl();
751    
752                    syndLinks.add(syndLinkSelf);
753    
754                    syndLinkSelf.setHref(feedURL);
755                    syndLinkSelf.setRel("self");
756    
757                    syndFeed.setPublishedDate(new Date());
758                    syndFeed.setTitle(name);
759                    syndFeed.setUri(feedURL);
760    
761                    try {
762                            return RSSUtil.export(syndFeed);
763                    }
764                    catch (FeedException fe) {
765                            throw new SystemException(fe);
766                    }
767            }
768    
769    }