use of com.enonic.xp.region.ComponentDescriptor in project xp by enonic.
the class DescriptorBasedComponentRenderer method doRender.
private PortalResponse doRender(final R component, final PortalRequest portalRequest) {
final ComponentDescriptor descriptor = resolveDescriptor(component);
if (descriptor == null) {
return renderEmptyComponent(component, portalRequest);
}
// create controller
final ControllerScript controllerScript = this.controllerScriptFactory.fromDir(descriptor.getComponentPath());
// render
final Component previousComponent = portalRequest.getComponent();
final ApplicationKey previousApplication = portalRequest.getApplicationKey();
try {
portalRequest.setComponent(component);
portalRequest.setApplicationKey(descriptor.getKey().getApplicationKey());
final PortalResponse portalResponse = controllerScript.execute(portalRequest);
final RenderMode renderMode = portalRequest.getMode();
final MediaType contentType = portalResponse.getContentType();
if (renderMode == RenderMode.EDIT && contentType != null && contentType.withoutParameters().type().equals("text")) {
final Object bodyObj = portalResponse.getBody();
if (bodyObj == null || (bodyObj instanceof String && nullToEmpty((String) bodyObj).isBlank())) {
if (portalResponse.getStatus().equals(HttpStatus.METHOD_NOT_ALLOWED)) {
final String errorMessage = "No method provided to handle request";
return renderErrorComponentPlaceHolder(component, errorMessage);
}
return renderEmptyComponent(component, portalRequest);
}
}
final PortalResponse injectedResponse = LIVE_EDIT_ATTRIBUTE_INJECTION.injectLiveEditAttribute(portalResponse, component.getType());
return injectedResponse;
} finally {
portalRequest.setComponent(previousComponent);
portalRequest.setApplicationKey(previousApplication);
}
}
Aggregations