Search in sources :

Example 1 with LayoutComponent

use of com.enonic.xp.region.LayoutComponent in project xp by enonic.

the class TestDataFixtures method newLayoutComponent.

public static LayoutComponent newLayoutComponent() {
    final LayoutComponent.Builder builder = LayoutComponent.create();
    builder.config(newTinyPropertyTree());
    builder.descriptor(DescriptorKey.from("myapplication:mylayout"));
    builder.regions(newLayoutRegions());
    final LayoutComponent layout = builder.build();
    Region.create().name("main").add(layout).build();
    return layout;
}
Also used : LayoutComponent(com.enonic.xp.region.LayoutComponent)

Example 2 with LayoutComponent

use of com.enonic.xp.region.LayoutComponent 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 3 with LayoutComponent

use of com.enonic.xp.region.LayoutComponent 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);
            }
        }
    }
}
Also used : LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) PartDescriptor(com.enonic.xp.region.PartDescriptor) PartComponent(com.enonic.xp.region.PartComponent) LayoutComponent(com.enonic.xp.region.LayoutComponent)

Example 4 with LayoutComponent

use of com.enonic.xp.region.LayoutComponent in project xp by enonic.

the class LayoutComponentDataSerializer method fromData.

public LayoutComponent fromData(final PropertySet layoutData, final List<PropertySet> componentsAsData) {
    final LayoutComponent.Builder layoutComponent = LayoutComponent.create();
    final LayoutRegions.Builder layoutRegionsBuilder = LayoutRegions.create();
    final PropertySet specialBlockSet = layoutData.getSet(LayoutComponentType.INSTANCE.toString());
    if (specialBlockSet != null && specialBlockSet.isNotNull(DESCRIPTOR)) {
        final DescriptorKey descriptorKey = DescriptorKey.from(specialBlockSet.getString(DESCRIPTOR));
        layoutComponent.descriptor(descriptorKey);
        layoutComponent.config(getConfigFromData(specialBlockSet, descriptorKey));
        final LayoutDescriptor layoutDescriptor = layoutDescriptorService.getByKey(descriptorKey);
        final String layoutPath = layoutData.getString(PATH);
        if (layoutDescriptor.getRegions() != null && layoutDescriptor.getRegions().numberOfRegions() > 0) {
            layoutDescriptor.getRegions().forEach(regionDescriptor -> {
                layoutRegionsBuilder.add(regionDataSerializer.fromData(regionDescriptor, layoutPath, componentsAsData));
            });
        }
    }
    layoutComponent.regions(layoutRegionsBuilder.build());
    return layoutComponent.build();
}
Also used : LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) PropertySet(com.enonic.xp.data.PropertySet) DescriptorKey(com.enonic.xp.page.DescriptorKey) LayoutComponent(com.enonic.xp.region.LayoutComponent) LayoutRegions(com.enonic.xp.region.LayoutRegions)

Example 5 with LayoutComponent

use of com.enonic.xp.region.LayoutComponent in project xp by enonic.

the class PageRegionsConfigProcessor method processDescriptorBasedComponent.

private void processDescriptorBasedComponent(final DescriptorBasedComponent component, final PatternIndexConfigDocument.Builder builder) {
    final String appNameAsString = getSanitizedAppName(component.getDescriptor());
    final String componentNameAsString = getSanitizedComponentName(component.getDescriptor());
    final IndexConfigVisitor indexConfigVisitor = new IndexConfigVisitor(String.join(ELEMENT_DIVIDER, COMPONENTS, component.getType().toString(), CONFIG, appNameAsString, componentNameAsString), builder);
    indexConfigVisitor.traverse(getComponentConfig(component));
    builder.add(String.join(ELEMENT_DIVIDER, COMPONENTS, component.getType().toString(), CONFIG, appNameAsString, componentNameAsString), IndexConfig.BY_TYPE);
    if (component instanceof LayoutComponent) {
        parseLayoutRegions(((LayoutComponent) component).getRegions(), builder);
    }
}
Also used : LayoutComponent(com.enonic.xp.region.LayoutComponent) IndexConfigVisitor(com.enonic.xp.core.impl.content.index.IndexConfigVisitor)

Aggregations

LayoutComponent (com.enonic.xp.region.LayoutComponent)12 Component (com.enonic.xp.region.Component)6 PartComponent (com.enonic.xp.region.PartComponent)6 LayoutDescriptor (com.enonic.xp.region.LayoutDescriptor)4 Page (com.enonic.xp.page.Page)3 LayoutRegions (com.enonic.xp.region.LayoutRegions)3 PartDescriptor (com.enonic.xp.region.PartDescriptor)3 Test (org.junit.jupiter.api.Test)3 AbstractDescriptorServiceTest (com.enonic.xp.core.impl.content.page.AbstractDescriptorServiceTest)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 Form (com.enonic.xp.form.Form)2 DescriptorKey (com.enonic.xp.page.DescriptorKey)2 PageDescriptor (com.enonic.xp.page.PageDescriptor)2 Region (com.enonic.xp.region.Region)2 Content (com.enonic.xp.content.Content)1 EditableContent (com.enonic.xp.content.EditableContent)1 IndexConfigVisitor (com.enonic.xp.core.impl.content.index.IndexConfigVisitor)1 PropertySet (com.enonic.xp.data.PropertySet)1 FormDefaultValuesProcessor (com.enonic.xp.form.FormDefaultValuesProcessor)1 PageDescriptorService (com.enonic.xp.page.PageDescriptorService)1