Search in sources :

Example 6 with PageRegions

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

the class PageRegionsTest method getComponent.

@Test
public void getComponent() {
    final PageRegions regions = PageRegions.create().add(Region.create().name("a-region").add(PartComponent.create().descriptor("myapp:part-1-in-region-a").build()).build()).add(Region.create().name("b-region").add(PartComponent.create().descriptor("myapp:part-1-in-region-b").build()).build()).build();
    assertEquals("myapp:part-1-in-region-a", ((PartComponent) regions.getComponent(ComponentPath.from("a-region/0"))).getDescriptor().toString());
    assertEquals("myapp:part-1-in-region-b", ((PartComponent) regions.getComponent(ComponentPath.from("b-region/0"))).getDescriptor().toString());
    assertNull(regions.getComponent(ComponentPath.from("a-region/1")));
}
Also used : PageRegions(com.enonic.xp.page.PageRegions) Test(org.junit.jupiter.api.Test)

Example 7 with PageRegions

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

the class PageDataSerializerTest method createPage.

private Page createPage() {
    final PropertyTree myPartConfig = new PropertyTree();
    myPartConfig.addString("some", "somevalue");
    final PropertyTree imageConfig = new PropertyTree();
    imageConfig.addString("caption", "Caption");
    final DescriptorKey pageDescriptorKey = DescriptorKey.from("app-key:d-name");
    final String regionName1 = "top";
    final String regionName2 = "bottom";
    final Region mainRegion1 = Region.create().name(regionName1).add(createPartComponent("MyPart1", "app-descriptor-x:name-x", myPartConfig)).add(createLayoutComponent()).add(LayoutComponent.create().build()).build();
    final Region mainRegion2 = Region.create().name(regionName2).add(createPartComponent("MyPart2", "app-descriptor-y:name-y", myPartConfig)).add(createImageComponent("img-id-x", "Image Component", imageConfig)).add(ImageComponent.create().build()).build();
    final PageRegions regions = PageRegions.create().add(mainRegion1).add(mainRegion2).build();
    final PropertyTree pageConfig = new PropertyTree();
    pageConfig.addString("some", "config");
    pageConfig.addDouble("aim", 42.0);
    final Page page = Page.create().config(pageConfig).descriptor(pageDescriptorKey).regions(regions).build();
    Mockito.when(pageDescriptorService.getByKey(pageDescriptorKey)).thenReturn(PageDescriptor.create().config(Form.create().build()).key(pageDescriptorKey).regions(RegionDescriptors.create().add(RegionDescriptor.create().name(regionName1).build()).add(RegionDescriptor.create().name(regionName2).build()).build()).build());
    return page;
}
Also used : PageRegions(com.enonic.xp.page.PageRegions) PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) Region(com.enonic.xp.region.Region) Page(com.enonic.xp.page.Page)

Example 8 with PageRegions

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

the class ProjectContentEventListenerTest method createPage.

private Page createPage() {
    PropertyTree componentConfig = new PropertyTree();
    componentConfig.setString("my-prop", "value");
    PartComponent component = PartComponent.create().descriptor(DescriptorKey.from("mainapplication:partTemplateName")).config(componentConfig).build();
    Region region = Region.create().name("my-region").add(component).build();
    PageRegions regions = PageRegions.create().add(region).build();
    PropertyTree pageConfig = new PropertyTree();
    pageConfig.setString("background-color", "blue");
    Mockito.when(partDescriptorService.getByKey(DescriptorKey.from("mainapplication:partTemplateName"))).thenReturn(PartDescriptor.create().key(DescriptorKey.from("mainapplication:partTemplateName")).displayName("my-component").config(Form.create().build()).build());
    return Page.create().template(PageTemplateKey.from("mypagetemplate")).regions(regions).build();
}
Also used : PageRegions(com.enonic.xp.page.PageRegions) PropertyTree(com.enonic.xp.data.PropertyTree) Region(com.enonic.xp.region.Region) PartComponent(com.enonic.xp.region.PartComponent)

Example 9 with PageRegions

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

the class ComponentInstruction method resolveComponent.

private Component resolveComponent(final PortalRequest portalRequest, final ComponentPath path) {
    final Content content = portalRequest.getContent();
    if (content == null) {
        return null;
    }
    final Page page = content.getPage();
    if (content.getType().isFragment()) {
        return resolveComponentInFragment(page, path);
    }
    final PageRegions pageRegions = page.getRegions();
    Component component = pageRegions.getComponent(path);
    if (component == null) {
        throw new RenderException("Component not found: [{0}]", path);
    }
    return component;
}
Also used : PageRegions(com.enonic.xp.page.PageRegions) RenderException(com.enonic.xp.portal.impl.rendering.RenderException) Content(com.enonic.xp.content.Content) Page(com.enonic.xp.page.Page) LayoutComponent(com.enonic.xp.region.LayoutComponent) Component(com.enonic.xp.region.Component)

Example 10 with PageRegions

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

the class PageRegionsTest method getRegion.

@Test
public void getRegion() {
    final PageRegions regions = PageRegions.create().add(Region.create().name("a-region").build()).add(Region.create().name("b-region").build()).add(Region.create().name("c-region").build()).build();
    assertEquals("a-region", regions.getRegion("a-region").getName());
    assertEquals("b-region", regions.getRegion("b-region").getName());
    assertEquals("c-region", regions.getRegion("c-region").getName());
    assertNull(regions.getRegion("no-region"));
}
Also used : PageRegions(com.enonic.xp.page.PageRegions) Test(org.junit.jupiter.api.Test)

Aggregations

PageRegions (com.enonic.xp.page.PageRegions)17 PropertyTree (com.enonic.xp.data.PropertyTree)9 Page (com.enonic.xp.page.Page)8 Content (com.enonic.xp.content.Content)6 Test (org.junit.jupiter.api.Test)6 Region (com.enonic.xp.region.Region)3 DescriptorKey (com.enonic.xp.page.DescriptorKey)1 PageDescriptor (com.enonic.xp.page.PageDescriptor)1 PageTemplate (com.enonic.xp.page.PageTemplate)1 RenderException (com.enonic.xp.portal.impl.rendering.RenderException)1 Component (com.enonic.xp.region.Component)1 LayoutComponent (com.enonic.xp.region.LayoutComponent)1 PartComponent (com.enonic.xp.region.PartComponent)1 RegionDescriptors (com.enonic.xp.region.RegionDescriptors)1