use of com.enonic.xp.content.ContentId in project xp by enonic.
the class ArchiveContentHandler method executeArchive.
private List<String> executeArchive() {
final ContentId sourceId;
final ContentPath sourcePath;
if (this.content.startsWith("/")) {
// source is path
sourcePath = ContentPath.from(this.content);
final Content sourceContent = contentService.getByPath(sourcePath);
sourceId = sourceContent.getId();
} else {
// source is key
sourceId = ContentId.from(this.content);
}
return archive(sourceId);
}
use of com.enonic.xp.content.ContentId in project xp by enonic.
the class HtmlAreaContentProcessor method processString.
private void processString(final String value, final ContentIds.Builder processedIds) {
if (nullToEmpty(value).isBlank()) {
return;
}
final Matcher contentMatcher = HtmlLinkProcessor.CONTENT_PATTERN.matcher(value);
while (contentMatcher.find()) {
if (contentMatcher.groupCount() >= HtmlLinkProcessor.NB_GROUPS) {
final String id = contentMatcher.group(HtmlLinkProcessor.ID_INDEX);
final ContentId contentId = ContentId.from(id);
processedIds.add(contentId);
}
}
}
use of com.enonic.xp.content.ContentId in project xp by enonic.
the class ImageUrlBuilderTest method init.
@BeforeEach
public void init() {
final PortalRequest portalRequest = new PortalRequest();
portalRequest.setBranch(Branch.from("draft"));
portalRequest.setApplicationKey(ApplicationKey.from("myapplication"));
portalRequest.setBaseUri("/site");
portalRequest.setContentPath(ContentPath.from("context/path"));
this.imageUrlParams = new ImageUrlParams().portalRequest(portalRequest).scale("testScale");
urlBuilder = new ImageUrlBuilder();
urlBuilder.setParams(imageUrlParams);
final Attachment attachment = Attachment.create().name("attachmentName").mimeType("attachmentMimeType").size(1).build();
media = Mockito.mock(Media.class);
final ContentId contentId = ContentId.from("testID");
Mockito.when(media.getId()).thenReturn(contentId);
Mockito.when(media.getName()).thenReturn(ContentName.from("testName"));
Mockito.when(media.getType()).thenReturn(ContentTypeName.imageMedia());
Mockito.when(media.getMediaAttachment()).thenReturn(attachment);
final ContentService contentService = Mockito.mock(ContentService.class);
Mockito.when(contentService.getByPath(Mockito.any())).thenReturn(media);
Mockito.when(contentService.getById(Mockito.any())).thenReturn(media);
Mockito.when(contentService.getBinaryKey(contentId, attachment.getBinaryReference())).thenReturn("binaryHash");
urlBuilder.contentService = contentService;
}
use of com.enonic.xp.content.ContentId 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.content.ContentId in project xp by enonic.
the class PortalUrlServiceImpl_processHtmlTest method process_unknown_media.
@Test
public void process_unknown_media() {
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=\"media://inline/123\">Media</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/404?message=Content+with+id+%5B123%5D+was+not+found+in+branch+%5Bdraft%5D\">Media</a>", processedHtml);
}
Aggregations