Search in sources :

Example 41 with ContentId

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);
}
Also used : Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId) ContentPath(com.enonic.xp.content.ContentPath)

Example 42 with ContentId

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);
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) ContentId(com.enonic.xp.content.ContentId)

Example 43 with 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;
}
Also used : Media(com.enonic.xp.content.Media) Attachment(com.enonic.xp.attachment.Attachment) ContentId(com.enonic.xp.content.ContentId) ContentService(com.enonic.xp.content.ContentService) PortalRequest(com.enonic.xp.portal.PortalRequest) ImageUrlParams(com.enonic.xp.portal.url.ImageUrlParams) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 44 with ContentId

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);
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Example 45 with ContentId

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);
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Aggregations

ContentId (com.enonic.xp.content.ContentId)83 Content (com.enonic.xp.content.Content)34 Test (org.junit.jupiter.api.Test)33 PropertyTree (com.enonic.xp.data.PropertyTree)16 ContentPath (com.enonic.xp.content.ContentPath)14 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)13 ContentIds (com.enonic.xp.content.ContentIds)11 PropertySet (com.enonic.xp.data.PropertySet)10 NodeId (com.enonic.xp.node.NodeId)9 BeforeEach (org.junit.jupiter.api.BeforeEach)8 ContentInheritType (com.enonic.xp.content.ContentInheritType)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)7 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)6 Context (com.enonic.xp.context.Context)6 DeleteContentParams (com.enonic.xp.content.DeleteContentParams)5 Node (com.enonic.xp.node.Node)5 Branch (com.enonic.xp.branch.Branch)4 ContentConstants (com.enonic.xp.content.ContentConstants)4 ContextBuilder (com.enonic.xp.context.ContextBuilder)4