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);
}
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());
}
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();
}
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);
}
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());
}
Aggregations