<commit_before>/*
 * Copyright (C) 2013 XSite Committers.
 * All rights reserved.
 *
 * Created on 06.06.2013 by <NAME>
 */
package org.codehaus.xsite.extractors.sitemesh.filters;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.opensymphony.module.sitemesh.html.TextFilter;

import org.apache.commons.lang.StringUtils;

/**
 * A text filter to inject a mailto: URL.
 * 
 * <p>It provides the following syntax:</p>
 * <pre>
 * %{MAIL:id|link text[|subject text[|body text]]}%
 * </pre>
 * <p>where <em>id</em> is either an email address or an identifier in the map provided with the constructor that
 * should map to an email address, <em>text</em> is the text of the link, <em>subject</em> is the subject of
 * the email and <em>body</em> is the body of the email. The <em>subject</em> and <em>body</em> parameters
 * are optional, but both values will be encoded according RFC 3987.</p>
 * <p>It will be converted into:</p>
 * <pre>
 * &lt;a href=&quot;mailto:<EMAIL>?subject=subject%20text&amp;body=body%20text&quot;&gt;link text&lt;/a&gt;
 * </pre>
 * 
 * @author J&ouml;<NAME>
 * @since upcoming
 */
public class MailToLinkTextFilter implements TextFilter {

	private static final Pattern PATTERN = Pattern.compile("(.*)%\\{MAIL:(.+?)\\|(.+?)(?:\\|(.+?))?(?:\\|(?s)(.+?)(?-s))?\\}%(.*)");
	private final Map<String, String> mailMap;
	private final String classAttribute;

	public MailToLinkTextFilter(Map<String,String> mailMap) {
		this(mailMap, null);
	}

	public MailToLinkTextFilter(Map<String,String> mailMap, String classAttribute) {
		this.mailMap = mailMap;
		this.classAttribute = classAttribute;
	}

	@Override
	public String filter(final String text) {
		Matcher matcher = PATTERN.matcher(text);
		if (matcher.matches()) {
			int groups = matcher.groupCount();
			final StringBuilder sb = new StringBuilder(matcher.group(1));
			sb.append("<a ");<commit_msg>FIx @since<commit_after>/*
 * Copyright (C) 2013 XSite Committers.
 * All rights reserved.
 *
 * Created on 06.06.2013 by <NAME>
 */
package org.codehaus.xsite.extractors.sitemesh.filters;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.opensymphony.module.sitemesh.html.TextFilter;

import org.apache.commons.lang.StringUtils;

/**
 * A text filter to inject a mailto: URL.
 * 
 * <p>It provides the following syntax:</p>
 * <pre>
 * %{MAIL:id|link text[|subject text[|body text]]}%
 * </pre>
 * <p>where <em>id</em> is either an email address or an identifier in the map provided with the constructor that
 * should map to an email address, <em>text</em> is the text of the link, <em>subject</em> is the subject of
 * the email and <em>body</em> is the body of the email. The <em>subject</em> and <em>body</em> parameters
 * are optional, but both values will be encoded according RFC 3987.</p>
 * <p>It will be converted into:</p>
 * <pre>
 * &lt;a href=&quot;mailto:<EMAIL>?subject=subject%20text&amp;body=body%20text&quot;&gt;link text&lt;/a&gt;
 * </pre>
 * 
 * @author J&ouml;<NAME>
 * @since 1.3
 */
public class MailToLinkTextFilter implements TextFilter {

	private static final Pattern PATTERN = Pattern.compile("(.*)%\\{MAIL:(.+?)\\|(.+?)(?:\\|(.+?))?(?:\\|(?s)(.+?)(?-s))?\\}%(.*)");
	private final Map<String, String> mailMap;
	private final String classAttribute;

	public MailToLinkTextFilter(Map<String,String> mailMap) {
		this(mailMap, null);
	}

	public MailToLinkTextFilter(Map<String,String> mailMap, String classAttribute) {
		this.mailMap = mailMap;
		this.classAttribute = classAttribute;
	}

	@Override
	public String filter(final String text) {
		Matcher matcher = PATTERN.matcher(text);
		if (matcher.matches()) {
			int groups = matcher.groupCount();
			final StringBuilder sb = new StringBuilder(matcher.group(1));
			sb.append("<a ");
{'fraction_non_alphanumeric': 0.16197916666666667, 'fraction_numerical': 0.011458333333333333, 'mean_word_length': 4.5747460087082725, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 59, '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': '988406', 'n_tokens_mistral': 1365, 'n_tokens_neox': 1267, 'n_words': 351}