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")));
}
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;
}
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();
}
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;
}
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"));
}
Aggregations