List of usage examples for com.liferay.portal.kernel.webdav WebDAVUtil getResourceName
public static String getResourceName(String[] pathArray)
From source file:com.liferay.compat.hook.webdav.CompatDLWebDAVStorageImpl.java
License:Open Source License
public Status lockResource(WebDAVRequest webDAVRequest, String owner, long timeout) throws WebDAVException { Resource resource = getResource(webDAVRequest); Lock lock = null;/*from w w w. ja v a 2s. c om*/ int status = HttpServletResponse.SC_OK; try { if (resource == null) { status = HttpServletResponse.SC_CREATED; HttpServletRequest request = webDAVRequest.getHttpServletRequest(); String[] pathArray = webDAVRequest.getPathArray(); long companyId = webDAVRequest.getCompanyId(); long groupId = webDAVRequest.getGroupId(); long parentFolderId = getParentFolderId(companyId, pathArray); String title = WebDAVUtil.getResourceName(pathArray); String contentType = GetterUtil.get(request.getHeader(HttpHeaders.CONTENT_TYPE), ContentTypes.APPLICATION_OCTET_STREAM); if (contentType.equals(ContentTypes.APPLICATION_OCTET_STREAM)) { contentType = MimeTypesUtil.getContentType(request.getInputStream(), title); } String description = StringPool.BLANK; String changeLog = StringPool.BLANK; File file = FileUtil.createTempFile(FileUtil.getExtension(title)); file.createNewFile(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId)); serviceContext.setAddGuestPermissions(true); FileEntry fileEntry = DLAppServiceUtil.addFileEntry(groupId, parentFolderId, title, contentType, title, description, changeLog, file, serviceContext); resource = toResource(webDAVRequest, fileEntry, false); } if (isInstanceOfDLFileEntryResourceImpl(super.getResource(webDAVRequest))) { FileEntry fileEntry = (FileEntry) resource.getModel(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAttribute(DLUtil.MANUAL_CHECK_IN_REQUIRED, CompatWebDAVThreadLocal.isManualCheckInRequired()); DLAppServiceUtil.checkOutFileEntry(fileEntry.getFileEntryId(), owner, timeout, serviceContext); lock = fileEntry.getLock(); } else { boolean inheritable = false; long depth = WebDAVUtil.getDepth(webDAVRequest.getHttpServletRequest()); if (depth != 0) { inheritable = true; } Folder folder = (Folder) resource.getModel(); lock = DLAppServiceUtil.lockFolder(folder.getRepositoryId(), folder.getFolderId(), owner, inheritable, timeout); } } catch (Exception e) { // DuplicateLock is 423 not 501 if (!(e instanceof DuplicateLockException)) { throw new WebDAVException(e); } status = WebDAVUtil.SC_LOCKED; } return new Status(lock, status); }
From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public int copyCollectionResource(WebDAVRequest webDAVRequest, Resource resource, String destination, boolean overwrite, long depth) throws WebDAVException { try {/*w ww . ja va2s . c o m*/ String[] destinationArray = WebDAVUtil.getPathArray(destination, true); long companyId = webDAVRequest.getCompanyId(); long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID; try { parentFolderId = getParentFolderId(companyId, destinationArray); } catch (NoSuchFolderException nsfe) { if (_log.isDebugEnabled()) { _log.debug(nsfe, nsfe); } return HttpServletResponse.SC_CONFLICT; } Folder folder = (Folder) resource.getModel(); long groupId = WebDAVUtil.getGroupId(companyId, destination); String name = WebDAVUtil.getResourceName(destinationArray); String description = folder.getDescription(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId)); serviceContext.setAddGuestPermissions(true); int status = HttpServletResponse.SC_CREATED; if (overwrite) { if (deleteResource(groupId, parentFolderId, name, webDAVRequest.getLockUuid())) { status = HttpServletResponse.SC_NO_CONTENT; } } if (depth == 0) { _dlAppService.addFolder(groupId, parentFolderId, name, description, serviceContext); } else { _dlAppService.copyFolder(groupId, folder.getFolderId(), parentFolderId, name, description, serviceContext); } return status; } catch (DuplicateFolderNameException dfne) { if (_log.isDebugEnabled()) { _log.debug(dfne, dfne); } return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (PrincipalException pe) { if (_log.isDebugEnabled()) { _log.debug(pe, pe); } return HttpServletResponse.SC_FORBIDDEN; } catch (Exception e) { throw new WebDAVException(e); } }
From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public Resource getResource(WebDAVRequest webDAVRequest) throws WebDAVException { try {/*from w w w.j a v a 2 s . c o m*/ String[] pathArray = webDAVRequest.getPathArray(); long companyId = webDAVRequest.getCompanyId(); long parentFolderId = getParentFolderId(companyId, pathArray); String name = WebDAVUtil.getResourceName(pathArray); if (Validator.isNull(name)) { String path = getRootPath() + webDAVRequest.getPath(); return new BaseResourceImpl(path, StringPool.BLANK, getToken()); } try { Folder folder = _dlAppService.getFolder(webDAVRequest.getGroupId(), parentFolderId, name); if ((folder.getParentFolderId() != parentFolderId) || (webDAVRequest.getGroupId() != folder.getRepositoryId())) { StringBundler sb = new StringBundler(6); sb.append("No DLFolder exists with the key "); sb.append("{parendFolderId="); sb.append(parentFolderId); sb.append(", repositoryId="); sb.append(webDAVRequest.getGroupId()); sb.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchFolderException(sb.toString()); } return toResource(webDAVRequest, folder, false); } catch (NoSuchFolderException nsfe) { if (_log.isDebugEnabled()) { _log.debug(nsfe, nsfe); } try { String title = getTitle(pathArray); FileEntry fileEntry = _dlAppService.getFileEntry(webDAVRequest.getGroupId(), parentFolderId, title); return toResource(webDAVRequest, fileEntry, false); } catch (NoSuchFileEntryException nsfee) { if (_log.isDebugEnabled()) { _log.debug(nsfee, nsfee); } return null; } } } catch (Exception e) { throw new WebDAVException(e); } }
From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public Status makeCollection(WebDAVRequest webDAVRequest) throws WebDAVException { try {//from w ww .j ava 2s . c o m HttpServletRequest request = webDAVRequest.getHttpServletRequest(); if (request.getContentLength() > 0) { return new Status(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); } String[] pathArray = webDAVRequest.getPathArray(); long companyId = webDAVRequest.getCompanyId(); long groupId = webDAVRequest.getGroupId(); long parentFolderId = getParentFolderId(companyId, pathArray); String name = WebDAVUtil.getResourceName(pathArray); String description = StringPool.BLANK; ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId)); serviceContext.setAddGuestPermissions(true); _dlAppService.addFolder(groupId, parentFolderId, name, description, serviceContext); String location = StringUtil.merge(pathArray, StringPool.SLASH); return new Status(location, HttpServletResponse.SC_CREATED); } catch (DuplicateFolderNameException dfne) { if (_log.isDebugEnabled()) { _log.debug(dfne, dfne); } return new Status(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } catch (DuplicateFileEntryException dfee) { if (_log.isDebugEnabled()) { _log.debug(dfee, dfee); } return new Status(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } catch (NoSuchFolderException nsfe) { if (_log.isDebugEnabled()) { _log.debug(nsfe, nsfe); } return new Status(HttpServletResponse.SC_CONFLICT); } catch (PrincipalException pe) { if (_log.isDebugEnabled()) { _log.debug(pe, pe); } return new Status(HttpServletResponse.SC_FORBIDDEN); } catch (Exception e) { throw new WebDAVException(e); } }
From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public int moveCollectionResource(WebDAVRequest webDAVRequest, Resource resource, String destination, boolean overwrite) throws WebDAVException { try {// w w w.ja v a 2 s .c o m String[] destinationArray = WebDAVUtil.getPathArray(destination, true); Folder folder = (Folder) resource.getModel(); long companyId = webDAVRequest.getCompanyId(); long groupId = WebDAVUtil.getGroupId(companyId, destinationArray); long folderId = folder.getFolderId(); long parentFolderId = getParentFolderId(companyId, destinationArray); String name = WebDAVUtil.getResourceName(destinationArray); String description = folder.getDescription(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setUserId(webDAVRequest.getUserId()); int status = HttpServletResponse.SC_CREATED; if (overwrite) { if (deleteResource(groupId, parentFolderId, name, webDAVRequest.getLockUuid())) { status = HttpServletResponse.SC_NO_CONTENT; } } if (parentFolderId != folder.getParentFolderId()) { _dlAppService.moveFolder(folderId, parentFolderId, serviceContext); } if (!name.equals(folder.getName())) { _dlAppService.updateFolder(folderId, name, description, serviceContext); } return status; } catch (PrincipalException pe) { if (_log.isDebugEnabled()) { _log.debug(pe, pe); } return HttpServletResponse.SC_FORBIDDEN; } catch (DuplicateFolderNameException dfne) { if (_log.isDebugEnabled()) { _log.debug(dfne, dfne); } return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (Exception e) { throw new WebDAVException(e); } }
From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java
License:Open Source License
protected String getTitle(String[] pathArray) { return DLWebDAVUtil.unescapeRawTitle(WebDAVUtil.getResourceName(pathArray)); }
From source file:com.liferay.portlet.documentlibrary.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public int copyCollectionResource(WebDAVRequest webDavRequest, Resource resource, String destination, boolean overwrite, long depth) throws WebDAVException { try {/*from www . j av a 2s. c o m*/ String[] destinationArray = WebDAVUtil.getPathArray(destination, true); long companyId = webDavRequest.getCompanyId(); long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID; try { parentFolderId = getParentFolderId(companyId, destinationArray); } catch (NoSuchFolderException nsfe) { return HttpServletResponse.SC_CONFLICT; } Folder folder = (Folder) resource.getModel(); long groupId = WebDAVUtil.getGroupId(companyId, destination); String name = WebDAVUtil.getResourceName(destinationArray); String description = folder.getDescription(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId)); serviceContext.setAddGuestPermissions(true); int status = HttpServletResponse.SC_CREATED; if (overwrite) { if (deleteResource(groupId, parentFolderId, name, webDavRequest.getLockUuid())) { status = HttpServletResponse.SC_NO_CONTENT; } } if (depth == 0) { DLAppServiceUtil.addFolder(groupId, parentFolderId, name, description, serviceContext); } else { DLAppServiceUtil.copyFolder(groupId, folder.getFolderId(), parentFolderId, name, description, serviceContext); } return status; } catch (DuplicateFolderNameException dfne) { return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (PrincipalException pe) { return HttpServletResponse.SC_FORBIDDEN; } catch (Exception e) { throw new WebDAVException(e); } }
From source file:com.liferay.portlet.documentlibrary.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public int copySimpleResource(WebDAVRequest webDavRequest, Resource resource, String destination, boolean overwrite) throws WebDAVException { File file = null;//w ww . ja v a2 s . co m try { String[] destinationArray = WebDAVUtil.getPathArray(destination, true); long companyId = webDavRequest.getCompanyId(); long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID; try { parentFolderId = getParentFolderId(companyId, destinationArray); } catch (NoSuchFolderException nsfe) { return HttpServletResponse.SC_CONFLICT; } FileEntry fileEntry = (FileEntry) resource.getModel(); long groupId = WebDAVUtil.getGroupId(companyId, destination); String mimeType = fileEntry.getMimeType(); String title = WebDAVUtil.getResourceName(destinationArray); String description = fileEntry.getDescription(); String changeLog = StringPool.BLANK; InputStream is = fileEntry.getContentStream(); file = FileUtil.createTempFile(is); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId)); serviceContext.setAddGuestPermissions(true); int status = HttpServletResponse.SC_CREATED; if (overwrite) { if (deleteResource(groupId, parentFolderId, title, webDavRequest.getLockUuid())) { status = HttpServletResponse.SC_NO_CONTENT; } } DLAppServiceUtil.addFileEntry(groupId, parentFolderId, title, mimeType, title, description, changeLog, file, serviceContext); return status; } catch (DuplicateFileException dfe) { return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (DuplicateFolderNameException dfne) { return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (LockException le) { return WebDAVUtil.SC_LOCKED; } catch (PrincipalException pe) { return HttpServletResponse.SC_FORBIDDEN; } catch (Exception e) { throw new WebDAVException(e); } finally { FileUtil.delete(file); } }
From source file:com.liferay.portlet.documentlibrary.webdav.DLWebDAVStorageImpl.java
License:Open Source License
public Resource getResource(WebDAVRequest webDavRequest) throws WebDAVException { try {//from w w w . j ava 2 s .co m String[] pathArray = webDavRequest.getPathArray(); long companyId = webDavRequest.getCompanyId(); long parentFolderId = getParentFolderId(companyId, pathArray); String name = WebDAVUtil.getResourceName(pathArray); if (Validator.isNull(name)) { String path = getRootPath() + webDavRequest.getPath(); return new BaseResourceImpl(path, StringPool.BLANK, getToken()); } try { Folder folder = DLAppServiceUtil.getFolder(webDavRequest.getGroupId(), parentFolderId, name); if ((folder.getParentFolderId() != parentFolderId) || (webDavRequest.getGroupId() != folder.getRepositoryId())) { throw new NoSuchFolderException(); } return toResource(webDavRequest, folder, false); } catch (NoSuchFolderException nsfe) { try { String titleWithExtension = name; FileEntry fileEntry = DLAppServiceUtil.getFileEntry(webDavRequest.getGroupId(), parentFolderId, titleWithExtension); return toResource(webDavRequest, fileEntry, false); } catch (NoSuchFileEntryException nsfee) { return null; } } } catch (Exception e) { throw new WebDAVException(e); } }
From source file:com.liferay.portlet.documentlibrary.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public Status lockResource(WebDAVRequest webDavRequest, String owner, long timeout) throws WebDAVException { Resource resource = getResource(webDavRequest); Lock lock = null;/*from w ww . j av a2s . c om*/ int status = HttpServletResponse.SC_OK; try { if (resource == null) { status = HttpServletResponse.SC_CREATED; HttpServletRequest request = webDavRequest.getHttpServletRequest(); String[] pathArray = webDavRequest.getPathArray(); long companyId = webDavRequest.getCompanyId(); long groupId = webDavRequest.getGroupId(); long parentFolderId = getParentFolderId(companyId, pathArray); String title = WebDAVUtil.getResourceName(pathArray); String contentType = GetterUtil.get(request.getHeader(HttpHeaders.CONTENT_TYPE), ContentTypes.APPLICATION_OCTET_STREAM); if (contentType.equals(ContentTypes.APPLICATION_OCTET_STREAM)) { contentType = MimeTypesUtil.getContentType(request.getInputStream(), title); } String description = StringPool.BLANK; String changeLog = StringPool.BLANK; File file = FileUtil.createTempFile(FileUtil.getExtension(title)); file.createNewFile(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId)); serviceContext.setAddGuestPermissions(true); FileEntry fileEntry = DLAppServiceUtil.addFileEntry(groupId, parentFolderId, title, contentType, title, description, changeLog, file, serviceContext); resource = toResource(webDavRequest, fileEntry, false); } if (resource instanceof DLFileEntryResourceImpl) { FileEntry fileEntry = (FileEntry) resource.getModel(); lock = DLAppServiceUtil.lockFileEntry(fileEntry.getFileEntryId(), owner, timeout); } else { boolean inheritable = false; long depth = WebDAVUtil.getDepth(webDavRequest.getHttpServletRequest()); if (depth != 0) { inheritable = true; } Folder folder = (Folder) resource.getModel(); lock = DLAppServiceUtil.lockFolder(folder.getRepositoryId(), folder.getFolderId(), owner, inheritable, timeout); } } catch (Exception e) { // DuplicateLock is 423 not 501 if (!(e instanceof DuplicateLockException)) { throw new WebDAVException(e); } status = WebDAVUtil.SC_LOCKED; } return new Status(lock, status); }