use of com.enonic.xp.region.Region in project xp by enonic.
the class ComponentInstructionTest method createPage.
private Content createPage(final String id, final String name, final String contentTypeName) {
PropertyTree rootDataSet = new PropertyTree();
rootDataSet.addString("property1", "value1");
Region region = Region.create().name("myRegion").add(PartComponent.create().descriptor(DescriptorKey.from("myapplication:myparttemplate")).build()).build();
PageRegions pageRegions = PageRegions.create().add(region).build();
Page page = Page.create().template(PageTemplateKey.from("my-page")).regions(pageRegions).build();
return Content.create().id(ContentId.from(id)).path(ContentPath.from(name)).owner(PrincipalKey.from("user:myStore:me")).displayName("My Content").modifier(PrincipalKey.from("user:system:admin")).type(ContentTypeName.from(contentTypeName)).page(page).build();
}
use of com.enonic.xp.region.Region in project xp by enonic.
the class FragmentPageResolver method replaceComponentInPage.
private PageRegions replaceComponentInPage(final PageRegions pageRegions, final ImmutableList<ComponentPath.RegionAndComponent> pathItems, final Component component) {
final ComponentPath.RegionAndComponent regionCmp = pathItems.isEmpty() ? null : pathItems.get(0);
final Region region = regionCmp == null ? null : pageRegions.getRegion(regionCmp.getRegionName());
if (region == null) {
return pageRegions;
}
final int componentIndex = regionCmp.getComponentIndex();
final Component existingCmp = region.getComponent(componentIndex);
if (existingCmp == null) {
return pageRegions;
}
final int numberOfLevels = pathItems.size();
if (numberOfLevels == 1) {
final Region updatedRegion = Region.create(region).set(componentIndex, component).build();
return replaceRegionInPage(pageRegions, region, updatedRegion);
} else {
if (!(existingCmp instanceof LayoutComponent)) {
return pageRegions;
}
final LayoutComponent layoutComponent = (LayoutComponent) existingCmp;
final LayoutRegions layoutRegions = replaceComponentInLayout(layoutComponent.getRegions(), removeFirstLevel(pathItems), component);
final LayoutComponent updatedLayout = LayoutComponent.create(layoutComponent).regions(layoutRegions).build();
final Region updatedRegion = Region.create(region).set(componentIndex, updatedLayout).build();
return replaceRegionInPage(pageRegions, region, updatedRegion);
}
}
Aggregations