Search in sources :

Example 6 with RenderMode

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();
}
Also used : RenderMode(com.enonic.xp.portal.RenderMode) PortalResponse(com.enonic.xp.portal.PortalResponse) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams)

Aggregations

RenderMode (com.enonic.xp.portal.RenderMode)6 PortalResponse (com.enonic.xp.portal.PortalResponse)5 PortalRequest (com.enonic.xp.portal.PortalRequest)2 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)2 Component (com.enonic.xp.region.Component)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 Content (com.enonic.xp.content.Content)1 Page (com.enonic.xp.page.Page)1 PageDescriptor (com.enonic.xp.page.PageDescriptor)1 ProcessHtmlParams (com.enonic.xp.portal.url.ProcessHtmlParams)1 ComponentDescriptor (com.enonic.xp.region.ComponentDescriptor)1 DescriptorBasedComponent (com.enonic.xp.region.DescriptorBasedComponent)1 FragmentComponent (com.enonic.xp.region.FragmentComponent)1 WebResponse (com.enonic.xp.web.WebResponse)1 MediaType (com.google.common.net.MediaType)1 Matcher (java.util.regex.Matcher)1