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