Search in sources :

Example 6 with MediaInfo

use of com.enonic.xp.media.MediaInfo in project xp by enonic.

the class MediaInfoServiceTest method multiple_colorSpace_entries.

@Test
public void multiple_colorSpace_entries() {
    final ByteSource byteSource = Resources.asByteSource(getClass().getResource("Multiple-colorSpace-entries.jpg"));
    final MediaInfo mediaInfo = this.service.parseMediaInfo(byteSource);
}
Also used : MediaInfo(com.enonic.xp.media.MediaInfo) ByteSource(com.google.common.io.ByteSource) Test(org.junit.jupiter.api.Test)

Example 7 with MediaInfo

use of com.enonic.xp.media.MediaInfo in project xp by enonic.

the class CreateMediaCommand method doExecute.

private Content doExecute() {
    final MediaInfo mediaInfo = mediaInfoService.parseMediaInfo(params.getByteSource());
    if ((params.getMimeType() == null || isBinaryContentType(params.getMimeType())) && mediaInfo.getMediaType() != null) {
        params.mimeType(mediaInfo.getMediaType());
    }
    Preconditions.checkNotNull(params.getMimeType(), "Unable to resolve media type");
    final ContentTypeName resolvedTypeFromMimeType = ContentTypeFromMimeTypeResolver.resolve(params.getMimeType());
    final ContentTypeName type = resolvedTypeFromMimeType != null ? resolvedTypeFromMimeType : isExecutableContentType(params.getMimeType(), params.getName()) ? ContentTypeName.executableMedia() : ContentTypeName.unknownMedia();
    final PropertyTree data = new PropertyTree();
    new MediaFormDataBuilder().type(type).attachment(params.getName()).focalX(params.getFocalX()).focalY(params.getFocalY()).caption(params.getCaption()).artist(params.getArtist()).copyright(params.getCopyright()).tags(params.getTags()).build(data);
    final CreateAttachment mediaAttachment = CreateAttachment.create().name(params.getName()).mimeType(params.getMimeType()).label("source").byteSource(params.getByteSource()).text(type.isTextualMedia() ? mediaInfo.getTextContent() : "").build();
    final CreateContentParams createContentParams = CreateContentParams.create().name(params.getName()).parent(params.getParent()).requireValid(true).type(type).displayName(trimExtension(params.getName())).contentData(data).createAttachments(CreateAttachments.from(mediaAttachment)).inheritPermissions(true).build();
    final CreateContentCommand createCommand = CreateContentCommand.create(this).mediaInfo(mediaInfo).params(createContentParams).siteService(this.siteService).xDataService(this.xDataService).formDefaultValuesProcessor(this.formDefaultValuesProcessor).pageDescriptorService(this.pageDescriptorService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).allowUnsafeAttachmentNames(this.allowUnsafeAttachmentNames).build();
    return createCommand.execute();
}
Also used : MediaInfo(com.enonic.xp.media.MediaInfo) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) CreateContentParams(com.enonic.xp.content.CreateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName)

Example 8 with MediaInfo

use of com.enonic.xp.media.MediaInfo in project xp by enonic.

the class ImageContentProcessor method processUpdate.

