<commit_before>package com.aquent.viewtools;

import org.apache.velocity.tools.view.tools.ViewTool;

import com.dotmarketing.util.Logger;

import java.util.Random;
import java.lang.StringBuffer;

/**
 * 
 * @author cfalzone
 * 
 * A Viewtool Implementation of the Spam-me-not Java version by <NAME>
 * Original Version can be found at:  http://paula.edmiston.org/nb/spamx/SpamMeNot.java
 *
 */
public class SpamMeNot implements ViewTool {

	@Override
	public void init(Object initData) {
		Logger.info(this, "Spam Me Not Viewtool Initialized");
	}
	
	/**
	 * Encode email addresses to make it harder for spammers to harvest them.
	 * 
	 * @param emailAddress    the address to encode
	 * @param name            the name to be displayed in statusbar
	 * @return                a complete email link
	 */
	public static String encodeEmail(String emailAddress, String name) {
		long seed = System.currentTimeMillis();
		Random random = new Random(seed);
		
		if( name == null)
			name = "";
		
		String originalString = "mailto:" + emailAddress;

		StringBuffer encodedName = new StringBuffer();
		StringBuffer encodedMailto = new StringBuffer();

		int originalLenght = originalString.length();
		int nameLength = name.length();

		int i;
		for (i = 0; i < originalLenght; i++) {
			switch (random.nextInt(3)) {
				case 0 : //Decimal code
					encodedMailto.append("&#" + (int)originalString.charAt(i) + ";");
					break;
				case 1 : //Hexadecial code
					encodedMailto.append("&#x" + Integer.toHexString(originalString.charAt(i)) + ";");
					break;
				case 2 : //No action code
					encodedMailto.append(originalString.charAt(i));
					break;
			}
		}

		for (i = 0; i < nameLength; i++) {
			switch (random.nextInt(3)) {
				case 0 : //Decimal code
					encodedName.append("&#" + (int)name.charAt(i) + ";");
					break;
				case 1 : //Hexadecial code
					encodedName.append("&#x" + Integer.toHexString(name.charAt(i)) + ";");
					break;
				case 2 : //No action code
					encodedName.append(name.charAt(i));
					break;
			}
		}
		
		//if no name is supplied, use email in statusbar
		if( nameLength == 0 ) {
			return "<a href=\"" + encodedMailto.toString() + "\">" +
					encodedMailto.toString() + "</a>";
		} else {
			return "<a href=\"" + encodedMailto.toString() + "\">" +
					encodedName.toString() + "</a>";
		}
	}

}<commit_msg>Fixes #1 by adding a method to encode a string<commit_after>package com.aquent.viewtools;

import org.apache.velocity.tools.view.tools.ViewTool;

import com.dotmarketing.util.Logger;

import java.util.Random;
import java.lang.StringBuffer;

/**
 * 
 * @author cfalzone
 * 
 * A Viewtool Implementation of the Spam-me-not Java version by <NAME>
 * Original Version can be found at:  http://paula.edmiston.org/nb/spamx/SpamMeNot.java
 *
 */
public class SpamMeNot implements ViewTool {

	@Override
	public void init(Object initData) {
		Logger.info(this, "Spam Me Not Viewtool Initialized");
	}
	
	/**
	 * Encode email addresses to make it harder for spammers to harvest them.
	 * 
	 * @param emailAddress    the address to encode
	 * @param name            the name to be displayed in statusbar
	 * @return                a complete email link
	 */
	public String encodeEmail(String emailAddress, String name) {
		long seed = System.currentTimeMillis();
		Random random = new Random(seed);
		
		if( name == null) name = "";
		
		String originalString = "mailto:" + emailAddress;

		StringBuffer encodedName = new StringBuffer();
		StringBuffer encodedMailto = new StringBuffer();

		int originalLenght = originalString.length();
		int nameLength = name.length();

		int i;
		for (i = 0; i < originalLenght; i++) {
			switch (random.nextInt(3)) {
				case 0 : //Decimal code
					encodedMailto.append("&#" + (int)originalString.charAt(i) + ";");
					break;
				case 1 : //Hexadecial code
					encodedMailto.append("&#x" + Integer.toHexString(originalString.charAt(i)) + ";");
					break;
				case 2 : //No action code
					encodedMailto.append(originalString.charAt(i));
					break;
			}
		}

		for (i = 0; i < nameLength; i++) {
			switch (random.nextInt(3)) {
				case 0 : //Decimal code
					encodedName.append("&#" + (int)name.charAt(i) + ";");
					break;
				case 1 : //Hexadecial code
					encodedName.append("&#x" + Integer.toHexString(name.charAt(i)) + ";");
					break;
				case 2 : //No action code
					encodedName.append(name.charAt(i));
					break;
			}
		}
		
		//if no name is supplied, use email in statusbar
		if( nameLength == 0 ) {
			return "<a href=\"" + encodedMailto.toString() + "\">" +
					encodedMailto.toString() + "</a>";
		} else {
			return "<a href=\"" + encodedMailto.toString() + "\">" +
					encodedName.toString() + "</a>";
		}
	}
	
	/**
	 * Encode a string 
	 * 
	 * @param s		The String to Encode
	 * @return		The encoded String
	 */
	public String encodeString(String s) {
		long seed = System.currentTimeMillis();
		Random random = new Random(seed);
		
		if(s == null) s = "";
		
		StringBuffer encodedString = new StringBuffer();
		int originalLenght = s.length();
		
		int i;
		for (i = 0; i < originalLenght; i++) {
			switch (random.nextInt(3)) {
				case 0 : //Decimal code
					encodedString.append("&#" + (int)s.charAt(i) + ";");
					break;
				case 1 : //Hexadecial code
					encodedString.append("&#x" + Integer.toHexString(s.charAt(i)) + ";");
					break;
				case 2 : //No action code
					encodedString.append(s.charAt(i));
					break;
			}
		}
		
		return encodedString.toString();
	}

}
{'fraction_non_alphanumeric': 0.14397667213413523, 'fraction_numerical': 0.005102970657918717, 'mean_word_length': 2.9854756717501814, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 13, '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': '3939783', 'n_tokens_mistral': 2108, 'n_tokens_neox': 1741, 'n_words': 471}