Search in sources :

Example 11 with Media

use of com.enonic.xp.content.Media in project xp by enonic.

the class PortalUrlServiceImpl_processHtmlTest method process_single_image.

@Test
public void process_single_image() {
    // Creates a content
    final Media media = ContentFixtures.newMedia();
    Mockito.when(this.contentService.getById(media.getId())).thenReturn(media);
    Mockito.when(this.contentService.getBinaryKey(media.getId(), media.getMediaAttachment().getBinaryReference())).thenReturn("binaryHash");
    // Process an html text containing a link to this content
    final ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<a href=\"image://" + media.getId() + "\">Image</a>");
    // Checks that the page URL of the content is returned
    final String processedHtml = this.service.processHtml(params);
    assertEquals("<a href=\"/site/default/draft/context/path/_/image/" + media.getId() + ":8cf45815bba82c9711c673c9bb7304039a790026/" + "width-768" + "/" + media.getName() + "\">Image</a>", processedHtml);
}
Also used : Media(com.enonic.xp.content.Media) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) Test(org.junit.jupiter.api.Test)

Example 12 with Media

use of com.enonic.xp.content.Media in project xp by enonic.

the class ImageUrlBuilder method buildUrl.

@Override
protected void buildUrl(final StringBuilder url, final Multimap<String, String> params) {
    super.buildUrl(url, params);
    final ContentId id = resolveId();
    final Media media = resolveMedia(id);
    final String hash = resolveHash(media);
    final String name = resolveName(media);
    final String scale = resolveScale();
    appendPart(url, id + ":" + hash);
    appendPart(url, scale);
    appendPart(url, name);
    addParamIfNeeded(params, "quality", this.params.getQuality());
    addParamIfNeeded(params, "background", this.params.getBackground());
    addParamIfNeeded(params, "filter", this.params.getFilter());
}
Also used : Media(com.enonic.xp.content.Media) ContentId(com.enonic.xp.content.ContentId)

Example 13 with Media

use of com.enonic.xp.content.Media in project xp by enonic.

the class ContentFixtures method newMedia.

public static Media newMedia() {
    final Attachment attachment = Attachment.create().name("logo.png").mimeType("image/png").label("small").build();
    final PropertyTree data = newPropertyTree();
    data.addString("media", attachment.getName());
    final PropertyTree mediaData = newPropertyTree();
    mediaData.setLong(IMAGE_INFO_PIXEL_SIZE, 300L * 200L);
    mediaData.setLong(IMAGE_INFO_IMAGE_HEIGHT, 200L);
    mediaData.setLong(IMAGE_INFO_IMAGE_WIDTH, 300L);
    mediaData.setLong(MEDIA_INFO_BYTE_SIZE, 100000L);
    final ExtraData mediaExtraData = new ExtraData(MediaInfo.IMAGE_INFO_METADATA_NAME, mediaData);
    final Media.Builder builder = Media.create();
    builder.id(ContentId.from("123456"));
    builder.type(ContentTypeName.imageMedia());
    builder.name("mycontent");
    builder.displayName("My Content");
    builder.parentPath(ContentPath.from("/a/b"));
    builder.modifier(PrincipalKey.from("user:system:admin"));
    builder.modifiedTime(Instant.ofEpochSecond(0));
    builder.creator(PrincipalKey.from("user:system:admin"));
    builder.createdTime(Instant.ofEpochSecond(0));
    builder.attachments(Attachments.from(attachment));
    builder.data(data);
    builder.addExtraData(new ExtraData(XDataName.from("myapplication:myschema"), newTinyPropertyTree()));
    builder.addExtraData(mediaExtraData);
    builder.page(newPage());
    return builder.build();
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Media(com.enonic.xp.content.Media) Attachment(com.enonic.xp.attachment.Attachment) ExtraData(com.enonic.xp.content.ExtraData)

Example 14 with Media

use of com.enonic.xp.content.Media in project xp by enonic.

the class PortalUrlServiceImpl_processHtmlTest method processHtml_image_imageWidths.

@Test
public void processHtml_image_imageWidths() {
    // Creates a content
    final Media media = ContentFixtures.newMedia();
    Mockito.when(this.contentService.getById(media.getId())).thenReturn(media);
    Mockito.when(this.contentService.getBinaryKey(media.getId(), media.getMediaAttachment().getBinaryReference())).thenReturn("binaryHash");
    // Process an html text containing a link to this content
    final ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<p><figure class=\"editor-align-justify\"><img alt=\"Alt text\" src=\"image://" + media.getId() + "\"/><figcaption>Caption text</figcaption></figure></p>").imageWidths(List.of(660, 1024)).imageSizes(" ");
    // Checks that the page URL of the content is returned
    final String processedHtml = this.service.processHtml(params);
    assertEquals("<p><figure class=\"editor-align-justify\">" + "<img alt=\"Alt text\" src=\"/site/default/draft/context/path/_/image/" + media.getId() + ":8cf45815bba82c9711c673c9bb7304039a790026/width-768/mycontent\" " + "srcset=\"/site/default/draft/context/path/_/image/" + media.getId() + ":8cf45815bba82c9711c673c9bb7304039a790026/width-660/mycontent 660w," + "/site/default/draft/context/path/_/image/" + media.getId() + ":8cf45815bba82c9711c673c9bb7304039a790026/width-1024/mycontent 1024w\"/><figcaption>Caption text</figcaption></figure></p>", processedHtml);
}
Also used : Media(com.enonic.xp.content.Media) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) Test(org.junit.jupiter.api.Test)

Example 15 with Media

use of com.enonic.xp.content.Media in project xp by enonic.

the class MediaInfoServiceTest method loadImageWithEditedOrientation.

@Test
public void loadImageWithEditedOrientation() {
    final ByteSource byteSource = Resources.asByteSource(getClass().getResource("NikonD100.jpg"));
    final Media media = this.createMedia("image", ContentPath.ROOT, true);
    final ImageOrientation orientation = this.service.getImageOrientation(byteSource, media);
    assertEquals(3, orientation.getValue());
}
Also used : Media(com.enonic.xp.content.Media) ByteSource(com.google.common.io.ByteSource) ImageOrientation(com.enonic.xp.media.ImageOrientation) Test(org.junit.jupiter.api.Test)

Aggregations

Media (com.enonic.xp.content.Media)19 Test (org.junit.jupiter.api.Test)7 Attachment (com.enonic.xp.attachment.Attachment)6 ProcessHtmlParams (com.enonic.xp.portal.url.ProcessHtmlParams)5 ByteSource (com.google.common.io.ByteSource)5 ContentId (com.enonic.xp.content.ContentId)4 Content (com.enonic.xp.content.Content)3 ExtraData (com.enonic.xp.content.ExtraData)3 PropertyTree (com.enonic.xp.data.PropertyTree)3 ImageOrientation (com.enonic.xp.media.ImageOrientation)3 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)2 BinaryReference (com.enonic.xp.util.BinaryReference)2 ContentService (com.enonic.xp.content.ContentService)1 CreateMediaParams (com.enonic.xp.content.CreateMediaParams)1 ThrottlingException (com.enonic.xp.exception.ThrottlingException)1 Cropping (com.enonic.xp.image.Cropping)1 ReadImageParams (com.enonic.xp.image.ReadImageParams)1 MediaInfo (com.enonic.xp.media.MediaInfo)1 PortalRequest (com.enonic.xp.portal.PortalRequest)1 PortalResponse (com.enonic.xp.portal.PortalResponse)1