Search in sources :

Example 1 with PageDescriptor

use of com.enonic.xp.page.PageDescriptor in project xp by enonic.

the class HtmlAreaContentProcessorTest method component_config_data.

@Test
public void component_config_data() throws IOException {
    final PropertyTree data = new PropertyTree();
    data.addProperty("htmlData", ValueFactory.newString("<img data-src=\"image://image-id\"/>"));
    final Form form = Form.create().addFormItem(Input.create().name("htmlData").label("htmlData").inputType(InputTypeName.HTML_AREA).build()).build();
    final PartDescriptor partDescriptor = PartDescriptor.create().key(DescriptorKey.from("app:part")).config(form).build();
    Mockito.when(partDescriptorService.getByKey(partDescriptor.getKey())).thenReturn(partDescriptor);
    final PartComponent partComponent = PartComponent.create().descriptor("myapp:part").descriptor(partDescriptor.getKey()).config(data).build();
    final PageDescriptor pageDescriptor = PageDescriptor.create().regions(RegionDescriptors.create().add(RegionDescriptor.create().name("region").build()).build()).key(DescriptorKey.from("app:page")).config(Form.create().build()).build();
    Mockito.when(pageDescriptorService.getByKey(pageDescriptor.getKey())).thenReturn(pageDescriptor);
    final Page page = Page.create().config(new PropertyTree()).descriptor(pageDescriptor.getKey()).regions(PageRegions.create().add(Region.create().name("region").add(partComponent).build()).build()).build();
    final EditableContent editableContent = new EditableContent(Media.create().name("myContentName").type(contentTypeName).page(page).parentPath(ContentPath.ROOT).data(new PropertyTree()).build());
    result.getEditor().edit(editableContent);
    assertEquals(1, editableContent.processedReferences.build().getSize());
    assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id")));
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) Form(com.enonic.xp.form.Form) PartDescriptor(com.enonic.xp.region.PartDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) EditableContent(com.enonic.xp.content.EditableContent) Page(com.enonic.xp.page.Page) PartComponent(com.enonic.xp.region.PartComponent) Test(org.junit.jupiter.api.Test)

Example 2 with PageDescriptor

use of com.enonic.xp.page.PageDescriptor in project xp by enonic.

the class HtmlAreaContentProcessorTest method text_component_value.

@Test
public void text_component_value() throws IOException {
    // final PropertyTree data = new PropertyTree();
    // data.addProperty( "htmlData", ValueFactory.newString( "<img data-src=\"image://image-id\"/>" ) );
    // final Form form = Form.create().addFormItem(
    // Input.create().name( "htmlData" ).label( "htmlData" ).inputType( InputTypeName.HTML_AREA ).build() ).build();
    // final PartDescriptor partDescriptor = PartDescriptor.create().key( DescriptorKey.from( "app:part" ) ).config( form ).build();
    // Mockito.when( partDescriptorService.getByKey( partDescriptor.getKey() ) ).thenReturn( partDescriptor );
    final TextComponent textComponent = TextComponent.create().text("<img data-src=\"image://image-id\"/>").build();
    final PageDescriptor pageDescriptor = PageDescriptor.create().regions(RegionDescriptors.create().add(RegionDescriptor.create().name("region").build()).build()).key(DescriptorKey.from("app:page")).config(Form.create().build()).build();
    Mockito.when(pageDescriptorService.getByKey(pageDescriptor.getKey())).thenReturn(pageDescriptor);
    final Page page = Page.create().config(new PropertyTree()).descriptor(pageDescriptor.getKey()).regions(PageRegions.create().add(Region.create().name("region").add(textComponent).build()).build()).build();
    final EditableContent editableContent = new EditableContent(Media.create().name("myContentName").type(contentTypeName).page(page).parentPath(ContentPath.ROOT).data(new PropertyTree()).build());
    result.getEditor().edit(editableContent);
    assertEquals(1, editableContent.processedReferences.build().getSize());
    assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id")));
}
Also used : TextComponent(com.enonic.xp.region.TextComponent) PageDescriptor(com.enonic.xp.page.PageDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) EditableContent(com.enonic.xp.content.EditableContent) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test)

