<commit_before>package org.qfox.jestful.form;

import org.qfox.jestful.core.BeanContainer;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import java.util.Enumeration;

/**
 * Created by yangchangpei on 17/8/21.
 */
public class TokenInput extends TagSupport {
    private static final long serialVersionUID = 8901103747024632711L;

    @Override
    public int doStartTag() throws JspException {
        try {
            BeanContainer beanContainer = (BeanContainer) pageContext.getServletContext().getAttribute(BeanContainer.ROOT_BEAN_CONTAINER_CONTEXT_ATTRIBUTE);
            TokenManager tokenManager = beanContainer.get(TokenManager.class);
            String token = tokenManager.create();

            if (getValue("type") == null) setValue("type", "hidden");
            if (getValue("name") == null) setValue("name", "form-token");
            if (getValue("value") == null) setValue("value", token);
            StringBuilder sb = new StringBuilder();
            sb.append("<input");

            Enumeration<String> names = getValues();
            while (names.hasMoreElements()) {
                String name = names.nextElement();
                Object value = getValue(name);
                if (value == null) continue;
                else sb.append(" ");
                sb.append(name).append("=").append("\"").append(value.toString()).append("\"");
            }

            sb.append("/>");
            pageContext.getOut().write(sb.toString());
            return SKIP_BODY;
        } catch (Exception e) {
            throw new JspException(e);
        }
    }

}<commit_msg>Add Anti Form Repeat Submit Supports<commit_after>package org.qfox.jestful.form;

import org.qfox.jestful.core.BeanContainer;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.DynamicAttributes;
import javax.servlet.jsp.tagext.TagSupport;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Created by yangchangpei on 17/8/21.
 */
public class TokenInput extends TagSupport implements DynamicAttributes {
    private static final long serialVersionUID = 8901103747024632711L;

    private final Map<String, Object> attributes = new LinkedHashMap<String, Object>();

    @Override
    public int doStartTag() throws JspException {
        try {
            BeanContainer beanContainer = (BeanContainer) pageContext.getServletContext().getAttribute(BeanContainer.ROOT_BEAN_CONTAINER_CONTEXT_ATTRIBUTE);
            TokenManager tokenManager = beanContainer.get(TokenManager.class);
            String token = tokenManager.create();

            if (!attributes.containsKey("name")) attributes.put("name", "form-token");
            if (!attributes.containsKey("type")) attributes.put("type", "hidden");
            if (!attributes.containsKey("value")) attributes.put("value", token);

            StringBuilder sb = new StringBuilder();
            sb.append("<input");

            for (Map.Entry<String, Object> entry : attributes.entrySet()) {
                String name = entry.getKey();
                Object value = entry.getValue();
                if (value == null) continue;
                else sb.append(" ");
                sb.append(name).append("=").append("\"").append(value.toString()).append("\"");
            }

            sb.append("/>");
            pageContext.getOut().write(sb.toString());
            return SKIP_BODY;
        } catch (Exception e) {
            throw new JspException(e);
        }
    }

    @Override
    public void setDynamicAttribute(String uri, String localName, Object value) throws JspException {
        attributes.put(localName, value);
    }

    @Override
    public void release() {
        attributes.clear();
        super.release();
    }
}
{'fraction_non_alphanumeric': 0.12506624271330152, 'fraction_numerical': 0.012718600953895072, 'mean_word_length': 2.6298076923076925, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3402111', 'n_tokens_mistral': 1045, 'n_tokens_neox': 985, 'n_words': 217}