List of usage examples for com.liferay.portal.kernel.repository.model FileVersion getSize
public long getSize();
From source file:com.liferay.adaptive.media.image.internal.handler.AdaptiveMediaImageRequestHandler.java
License:Open Source License
private AdaptiveMedia<AdaptiveMediaImageProcessor> _createRawAdaptiveMedia(FileVersion fileVersion) throws PortalException { Map<String, String> properties = new HashMap<>(); AdaptiveMediaAttribute<Object, String> fileName = AdaptiveMediaAttribute.fileName(); properties.put(fileName.getName(), fileVersion.getFileName()); AdaptiveMediaAttribute<Object, String> contentType = AdaptiveMediaAttribute.contentType(); properties.put(contentType.getName(), fileVersion.getMimeType()); AdaptiveMediaAttribute<Object, Integer> contentLength = AdaptiveMediaAttribute.contentLength(); properties.put(contentLength.getName(), String.valueOf(fileVersion.getSize())); return new AdaptiveMediaImage(() -> { try {// ww w . j av a 2 s. c o m return fileVersion.getContentStream(false); } catch (PortalException pe) { throw new AdaptiveMediaRuntimeException(pe); } }, AdaptiveMediaImageAttributeMapping.fromProperties(properties), null); }
From source file:com.liferay.adaptive.media.image.internal.handler.AdaptiveMediaImageRequestHandler.java
License:Open Source License
private Optional<Tuple<FileVersion, AdaptiveMediaImageAttributeMapping>> _interpretPath(String pathInfo) { try {/*w ww . j av a 2 s . c o m*/ Optional<Tuple<FileVersion, Map<String, String>>> fileVersionPropertiesTupleOptional = _pathInterpreter .interpretPath(pathInfo); if (!fileVersionPropertiesTupleOptional.isPresent()) { return Optional.empty(); } Tuple<FileVersion, Map<String, String>> fileVersionMapTuple = fileVersionPropertiesTupleOptional.get(); FileVersion fileVersion = fileVersionMapTuple.first; Map<String, String> properties = fileVersionMapTuple.second; AdaptiveMediaAttribute<Object, Integer> contentLengthAttribute = AdaptiveMediaAttribute.contentLength(); properties.put(contentLengthAttribute.getName(), String.valueOf(fileVersion.getSize())); AdaptiveMediaAttribute<Object, String> contentTypeAttribute = AdaptiveMediaAttribute.contentType(); properties.put(contentTypeAttribute.getName(), fileVersion.getMimeType()); AdaptiveMediaAttribute<Object, String> fileNameAttribute = AdaptiveMediaAttribute.fileName(); properties.put(fileNameAttribute.getName(), fileVersion.getFileName()); AdaptiveMediaImageAttributeMapping attributeMapping = AdaptiveMediaImageAttributeMapping .fromProperties(properties); return Optional.of(Tuple.of(fileVersion, attributeMapping)); } catch (AdaptiveMediaRuntimeException | NumberFormatException e) { _log.error(e); return Optional.empty(); } }
From source file:com.liferay.adaptive.media.image.internal.handler.AdaptiveMediaImageRequestHandlerTest.java
License:Open Source License
private AdaptiveMedia<AdaptiveMediaImageProcessor> _createAdaptiveMedia(FileVersion fileVersion, AdaptiveMediaImageConfigurationEntry configurationEntry) throws Exception { Map<String, String> properties = new HashMap<>(); AdaptiveMediaAttribute<Object, String> configurationUuid = AdaptiveMediaAttribute.configurationUuid(); properties.put(configurationUuid.getName(), configurationEntry.getUUID()); AdaptiveMediaAttribute<Object, String> fileName = AdaptiveMediaAttribute.fileName(); properties.put(fileName.getName(), fileVersion.getFileName()); AdaptiveMediaAttribute<Object, String> contentType = AdaptiveMediaAttribute.contentType(); properties.put(contentType.getName(), fileVersion.getMimeType()); AdaptiveMediaAttribute<Object, Integer> contentLength = AdaptiveMediaAttribute.contentLength(); properties.put(contentLength.getName(), String.valueOf(fileVersion.getSize())); Map<String, String> configurationEntryProperties = configurationEntry.getProperties(); properties.put(AdaptiveMediaImageAttribute.IMAGE_WIDTH.getName(), configurationEntryProperties.get("max-width")); properties.put(AdaptiveMediaImageAttribute.IMAGE_HEIGHT.getName(), configurationEntryProperties.get("max-height")); return new AdaptiveMediaImage(() -> { try {//from ww w .jav a2 s.c om return fileVersion.getContentStream(false); } catch (PortalException pe) { throw new AdaptiveMediaRuntimeException(pe); } }, AdaptiveMediaImageAttributeMapping.fromProperties(properties), null); }
From source file:com.liferay.adaptive.media.image.internal.handler.AdaptiveMediaImageRequestHandlerTest.java
License:Open Source License
private FileVersion _getFileVersion() throws PortalException { FileVersion fileVersion = Mockito.mock(FileVersion.class); Mockito.when(fileVersion.getCompanyId()).thenReturn(1234L); Mockito.when(fileVersion.getContentStream(false)).thenReturn(Mockito.mock(InputStream.class)); Mockito.when(fileVersion.getMimeType()).thenReturn("image/jpg"); Mockito.when(fileVersion.getFileName()).thenReturn("fileName"); Mockito.when(fileVersion.getSize()).thenReturn(2048L); return fileVersion; }
From source file:com.liferay.adaptive.media.image.internal.handler.AMImageRequestHandler.java
License:Open Source License
private AdaptiveMedia<AMImageProcessor> _createRawAdaptiveMedia(FileVersion fileVersion) throws PortalException { Map<String, String> properties = new HashMap<>(); AMAttribute<Object, String> fileNameAMAttribute = AMAttribute.getFileNameAMAttribute(); properties.put(fileNameAMAttribute.getName(), fileVersion.getFileName()); AMAttribute<Object, String> contentTypeAMAttribute = AMAttribute.getContentTypeAMAttribute(); properties.put(contentTypeAMAttribute.getName(), fileVersion.getMimeType()); AMAttribute<Object, Long> contentLengthAMAttribute = AMAttribute.getContentLengthAMAttribute(); properties.put(contentLengthAMAttribute.getName(), String.valueOf(fileVersion.getSize())); return new AMImage(() -> { try {/*from w w w . j ava 2 s .c o m*/ return fileVersion.getContentStream(false); } catch (PortalException pe) { throw new AMRuntimeException(pe); } }, AMImageAttributeMapping.fromProperties(properties), null); }
From source file:com.liferay.adaptive.media.image.internal.handler.AMImageRequestHandler.java
License:Open Source License
private Optional<Tuple<FileVersion, AMImageAttributeMapping>> _interpretPath(String pathInfo) { try {/*from w ww . ja v a2 s . c o m*/ Optional<Tuple<FileVersion, Map<String, String>>> fileVersionPropertiesTupleOptional = _pathInterpreter .interpretPath(pathInfo); if (!fileVersionPropertiesTupleOptional.isPresent()) { return Optional.empty(); } Tuple<FileVersion, Map<String, String>> fileVersionMapTuple = fileVersionPropertiesTupleOptional.get(); FileVersion fileVersion = fileVersionMapTuple.first; if (fileVersion.getStatus() == WorkflowConstants.STATUS_IN_TRASH) { return Optional.empty(); } Map<String, String> properties = fileVersionMapTuple.second; AMAttribute<Object, Long> contentLengthAMAttribute = AMAttribute.getContentLengthAMAttribute(); properties.put(contentLengthAMAttribute.getName(), String.valueOf(fileVersion.getSize())); AMAttribute<Object, String> contentTypeAMAttribute = AMAttribute.getContentTypeAMAttribute(); properties.put(contentTypeAMAttribute.getName(), fileVersion.getMimeType()); AMAttribute<Object, String> fileNameAMAttribute = AMAttribute.getFileNameAMAttribute(); properties.put(fileNameAMAttribute.getName(), fileVersion.getFileName()); AMImageAttributeMapping amImageAttributeMapping = AMImageAttributeMapping.fromProperties(properties); return Optional.of(Tuple.of(fileVersion, amImageAttributeMapping)); } catch (AMRuntimeException | NumberFormatException e) { _log.error(e); return Optional.empty(); } }
From source file:com.liferay.adaptive.media.image.internal.handler.AMImageRequestHandlerTest.java
License:Open Source License
private AdaptiveMedia<AMImageProcessor> _createAdaptiveMedia(FileVersion fileVersion, AMImageConfigurationEntry amImageConfigurationEntry) throws Exception { Map<String, String> properties = new HashMap<>(); AMAttribute<Object, String> configurationUuidAMAttribute = AMAttribute.getConfigurationUuidAMAttribute(); properties.put(configurationUuidAMAttribute.getName(), amImageConfigurationEntry.getUUID()); AMAttribute<Object, String> fileNameAMAttribute = AMAttribute.getFileNameAMAttribute(); properties.put(fileNameAMAttribute.getName(), fileVersion.getFileName()); AMAttribute<Object, String> contentTypeAMAttribute = AMAttribute.getContentTypeAMAttribute(); properties.put(contentTypeAMAttribute.getName(), fileVersion.getMimeType()); AMAttribute<Object, Long> contentLengthAMAttribute = AMAttribute.getContentLengthAMAttribute(); properties.put(contentLengthAMAttribute.getName(), String.valueOf(fileVersion.getSize())); Map<String, String> configurationEntryProperties = amImageConfigurationEntry.getProperties(); properties.put(AMImageAttribute.AM_IMAGE_ATTRIBUTE_WIDTH.getName(), configurationEntryProperties.get("max-width")); properties.put(AMImageAttribute.AM_IMAGE_ATTRIBUTE_HEIGHT.getName(), configurationEntryProperties.get("max-height")); return new AMImage(() -> { try {//from ww w . j av a 2 s . co m return fileVersion.getContentStream(false); } catch (PortalException pe) { throw new AMRuntimeException(pe); } }, AMImageAttributeMapping.fromProperties(properties), null); }
From source file:com.liferay.adaptive.media.image.internal.handler.ImageAdaptiveMediaRequestHandler.java
License:Open Source License
private Optional<Tuple<FileVersion, ImageAdaptiveMediaAttributeMapping>> _interpretPath(String pathInfo) { try {/*from w w w .j a v a2 s . c om*/ Optional<Tuple<FileVersion, Map<String, String>>> fileVersionPropertiesTupleOptional = _pathInterpreter .interpretPath(pathInfo); if (!fileVersionPropertiesTupleOptional.isPresent()) { return Optional.empty(); } Tuple<FileVersion, Map<String, String>> fileVersionMapTuple = fileVersionPropertiesTupleOptional.get(); FileVersion fileVersion = fileVersionMapTuple.first; Map<String, String> properties = fileVersionMapTuple.second; AdaptiveMediaAttribute<Object, Integer> contentLengthAttribute = AdaptiveMediaAttribute.contentLength(); properties.put(contentLengthAttribute.getName(), String.valueOf(fileVersion.getSize())); AdaptiveMediaAttribute<Object, String> contentTypeAttribute = AdaptiveMediaAttribute.contentType(); properties.put(contentTypeAttribute.getName(), fileVersion.getMimeType()); AdaptiveMediaAttribute<Object, String> fileNameAttribute = AdaptiveMediaAttribute.fileName(); properties.put(fileNameAttribute.getName(), fileVersion.getFileName()); ImageAdaptiveMediaAttributeMapping attributeMapping = ImageAdaptiveMediaAttributeMapping .fromProperties(properties); return Optional.of(Tuple.of(fileVersion, attributeMapping)); } catch (NumberFormatException | AdaptiveMediaRuntimeException e) { _log.error(e); return Optional.empty(); } }
From source file:com.liferay.adaptive.media.image.internal.validator.AMImageValidatorImpl.java
License:Open Source License
@Override public boolean isValid(FileVersion fileVersion) { long imageMaxSize = _amImageConfiguration.imageMaxSize(); if ((imageMaxSize != -1) && ((imageMaxSize == 0) || (fileVersion.getSize() >= imageMaxSize))) { return false; }/* w w w. j a va 2s.c o m*/ if (!_amImageMimeTypeProvider.isMimeTypeSupported(fileVersion.getMimeType())) { return false; } return true; }
From source file:com.liferay.compat.hook.webdav.CompatResourceInvocationHandler.java
License:Open Source License
protected long getSize() { try {// w w w .j a v a 2 s .c om FileVersion fileVersion = _fileEntry.getLatestFileVersion(); return fileVersion.getSize(); } catch (Exception e) { return _fileEntry.getSize(); } }