1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.documentlibrary.lar;
24  
25  import com.liferay.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.util.FileUtil;
28  import com.liferay.portal.kernel.util.StringPool;
29  import com.liferay.portal.kernel.xml.Document;
30  import com.liferay.portal.kernel.xml.Element;
31  import com.liferay.portal.kernel.xml.SAXReaderUtil;
32  import com.liferay.portal.lar.PortletDataContext;
33  import com.liferay.portal.lar.PortletDataException;
34  import com.liferay.portal.lar.PortletDataHandler;
35  import com.liferay.portal.lar.PortletDataHandlerBoolean;
36  import com.liferay.portal.lar.PortletDataHandlerControl;
37  import com.liferay.portal.lar.PortletDataHandlerKeys;
38  import com.liferay.portal.util.PortletKeys;
39  import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
40  import com.liferay.portlet.documentlibrary.NoSuchFileShortcutException;
41  import com.liferay.portlet.documentlibrary.NoSuchFolderException;
42  import com.liferay.portlet.documentlibrary.model.DLFileEntry;
43  import com.liferay.portlet.documentlibrary.model.DLFileRank;
44  import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
45  import com.liferay.portlet.documentlibrary.model.DLFolder;
46  import com.liferay.portlet.documentlibrary.model.impl.DLFolderImpl;
47  import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
48  import com.liferay.portlet.documentlibrary.service.DLFileRankLocalServiceUtil;
49  import com.liferay.portlet.documentlibrary.service.DLFileShortcutLocalServiceUtil;
50  import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
51  import com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryFinderUtil;
52  import com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryUtil;
53  import com.liferay.portlet.documentlibrary.service.persistence.DLFileRankUtil;
54  import com.liferay.portlet.documentlibrary.service.persistence.DLFileShortcutFinderUtil;
55  import com.liferay.portlet.documentlibrary.service.persistence.DLFileShortcutUtil;
56  import com.liferay.portlet.documentlibrary.service.persistence.DLFolderUtil;
57  import com.liferay.util.MapUtil;
58  
59  import java.io.IOException;
60  import java.io.InputStream;
61  
62  import java.util.List;
63  import java.util.Map;
64  import java.util.regex.Pattern;
65  
66  import javax.portlet.PortletPreferences;
67  
68  import org.apache.commons.logging.Log;
69  import org.apache.commons.logging.LogFactory;
70  
71  /**
72   * <a href="DLPortletDataHandlerImpl.java.html"><b><i>View Source</i></b></a>
73   *
74   * @author Bruno Farache
75   * @author Raymond Augé
76   *
77   */
78  public class DLPortletDataHandlerImpl implements PortletDataHandler {
79  
80      public static void exportFileEntry(
81              PortletDataContext context, Element foldersEl,
82              Element fileEntriesEl, Element fileRanksEl, DLFileEntry fileEntry)
83          throws PortalException, SystemException {
84  
85          if (!context.isWithinDateRange(fileEntry.getModifiedDate())) {
86              return;
87          }
88  
89          String path = getFileEntryPath(context, fileEntry);
90  
91          if (context.isPathNotProcessed(path)) {
92              Element fileEntryEl = fileEntriesEl.addElement("file-entry");
93  
94              fileEntryEl.addAttribute("path", path);
95  
96              String binPath = getFileEntryBinPath(context, fileEntry);
97  
98              fileEntryEl.addAttribute("bin-path", binPath);
99  
100             fileEntry.setUserUuid(fileEntry.getUserUuid());
101 
102             if (context.getBooleanParameter(_NAMESPACE, "comments")) {
103                 context.addComments(
104                     DLFileEntry.class, fileEntry.getFileEntryId());
105             }
106 
107             if (context.getBooleanParameter(_NAMESPACE, "ratings")) {
108                 context.addRatingsEntries(
109                     DLFileEntry.class, fileEntry.getFileEntryId());
110             }
111 
112             if (context.getBooleanParameter(_NAMESPACE, "tags")) {
113                 context.addTagsEntries(
114                     DLFileEntry.class, fileEntry.getFileEntryId());
115             }
116 
117             InputStream is = DLFileEntryLocalServiceUtil.getFileAsStream(
118                 fileEntry.getCompanyId(), fileEntry.getUserId(),
119                 fileEntry.getFolderId(), fileEntry.getName());
120 
121             try {
122                 context.addZipEntry(
123                     getFileEntryBinPath(context, fileEntry),
124                     FileUtil.getBytes(is));
125             }
126             catch (IOException ioe) {
127                 throw new SystemException(ioe);
128             }
129 
130             context.addZipEntry(path, fileEntry);
131 
132             if (context.getBooleanParameter(_NAMESPACE, "ranks")) {
133                 List<DLFileRank> fileRanks = DLFileRankUtil.findByF_N(
134                     fileEntry.getFolderId(), fileEntry.getName());
135 
136                 for (DLFileRank fileRank : fileRanks) {
137                     exportFileRank(context, fileRanksEl, fileRank);
138                 }
139             }
140         }
141 
142         exportParentFolder(context, foldersEl, fileEntry.getFolderId());
143     }
144 
145     public static void exportFolder(
146             PortletDataContext context, Element foldersEl,
147             Element fileEntriesEl, Element fileShortcutsEl, Element fileRanksEl,
148             DLFolder folder)
149         throws PortalException, SystemException {
150 
151         if (context.isWithinDateRange(folder.getModifiedDate())) {
152             String path = getFolderPath(context, folder);
153 
154             if (context.isPathNotProcessed(path)) {
155                 Element folderEl = foldersEl.addElement("folder");
156 
157                 folderEl.addAttribute("path", path);
158 
159                 folder.setUserUuid(folder.getUserUuid());
160 
161                 context.addZipEntry(path, folder);
162             }
163 
164             exportParentFolder(context, foldersEl, folder.getParentFolderId());
165         }
166 
167         List<DLFileEntry> fileEntries = DLFileEntryUtil.findByFolderId(
168         folder.getFolderId());
169 
170         for (DLFileEntry fileEntry : fileEntries) {
171             exportFileEntry(
172                 context, foldersEl, fileEntriesEl, fileRanksEl, fileEntry);
173         }
174 
175         if (context.getBooleanParameter(_NAMESPACE, "shortcuts")) {
176             List<DLFileShortcut> fileShortcuts =
177                 DLFileShortcutUtil.findByFolderId(folder.getFolderId());
178 
179             for (DLFileShortcut fileShortcut : fileShortcuts) {
180                 exportFileShortcut(
181                     context, foldersEl, fileShortcutsEl, fileShortcut);
182             }
183         }
184     }
185 
186     public static void importFileEntry(
187             PortletDataContext context, Map<Long, Long> folderPKs,
188             Map<String, String> fileEntryNames, DLFileEntry fileEntry,
189             String binPath)
190         throws Exception {
191 
192         long userId = context.getUserId(fileEntry.getUserUuid());
193         long folderId = MapUtil.getLong(
194             folderPKs, fileEntry.getFolderId(), fileEntry.getFolderId());
195 
196         String[] tagsEntries = null;
197 
198         if (context.getBooleanParameter(_NAMESPACE, "tags")) {
199             tagsEntries = context.getTagsEntries(
200                 DLFileEntry.class, fileEntry.getFileEntryId());
201         }
202 
203         boolean addCommunityPermissions = true;
204         boolean addGuestPermissions = true;
205 
206         byte[] bytes = context.getZipEntryAsByteArray(binPath);
207 
208         DLFileEntry existingFileEntry = null;
209 
210         try {
211             DLFolderUtil.findByPrimaryKey(folderId);
212 
213             if (context.getDataStrategy().equals(
214                     PortletDataHandlerKeys.DATA_STRATEGY_MIRROR)) {
215 
216                 try {
217                     existingFileEntry = DLFileEntryFinderUtil.findByUuid_G(
218                         fileEntry.getUuid(), context.getGroupId());
219 
220                     existingFileEntry =
221                         DLFileEntryLocalServiceUtil.updateFileEntry(
222                             userId, existingFileEntry.getFolderId(), folderId,
223                             existingFileEntry.getName(), fileEntry.getName(),
224                             fileEntry.getTitle(), fileEntry.getDescription(),
225                             tagsEntries, fileEntry.getExtraSettings(), bytes);
226                 }
227                 catch (NoSuchFileEntryException nsfee) {
228                     existingFileEntry =
229                         DLFileEntryLocalServiceUtil.addFileEntry(
230                             fileEntry.getUuid(), userId, folderId,
231                             fileEntry.getName(), fileEntry.getTitle(),
232                             fileEntry.getDescription(), tagsEntries,
233                             fileEntry.getExtraSettings(), bytes,
234                             addCommunityPermissions, addGuestPermissions);
235                 }
236             }
237             else {
238                 existingFileEntry = DLFileEntryLocalServiceUtil.addFileEntry(
239                     userId, folderId, fileEntry.getName(), fileEntry.getTitle(),
240                     fileEntry.getDescription(), tagsEntries,
241                     fileEntry.getExtraSettings(), bytes,
242                     addCommunityPermissions, addGuestPermissions);
243             }
244 
245             fileEntryNames.put(
246                 fileEntry.getName(), existingFileEntry.getName());
247 
248             if (context.getBooleanParameter(_NAMESPACE, "comments")) {
249                 context.importComments(
250                     DLFileEntry.class, fileEntry.getFileEntryId(),
251                     existingFileEntry.getFileEntryId(), context.getGroupId());
252             }
253 
254             if (context.getBooleanParameter(_NAMESPACE, "ratings")) {
255                 context.importRatingsEntries(
256                     DLFileEntry.class, fileEntry.getFileEntryId(),
257                     existingFileEntry.getFileEntryId());
258             }
259         }
260         catch (NoSuchFolderException nsfe) {
261             _log.error(
262                 "Could not find the parent folder for entry " +
263                     fileEntry.getFileEntryId());
264         }
265     }
266 
267     public static void importFileRank(
268             PortletDataContext context, Map<Long, Long> folderPKs,
269             Map<String, String> fileEntryNames, DLFileRank rank)
270         throws Exception {
271 
272         long userId = context.getUserId(rank.getUserUuid());
273         long folderId = MapUtil.getLong(
274             folderPKs, rank.getFolderId(), rank.getFolderId());
275 
276         String name = fileEntryNames.get(rank.getName());
277 
278         if (name == null) {
279             name = rank.getName();
280         }
281 
282         try {
283             DLFolderUtil.findByPrimaryKey(folderId);
284 
285             DLFileRankLocalServiceUtil.updateFileRank(
286                 context.getGroupId(), context.getCompanyId(), userId, folderId,
287                 name);
288         }
289         catch (NoSuchFolderException nsfe) {
290             _log.error(
291                 "Could not find the folder for rank " + rank.getFileRankId());
292         }
293     }
294 
295     public static void importFolder(
296             PortletDataContext context, Map<Long, Long> folderPKs,
297             DLFolder folder)
298         throws Exception {
299 
300         long userId = context.getUserId(folder.getUserUuid());
301         long plid = context.getPlid();
302         long parentFolderId = MapUtil.getLong(
303             folderPKs, folder.getParentFolderId(), folder.getParentFolderId());
304 
305         boolean addCommunityPermissions = true;
306         boolean addGuestPermissions = true;
307 
308         DLFolder existingFolder = null;
309 
310         try {
311             if (parentFolderId != DLFolderImpl.DEFAULT_PARENT_FOLDER_ID) {
312                 DLFolderUtil.findByPrimaryKey(parentFolderId);
313             }
314 
315             if (context.getDataStrategy().equals(
316                     PortletDataHandlerKeys.DATA_STRATEGY_MIRROR)) {
317 
318                 existingFolder = DLFolderUtil.fetchByUUID_G(
319                     folder.getUuid(), context.getGroupId());
320 
321                 if (existingFolder == null) {
322                     String name = getFolderName(
323                         context.getCompanyId(), context.getGroupId(),
324                         parentFolderId, folder.getName(), 2);
325 
326                     existingFolder = DLFolderLocalServiceUtil.addFolder(
327                         folder.getUuid(), userId, plid, parentFolderId,
328                         name, folder.getDescription(), addCommunityPermissions,
329                         addGuestPermissions);
330                 }
331                 else {
332                     existingFolder = DLFolderLocalServiceUtil.updateFolder(
333                         existingFolder.getFolderId(), parentFolderId,
334                         folder.getName(), folder.getDescription());
335                 }
336             }
337             else {
338                 String name = getFolderName(
339                     context.getCompanyId(), context.getGroupId(),
340                     parentFolderId, folder.getName(), 2);
341 
342                 existingFolder = DLFolderLocalServiceUtil.addFolder(
343                     userId, plid, parentFolderId, name, folder.getDescription(),
344                     addCommunityPermissions, addGuestPermissions);
345             }
346 
347             folderPKs.put(folder.getFolderId(), existingFolder.getFolderId());
348         }
349         catch (NoSuchFolderException nsfe) {
350             _log.error(
351                 "Could not find the parent folder for folder " +
352                     folder.getFolderId());
353         }
354     }
355 
356     public PortletPreferences deleteData(
357             PortletDataContext context, String portletId,
358             PortletPreferences prefs)
359         throws PortletDataException {
360 
361         try {
362             if (!context.addPrimaryKey(
363                     DLPortletDataHandlerImpl.class, "deleteData")) {
364 
365                 DLFolderLocalServiceUtil.deleteFolders(context.getGroupId());
366             }
367 
368             return null;
369         }
370         catch (Exception e) {
371             throw new PortletDataException(e);
372         }
373     }
374 
375     public String exportData(
376             PortletDataContext context, String portletId,
377             PortletPreferences prefs)
378         throws PortletDataException {
379 
380         try {
381             Document doc = SAXReaderUtil.createDocument();
382 
383             Element root = doc.addElement("documentlibrary-data");
384 
385             root.addAttribute("group-id", String.valueOf(context.getGroupId()));
386 
387             Element foldersEl = root.addElement("folders");
388             Element fileEntriesEl = root.addElement("file-entries");
389             Element fileShortcutsEl = root.addElement("file-shortcuts");
390             Element fileRanksEl = root.addElement("file-ranks");
391 
392             List<DLFolder> folders = DLFolderUtil.findByGroupId(
393                 context.getGroupId());
394 
395             for (DLFolder folder : folders) {
396                 exportFolder(
397                     context, foldersEl, fileEntriesEl, fileShortcutsEl,
398                     fileRanksEl, folder);
399             }
400 
401             return doc.formattedString();
402         }
403         catch (Exception e) {
404             throw new PortletDataException(e);
405         }
406     }
407 
408     public PortletDataHandlerControl[] getExportControls() {
409         return new PortletDataHandlerControl[] {
410             _foldersAndDocuments, _shortcuts, _ranks, _comments, _ratings, _tags
411         };
412     }
413 
414     public PortletDataHandlerControl[] getImportControls() {
415         return new PortletDataHandlerControl[] {
416             _foldersAndDocuments, _shortcuts, _ranks, _comments, _ratings, _tags
417         };
418     }
419 
420     public PortletPreferences importData(
421             PortletDataContext context, String portletId,
422             PortletPreferences prefs, String data)
423         throws PortletDataException {
424 
425         try {
426             Document doc = SAXReaderUtil.read(data);
427 
428             Element root = doc.getRootElement();
429 
430             List<Element> folderEls = root.element("folders").elements(
431                 "folder");
432 
433             Map<Long, Long> folderPKs =
434                 (Map<Long, Long>)context.getNewPrimaryKeysMap(DLFolder.class);
435 
436             for (Element folderEl : folderEls) {
437                 String path = folderEl.attributeValue("path");
438 
439                 if (!context.isPathNotProcessed(path)) {
440                     continue;
441                 }
442 
443                 DLFolder folder = (DLFolder)context.getZipEntryAsObject(path);
444 
445                 importFolder(context, folderPKs, folder);
446             }
447 
448             List<Element> fileEntryEls = root.element("file-entries").elements(
449                 "file-entry");
450 
451             Map<String, String> fileEntryNames =
452                 (Map<String, String>)context.getNewPrimaryKeysMap(
453                     DLFileEntry.class);
454 
455             for (Element fileEntryEl : fileEntryEls) {
456                 String path = fileEntryEl.attributeValue("path");
457 
458                 if (!context.isPathNotProcessed(path)) {
459                     continue;
460                 }
461 
462                 DLFileEntry fileEntry =
463                     (DLFileEntry)context.getZipEntryAsObject(path);
464 
465                 String binPath = fileEntryEl.attributeValue("bin-path");
466 
467                 importFileEntry(
468                     context, folderPKs, fileEntryNames, fileEntry, binPath);
469             }
470 
471             if (context.getBooleanParameter(_NAMESPACE, "shortcuts")) {
472                 List<Element> fileShortcutEls = root.element(
473                     "file-shortcuts").elements("file-shortcut");
474 
475                 for (Element fileShortcutEl : fileShortcutEls) {
476                     String path = fileShortcutEl.attributeValue("path");
477 
478                     if (!context.isPathNotProcessed(path)) {
479                         continue;
480                     }
481 
482                     DLFileShortcut fileShortcut =
483                         (DLFileShortcut)context.getZipEntryAsObject(path);
484 
485                     importFileShortcut(
486                         context, folderPKs, fileEntryNames, fileShortcut);
487                 }
488             }
489 
490             if (context.getBooleanParameter(_NAMESPACE, "ranks")) {
491                 List<Element> fileRankEls = root.element("file-ranks").elements(
492                     "file-rank");
493 
494                 for (Element fileRankEl : fileRankEls) {
495                     String path = fileRankEl.attributeValue("path");
496 
497                     if (!context.isPathNotProcessed(path)) {
498                         continue;
499                     }
500 
501                     DLFileRank fileRank =
502                         (DLFileRank)context.getZipEntryAsObject(path);
503 
504                     importFileRank(
505                         context, folderPKs, fileEntryNames, fileRank);
506                 }
507             }
508 
509             return null;
510         }
511         catch (Exception e) {
512             throw new PortletDataException(e);
513         }
514     }
515 
516     public boolean isPublishToLiveByDefault() {
517         return false;
518     }
519 
520     protected static void exportFileRank(
521             PortletDataContext context, Element fileRanksEl,
522             DLFileRank fileRank)
523         throws SystemException {
524 
525         String path = getFileRankPath(context, fileRank);
526 
527         if (!context.isPathNotProcessed(path)) {
528             return;
529         }
530 
531         Element fileRankEl = fileRanksEl.addElement("file-rank");
532 
533         fileRankEl.addAttribute("path", path);
534 
535         fileRank.setUserUuid(fileRank.getUserUuid());
536 
537         context.addZipEntry(path, fileRank);
538     }
539 
540     protected static void exportFileShortcut(
541             PortletDataContext context, Element foldersEl,
542             Element fileShortcutsEl, DLFileShortcut fileShortcut)
543         throws PortalException, SystemException {
544 
545         String path = getFileShortcutPath(context, fileShortcut);
546 
547         if (context.isPathNotProcessed(path)) {
548             Element fileShortcutEl = fileShortcutsEl.addElement(
549                 "file-shortcut");
550 
551             fileShortcutEl.addAttribute("path", path);
552 
553             fileShortcut.setUserUuid(fileShortcut.getUserUuid());
554 
555             context.addZipEntry(path, fileShortcut);
556         }
557 
558         exportParentFolder(context, foldersEl, fileShortcut.getFolderId());
559     }
560 
561     protected static void exportParentFolder(
562             PortletDataContext context, Element foldersEl, long folderId)
563         throws PortalException, SystemException {
564 
565         if (folderId == DLFolderImpl.DEFAULT_PARENT_FOLDER_ID) {
566             return;
567         }
568 
569         DLFolder folder = DLFolderUtil.findByPrimaryKey(folderId);
570 
571         String path = getFolderPath(context, folder);
572 
573         if (context.isPathNotProcessed(path)) {
574             Element folderEl = foldersEl.addElement("folder");
575 
576             folderEl.addAttribute("path", path);
577 
578             folder.setUserUuid(folder.getUserUuid());
579 
580             context.addZipEntry(path, folder);
581         }
582 
583         exportParentFolder(context, foldersEl, folder.getParentFolderId());
584     }
585 
586     protected static String getFileEntryBinPath(
587         PortletDataContext context, DLFileEntry fileEntry) {
588 
589         StringBuilder sb = new StringBuilder();
590 
591         sb.append(context.getPortletPath(PortletKeys.DOCUMENT_LIBRARY));
592         sb.append("/bin/");
593         sb.append(fileEntry.getFileEntryId());
594         sb.append(StringPool.SLASH);
595         sb.append(fileEntry.getVersion());
596         sb.append(StringPool.SLASH);
597         sb.append(fileEntry.getTitleWithExtension());
598 
599         return sb.toString();
600     }
601 
602     protected static String getFileEntryPath(
603         PortletDataContext context, DLFileEntry fileEntry) {
604 
605         StringBuilder sb = new StringBuilder();
606 
607         sb.append(context.getPortletPath(PortletKeys.DOCUMENT_LIBRARY));
608         sb.append("/file-entries/");
609         sb.append(fileEntry.getFileEntryId());
610         sb.append(StringPool.SLASH);
611         sb.append(fileEntry.getVersion());
612         sb.append(".xml");
613 
614         return sb.toString();
615     }
616 
617     protected static String getFolderName(
618             long companyId, long groupId, long parentFolderId, String name,
619             int count)
620         throws SystemException {
621 
622         DLFolder folder = DLFolderUtil.fetchByG_P_N(
623             groupId, parentFolderId, name);
624 
625         if (folder == null) {
626             return name;
627         }
628 
629         if (Pattern.matches(".* \\(\\d+\\)", name)) {
630             int pos = name.lastIndexOf(" (");
631 
632             name = name.substring(0, pos);
633         }
634 
635         StringBuilder sb = new StringBuilder();
636 
637         sb.append(name);
638         sb.append(StringPool.SPACE);
639         sb.append(StringPool.OPEN_PARENTHESIS);
640         sb.append(count);
641         sb.append(StringPool.CLOSE_PARENTHESIS);
642 
643         name = sb.toString();
644 
645         return getFolderName(companyId, groupId, parentFolderId, name, ++count);
646     }
647 
648     protected static String getFolderPath(
649         PortletDataContext context, DLFolder folder) {
650 
651         return context.getPortletPath(PortletKeys.DOCUMENT_LIBRARY) +
652             "/folders/" + folder.getFolderId() + ".xml";
653     }
654 
655     protected static String getFileRankPath(
656         PortletDataContext context, DLFileRank fileRank) {
657 
658         return context.getPortletPath(PortletKeys.DOCUMENT_LIBRARY) +
659             "/ranks/" + fileRank.getFileRankId() + ".xml";
660     }
661 
662     protected static String getFileShortcutPath(
663         PortletDataContext context, DLFileShortcut fileShortcut) {
664 
665         return context.getPortletPath(PortletKeys.DOCUMENT_LIBRARY) +
666             "/shortcut/" + fileShortcut.getFileShortcutId() + ".xml";
667     }
668 
669     protected static void importFileShortcut(
670             PortletDataContext context, Map<Long, Long> folderPKs,
671             Map<String, String> fileEntryNames, DLFileShortcut fileShortcut)
672         throws Exception {
673 
674         long userId = context.getUserId(fileShortcut.getUserUuid());
675         long folderId = MapUtil.getLong(
676             folderPKs, fileShortcut.getFolderId(), fileShortcut.getFolderId());
677         long toFolderId = MapUtil.getLong(
678             folderPKs, fileShortcut.getToFolderId(),
679             fileShortcut.getToFolderId());
680         String toName = MapUtil.getString(
681             fileEntryNames, fileShortcut.getToName(), fileShortcut.getToName());
682 
683         boolean addCommunityPermissions = true;
684         boolean addGuestPermissions = true;
685 
686         try {
687             DLFolderUtil.findByPrimaryKey(folderId);
688             DLFolderUtil.findByPrimaryKey(toFolderId);
689 
690             if (context.getDataStrategy().equals(
691                     PortletDataHandlerKeys.DATA_STRATEGY_MIRROR)) {
692 
693                 try {
694                     DLFileShortcut existingFileShortcut =
695                         DLFileShortcutFinderUtil.findByUuid_G(
696                             fileShortcut.getUuid(), context.getGroupId());
697 
698                     DLFileShortcutLocalServiceUtil.updateFileShortcut(
699                         userId, existingFileShortcut.getFileShortcutId(),
700                         folderId, toFolderId, toName);
701                 }
702                 catch (NoSuchFileShortcutException nsfse) {
703                     DLFileShortcutLocalServiceUtil.addFileShortcut(
704                         fileShortcut.getUuid(), userId, folderId, toFolderId,
705                         toName, addCommunityPermissions, addGuestPermissions);
706                 }
707             }
708             else {
709                 DLFileShortcutLocalServiceUtil.addFileShortcut(
710                     userId, folderId, toFolderId, toName,
711                     addCommunityPermissions, addGuestPermissions);
712             }
713         }
714         catch (NoSuchFolderException nsfe) {
715             _log.error(
716                 "Could not find the folder for shortcut " +
717                     fileShortcut.getFileShortcutId());
718         }
719     }
720 
721     private static final String _NAMESPACE = "document_library";
722 
723     private static final PortletDataHandlerBoolean _foldersAndDocuments =
724         new PortletDataHandlerBoolean(
725             _NAMESPACE, "folders-and-documents", true, true);
726 
727     private static final PortletDataHandlerBoolean _ranks =
728         new PortletDataHandlerBoolean(_NAMESPACE, "ranks");
729 
730     private static final PortletDataHandlerBoolean _shortcuts=
731         new PortletDataHandlerBoolean(_NAMESPACE, "shortcuts");
732 
733     private static final PortletDataHandlerBoolean _comments =
734         new PortletDataHandlerBoolean(_NAMESPACE, "comments");
735 
736     private static final PortletDataHandlerBoolean _ratings =
737         new PortletDataHandlerBoolean(_NAMESPACE, "ratings");
738 
739     private static final PortletDataHandlerBoolean _tags =
740         new PortletDataHandlerBoolean(_NAMESPACE, "tags");
741 
742     private static Log _log = LogFactory.getLog(DLPortletDataHandlerImpl.class);
743 
744 }