Search in sources :

Example 11 with PageDescriptor

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

the class PageConfigProcessorTest method processForm.

private PatternIndexConfigDocument processForm(final Form form) {
    final PageDescriptor descriptor = PageDescriptor.create().key(descriptorKey).config(form).regions(RegionDescriptors.create().build()).build();
    final Page page = Page.create().descriptor(descriptorKey).build();
    Mockito.when(pageDescriptorService.getByKey(descriptorKey)).thenReturn(descriptor);
    final PageConfigProcessor configProcessor = new PageConfigProcessor(page, getPageConfigForm(pageDescriptorService, descriptorKey));
    return configProcessor.processDocument(PatternIndexConfigDocument.create()).build();
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) Page(com.enonic.xp.page.Page)

Example 12 with PageDescriptor

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

the class PageDescriptorServiceTest method testGetByKey.

@Test
public void testGetByKey() throws Exception {
    final DescriptorKey key = DescriptorKey.from("myapp1:mypage");
    final PageDescriptor descriptor = this.service.getByKey(key);
    assertNotNull(descriptor);
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) DescriptorKey(com.enonic.xp.page.DescriptorKey) Test(org.junit.jupiter.api.Test)

Example 13 with PageDescriptor

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

the class PageDataSerializer method getPageRegions.

private PageRegions getPageRegions(final DescriptorKey descriptorKey, final List<PropertySet> componentsAsData) {
    final PageDescriptor pageDescriptor = pageDescriptorService.getByKey(descriptorKey);
    final RegionDescriptors regionDescriptors = pageDescriptor.getRegions();
    if (regionDescriptors.numberOfRegions() == 0) {
        return null;
    }
    final PageRegions.Builder pageRegionsBuilder = PageRegions.create();
    regionDescriptors.forEach(regionDescriptor -> {
        pageRegionsBuilder.add(componentDataSerializerProvider.getRegionDataSerializer().fromData(regionDescriptor, ComponentPath.DIVIDER, componentsAsData));
    });
    return pageRegionsBuilder.build();
}
Also used : PageRegions(com.enonic.xp.page.PageRegions) PageDescriptor(com.enonic.xp.page.PageDescriptor) RegionDescriptors(com.enonic.xp.region.RegionDescriptors)

Example 14 with PageDescriptor

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

the class PageRenderer method doRender.

@Override
public PortalResponse doRender(final Content content, final PortalRequest portalRequest) {
    final PageDescriptor pageDescriptor = portalRequest.getPageDescriptor();
    final RenderMode mode = portalRequest.getMode();
    PortalResponse portalResponse;
    if (pageDescriptor != null) {
        final ControllerScript controllerScript = this.controllerScriptFactory.fromDir(pageDescriptor.getComponentPath());
        portalResponse = controllerScript.execute(portalRequest);
    } else if (portalRequest.getControllerScript() != null) {
        portalResponse = portalRequest.getControllerScript().execute(portalRequest);
    } else if ((mode == EDIT || mode == PREVIEW || mode == INLINE) && portalRequest.getContent().getType().isFragment()) {
        portalResponse = renderDefaultFragmentPage(portalRequest, content);
    } else {
        portalResponse = renderForNoPageDescriptor(portalRequest, content);
    }
    return portalResponse;
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) RenderMode(com.enonic.xp.portal.RenderMode) PortalResponse(com.enonic.xp.portal.PortalResponse) ControllerScript(com.enonic.xp.portal.controller.ControllerScript)

Example 15 with PageDescriptor

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

the class HtmlAreaContentProcessorTest method inner_component_data.

@Test
public void inner_component_data() throws IOException {
    final PropertyTree data1 = new PropertyTree();
    data1.addProperty("htmlData", ValueFactory.newString("<img data-src=\"image://image-id1\"/>"));
    final PropertyTree data2 = new PropertyTree();
    data2.addProperty("htmlData", ValueFactory.newString("<img data-src=\"image://image-id2\"/>"));
    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:partest").descriptor(partDescriptor.getKey()).config(data2).build();
    final LayoutDescriptor layoutDescriptor = LayoutDescriptor.create().key(DescriptorKey.from("app:layout")).config(form).regions(RegionDescriptors.create().add(RegionDescriptor.create().name("part").build()).build()).build();
    Mockito.when(layoutDescriptorService.getByKey(layoutDescriptor.getKey())).thenReturn(layoutDescriptor);
    final LayoutComponent layoutComponent = LayoutComponent.create().descriptor("myapp:layout").descriptor(layoutDescriptor.getKey()).regions(LayoutRegions.create().add(Region.create().name("part").add(partComponent).build()).build()).config(data1).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(layoutComponent).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(2, editableContent.processedReferences.build().getSize());
    assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id1")));
    assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id2")));
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) 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) LayoutComponent(com.enonic.xp.region.LayoutComponent) Test(org.junit.jupiter.api.Test)

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