1
14
15 package com.liferay.portlet.documentlibrary.webdav;
16
17 import com.liferay.documentlibrary.DuplicateFileException;
18 import com.liferay.portal.DuplicateLockException;
19 import com.liferay.portal.ExpiredLockException;
20 import com.liferay.portal.InvalidLockException;
21 import com.liferay.portal.NoSuchLockException;
22 import com.liferay.portal.PortalException;
23 import com.liferay.portal.kernel.log.Log;
24 import com.liferay.portal.kernel.log.LogFactoryUtil;
25 import com.liferay.portal.kernel.util.FileUtil;
26 import com.liferay.portal.kernel.util.StringPool;
27 import com.liferay.portal.kernel.util.StringUtil;
28 import com.liferay.portal.kernel.util.Validator;
29 import com.liferay.portal.model.Lock;
30 import com.liferay.portal.security.auth.PrincipalException;
31 import com.liferay.portal.webdav.BaseResourceImpl;
32 import com.liferay.portal.webdav.BaseWebDAVStorageImpl;
33 import com.liferay.portal.webdav.LockException;
34 import com.liferay.portal.webdav.Resource;
35 import com.liferay.portal.webdav.Status;
36 import com.liferay.portal.webdav.WebDAVException;
37 import com.liferay.portal.webdav.WebDAVRequest;
38 import com.liferay.portal.webdav.WebDAVUtil;
39 import com.liferay.portlet.documentlibrary.DuplicateFolderNameException;
40 import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
41 import com.liferay.portlet.documentlibrary.NoSuchFolderException;
42 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
43 import com.liferay.portlet.documentlibrary.model.DLFolder;
44 import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
45 import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
46 import com.liferay.portlet.documentlibrary.service.DLFileEntryServiceUtil;
47 import com.liferay.portlet.documentlibrary.service.DLFolderServiceUtil;
48 import com.liferay.portlet.tags.service.TagsEntryLocalServiceUtil;
49
50 import java.io.File;
51 import java.io.InputStream;
52
53 import java.util.ArrayList;
54 import java.util.List;
55
56 import javax.servlet.http.HttpServletRequest;
57 import javax.servlet.http.HttpServletResponse;
58
59
65 public class DLWebDAVStorageImpl extends BaseWebDAVStorageImpl {
66
67 public int copyCollectionResource(
68 WebDAVRequest webDavRequest, Resource resource, String destination,
69 boolean overwrite, long depth)
70 throws WebDAVException {
71
72 try {
73 String[] destinationArray = WebDAVUtil.getPathArray(
74 destination, true);
75
76 long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
77
78 try {
79 parentFolderId = getParentFolderId(destinationArray);
80 }
81 catch (NoSuchFolderException nsfe) {
82 return HttpServletResponse.SC_CONFLICT;
83 }
84
85 DLFolder folder = (DLFolder)resource.getModel();
86
87 long groupId = WebDAVUtil.getGroupId(destination);
88 long plid = getPlid(groupId);
89 String name = WebDAVUtil.getResourceName(destinationArray);
90 String description = folder.getDescription();
91 boolean addCommunityPermissions = isAddCommunityPermissions(
92 groupId);
93 boolean addGuestPermissions = true;
94
95 int status = HttpServletResponse.SC_CREATED;
96
97 if (overwrite) {
98 if (deleteResource(
99 groupId, parentFolderId, name,
100 webDavRequest.getLockUuid())) {
101
102 status = HttpServletResponse.SC_NO_CONTENT;
103 }
104 }
105
106 if (depth == 0) {
107 DLFolderServiceUtil.addFolder(
108 plid, parentFolderId, name, description,
109 addCommunityPermissions, addGuestPermissions);
110 }
111 else {
112 DLFolderServiceUtil.copyFolder(
113 plid, folder.getFolderId(), parentFolderId, name,
114 description, addCommunityPermissions, addGuestPermissions);
115 }
116
117 return status;
118 }
119 catch (DuplicateFolderNameException dfne) {
120 return HttpServletResponse.SC_PRECONDITION_FAILED;
121 }
122 catch (PrincipalException pe) {
123 return HttpServletResponse.SC_FORBIDDEN;
124 }
125 catch (Exception e) {
126 throw new WebDAVException(e);
127 }
128 }
129
130 public int copySimpleResource(
131 WebDAVRequest webDavRequest, Resource resource, String destination,
132 boolean overwrite)
133 throws WebDAVException {
134
135 File file = null;
136
137 try {
138 String[] destinationArray = WebDAVUtil.getPathArray(
139 destination, true);
140
141 long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
142
143 try {
144 parentFolderId = getParentFolderId(destinationArray);
145 }
146 catch (NoSuchFolderException nsfe) {
147 return HttpServletResponse.SC_CONFLICT;
148 }
149
150 DLFileEntry fileEntry = (DLFileEntry)resource.getModel();
151
152 long groupId = WebDAVUtil.getGroupId(destination);
153 long userId = webDavRequest.getUserId();
154 String name = WebDAVUtil.getResourceName(destinationArray);
155 String title = WebDAVUtil.getResourceName(destinationArray);
156 String description = fileEntry.getDescription();
157 String[] tagsEntries = null;
158 String extraSettings = fileEntry.getExtraSettings();
159
160 file = FileUtil.createTempFile(
161 FileUtil.getExtension(fileEntry.getName()));
162
163 InputStream is = DLFileEntryLocalServiceUtil.getFileAsStream(
164 fileEntry.getCompanyId(), userId, fileEntry.getFolderId(),
165 fileEntry.getName());
166
167 FileUtil.write(file, is);
168
169 boolean addCommunityPermissions = isAddCommunityPermissions(
170 groupId);
171 boolean addGuestPermissions = true;
172
173 int status = HttpServletResponse.SC_CREATED;
174
175 if (overwrite) {
176 if (deleteResource(
177 groupId, parentFolderId, title,
178 webDavRequest.getLockUuid())) {
179
180 status = HttpServletResponse.SC_NO_CONTENT;
181 }
182 }
183
184 DLFileEntryServiceUtil.addFileEntry(
185 parentFolderId, name, title, description, tagsEntries,
186 extraSettings, file, addCommunityPermissions,
187 addGuestPermissions);
188
189 return status;
190 }
191 catch (DuplicateFileException dfe) {
192 return HttpServletResponse.SC_PRECONDITION_FAILED;
193 }
194 catch (DuplicateFolderNameException dfne) {
195 return HttpServletResponse.SC_PRECONDITION_FAILED;
196 }
197 catch (LockException le) {
198 return WebDAVUtil.SC_LOCKED;
199 }
200 catch (PrincipalException pe) {
201 return HttpServletResponse.SC_FORBIDDEN;
202 }
203 catch (Exception e) {
204 throw new WebDAVException(e);
205 }
206 finally {
207 if (file != null) {
208 file.delete();
209 }
210 }
211 }
212
213 public int deleteResource(WebDAVRequest webDavRequest)
214 throws WebDAVException {
215
216 try {
217 Resource resource = getResource(webDavRequest);
218
219 if (resource == null) {
220 return HttpServletResponse.SC_NOT_FOUND;
221 }
222
223 Object model = resource.getModel();
224
225 if (model instanceof DLFolder) {
226 DLFolder folder = (DLFolder)model;
227
228 DLFolderServiceUtil.deleteFolder(folder.getFolderId());
229 }
230 else {
231 DLFileEntry fileEntry = (DLFileEntry)model;
232
233 if (isLocked(fileEntry, webDavRequest.getLockUuid())) {
234 return WebDAVUtil.SC_LOCKED;
235 }
236
237 DLFileEntryServiceUtil.deleteFileEntry(
238 fileEntry.getFolderId(), fileEntry.getName());
239 }
240
241 return HttpServletResponse.SC_NO_CONTENT;
242 }
243 catch (PrincipalException pe) {
244 return HttpServletResponse.SC_FORBIDDEN;
245 }
246 catch (Exception e) {
247 throw new WebDAVException(e);
248 }
249 }
250
251 public Resource getResource(WebDAVRequest webDavRequest)
252 throws WebDAVException {
253
254 try {
255 String[] pathArray = webDavRequest.getPathArray();
256
257 long parentFolderId = getParentFolderId(pathArray);
258 String name = WebDAVUtil.getResourceName(pathArray);
259
260 if (Validator.isNull(name)) {
261 String path = getRootPath() + webDavRequest.getPath();
262
263 return new BaseResourceImpl(path, StringPool.BLANK, getToken());
264 }
265
266 try {
267 DLFolder folder = DLFolderServiceUtil.getFolder(
268 webDavRequest.getGroupId(), parentFolderId, name);
269
270 if ((folder.getParentFolderId() != parentFolderId) ||
271 (webDavRequest.getGroupId() != folder.getGroupId())) {
272
273 throw new NoSuchFolderException();
274 }
275
276 return toResource(webDavRequest, folder, false);
277 }
278 catch (NoSuchFolderException nsfe) {
279 try {
280 String titleWithExtension = name;
281
282 DLFileEntry fileEntry =
283 DLFileEntryServiceUtil.getFileEntryByTitle(
284 parentFolderId, titleWithExtension);
285
286 return toResource(webDavRequest, fileEntry, false);
287 }
288 catch (NoSuchFileEntryException nsfee) {
289 return null;
290 }
291 }
292 }
293 catch (Exception e) {
294 throw new WebDAVException(e);
295 }
296 }
297
298 public List<Resource> getResources(WebDAVRequest webDavRequest)
299 throws WebDAVException {
300
301 try {
302 long folderId = getFolderId(webDavRequest.getPathArray());
303
304 List<Resource> folders = getFolders(webDavRequest, folderId);
305 List<Resource> fileEntries = getFileEntries(
306 webDavRequest, folderId);
307
308 List<Resource> resources = new ArrayList<Resource>(
309 folders.size() + fileEntries.size());
310
311 resources.addAll(folders);
312 resources.addAll(fileEntries);
313
314 return resources;
315 }
316 catch (Exception e) {
317 throw new WebDAVException(e);
318 }
319 }
320
321 public boolean isSupportsClassTwo() {
322 return true;
323 }
324
325 public Status lockResource(
326 WebDAVRequest webDavRequest, String owner, long timeout)
327 throws WebDAVException {
328
329 Resource resource = getResource(webDavRequest);
330
331 Lock lock = null;
332 int status = HttpServletResponse.SC_OK;
333
334 try {
335 if (resource == null) {
336 status = HttpServletResponse.SC_CREATED;
337
338 String[] pathArray = webDavRequest.getPathArray();
339
340 long groupId = webDavRequest.getGroupId();
341 long parentFolderId = getParentFolderId(pathArray);
342 String name = WebDAVUtil.getResourceName(pathArray);
343
344 String title = name;
345 String description = StringPool.BLANK;
346 String[] tagsEntries = null;
347 String extraSettings = StringPool.BLANK;
348 boolean addCommunityPermissions = isAddCommunityPermissions(
349 groupId);
350 boolean addGuestPermissions = true;
351
352 File file = FileUtil.createTempFile(
353 FileUtil.getExtension(name));
354
355 file.createNewFile();
356
357 DLFileEntry fileEntry = DLFileEntryServiceUtil.addFileEntry(
358 parentFolderId, name, title, description, tagsEntries,
359 extraSettings, file, addCommunityPermissions,
360 addGuestPermissions);
361
362 resource = toResource(webDavRequest, fileEntry, false);
363 }
364
365 if (resource instanceof DLFileEntryResourceImpl) {
366 DLFileEntry fileEntry = (DLFileEntry)resource.getModel();
367
368 lock = DLFileEntryServiceUtil.lockFileEntry(
369 fileEntry.getFolderId(), fileEntry.getName(), owner,
370 timeout);
371 }
372 }
373 catch (Exception e) {
374
375
377 if (!(e instanceof DuplicateLockException)) {
378 throw new WebDAVException(e);
379 }
380
381 status = WebDAVUtil.SC_LOCKED;
382 }
383
384 return new Status(lock, status);
385 }
386
387 public Status makeCollection(WebDAVRequest webDavRequest)
388 throws WebDAVException {
389
390 try {
391 HttpServletRequest request = webDavRequest.getHttpServletRequest();
392
393 if (request.getContentLength() > 0) {
394 return new Status(
395 HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
396 }
397
398 String[] pathArray = webDavRequest.getPathArray();
399
400 long groupId = webDavRequest.getGroupId();
401 long plid = getPlid(groupId);
402 long parentFolderId = getParentFolderId(pathArray);
403 String name = WebDAVUtil.getResourceName(pathArray);
404 String description = StringPool.BLANK;
405 boolean addCommunityPermissions = isAddCommunityPermissions(
406 groupId);
407 boolean addGuestPermissions = true;
408
409 DLFolderServiceUtil.addFolder(
410 plid, parentFolderId, name, description,
411 addCommunityPermissions, addGuestPermissions);
412
413 String location = StringUtil.merge(pathArray, StringPool.SLASH);
414
415 return new Status(location, HttpServletResponse.SC_CREATED);
416 }
417 catch (DuplicateFolderNameException dfne) {
418 return new Status(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
419 }
420 catch (DuplicateFileException dfe) {
421 return new Status(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
422 }
423 catch (NoSuchFolderException nsfe) {
424 return new Status(HttpServletResponse.SC_CONFLICT);
425 }
426 catch (PrincipalException pe) {
427 return new Status(HttpServletResponse.SC_FORBIDDEN);
428 }
429 catch (Exception e) {
430 throw new WebDAVException(e);
431 }
432 }
433
434 public int moveCollectionResource(
435 WebDAVRequest webDavRequest, Resource resource, String destination,
436 boolean overwrite)
437 throws WebDAVException {
438
439 try {
440 String[] destinationArray = WebDAVUtil.getPathArray(
441 destination, true);
442
443 DLFolder folder = (DLFolder)resource.getModel();
444
445 long groupId = WebDAVUtil.getGroupId(destinationArray);
446 long folderId = folder.getFolderId();
447 long parentFolderId = getParentFolderId(destinationArray);
448 String name = WebDAVUtil.getResourceName(destinationArray);
449 String description = folder.getDescription();
450
451 int status = HttpServletResponse.SC_CREATED;
452
453 if (overwrite) {
454 if (deleteResource(
455 groupId, parentFolderId, name,
456 webDavRequest.getLockUuid())) {
457
458 status = HttpServletResponse.SC_NO_CONTENT;
459 }
460 }
461
462 DLFolderServiceUtil.updateFolder(
463 folderId, parentFolderId, name, description);
464
465 return status;
466 }
467 catch (PrincipalException pe) {
468 return HttpServletResponse.SC_FORBIDDEN;
469 }
470 catch (DuplicateFolderNameException dfne) {
471 return HttpServletResponse.SC_PRECONDITION_FAILED;
472 }
473 catch (Exception e) {
474 throw new WebDAVException(e);
475 }
476 }
477
478 public int moveSimpleResource(
479 WebDAVRequest webDavRequest, Resource resource, String destination,
480 boolean overwrite)
481 throws WebDAVException {
482
483 try {
484 String[] destinationArray = WebDAVUtil.getPathArray(
485 destination, true);
486
487 DLFileEntry fileEntry = (DLFileEntry)resource.getModel();
488
489 if (isLocked(fileEntry, webDavRequest.getLockUuid())) {
490 return WebDAVUtil.SC_LOCKED;
491 }
492
493 long groupId = WebDAVUtil.getGroupId(destinationArray);
494 long userId = webDavRequest.getUserId();
495 long parentFolderId = getParentFolderId(destinationArray);
496 String name = fileEntry.getName();
497 String sourceFileName = null;
498 String title = WebDAVUtil.getResourceName(destinationArray);
499 String description = fileEntry.getDescription();
500 String[] tagsEntries = null;
501 String extraSettings = fileEntry.getExtraSettings();
502 byte[] bytes = null;
503
504 int status = HttpServletResponse.SC_CREATED;
505
506 if (overwrite) {
507 if (deleteResource(
508 groupId, parentFolderId, title,
509 webDavRequest.getLockUuid())) {
510
511 status = HttpServletResponse.SC_NO_CONTENT;
512 }
513 }
514
515
517 if (webDavRequest.isMac()) {
518 try {
519 DLFileEntry destFileEntry =
520 DLFileEntryServiceUtil.getFileEntryByTitle(
521 parentFolderId, title);
522
523 InputStream is =
524 DLFileEntryLocalServiceUtil.getFileAsStream(
525 fileEntry.getCompanyId(), userId,
526 fileEntry.getFolderId(), fileEntry.getName());
527
528 bytes = FileUtil.getBytes(is);
529
530 DLFileEntryServiceUtil.updateFileEntry(
531 parentFolderId, parentFolderId, destFileEntry.getName(),
532 destFileEntry.getTitle(), destFileEntry.getTitle(),
533 destFileEntry.getDescription(), tagsEntries,
534 destFileEntry.getExtraSettings(), bytes);
535
536 DLFileEntryServiceUtil.deleteFileEntry(
537 fileEntry.getFolderId(), fileEntry.getName());
538
539 return status;
540 }
541 catch (NoSuchFileEntryException nsfee) {
542 }
543 }
544
545 DLFileEntryServiceUtil.updateFileEntry(
546 fileEntry.getFolderId(), parentFolderId, name, sourceFileName,
547 title, description, tagsEntries, extraSettings, bytes);
548
549 return status;
550 }
551 catch (PrincipalException pe) {
552 return HttpServletResponse.SC_FORBIDDEN;
553 }
554 catch (DuplicateFileException dfe) {
555 return HttpServletResponse.SC_PRECONDITION_FAILED;
556 }
557 catch (DuplicateFolderNameException dfne) {
558 return HttpServletResponse.SC_PRECONDITION_FAILED;
559 }
560 catch (LockException le) {
561 return WebDAVUtil.SC_LOCKED;
562 }
563 catch (Exception e) {
564 throw new WebDAVException(e);
565 }
566 }
567
568 public int putResource(WebDAVRequest webDavRequest) throws WebDAVException {
569 File file = null;
570
571 try {
572 HttpServletRequest request = webDavRequest.getHttpServletRequest();
573
574 String[] pathArray = webDavRequest.getPathArray();
575
576 long groupId = webDavRequest.getGroupId();
577 long parentFolderId = getParentFolderId(pathArray);
578 String name = WebDAVUtil.getResourceName(pathArray);
579 String title = name;
580 String description = StringPool.BLANK;
581 String[] tagsEntries = null;
582 String extraSettings = StringPool.BLANK;
583 boolean addCommunityPermissions = isAddCommunityPermissions(
584 groupId);
585 boolean addGuestPermissions = true;
586
587 try {
588 DLFileEntry entry = DLFileEntryServiceUtil.getFileEntryByTitle(
589 parentFolderId, name);
590
591 if (isLocked(entry, webDavRequest.getLockUuid())) {
592 return WebDAVUtil.SC_LOCKED;
593 }
594
595 name = entry.getName();
596 description = entry.getDescription();
597 tagsEntries = TagsEntryLocalServiceUtil.getEntryNames(
598 DLFileEntry.class.getName(), entry.getFileEntryId());
599 extraSettings = entry.getExtraSettings();
600
601 file = FileUtil.createTempFile(FileUtil.getExtension(name));
602
603 FileUtil.write(file, request.getInputStream());
604
605 DLFileEntryServiceUtil.updateFileEntry(
606 parentFolderId, parentFolderId, name, title, title,
607 description, tagsEntries, extraSettings, file);
608 }
609 catch (NoSuchFileEntryException nsfee) {
610 file = FileUtil.createTempFile(FileUtil.getExtension(name));
611
612 FileUtil.write(file, request.getInputStream());
613
614 DLFileEntryServiceUtil.addFileEntry(
615 parentFolderId, name, title, description, tagsEntries,
616 extraSettings, file, addCommunityPermissions,
617 addGuestPermissions);
618 }
619
620 return HttpServletResponse.SC_CREATED;
621 }
622 catch (PrincipalException pe) {
623 return HttpServletResponse.SC_FORBIDDEN;
624 }
625 catch (NoSuchFolderException nsfe) {
626 return HttpServletResponse.SC_CONFLICT;
627 }
628 catch (PortalException pe) {
629 if (_log.isWarnEnabled()) {
630 _log.warn(pe, pe);
631 }
632
633 return HttpServletResponse.SC_CONFLICT;
634 }
635 catch (Exception e) {
636 throw new WebDAVException(e);
637 }
638 finally {
639 if (file != null) {
640 file.delete();
641 }
642 }
643 }
644
645 public Lock refreshResourceLock(
646 WebDAVRequest webDavRequest, String uuid, long timeout)
647 throws WebDAVException {
648
649 Resource resource = getResource(webDavRequest);
650
651 Lock lock = null;
652
653 if (resource instanceof DLFileEntryResourceImpl) {
654 try {
655 lock = DLFileEntryServiceUtil.refreshFileEntryLock(
656 uuid, timeout);
657 }
658 catch (Exception e) {
659 throw new WebDAVException(e);
660 }
661 }
662
663 return lock;
664 }
665
666 public boolean unlockResource(WebDAVRequest webDavRequest, String token)
667 throws WebDAVException {
668
669 Resource resource = getResource(webDavRequest);
670
671 try {
672 if (resource instanceof DLFileEntryResourceImpl) {
673 DLFileEntry fileEntry = (DLFileEntry)resource.getModel();
674
675 DLFileEntryServiceUtil.unlockFileEntry(
676 fileEntry.getFolderId(), fileEntry.getName(), token);
677
678 return true;
679 }
680 }
681 catch (Exception e) {
682 if (e instanceof InvalidLockException) {
683 if (_log.isWarnEnabled()) {
684 _log.warn(e.getMessage());
685 }
686 }
687 else {
688 if (_log.isWarnEnabled()) {
689 _log.warn("Unable to unlock file entry", e);
690 }
691 }
692 }
693
694 return false;
695 }
696
697 protected boolean deleteResource(
698 long groupId, long parentFolderId, String name, String lockUuid)
699 throws Exception {
700
701 try {
702 DLFolder folder = DLFolderServiceUtil.getFolder(
703 groupId, parentFolderId, name);
704
705 DLFolderServiceUtil.deleteFolder(folder.getFolderId());
706
707 return true;
708 }
709 catch (NoSuchFolderException nsfe) {
710 try {
711 DLFileEntry fileEntry =
712 DLFileEntryServiceUtil.getFileEntryByTitle(
713 parentFolderId, name);
714
715 if (isLocked(fileEntry, lockUuid)) {
716 throw new LockException();
717 }
718
719 DLFileEntryServiceUtil.deleteFileEntryByTitle(
720 parentFolderId, name);
721
722 return true;
723 }
724 catch (NoSuchFileEntryException nsfee) {
725 }
726 }
727
728 return false;
729 }
730
731 protected List<Resource> getFileEntries(
732 WebDAVRequest webDavRequest, long parentFolderId)
733 throws Exception {
734
735 List<Resource> resources = new ArrayList<Resource>();
736
737 List<DLFileEntry> fileEntries = DLFileEntryServiceUtil.getFileEntries(
738 parentFolderId);
739
740 for (DLFileEntry fileEntry : fileEntries) {
741 Resource resource = toResource(webDavRequest, fileEntry, true);
742
743 resources.add(resource);
744 }
745
746 return resources;
747 }
748
749 protected long getFolderId(String[] pathArray) throws Exception {
750 return getFolderId(pathArray, false);
751 }
752
753 protected long getFolderId(String[] pathArray, boolean parent)
754 throws Exception {
755
756 long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
757
758 if (pathArray.length <= 2) {
759 return folderId;
760 }
761 else {
762 long groupId = WebDAVUtil.getGroupId(pathArray);
763
764 int x = pathArray.length;
765
766 if (parent) {
767 x--;
768 }
769
770 for (int i = 3; i < x; i++) {
771 String name = pathArray[i];
772
773 DLFolder folder = DLFolderServiceUtil.getFolder(
774 groupId, folderId, name);
775
776 if (groupId == folder.getGroupId()) {
777 folderId = folder.getFolderId();
778 }
779 }
780 }
781
782 return folderId;
783 }
784
785 protected List<Resource> getFolders(
786 WebDAVRequest webDavRequest, long parentFolderId)
787 throws Exception {
788
789 List<Resource> resources = new ArrayList<Resource>();
790
791 long groupId = webDavRequest.getGroupId();
792
793 List<DLFolder> folders = DLFolderServiceUtil.getFolders(
794 groupId, parentFolderId);
795
796 for (DLFolder folder : folders) {
797 Resource resource = toResource(webDavRequest, folder, true);
798
799 resources.add(resource);
800 }
801
802 return resources;
803 }
804
805 protected long getParentFolderId(String[] pathArray) throws Exception {
806 return getFolderId(pathArray, true);
807 }
808
809 protected boolean isLocked(DLFileEntry fileEntry, String lockUuid)
810 throws Exception {
811
812 long parentFolderId = fileEntry.getFolderId();
813 String fileName = fileEntry.getName();
814
815 return isLocked(parentFolderId, fileName, lockUuid);
816 }
817
818 protected boolean isLocked(
819 long parentFolderId, String fileName, String lockUuid)
820 throws Exception {
821
822 boolean locked = false;
823
824 try {
825 Lock lock = DLFileEntryServiceUtil.getFileEntryLock(
826 parentFolderId, fileName);
827
828 if (!lock.getUuid().equals(lockUuid)) {
829 locked = true;
830 }
831 }
832 catch (PortalException pe) {
833 if (pe instanceof ExpiredLockException ||
834 pe instanceof NoSuchLockException) {
835 }
836 else {
837 throw pe;
838 }
839 }
840
841 return locked;
842 }
843
844 protected Resource toResource(
845 WebDAVRequest webDavRequest, DLFileEntry fileEntry,
846 boolean appendPath) {
847
848 String parentPath = getRootPath() + webDavRequest.getPath();
849 String name = StringPool.BLANK;
850
851 if (appendPath) {
852 name = fileEntry.getTitleWithExtension();
853 }
854
855 return new DLFileEntryResourceImpl(
856 webDavRequest, fileEntry, parentPath, name);
857 }
858
859 protected Resource toResource(
860 WebDAVRequest webDavRequest, DLFolder folder, boolean appendPath) {
861
862 String parentPath = getRootPath() + webDavRequest.getPath();
863 String name = StringPool.BLANK;
864
865 if (appendPath) {
866 name = folder.getName();
867 }
868
869 Resource resource = new BaseResourceImpl(
870 parentPath, name, folder.getName(), folder.getCreateDate(),
871 folder.getModifiedDate());
872
873 resource.setModel(folder);
874 resource.setClassName(DLFolder.class.getName());
875 resource.setPrimaryKey(folder.getPrimaryKey());
876
877 return resource;
878 }
879
880 private static Log _log = LogFactoryUtil.getLog(DLWebDAVStorageImpl.class);
881
882 }