1
14
15 package com.liferay.portlet.messageboards.lar;
16
17 import com.liferay.documentlibrary.service.DLServiceUtil;
18 import com.liferay.portal.PortalException;
19 import com.liferay.portal.SystemException;
20 import com.liferay.portal.kernel.log.Log;
21 import com.liferay.portal.kernel.log.LogFactoryUtil;
22 import com.liferay.portal.kernel.util.MapUtil;
23 import com.liferay.portal.kernel.util.ObjectValuePair;
24 import com.liferay.portal.kernel.util.StringBundler;
25 import com.liferay.portal.kernel.util.StringPool;
26 import com.liferay.portal.kernel.xml.Document;
27 import com.liferay.portal.kernel.xml.Element;
28 import com.liferay.portal.kernel.xml.SAXReaderUtil;
29 import com.liferay.portal.lar.BasePortletDataHandler;
30 import com.liferay.portal.lar.PortletDataContext;
31 import com.liferay.portal.lar.PortletDataException;
32 import com.liferay.portal.lar.PortletDataHandlerBoolean;
33 import com.liferay.portal.lar.PortletDataHandlerControl;
34 import com.liferay.portal.lar.PortletDataHandlerKeys;
35 import com.liferay.portal.model.CompanyConstants;
36 import com.liferay.portal.model.User;
37 import com.liferay.portal.service.ServiceContext;
38 import com.liferay.portal.service.persistence.UserUtil;
39 import com.liferay.portal.util.PortletKeys;
40 import com.liferay.portlet.messageboards.NoSuchCategoryException;
41 import com.liferay.portlet.messageboards.NoSuchMessageException;
42 import com.liferay.portlet.messageboards.NoSuchThreadException;
43 import com.liferay.portlet.messageboards.model.MBBan;
44 import com.liferay.portlet.messageboards.model.MBCategory;
45 import com.liferay.portlet.messageboards.model.MBMessage;
46 import com.liferay.portlet.messageboards.model.MBMessageFlag;
47 import com.liferay.portlet.messageboards.model.MBThread;
48 import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
49 import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
50 import com.liferay.portlet.messageboards.service.MBBanLocalServiceUtil;
51 import com.liferay.portlet.messageboards.service.MBCategoryLocalServiceUtil;
52 import com.liferay.portlet.messageboards.service.MBMessageFlagLocalServiceUtil;
53 import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
54 import com.liferay.portlet.messageboards.service.persistence.MBBanUtil;
55 import com.liferay.portlet.messageboards.service.persistence.MBCategoryUtil;
56 import com.liferay.portlet.messageboards.service.persistence.MBMessageFlagUtil;
57 import com.liferay.portlet.messageboards.service.persistence.MBMessageUtil;
58 import com.liferay.portlet.messageboards.service.persistence.MBThreadUtil;
59
60 import java.util.ArrayList;
61 import java.util.Iterator;
62 import java.util.List;
63 import java.util.Map;
64
65 import javax.portlet.PortletPreferences;
66
67
73 public class MBPortletDataHandlerImpl extends BasePortletDataHandler {
74
75 public PortletPreferences deleteData(
76 PortletDataContext context, String portletId,
77 PortletPreferences preferences)
78 throws PortletDataException {
79
80 try {
81 if (!context.addPrimaryKey(
82 MBPortletDataHandlerImpl.class, "deleteData")) {
83
84 MBCategoryLocalServiceUtil.deleteCategories(
85 context.getGroupId());
86 }
87
88 return null;
89 }
90 catch (Exception e) {
91 throw new PortletDataException(e);
92 }
93 }
94
95 public String exportData(
96 PortletDataContext context, String portletId,
97 PortletPreferences preferences)
98 throws PortletDataException {
99
100 try {
101 context.addPermissions(
102 "com.liferay.portlet.messageboards", context.getGroupId());
103
104 Document doc = SAXReaderUtil.createDocument();
105
106 Element root = doc.addElement("message-boards-data");
107
108 root.addAttribute("group-id", String.valueOf(context.getGroupId()));
109
110 Element categoriesEl = root.addElement("categories");
111 Element messagesEl = root.addElement("messages");
112 Element messageFlagsEl = root.addElement("message-flags");
113 Element userBansEl = root.addElement("user-bans");
114
115 List<MBCategory> categories = MBCategoryUtil.findByGroupId(
116 context.getGroupId());
117
118 for (MBCategory category : categories) {
119 exportCategory(
120 context, categoriesEl, messagesEl, messageFlagsEl,
121 category);
122 }
123
124 if (context.getBooleanParameter(_NAMESPACE, "user-bans")) {
125 List<MBBan> bans = MBBanUtil.findByGroupId(
126 context.getGroupId());
127
128 for (MBBan ban : bans) {
129 exportUserBan(context, userBansEl, ban);
130 }
131 }
132
133 return doc.formattedString();
134 }
135 catch (Exception e) {
136 throw new PortletDataException(e);
137 }
138 }
139
140 public PortletDataHandlerControl[] getExportControls() {
141 return new PortletDataHandlerControl[] {
142 _categoriesAndMessages, _attachments, _userBans, _flags, _ratings,
143 _tags
144 };
145 }
146
147 public PortletDataHandlerControl[] getImportControls() {
148 return new PortletDataHandlerControl[] {
149 _categoriesAndMessages, _attachments, _userBans, _flags, _ratings,
150 _tags
151 };
152 }
153
154 public PortletPreferences importData(
155 PortletDataContext context, String portletId,
156 PortletPreferences preferences, String data)
157 throws PortletDataException {
158
159 try {
160 context.importPermissions(
161 "com.liferay.portlet.messageboards", context.getSourceGroupId(),
162 context.getGroupId());
163
164 Document doc = SAXReaderUtil.read(data);
165
166 Element root = doc.getRootElement();
167
168 List<Element> categoryEls = root.element("categories").elements(
169 "category");
170
171 Map<Long, Long> categoryPKs =
172 (Map<Long, Long>)context.getNewPrimaryKeysMap(MBCategory.class);
173
174 for (Element categoryEl : categoryEls) {
175 String path = categoryEl.attributeValue("path");
176
177 if (!context.isPathNotProcessed(path)) {
178 continue;
179 }
180
181 MBCategory category = (MBCategory)context.getZipEntryAsObject(
182 path);
183
184 importCategory(context, categoryPKs, category);
185 }
186
187 List<Element> messageEls = root.element("messages").elements(
188 "message");
189
190 Map<Long, Long> threadPKs =
191 (Map<Long, Long>)context.getNewPrimaryKeysMap(MBThread.class);
192 Map<Long, Long> messagePKs =
193 (Map<Long, Long>)context.getNewPrimaryKeysMap(MBMessage.class);
194
195 for (Element messageEl : messageEls) {
196 String path = messageEl.attributeValue("path");
197
198 if (!context.isPathNotProcessed(path)) {
199 continue;
200 }
201
202 MBMessage message = (MBMessage)context.getZipEntryAsObject(
203 path);
204
205 importMessage(
206 context, categoryPKs, threadPKs, messagePKs, messageEl,
207 message);
208 }
209
210 if (context.getBooleanParameter(_NAMESPACE, "flags")) {
211 List<Element> flagEls = root.element("message-flags").elements(
212 "flag");
213
214 for (Element flagEl : flagEls) {
215 String path = flagEl.attributeValue("path");
216
217 if (!context.isPathNotProcessed(path)) {
218 continue;
219 }
220
221 MBMessageFlag flag =
222 (MBMessageFlag)context.getZipEntryAsObject(path);
223
224 importFlag(context, messagePKs, flag);
225 }
226 }
227
228 if (context.getBooleanParameter(_NAMESPACE, "user-bans")) {
229 List<Element> banEls = root.element("user-bans").elements(
230 "user-ban");
231
232 for (Element banEl : banEls) {
233 String path = banEl.attributeValue("path");
234
235 if (!context.isPathNotProcessed(path)) {
236 continue;
237 }
238
239 MBBan ban = (MBBan)context.getZipEntryAsObject(path);
240
241 importBan(context, ban);
242 }
243 }
244
245 return null;
246 }
247 catch (Exception e) {
248 throw new PortletDataException(e);
249 }
250 }
251
252 protected void exportCategory(
253 PortletDataContext context, Element categoriesEl,
254 Element messagesEl, Element messageFlagsEl, MBCategory category)
255 throws PortalException, SystemException {
256
257 if (context.isWithinDateRange(category.getModifiedDate())) {
258 exportParentCategory(
259 context, categoriesEl, category.getParentCategoryId());
260
261 String path = getCategoryPath(context, category);
262
263 if (context.isPathNotProcessed(path)) {
264 Element categoryEl = categoriesEl.addElement("category");
265
266 categoryEl.addAttribute("path", path);
267
268 category.setUserUuid(category.getUserUuid());
269
270 context.addPermissions(
271 MBCategory.class, category.getCategoryId());
272
273 context.addZipEntry(path, category);
274 }
275 }
276
277 List<MBMessage> messages = MBMessageUtil.findByCategoryId(
278 category.getCategoryId());
279
280 for (MBMessage message : messages) {
281 exportMessage(
282 context, categoriesEl, messagesEl, messageFlagsEl, message);
283 }
284 }
285
286 protected void exportMessage(
287 PortletDataContext context, Element categoriesEl,
288 Element messagesEl, Element messageFlagsEl, MBMessage message)
289 throws PortalException, SystemException {
290
291 if (!context.isWithinDateRange(message.getModifiedDate())) {
292 return;
293 }
294
295 exportParentCategory(context, categoriesEl, message.getCategoryId());
296
297 String path = getMessagePath(context, message);
298
299 if (context.isPathNotProcessed(path)) {
300 Element messageEl = messagesEl.addElement("message");
301
302 messageEl.addAttribute("path", path);
303
304 message.setUserUuid(message.getUserUuid());
305 message.setPriority(message.getPriority());
306
307 context.addPermissions(MBMessage.class, message.getMessageId());
308
309 if (context.getBooleanParameter(_NAMESPACE, "ratings")) {
310 context.addRatingsEntries(
311 MBMessage.class, message.getMessageId());
312 }
313
314 if (context.getBooleanParameter(_NAMESPACE, "tags")) {
315 context.addTagsEntries(
316 MBMessage.class, message.getMessageId());
317 }
318
319 if (context.getBooleanParameter(_NAMESPACE, "attachments") &&
320 message.isAttachments()) {
321
322 for (String attachment : message.getAttachmentsFiles()) {
323 int pos = attachment.lastIndexOf(StringPool.FORWARD_SLASH);
324
325 String name = attachment.substring(pos + 1);
326 String binPath = getMessageAttachementBinPath(
327 context, message, name);
328
329 Element attachmentEl = messageEl.addElement("attachment");
330
331 attachmentEl.addAttribute("name", name);
332 attachmentEl.addAttribute("bin-path", binPath);
333
334 byte[] bytes = DLServiceUtil.getFile(
335 context.getCompanyId(), CompanyConstants.SYSTEM,
336 attachment);
337
338 context.addZipEntry(binPath, bytes);
339 }
340
341 message.setAttachmentsDir(message.getAttachmentsDir());
342 }
343
344 if (context.getBooleanParameter(_NAMESPACE, "flags")) {
345 List<MBMessageFlag> messageFlags =
346 MBMessageFlagUtil.findByMessageId(
347 message.getMessageId());
348
349 for (MBMessageFlag messageFlag : messageFlags) {
350 exportMessageFlag(context, messageFlagsEl, messageFlag);
351 }
352 }
353
354 context.addZipEntry(path, message);
355 }
356 }
357
358 protected void exportMessageFlag(
359 PortletDataContext context, Element messageFlagsEl,
360 MBMessageFlag messageFlag)
361 throws SystemException {
362
363 String path = getMessageFlagPath(context, messageFlag);
364
365 if (!context.isPathNotProcessed(path)) {
366 return;
367 }
368
369 Element messageFlagEl = messageFlagsEl.addElement("message-flag");
370
371 messageFlagEl.addAttribute("path", path);
372
373 messageFlag.setUserUuid(messageFlag.getUserUuid());
374
375 context.addZipEntry(path, messageFlag);
376 }
377
378 protected void exportParentCategory(
379 PortletDataContext context, Element categoriesEl, long categoryId)
380 throws PortalException, SystemException {
381
382 if ((!context.hasDateRange()) ||
383 (categoryId == MBCategoryImpl.DEFAULT_PARENT_CATEGORY_ID)) {
384
385 return;
386 }
387
388 MBCategory category = MBCategoryUtil.findByPrimaryKey(categoryId);
389
390 exportParentCategory(
391 context, categoriesEl, category.getParentCategoryId());
392
393 String path = getCategoryPath(context, category);
394
395 if (context.isPathNotProcessed(path)) {
396 Element categoryEl = categoriesEl.addElement("category");
397
398 categoryEl.addAttribute("path", path);
399
400 category.setUserUuid(category.getUserUuid());
401
402 context.addPermissions(MBCategory.class, category.getCategoryId());
403
404 context.addZipEntry(path, category);
405 }
406 }
407
408 protected void exportUserBan(
409 PortletDataContext context, Element userBansEl, MBBan ban)
410 throws SystemException {
411
412 if (!context.isWithinDateRange(ban.getModifiedDate())) {
413 return;
414 }
415
416 String path = getUserBanPath(context, ban);
417
418 if (!context.isPathNotProcessed(path)) {
419 return;
420 }
421
422 Element userBanEl = userBansEl.addElement("user-ban");
423
424 userBanEl.addAttribute("path", path);
425
426 ban.setBanUserUuid(ban.getBanUserUuid());
427 ban.setUserUuid(ban.getUserUuid());
428
429 context.addZipEntry(path, ban);
430 }
431
432 protected void importBan(PortletDataContext context, MBBan ban)
433 throws Exception {
434
435 long userId = context.getUserId(ban.getUserUuid());
436
437 ServiceContext serviceContext = new ServiceContext();
438
439 serviceContext.setScopeGroupId(context.getGroupId());
440
441 List<User> users = UserUtil.findByUuid(ban.getBanUserUuid());
442
443 Iterator<User> itr = users.iterator();
444
445 if (itr.hasNext()) {
446 User user = itr.next();
447
448 MBBanLocalServiceUtil.addBan(
449 userId, user.getUserId(), serviceContext);
450 }
451 else {
452 _log.error(
453 "Could not find banned user with uuid " + ban.getBanUserUuid());
454 }
455 }
456
457 protected void importCategory(
458 PortletDataContext context, Map<Long, Long> categoryPKs,
459 MBCategory category)
460 throws Exception {
461
462 long userId = context.getUserId(category.getUserUuid());
463 long parentCategoryId = MapUtil.getLong(
464 categoryPKs, category.getParentCategoryId(),
465 category.getParentCategoryId());
466
467 String emailAddress = null;
468 String inProtocol = null;
469 String inServerName = null;
470 int inServerPort = 0;
471 boolean inUseSSL = false;
472 String inUserName = null;
473 String inPassword = null;
474 int inReadInterval = 0;
475 String outEmailAddress = null;
476 boolean outCustom = false;
477 String outServerName = null;
478 int outServerPort = 0;
479 boolean outUseSSL = false;
480 String outUserName = null;
481 String outPassword = null;
482 boolean mailingListActive = false;
483
484 ServiceContext serviceContext = new ServiceContext();
485
486 serviceContext.setAddCommunityPermissions(true);
487 serviceContext.setAddGuestPermissions(true);
488 serviceContext.setScopeGroupId(context.getGroupId());
489
490 if ((parentCategoryId != MBCategoryImpl.DEFAULT_PARENT_CATEGORY_ID) &&
491 (parentCategoryId == category.getParentCategoryId())) {
492
493 String path = getImportCategoryPath(context, parentCategoryId);
494
495 MBCategory parentCategory =
496 (MBCategory)context.getZipEntryAsObject(path);
497
498 importCategory(context, categoryPKs, parentCategory);
499
500 parentCategoryId = MapUtil.getLong(
501 categoryPKs, category.getParentCategoryId(),
502 category.getParentCategoryId());
503 }
504
505 MBCategory existingCategory = null;
506
507 try {
508 if (parentCategoryId != MBCategoryImpl.DEFAULT_PARENT_CATEGORY_ID) {
509 MBCategoryUtil.findByPrimaryKey(parentCategoryId);
510 }
511
512 if (context.getDataStrategy().equals(
513 PortletDataHandlerKeys.DATA_STRATEGY_MIRROR)) {
514
515 existingCategory = MBCategoryUtil.fetchByUUID_G(
516 category.getUuid(), context.getGroupId());
517
518 if (existingCategory == null) {
519 existingCategory = MBCategoryLocalServiceUtil.addCategory(
520 category.getUuid(), userId, parentCategoryId,
521 category.getName(), category.getDescription(),
522 emailAddress, inProtocol, inServerName, inServerPort,
523 inUseSSL, inUserName, inPassword, inReadInterval,
524 outEmailAddress, outCustom, outServerName,
525 outServerPort, outUseSSL, outUserName, outPassword,
526 mailingListActive, serviceContext);
527 }
528 else {
529 existingCategory =
530 MBCategoryLocalServiceUtil.updateCategory(
531 existingCategory.getCategoryId(), parentCategoryId,
532 category.getName(), category.getDescription(),
533 emailAddress, inProtocol, inServerName,
534 inServerPort, inUseSSL, inUserName, inPassword,
535 inReadInterval, outEmailAddress, outCustom,
536 outServerName, outServerPort, outUseSSL,
537 outUserName, outPassword, mailingListActive, false);
538 }
539 }
540 else {
541 existingCategory = MBCategoryLocalServiceUtil.addCategory(
542 userId, parentCategoryId, category.getName(),
543 category.getDescription(), emailAddress, inProtocol,
544 inServerName, inServerPort, inUseSSL, inUserName,
545 inPassword, inReadInterval, outEmailAddress, outCustom,
546 outServerName, outServerPort, outUseSSL, outUserName,
547 outPassword, mailingListActive, serviceContext);
548 }
549
550 categoryPKs.put(
551 category.getCategoryId(), existingCategory.getCategoryId());
552
553 context.importPermissions(
554 MBCategory.class, category.getCategoryId(),
555 existingCategory.getCategoryId());
556 }
557 catch (NoSuchCategoryException nsce) {
558 _log.error(
559 "Could not find the parent category for category " +
560 category.getCategoryId());
561 }
562 }
563
564 protected void importFlag(
565 PortletDataContext context, Map<Long, Long> messagePKs,
566 MBMessageFlag flag)
567 throws Exception {
568
569 long userId = context.getUserId(flag.getUserUuid());
570 long messageId = MapUtil.getLong(
571 messagePKs, flag.getMessageId(), flag.getMessageId());
572
573 try {
574 MBMessage message = MBMessageUtil.findByPrimaryKey(messageId);
575
576 MBThread thread = message.getThread();
577
578 MBMessageFlagLocalServiceUtil.addReadFlags(userId, thread);
579 }
580 catch (NoSuchMessageException nsme) {
581 _log.error(
582 "Could not find the message for flag " +
583 flag.getMessageFlagId());
584 }
585 }
586
587 protected void importMessage(
588 PortletDataContext context, Map<Long, Long> categoryPKs,
589 Map<Long, Long> threadPKs, Map<Long, Long> messagePKs,
590 Element messageEl, MBMessage message)
591 throws Exception {
592
593 long userId = context.getUserId(message.getUserUuid());
594 String userName = message.getUserName();
595 long categoryId = MapUtil.getLong(
596 categoryPKs, message.getCategoryId(), message.getCategoryId());
597 long threadId = MapUtil.getLong(
598 threadPKs, message.getThreadId(), message.getThreadId());
599 long parentMessageId = MapUtil.getLong(
600 messagePKs, message.getParentMessageId(),
601 message.getParentMessageId());
602
603 List<ObjectValuePair<String, byte[]>> files =
604 new ArrayList<ObjectValuePair<String, byte[]>>();
605 List<String> existingFiles = new ArrayList<String>();
606
607 if (context.getBooleanParameter(_NAMESPACE, "attachments") &&
608 message.isAttachments()) {
609
610 List<Element> attachmentEls = messageEl.elements("attachment");
611
612 for (Element attachmentEl : attachmentEls) {
613 String name = attachmentEl.attributeValue("name");
614 String binPath = attachmentEl.attributeValue("bin-path");
615
616 byte[] bytes = context.getZipEntryAsByteArray(binPath);
617
618 files.add(new ObjectValuePair<String, byte[]>(name, bytes));
619 }
620
621 if (files.size() <= 0) {
622 _log.error(
623 "Could not find attachments for message " +
624 message.getMessageId());
625 }
626 }
627
628 String[] tagsEntries = null;
629
630 if (context.getBooleanParameter(_NAMESPACE, "tags")) {
631 tagsEntries = context.getTagsEntries(
632 MBMessage.class, message.getMessageId());
633 }
634
635 ServiceContext serviceContext = new ServiceContext();
636
637 serviceContext.setAddCommunityPermissions(true);
638 serviceContext.setAddGuestPermissions(true);
639 serviceContext.setScopeGroupId(context.getGroupId());
640 serviceContext.setTagsEntries(tagsEntries);
641
642 if ((categoryId != MBCategoryImpl.DEFAULT_PARENT_CATEGORY_ID) &&
643 (categoryId == message.getCategoryId())) {
644
645 String path = getImportCategoryPath(context, categoryId);
646
647 MBCategory category = (MBCategory)context.getZipEntryAsObject(path);
648
649 importCategory(context, categoryPKs, category);
650
651 categoryId = MapUtil.getLong(
652 categoryPKs, message.getCategoryId(), message.getCategoryId());
653 }
654
655 MBMessage existingMessage = null;
656
657 try {
658 MBCategoryUtil.findByPrimaryKey(categoryId);
659
660 if (parentMessageId != MBMessageImpl.DEFAULT_PARENT_MESSAGE_ID) {
661 MBMessageUtil.findByPrimaryKey(parentMessageId);
662 MBThreadUtil.findByPrimaryKey(threadId);
663 }
664
665 if (context.getDataStrategy().equals(
666 PortletDataHandlerKeys.DATA_STRATEGY_MIRROR)) {
667
668 try {
669 existingMessage = MBMessageUtil.findByUUID_G(
670 message.getUuid(), context.getGroupId());
671
672 existingMessage = MBMessageLocalServiceUtil.updateMessage(
673 userId, existingMessage.getMessageId(),
674 message.getSubject(), message.getBody(), files,
675 existingFiles, message.getPriority(), serviceContext);
676 }
677 catch (NoSuchMessageException nsme) {
678 existingMessage = MBMessageLocalServiceUtil.addMessage(
679 message.getUuid(), userId, userName, categoryId,
680 threadId, parentMessageId, message.getSubject(),
681 message.getBody(), files, message.getAnonymous(),
682 message.getPriority(), serviceContext);
683 }
684 }
685 else {
686 existingMessage = MBMessageLocalServiceUtil.addMessage(
687 userId, userName, categoryId, threadId, parentMessageId,
688 message.getSubject(), message.getBody(), files,
689 message.getAnonymous(), message.getPriority(),
690 serviceContext);
691 }
692
693 threadPKs.put(message.getThreadId(), existingMessage.getThreadId());
694 messagePKs.put(
695 message.getMessageId(), existingMessage.getMessageId());
696
697 context.importPermissions(
698 MBMessage.class, message.getMessageId(),
699 existingMessage.getMessageId());
700
701 if (context.getBooleanParameter(_NAMESPACE, "ratings")) {
702 context.importRatingsEntries(
703 MBMessage.class, message.getMessageId(),
704 existingMessage.getMessageId());
705 }
706 }
707 catch (NoSuchCategoryException nsce) {
708 _log.error(
709 "Could not find the parent category for message " +
710 message.getMessageId());
711 }
712 catch (NoSuchMessageException nsme) {
713 _log.error(
714 "Could not find the parent message for message " +
715 message.getMessageId());
716 }
717 catch (NoSuchThreadException nste) {
718 _log.error(
719 "Could not find the thread for message " +
720 message.getMessageId());
721 }
722 }
723
724 protected String getCategoryPath(
725 PortletDataContext context, MBCategory category) {
726
727 StringBundler sb = new StringBundler(4);
728
729 sb.append(context.getPortletPath(PortletKeys.MESSAGE_BOARDS));
730 sb.append("/categories/");
731 sb.append(category.getCategoryId());
732 sb.append(".xml");
733
734 return sb.toString();
735 }
736
737 protected String getImportCategoryPath(
738 PortletDataContext context, long categoryId) {
739
740 StringBundler sb = new StringBundler(4);
741
742 sb.append(context.getSourcePortletPath(PortletKeys.MESSAGE_BOARDS));
743 sb.append("/categories/");
744 sb.append(categoryId);
745 sb.append(".xml");
746
747 return sb.toString();
748 }
749
750 protected String getMessageAttachementBinPath(
751 PortletDataContext context, MBMessage message, String attachment) {
752
753 StringBundler sb = new StringBundler(5);
754
755 sb.append(context.getPortletPath(PortletKeys.MESSAGE_BOARDS));
756 sb.append("/bin/");
757 sb.append(message.getMessageId());
758 sb.append(StringPool.SLASH);
759 sb.append(attachment);
760
761 return sb.toString();
762 }
763
764 protected String getMessageFlagPath(
765 PortletDataContext context, MBMessageFlag messageFlag) {
766
767 StringBundler sb = new StringBundler(4);
768
769 sb.append(context.getPortletPath(PortletKeys.MESSAGE_BOARDS));
770 sb.append("/message-flags/");
771 sb.append(messageFlag.getMessageFlagId());
772 sb.append(".xml");
773
774 return sb.toString();
775 }
776
777 protected String getMessagePath(
778 PortletDataContext context, MBMessage message) {
779
780 StringBundler sb = new StringBundler(4);
781
782 sb.append(context.getPortletPath(PortletKeys.MESSAGE_BOARDS));
783 sb.append("/messages/");
784 sb.append(message.getMessageId());
785 sb.append(".xml");
786
787 return sb.toString();
788 }
789
790 protected String getUserBanPath(PortletDataContext context, MBBan ban) {
791 StringBundler sb = new StringBundler(4);
792
793 sb.append(context.getPortletPath(PortletKeys.MESSAGE_BOARDS));
794 sb.append("/user-bans/");
795 sb.append(ban.getBanId());
796 sb.append(".xml");
797
798 return sb.toString();
799 }
800
801 private static final String _NAMESPACE = "message_board";
802
803 private static final PortletDataHandlerBoolean _categoriesAndMessages =
804 new PortletDataHandlerBoolean(
805 _NAMESPACE, "categories-and-messages", true, true);
806
807 private static final PortletDataHandlerBoolean _attachments =
808 new PortletDataHandlerBoolean(_NAMESPACE, "attachments");
809
810 private static final PortletDataHandlerBoolean _userBans =
811 new PortletDataHandlerBoolean(_NAMESPACE, "user-bans");
812
813 private static final PortletDataHandlerBoolean _flags =
814 new PortletDataHandlerBoolean(_NAMESPACE, "flags");
815
816 private static final PortletDataHandlerBoolean _ratings =
817 new PortletDataHandlerBoolean(_NAMESPACE, "ratings");
818
819 private static final PortletDataHandlerBoolean _tags =
820 new PortletDataHandlerBoolean(_NAMESPACE, "tags");
821
822 private static Log _log = LogFactoryUtil.getLog(
823 MBPortletDataHandlerImpl.class);
824
825 }