use of com.enonic.xp.region.PartDescriptor in project xp by enonic.
the class HtmlAreaContentProcessor method processComponent.
private void processComponent(final DescriptorBasedComponent component, final ContentIds.Builder processedIds) {
if (component.hasDescriptor()) {
if (component instanceof LayoutComponent) {
final LayoutDescriptor layoutDescriptor = this.layoutDescriptorService.getByKey(component.getDescriptor());
if (layoutDescriptor != null) {
processComponentDescriptor(component, layoutDescriptor, processedIds);
}
final LayoutComponent layoutComponent = (LayoutComponent) component;
if (layoutComponent.hasRegions()) {
processRegionsData(layoutComponent.getRegions(), processedIds);
}
}
if (component instanceof PartComponent) {
final PartDescriptor partDescriptor = this.partDescriptorService.getByKey(component.getDescriptor());
if (partDescriptor != null) {
processComponentDescriptor(component, partDescriptor, processedIds);
}
}
}
}
use of com.enonic.xp.region.PartDescriptor in project xp by enonic.
the class HtmlAreaContentProcessorTest method component_config_data.
@Test
public void component_config_data() throws IOException {
final PropertyTree data = new PropertyTree();
data.addProperty("htmlData", ValueFactory.newString("<img data-src=\"image://image-id\"/>"));
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:part").descriptor(partDescriptor.getKey()).config(data).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(partComponent).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(1, editableContent.processedReferences.build().getSize());
assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id")));
}
use of com.enonic.xp.region.PartDescriptor in project xp by enonic.
the class GetComponentByNameCommand method execute.
public Component execute() {
final String componentDescriptorName = name.toString();
final PartDescriptor partDescriptor = getPartDescriptor(componentDescriptorName);
if (partDescriptor != null && componentExists(partDescriptor.getComponentPath())) {
return PartComponent.create().descriptor(partDescriptor.getKey()).build();
}
final LayoutDescriptor layoutDescriptor = getLayoutDescriptor(componentDescriptorName);
if (layoutDescriptor != null && componentExists(layoutDescriptor.getComponentPath())) {
return LayoutComponent.create().descriptor(layoutDescriptor.getKey()).build();
}
return null;
}
use of com.enonic.xp.region.PartDescriptor 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")));
}
use of com.enonic.xp.region.PartDescriptor in project xp by enonic.
the class PartRendererTest method htmlResponseComponentEditModeNoMethodToHandleReq.
@Test
public void htmlResponseComponentEditModeNoMethodToHandleReq() {
final PartDescriptor partDescriptor = PartDescriptor.create().displayName("My part component").config(Form.create().build()).key(DescriptorKey.from("module:myPartComponent")).build();
final ControllerScript controllerScript = new ControllerScript() {
@Override
public PortalResponse execute(final PortalRequest portalRequest) {
return new PortalResponseSerializer(null, HttpStatus.METHOD_NOT_ALLOWED).serialize();
}
@Override
public void onSocketEvent(final WebSocketEvent event) {
}
};
final PartDescriptorService partDescriptorService = Mockito.mock(PartDescriptorService.class);
final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
renderer = new PartRenderer();
renderer.setPartDescriptorService(partDescriptorService);
renderer.setControllerScriptFactory(controllerScriptFactory);
when(partDescriptorService.getByKey(any())).thenReturn(partDescriptor);
when(controllerScriptFactory.fromDir(any())).thenReturn(controllerScript);
portalRequest.setMode(RenderMode.EDIT);
partComponent = PartComponent.create().descriptor("myapp:myPartComponent").descriptor(partDescriptor.getKey()).build();
// exercise
portalResponse = renderer.render(partComponent, portalRequest);
// verify
String expected = "<div data-portal-component-type=\"part\" data-portal-placeholder=\"true\" data-portal-placeholder-error=\"true\"><span class=\"data-portal-placeholder-error\">No method provided to handle request</span></div>";
assertEquals(expected, portalResponse.getAsString());
}
Aggregations