Search in sources :

Example 1 with HtmlBlockParser

use of com.enonic.xp.portal.impl.parser.HtmlBlockParser 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)1 HtmlBlockParser (com.enonic.xp.portal.impl.parser.HtmlBlockParser)1 PostProcessInstruction (com.enonic.xp.portal.postprocess.PostProcessInstruction)1