Search in sources :

Example 6 with PostProcessInstruction

use of com.enonic.xp.portal.postprocess.PostProcessInstruction in project xp by enonic.

the class PostProcessEvaluator method executeInstruction.

private HtmlBlocks executeInstruction(final String content) {
    for (final PostProcessInstruction instruction : this.instructions) {
        final PortalResponse instructionResponse = instruction.evaluate(this.portalRequest, content);
        if (instructionResponse == null) {
            continue;
        }
        final boolean hasHeaders = !instructionResponse.getHeaders().isEmpty();
        final boolean hasCookies = !instructionResponse.getCookies().isEmpty();
        final boolean hasContributions = instructionResponse.hasContributions();
        final boolean skipFilters = !instructionResponse.applyFilters();
        if (hasContributions || hasHeaders || skipFilters || hasCookies) {
            final PortalResponse.Builder newPortalResponse = PortalResponse.create(this.portalResponse);
            if (hasContributions) {
                newPortalResponse.contributionsFrom(instructionResponse);
            }
            if (hasHeaders) {
                newPortalResponse.headers(instructionResponse.getHeaders());
            }
            if (hasCookies) {
                newPortalResponse.cookies(instructionResponse.getCookies());
            }
            if (skipFilters) {
                newPortalResponse.applyFilters(false);
            }
            this.portalResponse = newPortalResponse.build();
        }
        final String resultBody = instructionResponse.getAsString();
        return resultBody == null ? null : new HtmlBlockParser().parse(resultBody);
    }
    return null;
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) PostProcessInstruction(com.enonic.xp.portal.postprocess.PostProcessInstruction) HtmlBlockParser(com.enonic.xp.portal.impl.parser.HtmlBlockParser)

Aggregations

PortalResponse (com.enonic.xp.portal.PortalResponse)6 PostProcessInstruction (com.enonic.xp.portal.postprocess.PostProcessInstruction)6 HtmlTag (com.enonic.xp.portal.postprocess.HtmlTag)5 PostProcessInjection (com.enonic.xp.portal.postprocess.PostProcessInjection)5 InputStream (java.io.InputStream)5 StandardCharsets (java.nio.charset.StandardCharsets)5 Arrays (java.util.Arrays)5 Collections (java.util.Collections)5 List (java.util.List)5 Collectors.joining (java.util.stream.Collectors.joining)5 Stream (java.util.stream.Stream)5 Cookie (javax.servlet.http.Cookie)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5 Test (org.junit.jupiter.api.Test)5 HtmlBlockParser (com.enonic.xp.portal.impl.parser.HtmlBlockParser)1