<commit_before>package com.nominanuda.rhino.host;

import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.RhinoHelper;
import org.mozilla.javascript.Scriptable;

public class DefinedClassModuleFactory implements ModuleFactory {
	private static final RhinoHelper rhino = new RhinoHelper();
	private Map<String,String> map = new HashMap<String,String>();
	
	public DefinedClassModuleFactory(Map<String,String> map){
		this.map.putAll(map);
	}
	
	public Object create(String key, Scriptable thisObj, Scriptable scope, Context context) throws Exception {
		String defClass = map.get(key);
		if(defClass == null) {
			return null;
		} else {
			@SuppressWarnings("unchecked")
			Object res = rhino.buildClassCtor(scope,(Class<? extends Scriptable>)Class.forName(defClass),false,false);
			if(res instanceof JavaJsHostObject) {
				String script = ((JavaJsHostObject)res).getJsScript();
				rhino.evaluateReader(context, new StringReader(script), defClass, scope);
			}
			return res;
		}
	}

}<commit_msg>added trim for fixing possible problems in configuration<commit_after>package com.nominanuda.rhino.host;

import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.RhinoHelper;
import org.mozilla.javascript.Scriptable;

public class DefinedClassModuleFactory implements ModuleFactory {
	private static final RhinoHelper rhino = new RhinoHelper();
	private Map<String,String> map = new HashMap<String,String>();
	
	public DefinedClassModuleFactory(Map<String,String> map){
		this.map.putAll(map);
	}
	
	public Object create(String key, Scriptable thisObj, Scriptable scope, Context context) throws Exception {
		String defClass = map.get(key);
		if(defClass == null) {
			return null;
		} else {
			@SuppressWarnings("unchecked")
			Object res = rhino.buildClassCtor(scope,(Class<? extends Scriptable>)Class.forName(defClass.trim()),false,false);
			if(res instanceof JavaJsHostObject) {
				String script = ((JavaJsHostObject)res).getJsScript();
				rhino.evaluateReader(context, new StringReader(script), defClass, scope);
			}
			return res;
		}
	}

}
{'fraction_non_alphanumeric': 0.10652173913043478, 'fraction_numerical': 0.0, 'mean_word_length': 4.681481481481481, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '682796', 'n_tokens_mistral': 736, 'n_tokens_neox': 674, 'n_words': 155}