Search in sources :

Example 11 with Page

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

the class PageResolver method resolve.

public PageResolverResult resolve(final RenderMode mode, final Content content, final Site site) {
    final Page page = content.getPage();
    final PageTemplate pageTemplate;
    final DescriptorKey controller;
    final Page effectivePage;
    if (content instanceof PageTemplate) {
        pageTemplate = (PageTemplate) content;
        controller = getControllerFromTemplate(pageTemplate, mode);
        effectivePage = pageTemplate.getPage();
    } else if (page != null) {
        if (page.getFragment() != null) {
            controller = null;
            effectivePage = page;
        } else if (page.getDescriptor() != null) {
            controller = page.getDescriptor();
            effectivePage = page;
        } else if (page.getTemplate() != null) {
            pageTemplate = getPageTemplateOrFindDefault(page.getTemplate(), content.getType(), site.getPath());
            if (pageTemplate != null) {
                controller = getControllerFromTemplate(pageTemplate, mode);
                effectivePage = mergePageFromPageTemplate(pageTemplate, page);
            } else {
                controller = errorOrNull(null, mode, String.format("Template [%s] is missing and no default template found for content", page.getTemplate()));
                effectivePage = page;
            }
        } else {
            controller = errorOrNull(null, mode, "Content page has neither template nor descriptor");
            effectivePage = page;
        }
    } else {
        pageTemplate = this.pageTemplateService.getDefault(GetDefaultPageTemplateParams.create().sitePath(site.getPath()).contentType(content.getType()).build());
        if (pageTemplate != null) {
            controller = getControllerFromTemplate(pageTemplate, mode);
            effectivePage = mergePageFromPageTemplate(pageTemplate, null);
        } else {
            controller = errorOrNull(null, mode, "No default template found for content");
            effectivePage = null;
        }
    }
    return new PageResolverResult(effectivePage, controller);
}
Also used : PageTemplate(com.enonic.xp.page.PageTemplate) DescriptorKey(com.enonic.xp.page.DescriptorKey) Page(com.enonic.xp.page.Page)

Example 12 with Page

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

the class ComponentHandlerWorker method execute.

@Override
public PortalResponse execute() throws Exception {
    final ContentResolverResult resolvedContent = contentResolver.resolve(this.request);
    final Content content = resolvedContent.getContentOrElseThrow();
    final Site site = resolvedContent.getNearestSiteOrElseThrow();
    Page page = content.getPage();
    final PageResolverResult resolvedPage = pageResolver.resolve(request.getMode(), content, site);
    Component component = null;
    if (content.getType().isFragment()) {
        // fragment content, try resolving component path in Layout fragment
        final Component fragmentComponent = page.getFragment();
        if (this.componentPath.isEmpty()) {
            component = fragmentComponent;
        } else if (fragmentComponent instanceof LayoutComponent) {
            component = ((LayoutComponent) fragmentComponent).getComponent(this.componentPath);
        }
    }
    final Page effectivePage;
    if (component == null) {
        effectivePage = inlineFragments(resolvedPage.getEffectivePage(), this.componentPath);
        component = effectivePage.getRegions().getComponent(this.componentPath);
    } else {
        effectivePage = resolvedPage.getEffectivePage();
    }
    if (component == null) {
        throw WebException.notFound(String.format("Page component for [%s] not found", this.componentPath));
    }
    final Content effectiveContent = Content.create(content).page(effectivePage).build();
    final DescriptorKey controller = resolvedPage.getController();
    this.request.setSite(site);
    this.request.setContent(effectiveContent);
    this.request.setComponent(component);
    this.request.setApplicationKey(controller != null ? controller.getApplicationKey() : null);
    final Trace trace = Tracer.current();
    if (trace != null) {
        trace.put("componentPath", component.getPath());
        trace.put("type", component.getType().toString());
    }
    final PortalResponse response = rendererDelegate.render(component, this.request);
    return this.postProcessor.processResponseInstructions(this.request, response);
}
Also used : ContentResolverResult(com.enonic.xp.portal.impl.ContentResolverResult) Site(com.enonic.xp.site.Site) Trace(com.enonic.xp.trace.Trace) PortalResponse(com.enonic.xp.portal.PortalResponse) Content(com.enonic.xp.content.Content) DescriptorKey(com.enonic.xp.page.DescriptorKey) Page(com.enonic.xp.page.Page) FragmentComponent(com.enonic.xp.region.FragmentComponent) Component(com.enonic.xp.region.Component) LayoutComponent(com.enonic.xp.region.LayoutComponent) LayoutComponent(com.enonic.xp.region.LayoutComponent)

Example 13 with Page

use of com.enonic.xp.page.Page 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;
}
Also used : PageRegions(com.enonic.xp.page.PageRegions) RenderException(com.enonic.xp.portal.impl.rendering.RenderException) Content(com.enonic.xp.content.Content) Page(com.enonic.xp.page.Page) LayoutComponent(com.enonic.xp.region.LayoutComponent) Component(com.enonic.xp.region.Component)

Example 14 with Page

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

the class RenderBaseHandlerTest method setupCustomizedTemplateContentAndSite.

protected final void setupCustomizedTemplateContentAndSite() {
    Content content = createPage("id", "site/somepath/content", "myapplication:ctype", true);
    final PageDescriptor controllerDescriptor = createDescriptor();
    Page page = Page.create(content.getPage()).template(null).descriptor(controllerDescriptor.getKey()).build();
    content = Content.create(content).page(page).build();
    when(this.contentService.getByPath(ContentPath.from("site/somepath/content").asAbsolute())).thenReturn(content);
    when(this.contentService.getNearestSite(isA(ContentId.class))).thenReturn(createSite("id", "site"));
    when(this.contentService.getById(content.getId())).thenReturn(content);
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) Content(com.enonic.xp.content.Content) Page(com.enonic.xp.page.Page) ContentId(com.enonic.xp.content.ContentId)

Example 15 with Page

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

the class PageResolverTest method content_without_Page_and_no_default_template.

@Test
public void content_without_Page_and_no_default_template() {
    Site site = Site.create().id(ContentId.from("site-id")).path(ContentPath.from("/site")).displayName("My Site").type(ContentTypeName.from("portal:site")).build();
    Content content = Content.create().parentPath(site.getPath()).name("my-content").build();
    when(pageTemplateService.getDefault(notNull())).thenReturn(null);
    final WebException webExceptionInLive = assertThrows(WebException.class, () -> pageResolver.resolve(RenderMode.LIVE, content, site));
    assertEquals(HttpStatus.NOT_FOUND, webExceptionInLive.getStatus());
    assertEquals(webExceptionInLive.getMessage(), "No default template found for content");
    final WebException webExceptionInInline = assertThrows(WebException.class, () -> pageResolver.resolve(RenderMode.INLINE, content, site));
    assertEquals(HttpStatus.IM_A_TEAPOT, webExceptionInInline.getStatus());
    final WebException webExceptionInPreview = assertThrows(WebException.class, () -> pageResolver.resolve(RenderMode.PREVIEW, content, site));
    assertEquals(HttpStatus.NOT_FOUND, webExceptionInPreview.getStatus());
    final PageResolverResult result = pageResolver.resolve(RenderMode.EDIT, content, site);
    final Page effectivePage = result.getEffectivePage();
    assertNull(effectivePage);
    assertNull(result.getController());
}
Also used : Site(com.enonic.xp.site.Site) WebException(com.enonic.xp.web.WebException) Content(com.enonic.xp.content.Content) Page(com.enonic.xp.page.Page) 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