Example usage for com.liferay.portal.kernel.webdav WebDAVUtil SC_LOCKED

List of usage examples for com.liferay.portal.kernel.webdav WebDAVUtil SC_LOCKED

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.webdav WebDAVUtil SC_LOCKED.

Prototype

int SC_LOCKED

To view the source code for com.liferay.portal.kernel.webdav WebDAVUtil SC_LOCKED.

Click Source Link

Usage

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;//w  w  w.j  a  va 2 s .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 copySimpleResource(WebDAVRequest webDAVRequest, Resource resource, String destination,
        boolean overwrite) throws WebDAVException {

    File file = null;//w ww  .j  a  v a 2 s. c o 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) {
            if (_log.isDebugEnabled()) {
                _log.debug(nsfe, nsfe);
            }

            return HttpServletResponse.SC_CONFLICT;
        }

        FileEntry fileEntry = (FileEntry) resource.getModel();

        long groupId = WebDAVUtil.getGroupId(companyId, destination);
        String mimeType = fileEntry.getMimeType();
        String title = getTitle(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;
            }
        }

        _dlAppService.addFileEntry(groupId, parentFolderId, title, mimeType, title, description, changeLog,
                file, serviceContext);

        return status;
    } catch (DuplicateFileEntryException dfee) {
        if (_log.isDebugEnabled()) {
            _log.debug(dfee, dfee);
        }

        return HttpServletResponse.SC_PRECONDITION_FAILED;
    } catch (DuplicateFolderNameException dfne) {
        if (_log.isDebugEnabled()) {
            _log.debug(dfne, dfne);
        }

        return HttpServletResponse.SC_PRECONDITION_FAILED;
    } catch (LockException le) {
        if (_log.isDebugEnabled()) {
            _log.debug(le, le);
        }

        return WebDAVUtil.SC_LOCKED;
    } catch (PrincipalException pe) {
        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }

        return HttpServletResponse.SC_FORBIDDEN;
    } catch (Exception e) {
        throw new WebDAVException(e);
    } finally {
        FileUtil.delete(file);
    }
}

From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java

License:Open Source License

