use of com.enonic.xp.portal.RenderMode in project xp by enonic.
the class AdminSiteHandler method createPortalRequest.
@Override
protected PortalRequest createPortalRequest(final WebRequest webRequest, final WebResponse webResponse) {
final Matcher matcher = BASE_URI_PATTERN.matcher(webRequest.getRawPath());
if (!matcher.find()) {
throw WebException.notFound("Mode needs to be specified");
}
final String baseUri = matcher.group(0);
final RenderMode mode = RenderMode.from(matcher.group(1));
final String baseSubPath = webRequest.getRawPath().substring(baseUri.length() + 1);
final PortalRequest portalRequest = doCreatePortalRequest(webRequest, baseUri, baseSubPath);
portalRequest.setMode(mode);
return portalRequest;
}
use of com.enonic.xp.portal.RenderMode in project xp by enonic.
the class AdminSiteHandler method doHandle.
@Override
protected WebResponse doHandle(final WebRequest webRequest, final WebResponse webResponse, final WebHandlerChain webHandlerChain) {
final WebResponse response = super.doHandle(webRequest, webResponse, webHandlerChain);
final PortalRequest request = PortalRequestAccessor.get(webRequest.getRawRequest());
final RenderMode mode = request.getMode();
if (mode == RenderMode.LIVE || request.getEndpointPath() != null) {
return response;
}
final PortalResponse.Builder builder = PortalResponse.create(response);
if (mode == RenderMode.INLINE || mode == RenderMode.EDIT) {
builder.header("X-Frame-Options", "SAMEORIGIN");
}
if (mode == RenderMode.EDIT) {
builder.removeHeader("Content-Security-Policy");
} else if (!nullToEmpty(previewContentSecurityPolicy).isBlank() && !response.getHeaders().containsKey("Content-Security-Policy")) {
builder.header("Content-Security-Policy", previewContentSecurityPolicy);
}
return builder.build();
}
use of com.enonic.xp.portal.RenderMode 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);
}
}
use of com.enonic.xp.portal.RenderMode in project xp by enonic.
the class TextRenderer method render.
@Override
public PortalResponse render(final TextComponent textComponent, final PortalRequest portalRequest) {
final RenderMode renderMode = portalRequest.getMode();
final PortalResponse.Builder portalResponseBuilder = PortalResponse.create();
portalResponseBuilder.contentType(MediaType.create("text", "html")).postProcess(false);
if (textComponent.getText().isEmpty()) {
renderEmptyTextComponent(textComponent, renderMode, portalResponseBuilder);
} else {
if (renderMode == RenderMode.EDIT) {
portalResponseBuilder.body(MessageFormat.format(COMPONENT_EDIT_MODE_HTML, textComponent.getType().toString(), textComponent.getText()));
} else {
ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(portalRequest).value(textComponent.getText());
final String processedHtml = removeEmptyFigCaptionTags(service.processHtml(params));
portalResponseBuilder.body(MessageFormat.format(COMPONENT_PREVIEW_MODE_HTML, textComponent.getType().toString(), processedHtml));
}
}
return portalResponseBuilder.build();
}
use of com.enonic.xp.portal.RenderMode in project xp by enonic.
the class PageRenderer method doRender.
@Override
public PortalResponse doRender(final Content content, final PortalRequest portalRequest) {
final PageDescriptor pageDescriptor = portalRequest.getPageDescriptor();
final RenderMode mode = portalRequest.getMode();
PortalResponse portalResponse;
if (pageDescriptor != null) {
final ControllerScript controllerScript = this.controllerScriptFactory.fromDir(pageDescriptor.getComponentPath());
portalResponse = controllerScript.execute(portalRequest);
} else if (portalRequest.getControllerScript() != null) {
portalResponse = portalRequest.getControllerScript().execute(portalRequest);
} else if ((mode == EDIT || mode == PREVIEW || mode == INLINE) && portalRequest.getContent().getType().isFragment()) {
portalResponse = renderDefaultFragmentPage(portalRequest, content);
} else {
portalResponse = renderForNoPageDescriptor(portalRequest, content);
}
return portalResponse;
}
Aggregations