List of usage examples for com.liferay.portal.kernel.util ContentTypes APPLICATION_OCTET_STREAM
String APPLICATION_OCTET_STREAM
To view the source code for com.liferay.portal.kernel.util ContentTypes APPLICATION_OCTET_STREAM.
Click Source Link
From source file:au.com.permeance.liferay.portal.verify.CustomVerifyDocumentLibrary.java
License:Open Source License
@Override protected void checkMimeTypes() throws Exception { List<DLFileEntry> dlFileEntries = DLFileEntryLocalServiceUtil .getFileEntriesByMimeType(ContentTypes.APPLICATION_OCTET_STREAM); if (_log.isDebugEnabled()) { _log.debug("Processing " + dlFileEntries.size() + " file entries with " + ContentTypes.APPLICATION_OCTET_STREAM); }//from w w w . j a v a 2s . co m for (DLFileEntry dlFileEntry : dlFileEntries) { if (!fileEntryHasFile(dlFileEntry)) { if (_log.isDebugEnabled()) { String fileEntryDetails = buildFileEntryDetails(dlFileEntry); _log.warn("Skipping file entry " + dlFileEntry.getTitle() + " due to missing file : " + fileEntryDetails); } continue; } InputStream inputStream = DLFileEntryLocalServiceUtil.getFileAsStream(dlFileEntry.getUserId(), dlFileEntry.getFileEntryId(), dlFileEntry.getVersion(), false); String title = DLUtil.getTitleWithExtension(dlFileEntry.getTitle(), dlFileEntry.getExtension()); String mimeType = MimeTypesUtil.getContentType(inputStream, title); if (mimeType.equals(ContentTypes.APPLICATION_OCTET_STREAM)) { continue; } dlFileEntry.setMimeType(mimeType); DLFileEntryLocalServiceUtil.updateDLFileEntry(dlFileEntry); DLFileVersion dlFileVersion = dlFileEntry.getFileVersion(); dlFileVersion.setMimeType(mimeType); DLFileVersionLocalServiceUtil.updateDLFileVersion(dlFileVersion); } if (_log.isDebugEnabled()) { _log.debug("Fixed file entries with invalid mime types"); } }
From source file:au.com.permeance.liferay.portal.verify.CustomVerifyDocumentLibrary.java
License:Open Source License
/** * Remove empty DL file entries.//ww w. jav a2 s. c om * * @see https://issues.liferay.com/browse/LPS-35280 * @see https://issues.liferay.com/browse/LPS-37869 */ protected void removeEmptyDLFileEntries() throws Exception { List<DLFileEntry> dlFileEntries = DLFileEntryLocalServiceUtil .getFileEntriesByMimeType(ContentTypes.APPLICATION_OCTET_STREAM); if (_log.isDebugEnabled()) { _log.debug("Scanning " + dlFileEntries.size() + " file entries with " + ContentTypes.APPLICATION_OCTET_STREAM + " for empty entries"); } for (DLFileEntry dlFileEntry : dlFileEntries) { if (!fileEntryHasFile(dlFileEntry)) { try { if (_log.isWarnEnabled()) { String fileEntryDetails = buildFileEntryDetails(dlFileEntry); _log.warn("Removing file entry " + dlFileEntry.getTitle() + " due to missing file : " + fileEntryDetails); } DLFileEntryLocalServiceUtil.deleteFileEntry(dlFileEntry.getFileEntryId()); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Unable to remove file entry " + dlFileEntry.getFileEntryId() + ": " + e.getMessage()); } } } } if (_log.isDebugEnabled()) { _log.debug("Removed empty file entries"); } }
From source file:com.custom.portal.verify.CustomVerifyDocumentLibrary.java
License:Open Source License
protected void checkMimeTypes() throws Exception { String[] mimeTypes = { ContentTypes.APPLICATION_OCTET_STREAM, DLWebDAVStorageImpl.MS_OFFICE_2010_TEXT_XML_UTF8 }; for (String mimeType : mimeTypes) { checkFileEntryMimeTypes(mimeType); checkFileVersionMimeTypes(mimeType); }/* www . j a v a 2s . c o m*/ if (_log.isDebugEnabled()) { _log.debug("Fixed file entries with invalid mime types"); } }
From source file:com.liferay.adaptive.media.document.library.web.internal.counter.test.DLAMImageCounterTest.java
License:Open Source License
@Test public void testDLAMImageCounterOnlyCountsImagesWithSupportedMimeTypes() throws Exception { Assert.assertEquals(0, _amImageCounter.countExpectedAMImageEntries(_company1.getCompanyId())); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group1, _user1.getUserId()); _dlAppLocalService.addFileEntry(_user1.getUserId(), _group1.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString() + ".jpg", ContentTypes.IMAGE_JPEG, _getImageBytes(), serviceContext); _dlAppLocalService.addFileEntry(_user1.getUserId(), _group1.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString(), ContentTypes.APPLICATION_OCTET_STREAM, RandomTestUtil.randomBytes(), serviceContext); Assert.assertEquals(1, _amImageCounter.countExpectedAMImageEntries(_company1.getCompanyId())); }
From source file:com.liferay.adaptive.media.document.library.web.internal.optimizer.test.DLAMImageOptimizerTest.java
License:Open Source License
@Test public void testDLAMImageOptimizerOptimizesImagesWithSupportedMimeTypes() throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group1.getGroupId(), _user1.getUserId());/*from w w w .j av a 2 s. c o m*/ _dlAppLocalService.addFileEntry(_user1.getUserId(), _group1.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString() + ".jpg", ContentTypes.IMAGE_JPEG, _getImageBytes(), serviceContext); _dlAppLocalService.addFileEntry(_user1.getUserId(), _group1.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString(), ContentTypes.APPLICATION_OCTET_STREAM, RandomTestUtil.randomBytes(), serviceContext); AMImageConfigurationEntry amImageConfigurationEntry1 = _addAMImageConfigurationEntry( _company1.getCompanyId()); Assert.assertEquals(0, _amImageEntryLocalService.getAMImageEntriesCount(_company1.getCompanyId(), amImageConfigurationEntry1.getUUID())); _amImageOptimizer.optimize(_company1.getCompanyId(), amImageConfigurationEntry1.getUUID()); Assert.assertEquals(1, _amImageEntryLocalService.getAMImageEntriesCount(_company1.getCompanyId(), amImageConfigurationEntry1.getUUID())); }
From source file:com.liferay.adaptive.media.image.processor.test.AdaptiveMediaImageProcessorTest.java
License:Open Source License
private FileEntry _addNonImageFileEntry(ServiceContext serviceContext) throws Exception { return _dlAppLocalService.addFileEntry(TestPropsValues.getUserId(), _group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, StringUtil.randomString(), ContentTypes.APPLICATION_OCTET_STREAM, _getNonImageBytes(), serviceContext); }
From source file:com.liferay.adaptive.media.image.processor.test.AMImageProcessorTest.java
License:Open Source License
private FileEntry _addNonImageFileEntry(ServiceContext serviceContext) throws Exception { return _dlAppLocalService.addFileEntry(TestPropsValues.getUserId(), _group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString(), ContentTypes.APPLICATION_OCTET_STREAM, _getNonImageBytes(), serviceContext); }
From source file:com.liferay.adaptive.media.web.internal.servlet.AdaptiveMediaServlet.java
License:Open Source License
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try {/*from ww w .j av a2 s. co m*/ AdaptiveMediaRequestHandler requestHandler = _adaptiveMediaRequestHandlerLocator .locateForPattern(_getRequestHandlerPattern(request)); if (requestHandler == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND, request.getRequestURI()); return; } Optional<AdaptiveMedia<?>> adaptiveMediaOptional = requestHandler.handleRequest(request); AdaptiveMedia<?> adaptiveMedia = adaptiveMediaOptional .orElseThrow(AdaptiveMediaException.AdaptiveMediaNotFound::new); Optional<Integer> contentLengthOptional = adaptiveMedia .getValueOptional(AdaptiveMediaAttribute.contentLength()); Integer contentLength = contentLengthOptional.orElse(0); Optional<String> contentTypeOptional = adaptiveMedia .getValueOptional(AdaptiveMediaAttribute.contentType()); String contentType = contentTypeOptional.orElse(ContentTypes.APPLICATION_OCTET_STREAM); Optional<String> fileNameOptional = adaptiveMedia.getValueOptional(AdaptiveMediaAttribute.fileName()); String fileName = fileNameOptional.orElse(null); boolean download = ParamUtil.getBoolean(request, "download"); if (download) { ServletResponseUtil.sendFile(request, response, fileName, adaptiveMedia.getInputStream(), contentLength, contentType, HttpHeaders.CONTENT_DISPOSITION_ATTACHMENT); } else { ServletResponseUtil.sendFile(request, response, fileName, adaptiveMedia.getInputStream(), contentLength, contentType); } } catch (AdaptiveMediaException.AdaptiveMediaNotFound amnf) { response.sendError(HttpServletResponse.SC_NOT_FOUND, request.getRequestURI()); } catch (Exception e) { Throwable cause = e.getCause(); if (cause instanceof PrincipalException) { response.sendError(HttpServletResponse.SC_FORBIDDEN, request.getRequestURI()); } else { response.sendError(HttpServletResponse.SC_BAD_REQUEST, request.getRequestURI()); } } }
From source file:com.liferay.adaptive.media.web.internal.servlet.AMServlet.java
License:Open Source License
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try {/*from w w w . ja v a2 s. c om*/ AMRequestHandler amRequestHandler = _amRequestHandlerLocator .locateForPattern(_getRequestHandlerPattern(request)); if (amRequestHandler == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND, request.getRequestURI()); return; } Optional<AdaptiveMedia<?>> adaptiveMediaOptional = amRequestHandler.handleRequest(request); AdaptiveMedia<?> adaptiveMedia = adaptiveMediaOptional.orElseThrow(AMException.AMNotFound::new); Optional<Long> contentLengthOptional = adaptiveMedia .getValueOptional(AMAttribute.getContentLengthAMAttribute()); long contentLength = contentLengthOptional.orElse(0L); Optional<String> contentTypeOptional = adaptiveMedia .getValueOptional(AMAttribute.getContentTypeAMAttribute()); String contentType = contentTypeOptional.orElse(ContentTypes.APPLICATION_OCTET_STREAM); Optional<String> fileNameOptional = adaptiveMedia .getValueOptional(AMAttribute.getFileNameAMAttribute()); String fileName = fileNameOptional.orElse(null); boolean download = ParamUtil.getBoolean(request, "download"); if (download) { ServletResponseUtil.sendFile(request, response, fileName, adaptiveMedia.getInputStream(), contentLength, contentType, HttpHeaders.CONTENT_DISPOSITION_ATTACHMENT); } else { ServletResponseUtil.sendFile(request, response, fileName, adaptiveMedia.getInputStream(), contentLength, contentType); } } catch (AMException.AMNotFound amnf) { response.sendError(HttpServletResponse.SC_NOT_FOUND, request.getRequestURI()); } catch (Exception e) { Throwable cause = e.getCause(); if (cause instanceof PrincipalException) { response.sendError(HttpServletResponse.SC_FORBIDDEN, request.getRequestURI()); } else { response.sendError(HttpServletResponse.SC_BAD_REQUEST, request.getRequestURI()); } } }
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 va2 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 (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); }