@Override
public int deleteResource(WebDAVRequest webDAVRequest) throws WebDAVException {

    try {//from   w  w w.ja va2s  .  c om
        Resource resource = getResource(webDAVRequest);

        if (resource == null) {
            if (webDAVRequest.isAppleDoubleRequest()) {
                return HttpServletResponse.SC_NO_CONTENT;
            } else {
                return HttpServletResponse.SC_NOT_FOUND;
            }
        }

        Object model = resource.getModel();

        if (model instanceof Folder) {
            Folder folder = (Folder) model;

            long folderId = folder.getFolderId();

            if ((folder.getModel() instanceof DLFolder)
                    && _dlTrashUtil.isTrashEnabled(folder.getGroupId(), folder.getRepositoryId())) {

                _dlTrashService.moveFolderToTrash(folderId);
            } else {
                _dlAppService.deleteFolder(folderId);
            }
        } else {
            FileEntry fileEntry = (FileEntry) model;

            if (!hasLock(fileEntry, webDAVRequest.getLockUuid()) && (fileEntry.getLock() != null)) {

                return WebDAVUtil.SC_LOCKED;
            }

            long fileEntryId = fileEntry.getFileEntryId();

            if ((fileEntry.getModel() instanceof DLFileEntry)
                    && _dlTrashUtil.isTrashEnabled(fileEntry.getGroupId(), fileEntry.getRepositoryId())) {

                _dlTrashService.moveFileEntryToTrash(fileEntryId);
            } else {
                _dlAppService.deleteFileEntry(fileEntryId);
            }
        }

        return HttpServletResponse.SC_NO_CONTENT;
    } 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 Status lockResource(WebDAVRequest webDAVRequest, String owner, long timeout) throws WebDAVException {

    Resource resource = getResource(webDAVRequest);

    Lock lock = null;/*from  ww w .  j  a  va 2 s  .  c  o m*/
    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 = getTitle(pathArray);

            String extension = FileUtil.getExtension(title);

            String contentType = getContentType(request, null, title, extension);

            String description = StringPool.BLANK;
            String changeLog = StringPool.BLANK;

            File file = FileUtil.createTempFile(extension);

            file.createNewFile();

            ServiceContext serviceContext = new ServiceContext();

            serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId));
            serviceContext.setAddGuestPermissions(true);

            FileEntry fileEntry = _dlAppService.addFileEntry(groupId, parentFolderId, title, contentType, title,
                    description, changeLog, file, serviceContext);

            resource = toResource(webDAVRequest, fileEntry, false);
        }

        if (resource instanceof DLFileEntryResourceImpl) {
            FileEntry fileEntry = (FileEntry) resource.getModel();

            ServiceContext serviceContext = new ServiceContext();

            serviceContext.setAttribute(DL.MANUAL_CHECK_IN_REQUIRED, webDAVRequest.isManualCheckInRequired());

            populateServiceContext(serviceContext, fileEntry);

            _dlAppService.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 = _dlAppService.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 moveSimpleResource(WebDAVRequest webDAVRequest, Resource resource, String destination,
        boolean overwrite) throws WebDAVException {

    File file = null;/*from w ww . j a v  a2  s  . c  om*/

    try {
        String[] destinationArray = WebDAVUtil.getPathArray(destination, true);

        FileEntry fileEntry = (FileEntry) resource.getModel();

        if (!hasLock(fileEntry, webDAVRequest.getLockUuid()) && (fileEntry.getLock() != null)) {

            return WebDAVUtil.SC_LOCKED;
        }

        long companyId = webDAVRequest.getCompanyId();

        long groupId = WebDAVUtil.getGroupId(companyId, destinationArray);
        long newParentFolderId = getParentFolderId(companyId, destinationArray);

        String title = getTitle(destinationArray);
        String description = fileEntry.getDescription();
        String changeLog = StringPool.BLANK;

        ServiceContext serviceContext = new ServiceContext();

        populateServiceContext(serviceContext, fileEntry);

        int status = HttpServletResponse.SC_CREATED;

        if (overwrite) {
            if (deleteResource(groupId, newParentFolderId, title, webDAVRequest.getLockUuid())) {

                status = HttpServletResponse.SC_NO_CONTENT;
            }
        }

        // LPS-5415

        if (webDAVRequest.isMac()) {
            try {
                FileEntry destFileEntry = _dlAppService.getFileEntry(groupId, newParentFolderId, title);

                InputStream is = fileEntry.getContentStream();

                file = FileUtil.createTempFile(is);

                populateServiceContext(serviceContext, destFileEntry);

                _dlAppService.updateFileEntry(destFileEntry.getFileEntryId(), destFileEntry.getTitle(),
                        destFileEntry.getMimeType(), destFileEntry.getTitle(), destFileEntry.getDescription(),
                        changeLog, false, file, serviceContext);

                _dlAppService.deleteFileEntry(fileEntry.getFileEntryId());

                return status;
            } catch (NoSuchFileEntryException nsfee) {
                if (_log.isDebugEnabled()) {
                    _log.debug(nsfee, nsfee);
                }
            }
        }

        populateServiceContext(serviceContext, fileEntry);

        _dlAppService.updateFileEntry(fileEntry.getFileEntryId(), title, fileEntry.getMimeType(), title,
                description, changeLog, false, file, serviceContext);

        if (fileEntry.getFolderId() != newParentFolderId) {
            fileEntry = _dlAppService.moveFileEntry(fileEntry.getFileEntryId(), newParentFolderId,
                    serviceContext);
        }

        return status;
    } catch (PrincipalException pe) {
        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }

        return HttpServletResponse.SC_FORBIDDEN;
    } catch (DuplicateFileEntryException dfee) {
        if (_log.isDebugEnabled()) {
            _log.debug(dfee, dfee);
        }

        return HttpServletResponse.SC_PRECONDITION_FAILED;
    } catch (DuplicateFolderNameException dfne) {
        if (_log.isDebugEnabled()) {
            _log.debug(dfne, dfne);
        }

        return HttpServletResponse.SC_PRECONDITION_FAILED;
    } catch (LockException le) {
        if (_log.isDebugEnabled()) {
            _log.debug(le, le);
        }

        return WebDAVUtil.SC_LOCKED;
    } catch (Exception e) {
        throw new WebDAVException(e);
    } finally {
        FileUtil.delete(file);
    }
}

From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java

License:Open Source License

