Search in sources :

Example 56 with Page

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

the class FragmentRenderer method render.

public PortalResponse render(final FragmentComponent component, final PortalRequest portalRequest) {
    final RenderMode renderMode = portalRequest.getMode();
    final String type = component.getType().toString();
    if (component.getFragment() == null) {
        return renderEmptyFragment(renderMode, component);
    }
    final Component fragmentComponent = getFragmentComponent(component);
    if (fragmentComponent == null) {
        LOG.warn("Fragment content could not be found. ContentId: " + component.getFragment().toString());
        if (renderMode == RenderMode.EDIT) {
            final String errorMessage = "Fragment content could not be found";
            return renderErrorComponentPlaceHolder(component, errorMessage);
        } else {
            return renderEmptyFragment(renderMode, component);
        }
    }
    // replace resolved fragment in current PortalRequest Page
    final Page sourcePage = portalRequest.getContent().getPage();
    final Page page = fragmentPageResolver.inlineFragmentInPage(sourcePage, fragmentComponent, component.getPath());
    final Content content = Content.create(portalRequest.getContent()).page(page).build();
    portalRequest.setContent(content);
    final PortalResponse fragmentResponse = rendererDelegate.render(fragmentComponent, portalRequest);
    if (renderMode == RenderMode.EDIT && fragmentResponse != null) {
        if (!(fragmentResponse.getBody() instanceof String) || !fragmentResponse.getContentType().is(MediaType.parse("text/html"))) {
            return fragmentResponse;
        }
        final String body = (String) fragmentResponse.getBody();
        final String noMethodErrorMessage = "No method provided to handle request";
        if (body.contains(noMethodErrorMessage)) {
            return renderErrorComponentPlaceHolder(component, noMethodErrorMessage);
        }
        return wrapFragmentForEditMode(fragmentResponse, type);
    }
    return fragmentResponse;
}
Also used : RenderMode(com.enonic.xp.portal.RenderMode) PortalResponse(com.enonic.xp.portal.PortalResponse) Content(com.enonic.xp.content.Content) Page(com.enonic.xp.page.Page) FragmentComponent(com.enonic.xp.region.FragmentComponent) Component(com.enonic.xp.region.Component)

Example 57 with Page

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

the class ComponentInstructionTest method createFragmentPage.

private Content createFragmentPage(final String id, final String name) {
    PropertyTree rootDataSet = new PropertyTree();
    rootDataSet.addString("property1", "value1");
    PartComponent fragmentComponent = PartComponent.create().descriptor(DescriptorKey.from("myapplication:myparttemplate")).build();
    Page page = Page.create().template(PageTemplateKey.from("my-page")).fragment(fragmentComponent).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.fragment()).page(page).build();
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Page(com.enonic.xp.page.Page) PartComponent(com.enonic.xp.region.PartComponent)

Example 58 with Page

use of com.enonic.xp.page.Page 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")));
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) Form(com.enonic.xp.form.Form) PartDescriptor(com.enonic.xp.region.PartDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) EditableContent(com.enonic.xp.content.EditableContent) Page(com.enonic.xp.page.Page) PartComponent(com.enonic.xp.region.PartComponent) LayoutComponent(com.enonic.xp.region.LayoutComponent) Test(org.junit.jupiter.api.Test)

Aggregations

Page (com.enonic.xp.page.Page)58 PropertyTree (com.enonic.xp.data.PropertyTree)30 Test (org.junit.jupiter.api.Test)28 Content (com.enonic.xp.content.Content)25 Site (com.enonic.xp.site.Site)12 DescriptorKey (com.enonic.xp.page.DescriptorKey)9 PageRegions (com.enonic.xp.page.PageRegions)9 AbstractDataSerializerTest (com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest)7 PageDescriptor (com.enonic.xp.page.PageDescriptor)7 PageTemplate (com.enonic.xp.page.PageTemplate)7 PropertySet (com.enonic.xp.data.PropertySet)6 Form (com.enonic.xp.form.Form)5 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)5 LayoutComponent (com.enonic.xp.region.LayoutComponent)5 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)4 EditableContent (com.enonic.xp.content.EditableContent)4 Component (com.enonic.xp.region.Component)4 PartComponent (com.enonic.xp.region.PartComponent)4 ContentId (com.enonic.xp.content.ContentId)3 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)3