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