@Override
public int putResource(WebDAVRequest webDAVRequest) throws WebDAVException {
    File file = null;/*w w  w  .j a v a2s.c o m*/

    try {
        HttpServletRequest request = webDAVRequest.getHttpServletRequest();

        String[] pathArray = webDAVRequest.getPathArray();

        long companyId = webDAVRequest.getCompanyId();
        long groupId = webDAVRequest.getGroupId();
        long parentFolderId = getParentFolderId(companyId, pathArray);
        String title = getTitle(pathArray);
        String description = StringPool.BLANK;
        String changeLog = StringPool.BLANK;

        ServiceContext serviceContext = ServiceContextFactory.getInstance(request);

        serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId));
        serviceContext.setAddGuestPermissions(true);

        String extension = FileUtil.getExtension(title);

        file = FileUtil.createTempFile(extension);

        FileUtil.write(file, request.getInputStream());

        String contentType = getContentType(request, file, title, extension);

        try {
            FileEntry fileEntry = _dlAppService.getFileEntry(groupId, parentFolderId, title);

            if (!hasLock(fileEntry, webDAVRequest.getLockUuid()) && (fileEntry.getLock() != null)) {

                return WebDAVUtil.SC_LOCKED;
            }

            long fileEntryId = fileEntry.getFileEntryId();

            description = fileEntry.getDescription();

            populateServiceContext(serviceContext, fileEntry);

            serviceContext.setCommand(Constants.UPDATE_WEBDAV);

            _dlAppService.updateFileEntry(fileEntryId, title, contentType, title, description, changeLog, false,
                    file, serviceContext);
        } catch (NoSuchFileEntryException nsfee) {
            if (_log.isDebugEnabled()) {
                _log.debug(nsfee, nsfee);
            }

            serviceContext.setCommand(Constants.ADD_WEBDAV);

            _dlAppService.addFileEntry(groupId, parentFolderId, title, contentType, title, description,
                    changeLog, file, serviceContext);
        }

        if (_log.isInfoEnabled()) {
            _log.info("Added " + StringUtil.merge(pathArray, StringPool.SLASH));
        }

        return HttpServletResponse.SC_CREATED;
    } catch (FileSizeException fse) {
        if (_log.isDebugEnabled()) {
            _log.debug(fse, fse);
        }

        return HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE;
    } catch (NoSuchFolderException nsfe) {
        if (_log.isDebugEnabled()) {
            _log.debug(nsfe, nsfe);
        }

        return HttpServletResponse.SC_CONFLICT;
    } catch (PrincipalException pe) {
        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }

        return HttpServletResponse.SC_FORBIDDEN;
    } catch (PortalException pe) {
        if (_log.isWarnEnabled()) {
            _log.warn(pe, pe);
        }

        return HttpServletResponse.SC_CONFLICT;
    } catch (Exception e) {
        throw new WebDAVException(e);
    } finally {
        FileUtil.delete(file);
    }
}

From source file:com.liferay.document.library.web.webdav.DLWebDAVStorageImpl.java

License:Open Source License

