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