Search in sources :

Example 1 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 2 with MediaInfo

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

the class UpdateMediaCommand 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 Content existingContent = getContent(params.getContent());
    Preconditions.checkArgument(existingContent.getType().equals(type), "Updated content must be of type: " + existingContent.getType());
    final CreateAttachment mediaAttachment = CreateAttachment.create().name(params.getName()).mimeType(params.getMimeType()).label("source").byteSource(params.getByteSource()).text(type.isTextualMedia() ? mediaInfo.getTextContent() : null).build();
    final MediaFormDataBuilder mediaFormBuilder = 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());
    final UpdateContentParams updateParams = new UpdateContentParams().contentId(params.getContent()).clearAttachments(true).createAttachments(CreateAttachments.from(mediaAttachment)).editor(editable -> mediaFormBuilder.build(editable.data));
    return UpdateContentCommand.create(this).params(updateParams).mediaInfo(mediaInfo).contentTypeService(this.contentTypeService).siteService(this.siteService).xDataService(this.xDataService).pageDescriptorService(this.pageDescriptorService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).build().execute();
}
Also used : MediaInfo(com.enonic.xp.media.MediaInfo) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName)

Example 3 with MediaInfo

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

the class UpdatedEventSyncCommand method doSyncMedia.

private void doSyncMedia(final ContentToSync content, final UpdateContentParams updateParams) {
    if (content.getSourceContent() instanceof Media) {
        final Media sourceMedia = (Media) content.getSourceContent();
        final Attachment mediaAttachment = sourceMedia.getMediaAttachment();
        final ByteSource sourceBinary = content.getSourceContext().callWith(() -> contentService.getBinary(sourceMedia.getId(), mediaAttachment.getBinaryReference()));
        final MediaInfo mediaInfo = content.getSourceContext().callWith(() -> mediaInfoService.parseMediaInfo(sourceBinary));
        final ContentTypeName type = ContentTypeFromMimeTypeResolver.resolve(mediaAttachment.getMimeType());
        final CreateAttachment createAttachment = CreateAttachment.create().name(mediaAttachment.getName()).mimeType(mediaAttachment.getMimeType()).label("source").byteSource(sourceBinary).text(type != null && type.isTextualMedia() ? mediaInfo.getTextContent() : null).build();
        updateParams.clearAttachments(true).createAttachments(CreateAttachments.from(createAttachment));
    }
}
Also used : MediaInfo(com.enonic.xp.media.MediaInfo) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) Media(com.enonic.xp.content.Media) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) ByteSource(com.google.common.io.ByteSource) Attachment(com.enonic.xp.attachment.Attachment) CreateAttachment(com.enonic.xp.attachment.CreateAttachment)

Example 4 with MediaInfo

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

the class ImageContentProcessor method processCreate.

@Override
public ProcessCreateResult processCreate(final ProcessCreateParams params) {
    final CreateContentParams createContentParams = params.getCreateContentParams();
    final MediaInfo mediaInfo = params.getMediaInfo();
    final CreateAttachments originalAttachments = createContentParams.getCreateAttachments();
    Preconditions.checkArgument(originalAttachments.getSize() == 1, "Expected only one attachment");
    final CreateAttachment sourceAttachment = originalAttachments.first();
    final XDatas contentXDatas = getXDatas(createContentParams.getType());
    ExtraDatas extraDatas = null;
    if (mediaInfo != null) {
        extraDatas = extractMetadata(mediaInfo, contentXDatas, sourceAttachment);
    }
    final CreateAttachments.Builder builder = CreateAttachments.create();
    builder.add(sourceAttachment);
    return new ProcessCreateResult(CreateContentParams.create(createContentParams).createAttachments(builder.build()).extraDatas(extraDatas).build());
}
Also used : CreateAttachments(com.enonic.xp.attachment.CreateAttachments) MediaInfo(com.enonic.xp.media.MediaInfo) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) CreateContentParams(com.enonic.xp.content.CreateContentParams) XDatas(com.enonic.xp.schema.xdata.XDatas) ExtraDatas(com.enonic.xp.content.ExtraDatas) ProcessCreateResult(com.enonic.xp.content.processor.ProcessCreateResult)

Example 5 with MediaInfo

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

the class MediaInfoServiceImpl method parseMediaInfo.

@Override
public MediaInfo parseMediaInfo(final ByteSource byteSource) {
    final MediaInfo.Builder builder = MediaInfo.create();
    final ExtractedData extractedData = binaryExtractor.extract(byteSource);
    addMetadata(byteSource, builder, extractedData);
    builder.setTextContent(extractedData.getText());
    return builder.build();
}
Also used : ExtractedData(com.enonic.xp.extractor.ExtractedData) MediaInfo(com.enonic.xp.media.MediaInfo)

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