<commit_before>package org.csstudio.opibuilder.script;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.script.Bindings;
import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.ScriptEngine;

import org.csstudio.opibuilder.editparts.AbstractBaseEditPart;
import org.csstudio.simplepv.IPV;

/**
 * This is the implementation of {@link AbstractScriptStore} for the default javascript script engine embedded in Java. 
 * The default javascript engine is Rhino for Java 7, Nashorn for Java 8.
 */
public class JavaScriptStore extends AbstractScriptStore {

	private ScriptEngine engine;
	private Bindings bindings;
	private CompiledScript script;

	public JavaScriptStore(final ScriptData scriptData, final AbstractBaseEditPart editpart,
			final IPV[] pvArray) throws Exception {		
		super(scriptData, editpart, pvArray);		
		
	}
	
	@Override
	protected void initScriptEngine() throws Exception {
		engine = ScriptStoreFactory.getJavaScriptEngine();
		bindings = engine.createBindings();
		bindings.put(ScriptService.WIDGET, getEditPart());
		bindings.put(ScriptService.PVS, getPvArray());
		bindings.put(ScriptService.DISPLAY, getDisplayEditPart());
		bindings.put(ScriptService.WIDGET_CONTROLLER_DEPRECIATED, getEditPart());
		bindings.put(ScriptService.PV_ARRAY_DEPRECIATED, getPvArray());
	}

	@Override
	protected void compileString(String string) throws Exception {
		((Compilable) engine).compile(string);
	}

	@Override
	protected void compileInputStream(InputStream s) throws Exception {
		try (BufferedReader reader = new BufferedReader(new InputStreamReader(s))) {
			((Compilable) engine).compile(reader);
		}
	}

	@Override
	protected void execScript(IPV triggerPV) throws Exception {
		bindings.put(ScriptService.TRIGGER_PV, triggerPV);
		script.eval(bindings);
	}<commit_msg>o.c.opibuilder.script: fix from merge #528<commit_after>package org.csstudio.opibuilder.script;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.script.Bindings;
import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.ScriptEngine;

import org.csstudio.opibuilder.editparts.AbstractBaseEditPart;
import org.csstudio.simplepv.IPV;

/**
 * This is the implementation of {@link AbstractScriptStore} for the default javascript script engine embedded in Java. 
 * The default javascript engine is Rhino for Java 7, Nashorn for Java 8.
 */
public class JavaScriptStore extends AbstractScriptStore {

	private ScriptEngine engine;
	private Bindings bindings;
	private CompiledScript script;

	public JavaScriptStore(final ScriptData scriptData, final AbstractBaseEditPart editpart,
			final IPV[] pvArray) throws Exception {		
		super(scriptData, editpart, pvArray);		
		
	}
	
	@Override
	protected void initScriptEngine() throws Exception {
		engine = ScriptStoreFactory.getJavaScriptEngine();
		bindings = engine.createBindings();
		bindings.put(ScriptService.WIDGET, getEditPart());
		bindings.put(ScriptService.PVS, getPvArray());
		bindings.put(ScriptService.DISPLAY, getDisplayEditPart());
		bindings.put(ScriptService.WIDGET_CONTROLLER_DEPRECIATED, getEditPart());
		bindings.put(ScriptService.PV_ARRAY_DEPRECIATED, getPvArray());
	}

	@Override
	protected void compileString(String string) throws Exception {
		script = ((Compilable) engine).compile(string);
	}

	@Override
	protected void compileInputStream(InputStream s) throws Exception {
		try (BufferedReader reader = new BufferedReader(new InputStreamReader(s))) {
			script = ((Compilable) engine).compile(reader);
			s.close();
			reader.close();
		}
		
	}

	@Override
	protected void execScript(IPV triggerPV) throws Exception {
		bindings.put(ScriptService.TRIGGER_PV, triggerPV);
		script.eval(bindings);
	}
{'fraction_non_alphanumeric': 0.09351393592081271, 'fraction_numerical': 0.0018233915082052619, 'mean_word_length': 5.869409660107334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4560831', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1119, 'n_words': 272}