List of usage examples for com.liferay.portal.kernel.webdav WebDAVRequest getHttpServletRequest
public HttpServletRequest getHttpServletRequest();
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. j a va 2s .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 = 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 Status lockResource(WebDAVRequest webDAVRequest, String owner, long timeout) throws WebDAVException { Resource resource = getResource(webDAVRequest); Lock lock = null;// w ww. ja v a2s .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 Status makeCollection(WebDAVRequest webDAVRequest) throws WebDAVException { try {//from ww w.j a v a 2 s. com 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 putResource(WebDAVRequest webDAVRequest) throws WebDAVException { File file = null;// www . j a va 2s . com 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 Status lockResource(WebDAVRequest webDAVRequest, String owner, long timeout) throws WebDAVException { Resource resource = getResource(webDAVRequest); Lock lock = null;/* w ww. java 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.dynamic.data.mapping.webdav.DDMWebDav.java
License:Open Source License
public int addResource(WebDAVRequest webDavRequest, long classNameId) throws Exception { String[] pathArray = webDavRequest.getPathArray(); if (pathArray.length != 4) { return HttpServletResponse.SC_FORBIDDEN; }//from ww w .j a va 2 s . co m String type = pathArray[2]; String typeId = pathArray[3]; if (type.equals(TYPE_STRUCTURES)) { HttpServletRequest request = webDavRequest.getHttpServletRequest(); String definition = StringUtil.read(request.getInputStream()); DDMForm ddmForm = getDDMForm(definition); DDMFormLayout ddmFormLayout = _ddm.getDefaultDDMFormLayout(ddmForm); Map<Locale, String> nameMap = new HashMap<>(); Locale defaultLocale = ddmForm.getDefaultLocale(); nameMap.put(defaultLocale, typeId); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); _ddmStructureLocalService.addStructure(webDavRequest.getUserId(), webDavRequest.getGroupId(), classNameId, nameMap, null, ddmForm, ddmFormLayout, StorageType.JSON.toString(), serviceContext); return HttpServletResponse.SC_CREATED; } else if (type.equals(TYPE_TEMPLATES)) { // DDM templates can not be added via WebDAV because there is no way // to know the associated class name or class PK return HttpServletResponse.SC_FORBIDDEN; } return HttpServletResponse.SC_FORBIDDEN; }
From source file:com.liferay.dynamic.data.mapping.webdav.DDMWebDav.java
License:Open Source License
public int putResource(WebDAVRequest webDAVRequest, String rootPath, String token, long classNameId) throws WebDAVException { try {// www.j a v a 2 s .c o m Resource resource = getResource(webDAVRequest, rootPath, token, classNameId); if (resource == null) { return addResource(webDAVRequest, classNameId); } Object model = resource.getModel(); if (model instanceof DDMStructure) { DDMStructure structure = (DDMStructure) model; HttpServletRequest request = webDAVRequest.getHttpServletRequest(); String definition = StringUtil.read(request.getInputStream()); DDMForm ddmForm = getDDMForm(definition); DDMFormLayout ddmFormLayout = _ddm.getDefaultDDMFormLayout(ddmForm); _ddmStructureService.updateStructure(structure.getGroupId(), structure.getParentStructureId(), structure.getClassNameId(), structure.getStructureKey(), structure.getNameMap(), structure.getDescriptionMap(), ddmForm, ddmFormLayout, new ServiceContext()); return HttpServletResponse.SC_CREATED; } else if (model instanceof DDMTemplate) { DDMTemplate template = (DDMTemplate) model; HttpServletRequest request = webDAVRequest.getHttpServletRequest(); String script = StringUtil.read(request.getInputStream()); _ddmTemplateService.updateTemplate(template.getTemplateId(), template.getClassPK(), template.getNameMap(), template.getDescriptionMap(), template.getType(), template.getMode(), template.getLanguage(), script, template.isCacheable(), template.isSmallImage(), template.getSmallImageURL(), null, new ServiceContext()); return HttpServletResponse.SC_CREATED; } else { return HttpServletResponse.SC_FORBIDDEN; } } catch (PortalException pe) { if (_log.isDebugEnabled()) { _log.debug(pe, 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 Status lockResource(WebDAVRequest webDavRequest, String owner, long timeout) throws WebDAVException { Resource resource = getResource(webDavRequest); Lock lock = null;//from w ww.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 = 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); }
From source file:com.liferay.portlet.documentlibrary.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public Status makeCollection(WebDAVRequest webDavRequest) throws WebDAVException { try {/*from w ww . j av a 2 s. 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); DLAppServiceUtil.addFolder(groupId, parentFolderId, name, description, serviceContext); String location = StringUtil.merge(pathArray, StringPool.SLASH); return new Status(location, HttpServletResponse.SC_CREATED); } catch (DuplicateFolderNameException dfne) { return new Status(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } catch (DuplicateFileException dfe) { return new Status(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } catch (NoSuchFolderException nsfe) { return new Status(HttpServletResponse.SC_CONFLICT); } catch (PrincipalException pe) { return new Status(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 putResource(WebDAVRequest webDavRequest) throws WebDAVException { File file = null;//from w w w. j a v a 2 s . 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 = WebDAVUtil.getResourceName(pathArray); String description = StringPool.BLANK; String changeLog = StringPool.BLANK; ServiceContext serviceContext = ServiceContextFactory.getInstance(request); serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId)); serviceContext.setAddGuestPermissions(true); String contentType = GetterUtil.get(request.getHeader(HttpHeaders.CONTENT_TYPE), ContentTypes.APPLICATION_OCTET_STREAM); String extension = FileUtil.getExtension(title); file = FileUtil.createTempFile(extension); FileUtil.write(file, request.getInputStream()); if (contentType.equals(ContentTypes.APPLICATION_OCTET_STREAM)) { contentType = MimeTypesUtil.getContentType(file, title); } try { FileEntry fileEntry = DLAppServiceUtil.getFileEntry(groupId, parentFolderId, title); if (!hasLock(fileEntry, webDavRequest.getLockUuid()) && (fileEntry.getLock() != null)) { return WebDAVUtil.SC_LOCKED; } long fileEntryId = fileEntry.getFileEntryId(); description = fileEntry.getDescription(); String[] assetTagNames = AssetTagLocalServiceUtil.getTagNames(FileEntry.class.getName(), fileEntry.getFileEntryId()); serviceContext.setAssetTagNames(assetTagNames); DLAppServiceUtil.updateFileEntry(fileEntryId, title, contentType, title, description, changeLog, false, file, serviceContext); } catch (NoSuchFileEntryException nsfee) { if (file.length() == 0) { serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); } DLAppServiceUtil.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 (PrincipalException pe) { return HttpServletResponse.SC_FORBIDDEN; } catch (NoSuchFolderException nsfe) { return HttpServletResponse.SC_CONFLICT; } 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); } }