// 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;
package com.indeed.proctor.webapp.tags;



/**
 * @author yosukey
 */
public class RenderHelpButtonTagHandler extends TagSupport {
    public enum HelpType {
        TEST_TYPE,
        RULE
    }

    private static final String TEST_TYPE_DEFAULT_URL = "http://opensource.indeedeng.io/proctor/docs/terminology/#test-type";
    private static final String RULE_DEFAULT_URL = "http://opensource.indeedeng.io/proctor/docs/test-rules/";
    private static final Logger LOGGER = Logger.getLogger(RenderHelpButtonTagHandler.class);
    private HelpType helpType;

    public void setHelpType(HelpType helpType) { this.helpType = helpType; }

    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);
// 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;

package com.indeed.proctor.webapp.tags;



/**
 * @author yosukey
 */
public class RenderHelpButtonTagHandler extends TagSupport {
    public enum HelpType {
        TEST_TYPE,
        RULE
    }

    private static final String TEST_TYPE_DEFAULT_URL = "http://opensource.indeedeng.io/proctor/docs/terminology/#test-type";
    private static final String RULE_DEFAULT_URL = "http://opensource.indeedeng.io/proctor/docs/test-rules/";
    private static final Logger LOGGER = Logger.getLogger(RenderHelpButtonTagHandler.class);
    private HelpType helpType;

    public void setHelpType(HelpType helpType) { this.helpType = helpType; }

    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);