List of usage examples for com.liferay.portal.kernel.util FileUtil delete
public static boolean delete(String file)
From source file:ch.inofix.contact.service.impl.ContactLocalServiceImpl.java
License:Open Source License
@Override public void importContacts(ExportImportConfiguration exportImportConfiguration, InputStream inputStream) throws PortalException { File file = null;/*w w w . j a v a 2 s .co m*/ try { file = FileUtil.createTempFile("lar"); FileUtil.write(file, inputStream); importContacts(exportImportConfiguration, file); } catch (IOException ioe) { throw new SystemException(ioe); } finally { FileUtil.delete(file); } }
From source file:ch.inofix.contact.service.impl.ContactLocalServiceImpl.java
License:Open Source License
@Override public long importContactsInBackground(long userId, ExportImportConfiguration exportImportConfiguration, InputStream inputStream, String extension) throws PortalException { File file = null;/* w w w . j av a 2 s . c o m*/ try { file = FileUtil.createTempFile(extension); FileUtil.write(file, inputStream); return importContactsInBackground(userId, exportImportConfiguration, file); } catch (IOException ioe) { throw new SystemException(ioe); } finally { FileUtil.delete(file); } }
From source file:ch.inofix.referencemanager.service.impl.ReferenceLocalServiceImpl.java
License:Open Source License
/** * Imports the references from the input stream. * * @param userId//from w w w . java 2s. c o m * the primary key of the user * @param groupId * the primary key of the group * @param privateLayout * whether the layout is private to the group * @param parameterMap * the mapping of parameters indicating which information will be * imported. * @param inputStream * the input stream * @param serviceContext * @since 1.0.2 * @throws PortalException * if a group or user with the primary key could not be found, * or if some other portal exception occurred * @throws SystemException * if a system exception occurred */ public void importReferences(long userId, long groupId, boolean privateLayout, Map<String, String[]> parameterMap, InputStream inputStream, ServiceContext serviceContext) throws PortalException, SystemException { File file = null; try { file = FileUtil.createTempFile("bib"); FileUtil.write(file, inputStream); importReferences(userId, groupId, privateLayout, parameterMap, file, serviceContext); } catch (IOException ioe) { _log.error(ioe); throw new SystemException(ioe); } finally { FileUtil.delete(file); } }
From source file:com.liferay.content.targeting.service.test.lar.BaseExportImportTestCase.java
License:Open Source License
@After public void tearDown() throws Exception { try {/*from w ww. j ava 2s. co m*/ if (group != null) { GroupLocalServiceUtil.deleteGroup(group); } if (importedGroup != null) { GroupLocalServiceUtil.deleteGroup(importedGroup); } } catch (RequiredGroupException rge) { } if (layout != null) { LayoutLocalServiceUtil.deleteLayout(layout); } if (importedLayout != null) { LayoutLocalServiceUtil.deleteLayout(importedLayout); } if ((larFile != null) && larFile.exists()) { FileUtil.delete(larFile); } }
From source file:com.liferay.document.library.internal.repository.capabilities.TemporaryFileEntriesCapabilityImpl.java
License:Open Source License
@Override public FileEntry addTemporaryFileEntry(TemporaryFileEntriesScope temporaryFileEntriesScope, String fileName, String mimeType, InputStream inputStream) throws PortalException { Folder folder = addTempFolder(temporaryFileEntriesScope); File file = null;/*from w w w .j a v a 2 s. co m*/ try { if (inputStream == null) { inputStream = new UnsyncByteArrayInputStream(new byte[0]); } file = FileUtil.createTempFile(inputStream); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); return _documentRepository.addFileEntry(temporaryFileEntriesScope.getUserId(), folder.getFolderId(), fileName, mimeType, fileName, StringPool.BLANK, StringPool.BLANK, file, serviceContext); } catch (IOException ioe) { throw new SystemException("Unable to write temporary file", ioe); } finally { FileUtil.delete(file); } }
From source file:com.liferay.document.library.search.test.DLFileEntryIndexerLocalizedContentTest.java
License:Open Source License
protected FileEntry addFileEntry(String fileName, long groupId) throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(groupId); File file = null;/* w ww . j av a 2 s. c om*/ FileEntry fileEntry = null; try (InputStream inputStream = DLFileEntrySearchTest.class .getResourceAsStream("dependencies/" + fileName)) { String mimeType = MimeTypesUtil.getContentType(file, fileName); file = FileUtil.createTempFile(inputStream); fileEntry = DLAppLocalServiceUtil.addFileEntry(serviceContext.getUserId(), serviceContext.getScopeGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, fileName, mimeType, fileName, StringPool.BLANK, StringPool.BLANK, file, serviceContext); } finally { FileUtil.delete(file); } return fileEntry; }
From source file:com.liferay.document.library.search.test.DLFileEntrySearchTest.java
License:Open Source License
@Test public void testSearchTikaRawMetadata() throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId()); SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId()); int initialBaseModelsSearchCount = 0; assertBaseModelsCount(initialBaseModelsSearchCount, "Word", searchContext); String fileName = "OSX_Test.docx"; InputStream inputStream = DLFileEntrySearchTest.class.getResourceAsStream("dependencies/" + fileName); File file = null;//w w w .j a va2 s .co m try { String mimeType = MimeTypesUtil.getContentType(file, fileName); file = FileUtil.createTempFile(inputStream); DLAppLocalServiceUtil.addFileEntry(serviceContext.getUserId(), serviceContext.getScopeGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, fileName, mimeType, fileName, StringPool.BLANK, StringPool.BLANK, file, serviceContext); } finally { FileUtil.delete(file); } assertBaseModelsCount(initialBaseModelsSearchCount + 1, "Word", searchContext); }
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;//from w w w. j av 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 moveSimpleResource(WebDAVRequest webDAVRequest, Resource resource, String destination, boolean overwrite) throws WebDAVException { File file = null;/*from www .j a v a2 s . c o m*/ 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 ww .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 = 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); } }