Search in sources :

Example 1 with EditableSite

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

the class HtmlAreaContentProcessor method processUpdate.

@Override
public ProcessUpdateResult processUpdate(final ProcessUpdateParams params) {
    final CreateAttachments createAttachments = params.getCreateAttachments();
    final ContentEditor editor;
    editor = editable -> {
        final ContentIds.Builder processedIds = ContentIds.create();
        final ContentType contentType = contentTypeService.getByName(GetContentTypeParams.from(editable.source.getType()));
        processContentData(editable.data, contentType, processedIds);
        processExtraData(editable.extraDatas, processedIds);
        processPageData(editable.page, processedIds);
        if (editable instanceof EditableSite) {
            processSiteConfigData(((EditableSite) editable).siteConfigs, processedIds);
        }
        editable.processedReferences = processedIds;
    };
    return new ProcessUpdateResult(createAttachments, editor);
}
Also used : CreateAttachments(com.enonic.xp.attachment.CreateAttachments) ContentEditor(com.enonic.xp.content.ContentEditor) ContentType(com.enonic.xp.schema.content.ContentType) EditableSite(com.enonic.xp.content.EditableSite) ContentIds(com.enonic.xp.content.ContentIds) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult)

Example 2 with EditableSite

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

the class HtmlAreaContentProcessorTest method site_config_data.

@Test
public void site_config_data() throws IOException {
    final ContentType contentType = ContentType.create().name(ContentTypeName.site()).superType(ContentTypeName.folder()).form(Form.create().build()).build();
    Mockito.when(contentTypeService.getByName(GetContentTypeParams.from(contentType.getName()))).thenReturn(contentType);
    Mockito.when(siteService.getDescriptor(ApplicationKey.SYSTEM)).thenReturn(SiteDescriptor.create().form(Form.create().addFormItem(Input.create().name("htmlData").label("htmlData").inputType(InputTypeName.HTML_AREA).build()).build()).build());
    final PropertyTree data = new PropertyTree();
    data.addProperty("htmlData", ValueFactory.newString("<img alt=\"Dictyophorus_spumans01.jpg\" data-src=\"image://image-id\"/>"));
    final EditableSite editableSite = new EditableSite(Site.create().name("myContentName").type(ContentTypeName.site()).parentPath(ContentPath.ROOT).data(new PropertyTree()).siteConfigs(SiteConfigs.create().add(SiteConfig.create().config(data).application(ApplicationKey.SYSTEM).build()).build()).build());
    result.getEditor().edit(editableSite);
    assertEquals(1, editableSite.processedReferences.build().getSize());
    assertTrue(editableSite.processedReferences.build().contains(ContentId.from("image-id")));
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) EditableSite(com.enonic.xp.content.EditableSite) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 3 with EditableSite

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

the class HtmlAreaContentProcessorTest method extra_data.

@Test
public void extra_data() throws IOException {
    final XDataName xDataName = XDataName.from("xDataName");
    final XData xData = XData.create().name(xDataName).addFormItem(Input.create().name("htmlData").label("htmlData").inputType(InputTypeName.HTML_AREA).build()).build();
    final ContentType contentType = ContentType.create().name(contentTypeName).superType(ContentTypeName.folder()).xData(XDataNames.from(xDataName)).build();
    Mockito.when(contentTypeService.getByName(GetContentTypeParams.from(ContentTypeName.site()))).thenReturn(contentType);
    Mockito.when(xDataService.getByNames(XDataNames.from(xDataName))).thenReturn(XDatas.from(xData));
    final PropertyTree data = new PropertyTree();
    data.addProperty("htmlData", ValueFactory.newString("<img alt=\"Dictyophorus_spumans01.jpg\" data-src=\"image://image-id\"/>"));
    final EditableSite editableSite = new EditableSite(Site.create().name("myContentName").type(ContentTypeName.site()).parentPath(ContentPath.ROOT).data(new PropertyTree()).extraDatas(ExtraDatas.create().add(new ExtraData(XDataName.from("xDataName"), data)).build()).build());
    result.getEditor().edit(editableSite);
    assertEquals(1, editableSite.processedReferences.build().getSize());
    assertTrue(editableSite.processedReferences.build().contains(ContentId.from("image-id")));
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) EditableSite(com.enonic.xp.content.EditableSite) PropertyTree(com.enonic.xp.data.PropertyTree) XData(com.enonic.xp.schema.xdata.XData) ExtraData(com.enonic.xp.content.ExtraData) XDataName(com.enonic.xp.schema.xdata.XDataName) Test(org.junit.jupiter.api.Test)

Aggregations

EditableSite (com.enonic.xp.content.EditableSite)3 ContentType (com.enonic.xp.schema.content.ContentType)3 PropertyTree (com.enonic.xp.data.PropertyTree)2 Test (org.junit.jupiter.api.Test)2 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)1 ContentEditor (com.enonic.xp.content.ContentEditor)1 ContentIds (com.enonic.xp.content.ContentIds)1 ExtraData (com.enonic.xp.content.ExtraData)1 ProcessUpdateResult (com.enonic.xp.content.processor.ProcessUpdateResult)1 XData (com.enonic.xp.schema.xdata.XData)1 XDataName (com.enonic.xp.schema.xdata.XDataName)1