@Override
public int deleteResource(WebDAVRequest webDAVRequest) throws WebDAVException {

    try {/*from ww w. j  av  a2  s. c o  m*/
        Resource resource = getResource(webDAVRequest);

        if (resource == null) {
            if (webDAVRequest.isAppleDoubleRequest()) {
                return HttpServletResponse.SC_NO_CONTENT;
            } else {
                return HttpServletResponse.SC_NOT_FOUND;
            }
        }

        Object model = resource.getModel();

        if (model instanceof Folder) {
            Folder folder = (Folder) model;

            long folderId = folder.getFolderId();

            if ((folder.getModel() instanceof DLFolder)
                    && DLTrashUtil.isTrashEnabled(folder.getGroupId(), folder.getRepositoryId())) {

                _dlTrashService.moveFolderToTrash(folderId);
            } else {
                _dlAppService.deleteFolder(folderId);
            }
        } else {
            FileEntry fileEntry = (FileEntry) model;

            if (!hasLock(fileEntry, webDAVRequest.getLockUuid()) && (fileEntry.getLock() != null)) {

                return WebDAVUtil.SC_LOCKED;
            }

            long fileEntryId = fileEntry.getFileEntryId();

            if ((fileEntry.getModel() instanceof DLFileEntry)
                    && DLTrashUtil.isTrashEnabled(fileEntry.getGroupId(), fileEntry.getRepositoryId())) {

                _dlTrashService.moveFileEntryToTrash(fileEntryId);
            } else {
                _dlAppService.deleteFileEntry(fileEntryId);
            }
        }

        return HttpServletResponse.SC_NO_CONTENT;
    } 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.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  .  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 = getTitle(pathArray);

            String extension = FileUtil.getExtension(title);

            String contentType = getContentType(request, null, title, extension);

            String description = StringPool.BLANK;
            String changeLog = StringPool.BLANK;

            File file = FileUtil.createTempFile(extension);

            file.createNewFile();

            ServiceContext serviceContext = new ServiceContext();

            serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId));
            serviceContext.setAddGuestPermissions(true);

            FileEntry fileEntry = _dlAppService.addFileEntry(groupId, parentFolderId, title, contentType, title,
                    description, changeLog, file, serviceContext);

            resource = toResource(webDAVRequest, fileEntry, false);
        }

        if (resource instanceof DLFileEntryResourceImpl) {
            FileEntry fileEntry = (FileEntry) resource.getModel();

            ServiceContext serviceContext = new ServiceContext();

            serviceContext.setAttribute(DL.MANUAL_CHECK_IN_REQUIRED, webDAVRequest.isManualCheckInRequired());

            _dlAppService.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 = _dlAppService.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.webdav.DLWebDAVStorageImpl.java

License:Open Source License

@Override
public int moveSimpleResource(WebDAVRequest webDAVRequest, Resource resource, String destination,
        boolean overwrite) throws WebDAVException {

    File file = null;/*from  w w w  . ja  v  a  2 s .com*/

    try {
        String[] destinationArray = WebDAVUtil.getPathArray(destination, true);

        FileEntry fileEntry = (FileEntry) resource.getModel();

        if (!hasLock(fileEntry, webDAVRequest.getLockUuid()) && (fileEntry.getLock() != null)) {

            return WebDAVUtil.SC_LOCKED;
        }

        long companyId = webDAVRequest.getCompanyId();

        long groupId = WebDAVUtil.getGroupId(companyId, destinationArray);
        long newParentFolderId = getParentFolderId(companyId, destinationArray);

        String title = getTitle(destinationArray);
        String description = fileEntry.getDescription();
        String changeLog = StringPool.BLANK;

        ServiceContext serviceContext = new ServiceContext();

        populateServiceContext(serviceContext, fileEntry);

        int status = HttpServletResponse.SC_CREATED;

        if (overwrite) {
            if (deleteResource(groupId, newParentFolderId, title, webDAVRequest.getLockUuid())) {

                status = HttpServletResponse.SC_NO_CONTENT;
            }
        }

        // LPS-5415

        if (webDAVRequest.isMac()) {
            try {
                FileEntry destFileEntry = _dlAppService.getFileEntry(groupId, newParentFolderId, title);

                InputStream is = fileEntry.getContentStream();

                file = FileUtil.createTempFile(is);

                _dlAppService.updateFileEntry(destFileEntry.getFileEntryId(), destFileEntry.getTitle(),
                        destFileEntry.getMimeType(), destFileEntry.getTitle(), destFileEntry.getDescription(),
                        changeLog, false, file, serviceContext);

                _dlAppService.deleteFileEntry(fileEntry.getFileEntryId());

                return status;
            } catch (NoSuchFileEntryException nsfee) {
                if (_log.isDebugEnabled()) {
                    _log.debug(nsfee, nsfee);
                }
            }
        }

        _dlAppService.updateFileEntry(fileEntry.getFileEntryId(), title, fileEntry.getMimeType(), title,
                description, changeLog, false, file, serviceContext);

        if (fileEntry.getFolderId() != newParentFolderId) {
            fileEntry = _dlAppService.moveFileEntry(fileEntry.getFileEntryId(), newParentFolderId,
                    serviceContext);
        }

        return status;
    } catch (PrincipalException pe) {
        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }

        return HttpServletResponse.SC_FORBIDDEN;
    } catch (DuplicateFileEntryException dfee) {
        if (_log.isDebugEnabled()) {
            _log.debug(dfee, dfee);
        }

        return HttpServletResponse.SC_PRECONDITION_FAILED;
    } catch (DuplicateFolderNameException dfne) {
        if (_log.isDebugEnabled()) {
            _log.debug(dfne, dfne);
        }

        return HttpServletResponse.SC_PRECONDITION_FAILED;
    } catch (LockException le) {
        if (_log.isDebugEnabled()) {
            _log.debug(le, le);
        }

        return WebDAVUtil.SC_LOCKED;
    } 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

@Override
public int copySimpleResource(WebDAVRequest webDavRequest, Resource resource, String destination,
        boolean overwrite) throws WebDAVException {

    File file = null;//from   w w  w.ja  v  a 2 s .  c om

    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);
    }
}