@Override
public ProcessUpdateResult processUpdate(final ProcessUpdateParams params) {
    final CreateAttachments createAttachments = params.getCreateAttachments();
    final MediaInfo mediaInfo = params.getMediaInfo();
    final CreateAttachment sourceAttachment = createAttachments == null ? null : createAttachments.first();
    final ContentEditor editor;
    if (mediaInfo != null) {
        editor = editable -> {
            final Map<XDataName, ExtraData> extraDatas = editable.extraDatas.stream().collect(Collectors.toMap(ExtraData::getName, o -> o));
            final XDatas contentXDatas = getXDatas(params.getContentType().getName());
            extractMetadata(mediaInfo, contentXDatas, sourceAttachment).forEach(extraData -> extraDatas.put(extraData.getName(), extraData));
            editable.extraDatas = ExtraDatas.create().addAll(extraDatas.values()).build();
        };
    } else {
        editor = editable -> {
            if (!params.getContentType().getName().isDescendantOfMedia()) {
                return;
            }
            editable.extraDatas = updateImageMetadata(editable);
        };
    }
    return new ProcessUpdateResult(createAttachments, editor);
}
Also used : MediaInfo(com.enonic.xp.media.MediaInfo) Cropping(com.enonic.xp.image.Cropping) ContentTypeService(com.enonic.xp.schema.content.ContentTypeService) ContentEditor(com.enonic.xp.content.ContentEditor) MEDIA_INFO_BYTE_SIZE(com.enonic.xp.media.MediaInfo.MEDIA_INFO_BYTE_SIZE) Map(java.util.Map) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) ImageIO(javax.imageio.ImageIO) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) XDataName(com.enonic.xp.schema.xdata.XDataName) Media(com.enonic.xp.content.Media) Property(com.enonic.xp.data.Property) IMAGE_INFO_PIXEL_SIZE(com.enonic.xp.media.MediaInfo.IMAGE_INFO_PIXEL_SIZE) BufferedImage(java.awt.image.BufferedImage) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ContentProcessor(com.enonic.xp.content.processor.ContentProcessor) IMAGE_INFO_IMAGE_WIDTH(com.enonic.xp.media.MediaInfo.IMAGE_INFO_IMAGE_WIDTH) ContentType(com.enonic.xp.schema.content.ContentType) Collectors(java.util.stream.Collectors) ExtraDatas(com.enonic.xp.content.ExtraDatas) EditableContent(com.enonic.xp.content.EditableContent) InputTypeName(com.enonic.xp.inputtype.InputTypeName) FormItem(com.enonic.xp.form.FormItem) IMAGE_INFO_IMAGE_HEIGHT(com.enonic.xp.media.MediaInfo.IMAGE_INFO_IMAGE_HEIGHT) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult) CreateContentParams(com.enonic.xp.content.CreateContentParams) ContentService(com.enonic.xp.content.ContentService) IMAGE_INFO(com.enonic.xp.media.MediaInfo.IMAGE_INFO) ProcessCreateResult(com.enonic.xp.content.processor.ProcessCreateResult) HashMap(java.util.HashMap) Attachment(com.enonic.xp.attachment.Attachment) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) ProcessCreateParams(com.enonic.xp.content.processor.ProcessCreateParams) Component(org.osgi.service.component.annotations.Component) FormItemType(com.enonic.xp.form.FormItemType) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) ExtraData(com.enonic.xp.content.ExtraData) XData(com.enonic.xp.schema.xdata.XData) Exceptions(com.enonic.xp.util.Exceptions) GeoPoint(com.enonic.xp.util.GeoPoint) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ByteSource(com.google.common.io.ByteSource) XDataService(com.enonic.xp.schema.xdata.XDataService) PropertyTree(com.enonic.xp.data.PropertyTree) ProcessUpdateParams(com.enonic.xp.content.processor.ProcessUpdateParams) XDatas(com.enonic.xp.schema.xdata.XDatas) IOException(java.io.IOException) ValueTypes(com.enonic.xp.data.ValueTypes) Preconditions(com.google.common.base.Preconditions) Input(com.enonic.xp.form.Input) Reference(org.osgi.service.component.annotations.Reference) InputStream(java.io.InputStream) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) MediaInfo(com.enonic.xp.media.MediaInfo) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) ContentEditor(com.enonic.xp.content.ContentEditor) XDatas(com.enonic.xp.schema.xdata.XDatas) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult) ExtraData(com.enonic.xp.content.ExtraData) XDataName(com.enonic.xp.schema.xdata.XDataName)

Example 9 with MediaInfo

use of com.enonic.xp.media.MediaInfo in project xp by enonic.

the class MediaInfoServiceTest method multiple_FNumber_entries.

@Test
public void multiple_FNumber_entries() {
    final ByteSource byteSource = Resources.asByteSource(getClass().getResource("Multiple-FNumber-entries.JPG"));
    final MediaInfo mediaInfo = this.service.parseMediaInfo(byteSource);
}
Also used : MediaInfo(com.enonic.xp.media.MediaInfo) ByteSource(com.google.common.io.ByteSource) Test(org.junit.jupiter.api.Test)

Aggregations

MediaInfo (com.enonic.xp.media.MediaInfo)9 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)5 ByteSource (com.google.common.io.ByteSource)5 ContentTypeName (com.enonic.xp.schema.content.ContentTypeName)4 CreateContentParams (com.enonic.xp.content.CreateContentParams)3 Attachment (com.enonic.xp.attachment.Attachment)2 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)2 ExtraDatas (com.enonic.xp.content.ExtraDatas)2 Media (com.enonic.xp.content.Media)2 ProcessCreateResult (com.enonic.xp.content.processor.ProcessCreateResult)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 XDatas (com.enonic.xp.schema.xdata.XDatas)2 Test (org.junit.jupiter.api.Test)2 Content (com.enonic.xp.content.Content)1 ContentEditor (com.enonic.xp.content.ContentEditor)1 ContentService (com.enonic.xp.content.ContentService)1 EditableContent (com.enonic.xp.content.EditableContent)1 ExtraData (com.enonic.xp.content.ExtraData)1 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)1 ContentProcessor (com.enonic.xp.content.processor.ContentProcessor)1