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