/**
   * @param engineName the script engine name (eg "groovy", etc)
   * @return the Script engine to use to evaluate the script
   * @throws MacroExecutionException in case of an error in parsing the jars parameter
   */
  private ScriptEngine getScriptEngine(String engineName) throws MacroExecutionException {
    // Look for a script engine in the Execution Context since we want the same engine to be used
    // for all evals during the same execution lifetime.
    // We must use the same engine because that engine may create an internal ClassLoader in which
    // it loads new classes defined in the script and if we create a new engine then defined classes
    // will be lost.
    // However we also need to be able to execute several script Macros during a single execution
    // request
    // and for example the second macro could have jar parameters. In order to support this use case
    // we ensure in AbstractScriptMacro to reuse the same thread context ClassLoader during the
    // whole
    // request execution.
    ExecutionContext executionContext = this.execution.getContext();
    Map<String, ScriptEngine> scriptEngines =
        (Map<String, ScriptEngine>) executionContext.getProperty(EXECUTION_CONTEXT_ENGINE_KEY);
    if (scriptEngines == null) {
      scriptEngines = new HashMap<String, ScriptEngine>();
      executionContext.setProperty(EXECUTION_CONTEXT_ENGINE_KEY, scriptEngines);
    }
    ScriptEngine engine = scriptEngines.get(engineName);

    if (engine == null) {
      ScriptEngineManager sem = new ScriptEngineManager();
      engine = sem.getEngineByName(engineName);
      scriptEngines.put(engineName, engine);
    }

    return engine;
  }
 /** @return the XWikiContext */
 protected XWikiContext getXWikiContext() {
   ExecutionContext executionContext = this.execution.getContext();
   XWikiContext context =
       (XWikiContext) executionContext.getProperty(XWikiContext.EXECUTIONCONTEXT_KEY);
   // FIXME: Do we need this? Maybe when running an index Thread?
   // if (context == null) {
   // context = this.contextProvider.createStubContext();
   // executionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, context);
   // }
   return context;
 }