// Path: src/main/java/com/indeed/proctor/webapp/extensions/renderer/EditPageRenderer.java
// public interface EditPageRenderer {
//     enum EditPagePosition {
//         TOP_FORM,
//         MIDDLE_FORM,
//         BOTTOM_FORM,
//         SCRIPT,
//         SPECIAL_CONSTANTS
//     }
// 
//     EditPagePosition getEditPagePosition();
// 
//     @Deprecated
//     default String getRenderedHtml(final String testName, final String testDefinitionJson, final boolean isCreate){
//         return "";
//     }
// 
//     default String getRenderedHtml(final PageContext pageContext, final String testName, final String testDefinitionJson, final boolean isCreate){
//         return "";
//     }
// }
// 
// Path: src/main/java/com/indeed/proctor/webapp/extensions/renderer/EditPageRenderer.java
// enum EditPagePosition {
//     TOP_FORM,
//     MIDDLE_FORM,
//     BOTTOM_FORM,
//     SCRIPT,
//     SPECIAL_CONSTANTS
// }


import com.indeed.proctor.webapp.extensions.renderer.EditPageRenderer;
import com.indeed.proctor.webapp.extensions.renderer.EditPageRenderer.EditPagePosition;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import javax.servlet.ServletContext;
import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;
import java.util.Map;
    public void setTestDefinitionJson(final String testDefinitionJson) {
        this.testDefinitionJson = testDefinitionJson;
    }

    public void setIsCreate(final boolean isCreate) {
        this.isCreate = isCreate;
    }

    public int doStartTag() {
        try {
            pageContext.getOut().print(renderTemplates());
        } catch (IOException e) {
            LOGGER.error("Failed to write rendered html to page context", e);
        }

        return SKIP_BODY;
    }

    private String renderTemplates() {
        final StringBuilder renderedHTML = new StringBuilder();
        final ServletContext servletContext = pageContext.getServletContext();
        final WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        try {
            final Map<String, EditPageRenderer> rendererBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, EditPageRenderer.class);
            for (final EditPageRenderer renderer : rendererBeans.values()) {
                if (position == renderer.getEditPagePosition()) {
                    renderedHTML.append(renderer.getRenderedHtml(testName, testDefinitionJson, isCreate));
                    renderedHTML.append(renderer.getRenderedHtml(pageContext, testName, testDefinitionJson, isCreate));
                }
            }
// Path: src/main/java/com/indeed/proctor/webapp/extensions/renderer/EditPageRenderer.java
// public interface EditPageRenderer {
//     enum EditPagePosition {
//         TOP_FORM,
//         MIDDLE_FORM,
//         BOTTOM_FORM,
//         SCRIPT,
//         SPECIAL_CONSTANTS
//     }
// 
//     EditPagePosition getEditPagePosition();
// 
//     @Deprecated
//     default String getRenderedHtml(final String testName, final String testDefinitionJson, final boolean isCreate){
//         return "";
//     }
// 
//     default String getRenderedHtml(final PageContext pageContext, final String testName, final String testDefinitionJson, final boolean isCreate){
//         return "";
//     }
// }
// 
// Path: src/main/java/com/indeed/proctor/webapp/extensions/renderer/EditPageRenderer.java
// enum EditPagePosition {
//     TOP_FORM,
//     MIDDLE_FORM,
//     BOTTOM_FORM,
//     SCRIPT,
//     SPECIAL_CONSTANTS
// }


// Path: src/main/java/com/indeed/proctor/webapp/tags/RenderEditPageInjectionTemplatesTagHandler.java
import com.indeed.proctor.webapp.extensions.renderer.EditPageRenderer;
import com.indeed.proctor.webapp.extensions.renderer.EditPageRenderer.EditPagePosition;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import javax.servlet.ServletContext;
import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;
import java.util.Map;

    public void setTestDefinitionJson(final String testDefinitionJson) {
        this.testDefinitionJson = testDefinitionJson;
    }

    public void setIsCreate(final boolean isCreate) {
        this.isCreate = isCreate;
    }

    public int doStartTag() {
        try {
            pageContext.getOut().print(renderTemplates());
        } catch (IOException e) {
            LOGGER.error("Failed to write rendered html to page context", e);
        }

        return SKIP_BODY;
    }

    private String renderTemplates() {
        final StringBuilder renderedHTML = new StringBuilder();
        final ServletContext servletContext = pageContext.getServletContext();
        final WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        try {
            final Map<String, EditPageRenderer> rendererBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, EditPageRenderer.class);
            for (final EditPageRenderer renderer : rendererBeans.values()) {
                if (position == renderer.getEditPagePosition()) {
                    renderedHTML.append(renderer.getRenderedHtml(testName, testDefinitionJson, isCreate));
                    renderedHTML.append(renderer.getRenderedHtml(pageContext, testName, testDefinitionJson, isCreate));
                }
            }
        } catch (Exception e) {