<commit_before>/**
* http://surenpi.com
*/
package org.suren.autotest.web.framework.core.ui;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.suren.autotest.web.framework.core.action.ClickAble;
import org.suren.autotest.web.framework.core.action.ValueEditor;
import org.suren.autotest.web.framework.selenium.SeleniumEngine;

/**
 * 文本框封装
 * 
 * @author suren
 * @since jdk1.6 2016年6月29日
 */
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class Text extends AbstractElement
{
	private String		value;
	private String 		callback;

	@Autowired
	private ValueEditor	valueEditor;
	@Autowired
	private ClickAble	clickAble;
	@Autowired
	private SeleniumEngine engine;

	public Text()
	{
	}

	public Text(String value)
	{
		this.value = value;
	}

	/**
	 * 自动填充数据，不用关心数据来源
	 */
	public Text fillValue()
	{
		String val4Fill = value;
		if(StringUtils.isNotBlank(callback))
		{
			String methodName = "execute";
			String callbackClsName = callback;
			
			int methodIndex = callback.indexOf("!");
			if(methodIndex != -1 && !callback.endsWith("!"))
			{
				methodName = callback.substring(methodIndex + 1);
				callbackClsName = callback.substring(0, methodIndex);
			}
			
			try
			{
				Class<?> callbackCls = Class.forName(callbackClsName);
				Method callbackMethod = callbackCls.getMethod(methodName,
						SeleniumEngine.class, String.class);
				
				Object result = callbackMethod.invoke(null, engine, value);
				if(result != null)
				{
					val4Fill = result.toString();
				}
			}
			catch (ClassNotFoundException e)
			{
				e.printStackTrace();
			}
			catch (NoSuchMethodException e)
			{<commit_msg>回调类的动态数据中简化invoker<commit_after>/**
* http://surenpi.com
*/
package org.suren.autotest.web.framework.core.ui;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.suren.autotest.web.framework.core.action.ClickAble;
import org.suren.autotest.web.framework.core.action.ValueEditor;
import org.suren.autotest.web.framework.selenium.SeleniumEngine;

/**
 * 文本框封装
 * 
 * @author suren
 * @since jdk1.6 2016年6月29日
 */
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class Text extends AbstractElement
{
	private String		value;
	private String 		callback;

	@Autowired
	private ValueEditor	valueEditor;
	@Autowired
	private ClickAble	clickAble;
	@Autowired
	private SeleniumEngine engine;

	public Text()
	{
	}

	public Text(String value)
	{
		this.value = value;
	}

	/**
	 * 自动填充数据，不用关心数据来源
	 */
	public Text fillValue()
	{
		String val4Fill = value;
		if(StringUtils.isNotBlank(callback))
		{
			String methodName = "execute";
			String callbackClsName = callback;
			
			int methodIndex = callback.indexOf("!");
			if(methodIndex != -1 && !callback.endsWith("!"))
			{
				methodName = callback.substring(methodIndex + 1);
				callbackClsName = callback.substring(0, methodIndex);
			}
			
			try
			{
				if(!callbackClsName.contains("."))
				{
					//这种情况下，就调用框架内部的类
					Map<Object, Object> engineConfig = engine.getEngineConfig();
					String pkg = (String) engineConfig.get("invoker.package");
					
					callbackClsName = (pkg + "." + callbackClsName);
				}
				
				Class<?> callbackCls = Class.forName(callbackClsName);
				Method callbackMethod = callbackCls.getMethod(methodName,
						SeleniumEngine.class, String.class);
				
				Object result = callbackMethod.invoke(null, engine, value);
				if(result != null)
				{
					val4Fill = result.toString();
				}
			}
			catch (ClassNotFoundException e)
			{
				e.printStackTrace();
			}
			catch (NoSuchMethodException e)
			{
{'fraction_non_alphanumeric': 0.11589403973509933, 'fraction_numerical': 0.007095553453169348, 'mean_word_length': 4.040524433849821, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '1564395', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1409, 'n_words': 243}