Example 3 with PageDescriptor

use of com.enonic.xp.page.PageDescriptor in project xp by enonic.

the class HtmlAreaContentProcessor method processPageData.

private void processPageData(final Page page, final ContentIds.Builder processedIds) {
    if (page == null) {
        return;
    }
    if (page.hasDescriptor()) {
        final PageDescriptor pageDescriptor = pageDescriptorService.getByKey(page.getDescriptor());
        final Collection<Property> properties = getProperties(page.getConfig(), pageDescriptor.getConfig().getFormItems());
        processDataTree(properties, processedIds);
    }
    if (page.hasRegions()) {
        processRegionsData(page.getRegions(), processedIds);
    }
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) Property(com.enonic.xp.data.Property)

Example 4 with PageDescriptor

use of com.enonic.xp.page.PageDescriptor in project xp by enonic.

the class RenderBaseHandlerTest method createDescriptor.

private PageDescriptor createDescriptor() {
    final ApplicationKey applicationKey = ApplicationKey.from("mainapplication");
    final String name = "mypage";
    final DescriptorKey key = DescriptorKey.from(applicationKey, name);
    final String xml = "<?xml version=\"1.0\"?>\n" + "<page>\n" + "  <display-name>Landing page</display-name>\n" + "  <config/>\n" + "</page>";
    final PageDescriptor.Builder builder = PageDescriptor.create();
    parseXml(applicationKey, builder, xml);
    return builder.key(key).displayName("Landing page").build();
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) PageDescriptor(com.enonic.xp.page.PageDescriptor) DescriptorKey(com.enonic.xp.page.DescriptorKey) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 5 with PageDescriptor

use of com.enonic.xp.page.PageDescriptor in project xp by enonic.

the class RenderBaseHandlerTest method setupCustomizedTemplateContentAndSite.

protected final void setupCustomizedTemplateContentAndSite() {
    Content content = createPage("id", "site/somepath/content", "myapplication:ctype", true);
    final PageDescriptor controllerDescriptor = createDescriptor();
    Page page = Page.create(content.getPage()).template(null).descriptor(controllerDescriptor.getKey()).build();
    content = Content.create(content).page(page).build();
    when(this.contentService.getByPath(ContentPath.from("site/somepath/content").asAbsolute())).thenReturn(content);
    when(this.contentService.getNearestSite(isA(ContentId.class))).thenReturn(createSite("id", "site"));
    when(this.contentService.getById(content.getId())).thenReturn(content);
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) Content(com.enonic.xp.content.Content) Page(com.enonic.xp.page.Page) ContentId(com.enonic.xp.content.ContentId)

Aggregations

PageDescriptor (com.enonic.xp.page.PageDescriptor)15 Page (com.enonic.xp.page.Page)6 PropertyTree (com.enonic.xp.data.PropertyTree)5 Test (org.junit.jupiter.api.Test)5 EditableContent (com.enonic.xp.content.EditableContent)4 Form (com.enonic.xp.form.Form)4 DescriptorKey (com.enonic.xp.page.DescriptorKey)4 PartComponent (com.enonic.xp.region.PartComponent)2 PartDescriptor (com.enonic.xp.region.PartDescriptor)2 RegionDescriptors (com.enonic.xp.region.RegionDescriptors)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 Content (com.enonic.xp.content.Content)1 ContentId (com.enonic.xp.content.ContentId)1 Property (com.enonic.xp.data.Property)1 PageDescriptors (com.enonic.xp.page.PageDescriptors)1 PageRegions (com.enonic.xp.page.PageRegions)1 PortalResponse (com.enonic.xp.portal.PortalResponse)1 RenderMode (com.enonic.xp.portal.RenderMode)1 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)1 LayoutComponent (com.enonic.xp.region.LayoutComponent)1