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