// Path: src/main/java/com/indeed/proctor/webapp/extensions/HelpURLInformation.java
// public interface HelpURLInformation {
//     public String getTestTypeHelpURL();
//     public String getRuleHelpURL();
// }


import com.indeed.proctor.webapp.extensions.HelpURLInformation;
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 int doStartTag() {
        try {
            pageContext.getOut().print(helpButton(helpType));
        } catch (IOException e) {
            LOGGER.error("Failed to write help button to page context", e);
        }
        return SKIP_BODY;
    }

    public String helpButton(final HelpType helpType) {
        return String.format("<a class=\"ui-help-button\" target=\"_blank\" href=\"%s\">?</a>", getHelpURL(helpType));
    }

    public String getHelpURL(final HelpType helpType) {
        final ServletContext servletContext = pageContext.getServletContext();
        final WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        final Map<String, HelpURLInformation> formatterBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, HelpURLInformation.class);
        if (formatterBeans.size() == 1) {
            HelpURLInformation helpURLInformation = (HelpURLInformation) formatterBeans.values().toArray()[0];
            switch (helpType) {
                case TEST_TYPE:
                    return helpURLInformation.getTestTypeHelpURL();
                case RULE:
                    return helpURLInformation.getRuleHelpURL();
                default:
                    return "";
            }
        } else if (formatterBeans.size() > 1) {
            LOGGER.warn("Multiple beans of type " + HelpURLInformation.class.getSimpleName() + " found, expected 0 or 1.");
        }
// Path: src/main/java/com/indeed/proctor/webapp/extensions/HelpURLInformation.java
// public interface HelpURLInformation {
//     public String getTestTypeHelpURL();
//     public String getRuleHelpURL();
// }


// Path: src/main/java/com/indeed/proctor/webapp/tags/RenderHelpButtonTagHandler.java
import com.indeed.proctor.webapp.extensions.HelpURLInformation;
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 int doStartTag() {
        try {
            pageContext.getOut().print(helpButton(helpType));
        } catch (IOException e) {
            LOGGER.error("Failed to write help button to page context", e);
        }
        return SKIP_BODY;
    }

    public String helpButton(final HelpType helpType) {
        return String.format("<a class=\"ui-help-button\" target=\"_blank\" href=\"%s\">?</a>", getHelpURL(helpType));
    }

    public String getHelpURL(final HelpType helpType) {
        final ServletContext servletContext = pageContext.getServletContext();
        final WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        final Map<String, HelpURLInformation> formatterBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, HelpURLInformation.class);
        if (formatterBeans.size() == 1) {
            HelpURLInformation helpURLInformation = (HelpURLInformation) formatterBeans.values().toArray()[0];
            switch (helpType) {
                case TEST_TYPE:
                    return helpURLInformation.getTestTypeHelpURL();
                case RULE:
                    return helpURLInformation.getRuleHelpURL();
                default:
                    return "";
            }
        } else if (formatterBeans.size() > 1) {
            LOGGER.warn("Multiple beans of type " + HelpURLInformation.class.getSimpleName() + " found, expected 0 or 1.");
        }
        return getDefaultHelpURL(helpType);