public void execute()

in src/main/java/org/apache/sling/scripting/freemarker/internal/IncludeDirective.java [75:112]


    public void execute(final Environment environment, final Map parameters, final TemplateModel[] loopVars, final TemplateDirectiveBody body) throws TemplateException, IOException {

        final SlingHttpServletRequest slingHttpServletRequest = (SlingHttpServletRequest) DeepUnwrap.unwrap(environment.getVariable(SlingBindings.REQUEST));
        if (Objects.isNull(slingHttpServletRequest)) {
            throw new TemplateException("request is null", environment);
        }

        final SlingHttpServletResponse slingHttpServletResponse = (SlingHttpServletResponse) DeepUnwrap.unwrap(environment.getVariable(SlingBindings.RESPONSE));
        if (Objects.isNull(slingHttpServletResponse)) {
            throw new TemplateException("response is null", environment);
        }

        final TemplateModel templateModel = (TemplateModel) parameters.get("include");
        if (Objects.isNull(templateModel)) {
            throw new TemplateException("include is null", environment);
        }
        final Object include = DeepUnwrap.unwrap(templateModel);
        if (Objects.isNull(include)) {
            throw new TemplateException("unwrapping include failed", environment);
        }

        final Resource resource = include instanceof Resource ? (Resource) include : null;
        final String path = include instanceof String ? (String) include : null;
        final String content;
        if (!Objects.isNull(resource)) {
            content = dispatch(resource, requestDispatcherOptions(parameters), slingHttpServletRequest, slingHttpServletResponse);
        } else if (!Objects.isNull(path)) {
            content = dispatch(path, requestDispatcherOptions(parameters), slingHttpServletRequest, slingHttpServletResponse);
        } else {
            throw new TemplateException("resource and path are null", environment);
        }

        if (!Objects.isNull(content)) {
            environment.getOut().write(content);
        } else {
            throw new TemplateException("dispatching request failed, content is null", environment);
        }
    }