Search in sources :

Example 11 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)

Example 12 with PageRegions

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

the class PageRegionsTest method iterator.

@Test
public void iterator() {
    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();
    Iterator<Region> iterator = regions.iterator();
    Region nextRegion = iterator.next();
    assertNotNull(nextRegion);
    assertEquals("a-region", nextRegion.getName());
    nextRegion = iterator.next();
    assertNotNull(nextRegion);
    assertEquals("b-region", nextRegion.getName());
    nextRegion = iterator.next();
    assertNotNull(nextRegion);
    assertEquals("c-region", nextRegion.getName());
    assertFalse(iterator.hasNext());
}
Also used : PageRegions(com.enonic.xp.page.PageRegions) Test(org.junit.jupiter.api.Test)

Example 13 with PageRegions

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

the class PageRegionsTest method getComponent_throws_exception.

@Test
public void getComponent_throws_exception() {
    final PageRegions regions = PageRegions.create().add(Region.create().name("a-region").add(PartComponent.create().build()).add(PartComponent.create().build()).build()).build();
    assertThrows(IllegalArgumentException.class, () -> regions.getComponent(ComponentPath.from("a-region/1/2/3")));
}
Also used : PageRegions(com.enonic.xp.page.PageRegions) Test(org.junit.jupiter.api.Test)

Example 14 with PageRegions

use of com.enonic.xp.page.PageRegions 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 15 with PageRegions

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

the class ComponentHandlerTest method createPageWithFragment.

private Content createPageWithFragment(final String id, final String path, final String contentTypeName, final boolean withPage) {
    PropertyTree rootDataSet = new PropertyTree();
    rootDataSet.addString("property1", "value1");
    final Content.Builder content = Content.create().id(ContentId.from(id)).path(ContentPath.from(path)).owner(PrincipalKey.from("user:myStore:me")).displayName("My Content").modifier(PrincipalKey.from("user:system:admin")).type(ContentTypeName.from(contentTypeName));
    if (withPage) {
        PageRegions pageRegions = PageRegions.create().add(Region.create().name("main-region").add(FragmentComponent.create().fragment(ContentId.from("fragmentId")).build()).build()).build();
        Page page = Page.create().template(PageTemplateKey.from("my-page")).regions(pageRegions).config(rootDataSet).build();
        content.page(page);
    }
    return content.build();
}
Also used : PageRegions(com.enonic.xp.page.PageRegions) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Page(com.enonic.xp.page.Page)

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