1
14
15 package com.liferay.portlet.messageboards.lar;
16
17 import com.liferay.documentlibrary.service.DLServiceUtil;
18 import com.liferay.portal.kernel.exception.PortalException;
19 import com.liferay.portal.kernel.exception.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.MBCategoryConstants;
46 import com.liferay.portlet.messageboards.model.MBMessage;
47 import com.liferay.portlet.messageboards.model.MBMessageConstants;
48 import com.liferay.portlet.messageboards.model.MBMessageFlag;
49 import com.liferay.portlet.messageboards.model.MBThread;
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.findByG_C(
278 category.getGroupId(), 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.addAssetTags(MBMessage.class, message.getMessageId());
316 }
317
318 if (context.getBooleanParameter(_NAMESPACE, "attachments") &&
319 message.isAttachments()) {
320
321 for (String attachment : message.getAttachmentsFiles()) {
322 int pos = attachment.lastIndexOf(StringPool.FORWARD_SLASH);
323
324 String name = attachment.substring(pos + 1);
325 String binPath = getMessageAttachementBinPath(
326 context, message, name);
327
328 Element attachmentEl = messageEl.addElement("attachment");
329
330 attachmentEl.addAttribute("name", name);
331 attachmentEl.addAttribute("bin-path", binPath);
332
333 byte[] bytes = DLServiceUtil.getFile(
334 context.getCompanyId(), CompanyConstants.SYSTEM,
335 attachment);
336
337 context.addZipEntry(binPath, bytes);
338 }
339
340 message.setAttachmentsDir(message.getAttachmentsDir());
341 }
342
343 if (context.getBooleanParameter(_NAMESPACE, "flags")) {
344 List<MBMessageFlag> messageFlags =
345 MBMessageFlagUtil.findByMessageId(
346 message.getMessageId());
347
348 for (MBMessageFlag messageFlag : messageFlags) {
349 exportMessageFlag(context, messageFlagsEl, messageFlag);
350 }
351 }
352
353 context.addZipEntry(path, message);
354 }
355 }
356
357 protected void exportMessageFlag(
358 PortletDataContext context, Element messageFlagsEl,
359 MBMessageFlag messageFlag)
360 throws SystemException {
361
362 String path = getMessageFlagPath(context, messageFlag);
363
364 if (!context.isPathNotProcessed(path)) {
365 return;
366 }
367
368 Element messageFlagEl = messageFlagsEl.addElement("message-flag");
369
370 messageFlagEl.addAttribute("path", path);
371
372 messageFlag.setUserUuid(messageFlag.getUserUuid());
373
374 context.addZipEntry(path, messageFlag);
375 }
376
377 protected void exportParentCategory(
378 PortletDataContext context, Element categoriesEl, long categoryId)
379 throws PortalException, SystemException {
380
381 if ((!context.hasDateRange()) ||
382 (categoryId == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID)) {
383
384 return;
385 }
386
387 MBCategory category = MBCategoryUtil.findByPrimaryKey(categoryId);
388
389 exportParentCategory(
390 context, categoriesEl, category.getParentCategoryId());
391
392 String path = getCategoryPath(context, category);
393
394 if (context.isPathNotProcessed(path)) {
395 Element categoryEl = categoriesEl.addElement("category");
396
397 categoryEl.addAttribute("path", path);
398
399 category.setUserUuid(category.getUserUuid());
400
401 context.addPermissions(MBCategory.class, category.getCategoryId());
402
403 context.addZipEntry(path, category);
404 }
405 }
406
407 protected void exportUserBan(
408 PortletDataContext context, Element userBansEl, MBBan ban)
409 throws SystemException {
410
411 if (!context.isWithinDateRange(ban.getModifiedDate())) {
412 return;
413 }
414
415 String path = getUserBanPath(context, ban);
416
417 if (!context.isPathNotProcessed(path)) {
418 return;
419 }
420
421 Element userBanEl = userBansEl.addElement("user-ban");
422
423 userBanEl.addAttribute("path", path);
424
425 ban.setBanUserUuid(ban.getBanUserUuid());
426 ban.setUserUuid(ban.getUserUuid());
427
428 context.addZipEntry(path, ban);
429 }
430
431 protected void importBan(PortletDataContext context, MBBan ban)
432 throws Exception {
433
434 long userId = context.getUserId(ban.getUserUuid());
435
436 ServiceContext serviceContext = new ServiceContext();
437
438 serviceContext.setScopeGroupId(context.getGroupId());
439
440 List<User> users = UserUtil.findByUuid(ban.getBanUserUuid());
441
442 Iterator<User> itr = users.iterator();
443
444 if (itr.hasNext()) {
445 User user = itr.next();
446
447 MBBanLocalServiceUtil.addBan(
448 userId, user.getUserId(), serviceContext);
449 }
450 else {
451 _log.error(
452 "Could not find banned user with uuid " + ban.getBanUserUuid());
453 }
454 }
455
456 protected void importCategory(
457 PortletDataContext context, Map<Long, Long> categoryPKs,
458 MBCategory category)
459 throws Exception {
460
461 long userId = context.getUserId(category.getUserUuid());
462 long parentCategoryId = MapUtil.getLong(
463 categoryPKs, category.getParentCategoryId(),
464 category.getParentCategoryId());
465
466 String emailAddress = null;
467 String inProtocol = null;
468 String inServerName = null;
469 int inServerPort = 0;
470 boolean inUseSSL = false;
471 String inUserName = null;
472 String inPassword = null;
473 int inReadInterval = 0;
474 String outEmailAddress = null;
475 boolean outCustom = false;
476 String outServerName = null;
477 int outServerPort = 0;
478 boolean outUseSSL = false;
479 String outUserName = null;
480 String outPassword = null;
481 boolean mailingListActive = false;
482
483 ServiceContext serviceContext = new ServiceContext();
484
485 serviceContext.setAddCommunityPermissions(true);
486 serviceContext.setAddGuestPermissions(true);
487 serviceContext.setScopeGroupId(context.getGroupId());
488
489 if ((parentCategoryId !=
490 MBCategoryConstants.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 importedCategory = null;
506
507 try {
508 if (parentCategoryId !=
509 MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {
510
511 MBCategoryUtil.findByPrimaryKey(parentCategoryId);
512 }
513
514 if (context.getDataStrategy().equals(
515 PortletDataHandlerKeys.DATA_STRATEGY_MIRROR)) {
516
517 MBCategory existingCategory = MBCategoryUtil.fetchByUUID_G(
518 category.getUuid(), context.getGroupId());
519
520 if (existingCategory == null) {
521 importedCategory = MBCategoryLocalServiceUtil.addCategory(
522 category.getUuid(), userId, parentCategoryId,
523 category.getName(), category.getDescription(),
524 emailAddress, inProtocol, inServerName, inServerPort,
525 inUseSSL, inUserName, inPassword, inReadInterval,
526 outEmailAddress, outCustom, outServerName,
527 outServerPort, outUseSSL, outUserName, outPassword,
528 mailingListActive, serviceContext);
529 }
530 else {
531 importedCategory =
532 MBCategoryLocalServiceUtil.updateCategory(
533 existingCategory.getCategoryId(), parentCategoryId,
534 category.getName(), category.getDescription(),
535 emailAddress, inProtocol, inServerName,
536 inServerPort, inUseSSL, inUserName, inPassword,
537 inReadInterval, outEmailAddress, outCustom,
538 outServerName, outServerPort, outUseSSL,
539 outUserName, outPassword, mailingListActive, false,
540 serviceContext);
541 }
542 }
543 else {
544 importedCategory = MBCategoryLocalServiceUtil.addCategory(
545 userId, parentCategoryId, category.getName(),
546 category.getDescription(), emailAddress, inProtocol,
547 inServerName, inServerPort, inUseSSL, inUserName,
548 inPassword, inReadInterval, outEmailAddress, outCustom,
549 outServerName, outServerPort, outUseSSL, outUserName,
550 outPassword, mailingListActive, serviceContext);
551 }
552
553 categoryPKs.put(
554 category.getCategoryId(), importedCategory.getCategoryId());
555
556 context.importPermissions(
557 MBCategory.class, category.getCategoryId(),
558 importedCategory.getCategoryId());
559 }
560 catch (NoSuchCategoryException nsce) {
561 _log.error(
562 "Could not find the parent category for category " +
563 category.getCategoryId());
564 }
565 }
566
567 protected void importFlag(
568 PortletDataContext context, Map<Long, Long> messagePKs,
569 MBMessageFlag flag)
570 throws Exception {
571
572 long userId = context.getUserId(flag.getUserUuid());
573 long messageId = MapUtil.getLong(
574 messagePKs, flag.getMessageId(), flag.getMessageId());
575
576 try {
577 MBMessage message = MBMessageUtil.findByPrimaryKey(messageId);
578
579 MBThread thread = message.getThread();
580
581 MBMessageFlagLocalServiceUtil.addReadFlags(userId, thread);
582 }
583 catch (NoSuchMessageException nsme) {
584 _log.error(
585 "Could not find the message for flag " +
586 flag.getMessageFlagId());
587 }
588 }
589
590 protected void importMessage(
591 PortletDataContext context, Map<Long, Long> categoryPKs,
592 Map<Long, Long> threadPKs, Map<Long, Long> messagePKs,
593 Element messageEl, MBMessage message)
594 throws Exception {
595
596 long userId = context.getUserId(message.getUserUuid());
597 String userName = message.getUserName();
598 long categoryId = MapUtil.getLong(
599 categoryPKs, message.getCategoryId(), message.getCategoryId());
600 long threadId = MapUtil.getLong(
601 threadPKs, message.getThreadId(), message.getThreadId());
602 long parentMessageId = MapUtil.getLong(
603 messagePKs, message.getParentMessageId(),
604 message.getParentMessageId());
605
606 List<ObjectValuePair<String, byte[]>> files =
607 new ArrayList<ObjectValuePair<String, byte[]>>();
608 List<String> existingFiles = new ArrayList<String>();
609
610 if (context.getBooleanParameter(_NAMESPACE, "attachments") &&
611 message.isAttachments()) {
612
613 List<Element> attachmentEls = messageEl.elements("attachment");
614
615 for (Element attachmentEl : attachmentEls) {
616 String name = attachmentEl.attributeValue("name");
617 String binPath = attachmentEl.attributeValue("bin-path");
618
619 byte[] bytes = context.getZipEntryAsByteArray(binPath);
620
621 files.add(new ObjectValuePair<String, byte[]>(name, bytes));
622 }
623
624 if (files.size() <= 0) {
625 _log.error(
626 "Could not find attachments for message " +
627 message.getMessageId());
628 }
629 }
630
631 String[] assetTagNames = null;
632
633 if (context.getBooleanParameter(_NAMESPACE, "tags")) {
634 assetTagNames = context.getAssetTagNames(
635 MBMessage.class, message.getMessageId());
636 }
637
638 ServiceContext serviceContext = new ServiceContext();
639
640 serviceContext.setAddCommunityPermissions(true);
641 serviceContext.setAddGuestPermissions(true);
642 serviceContext.setAssetTagNames(assetTagNames);
643 serviceContext.setScopeGroupId(context.getGroupId());
644 serviceContext.setStartWorkflow(false);
645 serviceContext.setStatus(message.getStatus());
646
647 if ((categoryId != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) &&
648 (categoryId == message.getCategoryId())) {
649
650 String path = getImportCategoryPath(context, categoryId);
651
652 MBCategory category = (MBCategory)context.getZipEntryAsObject(path);
653
654 importCategory(context, categoryPKs, category);
655
656 categoryId = MapUtil.getLong(
657 categoryPKs, message.getCategoryId(), message.getCategoryId());
658 }
659
660 MBMessage importedMessage = null;
661
662 try {
663 MBCategoryUtil.findByPrimaryKey(categoryId);
664
665 if (parentMessageId !=
666 MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID) {
667
668 MBMessageUtil.findByPrimaryKey(parentMessageId);
669 MBThreadUtil.findByPrimaryKey(threadId);
670 }
671
672 if (context.getDataStrategy().equals(
673 PortletDataHandlerKeys.DATA_STRATEGY_MIRROR)) {
674
675 MBMessage existingMessage = MBMessageUtil.fetchByUUID_G(
676 message.getUuid(), context.getGroupId());
677
678 if (existingMessage == null) {
679 importedMessage = MBMessageLocalServiceUtil.addMessage(
680 message.getUuid(), userId, userName,
681 message.getGroupId(), categoryId, threadId,
682 parentMessageId, message.getSubject(),
683 message.getBody(), files, message.getAnonymous(),
684 message.getPriority(), message.getAllowPingbacks(),
685 serviceContext);
686 }
687 else {
688 importedMessage = MBMessageLocalServiceUtil.updateMessage(
689 userId, existingMessage.getMessageId(),
690 message.getSubject(), message.getBody(), files,
691 existingFiles, message.getPriority(),
692 message.getAllowPingbacks(), serviceContext);
693 }
694 }
695 else {
696 importedMessage = MBMessageLocalServiceUtil.addMessage(
697 userId, userName, message.getGroupId(), categoryId,
698 threadId, parentMessageId, message.getSubject(),
699 message.getBody(), files, message.getAnonymous(),
700 message.getPriority(), message.getAllowPingbacks(),
701 serviceContext);
702 }
703
704 threadPKs.put(message.getThreadId(), importedMessage.getThreadId());
705 messagePKs.put(
706 message.getMessageId(), importedMessage.getMessageId());
707
708 context.importPermissions(
709 MBMessage.class, message.getMessageId(),
710 importedMessage.getMessageId());
711
712 if (context.getBooleanParameter(_NAMESPACE, "ratings")) {
713 context.importRatingsEntries(
714 MBMessage.class, message.getMessageId(),
715 importedMessage.getMessageId());
716 }
717 }
718 catch (NoSuchCategoryException nsce) {
719 _log.error(
720 "Could not find the parent category for message " +
721 message.getMessageId());
722 }
723 catch (NoSuchMessageException nsme) {
724 _log.error(
725 "Could not find the parent message for message " +
726 message.getMessageId());
727 }
728 catch (NoSuchThreadException nste) {
729 _log.error(
730 "Could not find the thread for message " +
731 message.getMessageId());
732 }
733 }
734
735 protected String getCategoryPath(
736 PortletDataContext context, MBCategory category) {
737
738 StringBundler sb = new StringBundler(4);
739
740 sb.append(context.getPortletPath(PortletKeys.MESSAGE_BOARDS));
741 sb.append("/categories/");
742 sb.append(category.getCategoryId());
743 sb.append(".xml");
744
745 return sb.toString();
746 }
747
748 protected String getImportCategoryPath(
749 PortletDataContext context, long categoryId) {
750
751 StringBundler sb = new StringBundler(4);
752
753 sb.append(context.getSourcePortletPath(PortletKeys.MESSAGE_BOARDS));
754 sb.append("/categories/");
755 sb.append(categoryId);
756 sb.append(".xml");
757
758 return sb.toString();
759 }
760
761 protected String getMessageAttachementBinPath(
762 PortletDataContext context, MBMessage message, String attachment) {
763
764 StringBundler sb = new StringBundler(5);
765
766 sb.append(context.getPortletPath(PortletKeys.MESSAGE_BOARDS));
767 sb.append("/bin/");
768 sb.append(message.getMessageId());
769 sb.append(StringPool.SLASH);
770 sb.append(attachment);
771
772 return sb.toString();
773 }
774
775 protected String getMessageFlagPath(
776 PortletDataContext context, MBMessageFlag messageFlag) {
777
778 StringBundler sb = new StringBundler(4);
779
780 sb.append(context.getPortletPath(PortletKeys.MESSAGE_BOARDS));
781 sb.append("/message-flags/");
782 sb.append(messageFlag.getMessageFlagId());
783 sb.append(".xml");
784
785 return sb.toString();
786 }
787
788 protected String getMessagePath(
789 PortletDataContext context, MBMessage message) {
790
791 StringBundler sb = new StringBundler(4);
792
793 sb.append(context.getPortletPath(PortletKeys.MESSAGE_BOARDS));
794 sb.append("/messages/");
795 sb.append(message.getMessageId());
796 sb.append(".xml");
797
798 return sb.toString();
799 }
800
801 protected String getUserBanPath(PortletDataContext context, MBBan ban) {
802 StringBundler sb = new StringBundler(4);
803
804 sb.append(context.getPortletPath(PortletKeys.MESSAGE_BOARDS));
805 sb.append("/user-bans/");
806 sb.append(ban.getBanId());
807 sb.append(".xml");
808
809 return sb.toString();
810 }
811
812 private static final String _NAMESPACE = "message_board";
813
814 private static final PortletDataHandlerBoolean _categoriesAndMessages =
815 new PortletDataHandlerBoolean(
816 _NAMESPACE, "categories-and-messages", true, true);
817
818 private static final PortletDataHandlerBoolean _attachments =
819 new PortletDataHandlerBoolean(_NAMESPACE, "attachments");
820
821 private static final PortletDataHandlerBoolean _userBans =
822 new PortletDataHandlerBoolean(_NAMESPACE, "user-bans");
823
824 private static final PortletDataHandlerBoolean _flags =
825 new PortletDataHandlerBoolean(_NAMESPACE, "flags");
826
827 private static final PortletDataHandlerBoolean _ratings =
828 new PortletDataHandlerBoolean(_NAMESPACE, "ratings");
829
830 private static final PortletDataHandlerBoolean _tags =
831 new PortletDataHandlerBoolean(_NAMESPACE, "tags");
832
833 private static Log _log = LogFactoryUtil.getLog(
834 MBPortletDataHandlerImpl.class);
835
836 }