List of usage examples for com.liferay.portal.kernel.util FileUtil createTempFile
public static File createTempFile(String extension)
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;//from ww w . j a v a2 s .com 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;/*from w w w . ja v a 2s .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//ww w . ja v a 2 s .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.adaptive.media.image.internal.scaler.AMGIFImageScaler.java
License:Open Source License
private File _getFile(FileVersion fileVersion) throws IOException, PortalException { if (fileVersion instanceof LiferayFileVersion) { LiferayFileVersion liferayFileVersion = (LiferayFileVersion) fileVersion; return liferayFileVersion.getFile(false); }//from w w w. java2 s .c o m try (InputStream inputStream = fileVersion.getContentStream(false)) { return FileUtil.createTempFile(inputStream); } }
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 ww.jav a 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.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 ww w. j a v a 2s . c om*/ 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 w w . j ava 2 s .c o m 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;//from w w w .j a va2 s. com 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;// www .java 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 Status lockResource(WebDAVRequest webDAVRequest, String owner, long timeout) throws WebDAVException { Resource resource = getResource(webDAVRequest); Lock lock = null;/*from w ww . j av a2 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); }