Example usage for com.liferay.portal.kernel.repository.model FileVersion getFileName

List of usage examples for com.liferay.portal.kernel.repository.model FileVersion getFileName

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.repository.model FileVersion getFileName.

Prototype

public String getFileName();

Source Link

Usage

From source file:com.liferay.adaptive.media.image.internal.finder.AdaptiveMediaImageFinderImpl.java

License:Open Source License

private AdaptiveMedia<AdaptiveMediaImageProcessor> _createMedia(FileVersion fileVersion,
        BiFunction<FileVersion, AdaptiveMediaImageConfigurationEntry, URI> uriFactory,
        AdaptiveMediaImageConfigurationEntry configurationEntry) {

    Map<String, String> properties = configurationEntry.getProperties();

    AdaptiveMediaAttribute<Object, String> configurationUuidAttribute = AdaptiveMediaAttribute
            .configurationUuid();/*from  ww  w .j a va 2  s .  c  om*/

    properties.put(configurationUuidAttribute.getName(), configurationEntry.getUUID());

    AdaptiveMediaAttribute<Object, String> fileNameAttribute = AdaptiveMediaAttribute.fileName();

    properties.put(fileNameAttribute.getName(), fileVersion.getFileName());

    AdaptiveMediaImageEntry imageEntry = _imageEntryLocalService
            .fetchAdaptiveMediaImageEntry(configurationEntry.getUUID(), fileVersion.getFileVersionId());

    if (imageEntry != null) {
        AdaptiveMediaAttribute<AdaptiveMediaImageProcessor, Integer> imageHeightAttribute = AdaptiveMediaImageAttribute.IMAGE_HEIGHT;

        properties.put(imageHeightAttribute.getName(), String.valueOf(imageEntry.getHeight()));

        AdaptiveMediaAttribute<AdaptiveMediaImageProcessor, Integer> imageWidthAttribute = AdaptiveMediaImageAttribute.IMAGE_WIDTH;

        properties.put(imageWidthAttribute.getName(), String.valueOf(imageEntry.getWidth()));

        AdaptiveMediaAttribute<Object, String> contentTypeAttribute = AdaptiveMediaAttribute.contentType();

        properties.put(contentTypeAttribute.getName(), imageEntry.getMimeType());

        AdaptiveMediaAttribute<Object, Integer> contentLengthAttribute = AdaptiveMediaAttribute.contentLength();

        properties.put(contentLengthAttribute.getName(), String.valueOf(imageEntry.getSize()));
    }

    AdaptiveMediaImageAttributeMapping attributeMapping = AdaptiveMediaImageAttributeMapping
            .fromProperties(properties);

    return new AdaptiveMediaImage(() -> _imageEntryLocalService
            .getAdaptiveMediaImageEntryContentStream(configurationEntry, fileVersion), attributeMapping,
            uriFactory.apply(fileVersion, configurationEntry));
}

From source file:com.liferay.adaptive.media.image.internal.finder.AMImageFinderImpl.java

License:Open Source License

private AdaptiveMedia<AMImageProcessor> _createMedia(FileVersion fileVersion,
        BiFunction<FileVersion, AMImageConfigurationEntry, URI> uriFactory,
        AMImageConfigurationEntry amImageConfigurationEntry) {

    Map<String, String> properties = amImageConfigurationEntry.getProperties();

    AMAttribute<Object, String> configurationUuidAMAttribute = AMAttribute.getConfigurationUuidAMAttribute();

    properties.put(configurationUuidAMAttribute.getName(), amImageConfigurationEntry.getUUID());

    AMAttribute<Object, String> fileNameAMAttribute = AMAttribute.getFileNameAMAttribute();

    properties.put(fileNameAMAttribute.getName(), fileVersion.getFileName());

    AMImageEntry amImageEntry = _amImageEntryLocalService.fetchAMImageEntry(amImageConfigurationEntry.getUUID(),
            fileVersion.getFileVersionId());

    if (amImageEntry != null) {
        AMAttribute<AMImageProcessor, Integer> imageHeightAMAttribute = AMImageAttribute.AM_IMAGE_ATTRIBUTE_HEIGHT;

        properties.put(imageHeightAMAttribute.getName(), String.valueOf(amImageEntry.getHeight()));

        AMAttribute<AMImageProcessor, Integer> imageWidthAMAttribute = AMImageAttribute.AM_IMAGE_ATTRIBUTE_WIDTH;

        properties.put(imageWidthAMAttribute.getName(), String.valueOf(amImageEntry.getWidth()));

        AMAttribute<Object, String> contentTypeAMAttribute = AMAttribute.getContentTypeAMAttribute();

        properties.put(contentTypeAMAttribute.getName(), amImageEntry.getMimeType());

        AMAttribute<Object, Long> contentLengthAMAttribute = AMAttribute.getContentLengthAMAttribute();

        properties.put(contentLengthAMAttribute.getName(), String.valueOf(amImageEntry.getSize()));
    }//from   w w w  .  j a v a2 s  .c o m

    AMImageAttributeMapping amImageAttributeMapping = AMImageAttributeMapping.fromProperties(properties);

    return new AMImage(
            () -> _amImageEntryLocalService.getAMImageEntryContentStream(amImageConfigurationEntry,
                    fileVersion),
            amImageAttributeMapping, uriFactory.apply(fileVersion, amImageConfigurationEntry));
}

