use of com.enonic.xp.portal.url.ProcessHtmlParams in project xp by enonic.
the class PortalUrlServiceImpl_processHtmlTest method process_image_with_styles.
@Test
public void process_image_with_styles() {
// 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");
final ImageStyle imageStyle = ImageStyle.create().name("mystyle").aspectRatio("2:1").filter("myfilter").build();
final StyleDescriptor styleDescriptor = StyleDescriptor.create().application(ApplicationKey.from("myapp")).addStyleElement(imageStyle).build();
Mockito.when(styleDescriptorService.getByApplications(Mockito.any())).thenReturn(StyleDescriptors.from(styleDescriptor));
// Process an html text containing a style
final String link1 = "<a href=\"image://" + media.getId() + "?style=mystyle\">Image</a>";
final String link2 = "<a href=\"image://" + media.getId() + "?style=missingstyle\">Image</a>";
final ProcessHtmlParams params1 = new ProcessHtmlParams().portalRequest(this.portalRequest).value(link1);
final ProcessHtmlParams params2 = new ProcessHtmlParams().portalRequest(this.portalRequest).value(link2);
final String processedLink1 = this.service.processHtml(params1);
final String processedLink2 = this.service.processHtml(params2);
// Checks that the page URL of the content is returned
final String expectedResult1 = "<a href=\"/site/default/draft/context/path/_/image/" + media.getId() + ":8cf45815bba82c9711c673c9bb7304039a790026/" + "block-768-384" + "/" + media.getName() + "?filter=myfilter\">Image</a>";
final String expectedResult2 = "<a href=\"/site/default/draft/context/path/_/image/" + media.getId() + ":8cf45815bba82c9711c673c9bb7304039a790026/" + "width-768" + "/" + media.getName() + "\">Image</a>";
assertEquals(expectedResult1, processedLink1);
assertEquals(expectedResult2, processedLink2);
}
use of com.enonic.xp.portal.url.ProcessHtmlParams in project xp by enonic.
the class PortalUrlServiceImpl_processHtmlTest method process_image_with_scale.
@Test
public void process_image_with_scale() {
// 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() + "?scale=21:9\">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/" + "block-768-324" + "/" + media.getName() + "\">Image</a>", processedHtml);
}
use of com.enonic.xp.portal.url.ProcessHtmlParams in project xp by enonic.
the class PortalUrlServiceImpl_processHtmlTest method process_unknown_image.
@Test
public void process_unknown_image() {
when(contentService.getById(isA(ContentId.class))).thenAnswer((params) -> {
final ContentId id = params.getArgument(0);
throw new ContentNotFoundException(id, ContextAccessor.current().getBranch());
});
// Process an html text containing a link to an unknown media
final ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<a href=\"image://123\">Image</a>");
// Checks that the error 500 page is returned
final String processedHtml = this.service.processHtml(params);
assertEquals("<a href=\"/site/default/draft/context/path/_/error/500?message=Image+with+%5B123%5D+id+not+found\">Image</a>", processedHtml);
}
use of com.enonic.xp.portal.url.ProcessHtmlParams in project xp by enonic.
the class PortalUrlServiceImpl_processHtmlTest method process_single_content.
@Test
public void process_single_content() {
// Creates a content
final Content content = ContentFixtures.newContent();
Mockito.when(this.contentService.getById(content.getId())).thenReturn(content);
// Process an html text containing a link to this content
final ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<a href=\"content://" + content.getId() + "\">Content</a>");
// Checks that the page URL of the content is returned
final String processedHtml = this.service.processHtml(params);
assertEquals("<a href=\"/site/default/draft" + content.getPath() + "\">Content</a>", processedHtml);
}
use of com.enonic.xp.portal.url.ProcessHtmlParams in project xp by enonic.
the class TextRenderer method render.
@Override
public PortalResponse render(final TextComponent textComponent, final PortalRequest portalRequest) {
final RenderMode renderMode = portalRequest.getMode();
final PortalResponse.Builder portalResponseBuilder = PortalResponse.create();
portalResponseBuilder.contentType(MediaType.create("text", "html")).postProcess(false);
if (textComponent.getText().isEmpty()) {
renderEmptyTextComponent(textComponent, renderMode, portalResponseBuilder);
} else {
if (renderMode == RenderMode.EDIT) {
portalResponseBuilder.body(MessageFormat.format(COMPONENT_EDIT_MODE_HTML, textComponent.getType().toString(), textComponent.getText()));
} else {
ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(portalRequest).value(textComponent.getText());
final String processedHtml = removeEmptyFigCaptionTags(service.processHtml(params));
portalResponseBuilder.body(MessageFormat.format(COMPONENT_PREVIEW_MODE_HTML, textComponent.getType().toString(), processedHtml));
}
}
return portalResponseBuilder.build();
}
Aggregations