Class RhinoInterpreter

java.lang.Object
org.apache.batik.bridge.RhinoInterpreter
All Implemented Interfaces:
Localizable, Interpreter
Direct Known Subclasses:
SVG12RhinoInterpreter

public class RhinoInterpreter extends Object implements Interpreter
A simple implementation of Interpreter interface to use Rhino ECMAScript interpreter.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    To build an argument list.
    protected static class 
    Class to store cached compiled scripts.
    protected class 
    Factory for Context objects.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Name of the "window" object when referenced by scripts
    protected org.mozilla.javascript.ClassShutter
    Class shutter.
    protected LinkedList
    List of cached compiled scripts.
    protected org.mozilla.javascript.ContextFactory
    Factory object for creating Contexts.
    protected static List
    Context vector, to make sure we are not setting the security context too many times
    protected org.mozilla.javascript.Context
    Default Context for scripts.
    protected org.mozilla.javascript.ScriptableObject
    The global object.
    The Rhino 'security domain'.
    protected org.mozilla.javascript.SecurityController
    The SecurityController implementation for Batik, which ensures scripts have access to the server they were downloaded from
    static final String
    Constant used to describe an SVG source
    protected Window
    The window object.
    protected org.mozilla.javascript.WrapFactory
    Factory for Java wrapper objects.
  • Constructor Summary

    Constructors
    Constructor
    Description
    RhinoInterpreter(URL documentURL)
    Build a Interpreter for ECMAScript using Rhino.
    RhinoInterpreter(URL documentURL, ImportInfo imports)
    Build a Interpreter for ECMAScript using Rhino.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    bindObject(String name, Object object)
    This method registers a particular Java Object in the environment of the interpreter.
    protected org.mozilla.javascript.ScriptableObject
    createGlobalObject(org.mozilla.javascript.Context ctx)
    Creates the global object.
    protected void
    defineGlobalWrapperClass(org.mozilla.javascript.Scriptable global)
    Defines the class for the global object.
    void
    For RhinoInterpreter this method flushes the Rhino caches to avoid memory leaks.
    evaluate(Reader scriptreader)
    This method evaluates a piece of ECMAScript.
    evaluate(Reader scriptReader, String description)
    This method evaluates a piece of ECMAScript.
    evaluate(String scriptStr)
    This method evaluates a piece of ECMA script.
    formatMessage(String key, Object[] args)
    Creates and returns a localized message, given the key of the message, 0, data.length in the resource bundle and the message parameters.
    Returns the AccessControlContext associated with this Interpreter.
    org.mozilla.javascript.ContextFactory
    Returns the ContextFactory for this interpreter.
    protected org.mozilla.javascript.ScriptableObject
    This method returns the ECMAScript global object used by this interpreter.
    Returns the current locale or null if the locale currently used is the default one.
    Returns the content types of the scripting languages this interpreter handles.
    Returns the window object for this interpreter.
    protected void
    init(URL documentURL, ImportInfo imports)
     
    void
    setLocale(Locale locale)
    Provides a way to the user to specify a locale which override the default one.
    void
    By default Rhino has no output method in its language.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SOURCE_NAME_SVG

      public static final String SOURCE_NAME_SVG
      Constant used to describe an SVG source
      See Also:
    • BIND_NAME_WINDOW

      public static final String BIND_NAME_WINDOW
      Name of the "window" object when referenced by scripts
      See Also:
    • contexts

      protected static List contexts
      Context vector, to make sure we are not setting the security context too many times
    • window

      protected Window window
      The window object.
    • globalObject

      protected org.mozilla.javascript.ScriptableObject globalObject
      The global object.
    • compiledScripts

      protected LinkedList compiledScripts
      List of cached compiled scripts.
    • wrapFactory

      protected org.mozilla.javascript.WrapFactory wrapFactory
      Factory for Java wrapper objects.
    • classShutter

      protected org.mozilla.javascript.ClassShutter classShutter
      Class shutter.
    • rhinoClassLoader

      protected RhinoClassLoader rhinoClassLoader
      The Rhino 'security domain'. We use the RhinoClassLoader which will grant permissions to connect to the document URL.
    • securityController

      protected org.mozilla.javascript.SecurityController securityController
      The SecurityController implementation for Batik, which ensures scripts have access to the server they were downloaded from
    • contextFactory

      protected org.mozilla.javascript.ContextFactory contextFactory
      Factory object for creating Contexts.
    • defaultContext

      protected org.mozilla.javascript.Context defaultContext
      Default Context for scripts. This is used only for efficiency reasons.
  • Constructor Details

    • RhinoInterpreter

      public RhinoInterpreter(URL documentURL)
      Build a Interpreter for ECMAScript using Rhino.
      Parameters:
      documentURL - the URL for the document which references
      See Also:
    • RhinoInterpreter

      public RhinoInterpreter(URL documentURL, ImportInfo imports)
      Build a Interpreter for ECMAScript using Rhino.
      Parameters:
      documentURL - the URL for the document which references
      imports - the set of Java classes/packages to import into the scripting enviornment.
      See Also:
  • Method Details

    • init

      protected void init(URL documentURL, ImportInfo imports)
    • getMimeTypes

      public String[] getMimeTypes()
      Returns the content types of the scripting languages this interpreter handles.
      Specified by:
      getMimeTypes in interface Interpreter
    • getWindow

      public Window getWindow()
      Returns the window object for this interpreter.
    • getContextFactory

      public org.mozilla.javascript.ContextFactory getContextFactory()
      Returns the ContextFactory for this interpreter.
    • defineGlobalWrapperClass

      protected void defineGlobalWrapperClass(org.mozilla.javascript.Scriptable global)
      Defines the class for the global object.
    • createGlobalObject

      protected org.mozilla.javascript.ScriptableObject createGlobalObject(org.mozilla.javascript.Context ctx)
      Creates the global object.
    • getAccessControlContext

      public AccessControlContext getAccessControlContext()
      Returns the AccessControlContext associated with this Interpreter.
      See Also:
    • getGlobalObject

      protected org.mozilla.javascript.ScriptableObject getGlobalObject()
      This method returns the ECMAScript global object used by this interpreter.
    • evaluate

      public Object evaluate(Reader scriptreader) throws IOException
      This method evaluates a piece of ECMAScript.
      Specified by:
      evaluate in interface Interpreter
      Parameters:
      scriptreader - a java.io.Reader on the piece of script
      Returns:
      if no exception is thrown during the call, should return the value of the last expression evaluated in the script.
      Throws:
      IOException
    • evaluate

      public Object evaluate(Reader scriptReader, String description) throws IOException
      This method evaluates a piece of ECMAScript.
      Specified by:
      evaluate in interface Interpreter
      Parameters:
      scriptReader - a java.io.Reader on the piece of script
      description - description which can be later used (e.g., for error messages).
      Returns:
      if no exception is thrown during the call, should return the value of the last expression evaluated in the script.
      Throws:
      IOException
    • evaluate

      public Object evaluate(String scriptStr)
      This method evaluates a piece of ECMA script. The first time a String is passed, it is compiled and evaluated. At next call, the piece of script will only be evaluated to prevent from recompiling it.
      Specified by:
      evaluate in interface Interpreter
      Parameters:
      scriptStr - the piece of script
      Returns:
      if no exception is thrown during the call, should return the value of the last expression evaluated in the script.
    • dispose

      public void dispose()
      For RhinoInterpreter this method flushes the Rhino caches to avoid memory leaks.
      Specified by:
      dispose in interface Interpreter
    • bindObject

      public void bindObject(String name, Object object)
      This method registers a particular Java Object in the environment of the interpreter.
      Specified by:
      bindObject in interface Interpreter
      Parameters:
      name - the name of the script object to create
      object - the Java object
    • setOut

      public void setOut(Writer out)
      By default Rhino has no output method in its language. That's why this method does nothing.
      Specified by:
      setOut in interface Interpreter
      Parameters:
      out - the new out Writer.
    • getLocale

      public Locale getLocale()
      Returns the current locale or null if the locale currently used is the default one.
      Specified by:
      getLocale in interface Localizable
    • setLocale

      public void setLocale(Locale locale)
      Provides a way to the user to specify a locale which override the default one. If null is passed to this method, the used locale becomes the global one.
      Specified by:
      setLocale in interface Localizable
      Parameters:
      locale - The locale to set.
    • formatMessage

      public String formatMessage(String key, Object[] args)
      Creates and returns a localized message, given the key of the message, 0, data.length in the resource bundle and the message parameters. The messages in the resource bundle must have the syntax described in the java.text.MessageFormat class documentation.
      Specified by:
      formatMessage in interface Localizable
      Parameters:
      key - The key used to retreive the message from the resource bundle.
      args - The objects that compose the message.
      Throws:
      MissingResourceException - if the key is not in the bundle.