From source file:com.liferay.adaptive.media.image.internal.finder.ImageAdaptiveMediaFinderImpl.java

License:Open Source License

private URI _createFileEntryURL(FileVersion fileVersion,
        ImageAdaptiveMediaConfigurationEntry configurationEntry) {

    String relativeURI = String.format("image/%d/%s/%s", fileVersion.getFileEntryId(),
            configurationEntry.getUUID(), _encode(fileVersion.getFileName()));

    return _uriResolver.resolveURI(URI.create(relativeURI));
}

From source file:com.liferay.adaptive.media.image.internal.finder.ImageAdaptiveMediaFinderImpl.java

License:Open Source License

private URI _createFileVersionURL(FileVersion fileVersion,
        ImageAdaptiveMediaConfigurationEntry configurationEntry) {

    String relativeURI = String.format("image/%d/%d/%s/%s", fileVersion.getFileEntryId(),
            fileVersion.getFileVersionId(), configurationEntry.getUUID(), _encode(fileVersion.getFileName()));

    return _uriResolver.resolveURI(URI.create(relativeURI));
}

From source file:com.liferay.adaptive.media.image.internal.finder.ImageAdaptiveMediaFinderImpl.java

License:Open Source License

private AdaptiveMedia<ImageAdaptiveMediaProcessor> _createMedia(FileVersion fileVersion,
        BiFunction<FileVersion, ImageAdaptiveMediaConfigurationEntry, URI> uriFactory,
        ImageAdaptiveMediaConfigurationEntry configurationEntry) {

    Map<String, String> properties = configurationEntry.getProperties();

    AdaptiveMediaAttribute<Object, Integer> contentLengthAttribute = AdaptiveMediaAttribute.contentLength();

    Optional<ImageInfo> imageInfoOptional = _imageStorage.getImageInfo(fileVersion, configurationEntry);

    imageInfoOptional.ifPresent(/*from  ww w .  j a v  a2s .co  m*/
            imageInfo -> properties.put(contentLengthAttribute.getName(), String.valueOf(imageInfo.getSize())));

    AdaptiveMediaAttribute<Object, String> contentTypeAttribute = AdaptiveMediaAttribute.contentType();

    imageInfoOptional
            .ifPresent(imageInfo -> properties.put(contentTypeAttribute.getName(), imageInfo.getMimeType()));

    AdaptiveMediaAttribute<Object, String> fileNameAttribute = AdaptiveMediaAttribute.fileName();

    properties.put(fileNameAttribute.getName(), fileVersion.getFileName());

    ImageAdaptiveMediaAttributeMapping attributeMapping = ImageAdaptiveMediaAttributeMapping
            .fromProperties(properties);

    return new ImageAdaptiveMedia(() -> _imageStorage.getContentStream(fileVersion, configurationEntry),
            attributeMapping, uriFactory.apply(fileVersion, configurationEntry));
}

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 {/*from w w w.j  ava2  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 {/* ww  w.ja  va2s. co  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  .j a v  a2  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.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  av a2  s .c om*/
            return fileVersion.getContentStream(false);
        } catch (PortalException pe) {
            throw new AMRuntimeException(pe);
        }
    }, AMImageAttributeMapping.fromProperties(properties), null);
}