Class Scripting


  • public final class Scripting
    extends java.lang.Object
    Author:
    Group 3
    • Constructor Summary

      Constructors 
      Constructor Description
      Scripting​(java.lang.String defaultLanguage, Engine globalEngine, java.io.Writer writer)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void evalElement​(Scriptable element)
      Evaluate the script on a given element.
      void evalString​(java.lang.String code, java.lang.String lang)
      Evaluate a string in the top-level context.
      protected void evalString​(java.lang.String code, java.lang.String lang, RecursiveBindings bindings)
      Evaluate a string of code.
      java.util.Optional<java.lang.Object> getGlobal​(java.lang.String name)
      Get a global variable.
      static RecursiveBindings getTopLevelBindings()
      Get Scripting global/top-level bindings.
      void invokeOnElement​(Scriptable element, java.lang.String function, java.lang.Object... args)
      Invoke function on element.
      void setGlobal​(java.lang.String name, java.lang.Object glob)
      Add an object to global bindings.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Scripting

        public Scripting​(java.lang.String defaultLanguage,
                         Engine globalEngine,
                         java.io.Writer writer)
        Constructor.
        Parameters:
        defaultLanguage - Default scripting language.
        globalEngine - Ref to the engine.
        writer - Default Output writer.
    • Method Detail

      • setGlobal

        public void setGlobal​(java.lang.String name,
                              java.lang.Object glob)
        Add an object to global bindings.
        Parameters:
        name - Object name.
        glob - Object.
      • getGlobal

        public java.util.Optional<java.lang.Object> getGlobal​(java.lang.String name)
        Get a global variable.
        Parameters:
        name - Variable name.
        Returns:
        Maybe variable.
      • getTopLevelBindings

        public static RecursiveBindings getTopLevelBindings()
        Get Scripting global/top-level bindings.
        Returns:
        RecursiveBindings
      • evalElement

        public void evalElement​(Scriptable element)
                         throws javax.script.ScriptException,
                                java.io.IOException
        Evaluate the script on a given element. Required before invoking any functions.
        Parameters:
        element - Element to eval script of.
        Throws:
        javax.script.ScriptException - Couldn't eval script.
        java.io.IOException - Couldn't get script.
      • evalString

        protected void evalString​(java.lang.String code,
                                  java.lang.String lang,
                                  RecursiveBindings bindings)
                           throws javax.script.ScriptException
        Evaluate a string of code. Provided for testing.
        Parameters:
        code - Code to eval.
        lang - Language.
        bindings - Bindings to use.
        Throws:
        javax.script.ScriptException - Bad script.
      • evalString

        public void evalString​(java.lang.String code,
                               java.lang.String lang)
                        throws javax.script.ScriptException
        Evaluate a string in the top-level context.
        Parameters:
        code - Code to evaluate.
        lang - Language code is.
        Throws:
        javax.script.ScriptException - Bad code.
      • invokeOnElement

        public void invokeOnElement​(Scriptable element,
                                    java.lang.String function,
                                    java.lang.Object... args)
                             throws javax.script.ScriptException,
                                    java.io.IOException
        Invoke function on element.
        Parameters:
        element - Element to start with.
        function - Function to try and call.
        args - Arguments to function.
        Throws:
        javax.script.ScriptException - Bad Script.
        java.io.IOException - Couldn't read file.