Class RhinoInterpreter
java.lang.Object
org.apache.batik.bridge.RhinoInterpreter
- All Implemented Interfaces:
Localizable, Interpreter
- Direct Known Subclasses:
SVG12RhinoInterpreter
A simple implementation of
Interpreter interface to use
Rhino ECMAScript interpreter.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceTo build an argument list.protected static classClass to store cached compiled scripts.protected classFactory for Context objects. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of the "window" object when referenced by scriptsprotected org.mozilla.javascript.ClassShutterClass shutter.protected LinkedListList of cached compiled scripts.protected org.mozilla.javascript.ContextFactoryFactory object for creating Contexts.protected static ListContext vector, to make sure we are not setting the security context too many timesprotected org.mozilla.javascript.ContextDefault Context for scripts.protected org.mozilla.javascript.ScriptableObjectThe global object.protected RhinoClassLoaderThe Rhino 'security domain'.protected org.mozilla.javascript.SecurityControllerThe SecurityController implementation for Batik, which ensures scripts have access to the server they were downloaded fromstatic final StringConstant used to describe an SVG sourceprotected WindowThe window object.protected org.mozilla.javascript.WrapFactoryFactory for Java wrapper objects. -
Constructor Summary
ConstructorsConstructorDescriptionRhinoInterpreter(URL documentURL) Build aInterpreterfor ECMAScript using Rhino.RhinoInterpreter(URL documentURL, ImportInfo imports) Build aInterpreterfor ECMAScript using Rhino. -
Method Summary
Modifier and TypeMethodDescriptionvoidbindObject(String name, Object object) This method registers a particular JavaObjectin the environment of the interpreter.protected org.mozilla.javascript.ScriptableObjectcreateGlobalObject(org.mozilla.javascript.Context ctx) Creates the global object.protected voiddefineGlobalWrapperClass(org.mozilla.javascript.Scriptable global) Defines the class for the global object.voiddispose()ForRhinoInterpreterthis method flushes the Rhino caches to avoid memory leaks.This method evaluates a piece of ECMAScript.This method evaluates a piece of ECMAScript.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.ContextFactoryReturns the ContextFactory for this interpreter.protected org.mozilla.javascript.ScriptableObjectThis 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.String[]Returns the content types of the scripting languages this interpreter handles.Returns the window object for this interpreter.protected voidinit(URL documentURL, ImportInfo imports) voidProvides a way to the user to specify a locale which override the default one.voidBy default Rhino has no output method in its language.
-
Field Details
-
SOURCE_NAME_SVG
-
BIND_NAME_WINDOW
Name of the "window" object when referenced by scripts- See Also:
-
contexts
Context vector, to make sure we are not setting the security context too many times -
window
The window object. -
globalObject
protected org.mozilla.javascript.ScriptableObject globalObjectThe global object. -
compiledScripts
List of cached compiled scripts. -
wrapFactory
protected org.mozilla.javascript.WrapFactory wrapFactoryFactory for Java wrapper objects. -
classShutter
protected org.mozilla.javascript.ClassShutter classShutterClass shutter. -
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 securityControllerThe SecurityController implementation for Batik, which ensures scripts have access to the server they were downloaded from -
contextFactory
protected org.mozilla.javascript.ContextFactory contextFactoryFactory object for creating Contexts. -
defaultContext
protected org.mozilla.javascript.Context defaultContextDefault Context for scripts. This is used only for efficiency reasons.
-
-
Constructor Details
-
RhinoInterpreter
Build aInterpreterfor ECMAScript using Rhino.- Parameters:
documentURL- the URL for the document which references- See Also:
-
RhinoInterpreter
Build aInterpreterfor ECMAScript using Rhino.- Parameters:
documentURL- the URL for the document which referencesimports- the set of Java classes/packages to import into the scripting enviornment.- See Also:
-
-
Method Details
-
init
-
getMimeTypes
Returns the content types of the scripting languages this interpreter handles.- Specified by:
getMimeTypesin interfaceInterpreter
-
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
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
This method evaluates a piece of ECMAScript.- Specified by:
evaluatein interfaceInterpreter- Parameters:
scriptreader- ajava.io.Readeron 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
This method evaluates a piece of ECMAScript.- Specified by:
evaluatein interfaceInterpreter- Parameters:
scriptReader- ajava.io.Readeron the piece of scriptdescription- 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
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:
evaluatein interfaceInterpreter- 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()ForRhinoInterpreterthis method flushes the Rhino caches to avoid memory leaks.- Specified by:
disposein interfaceInterpreter
-
bindObject
This method registers a particular JavaObjectin the environment of the interpreter.- Specified by:
bindObjectin interfaceInterpreter- Parameters:
name- the name of the script object to createobject- the Java object
-
setOut
By default Rhino has no output method in its language. That's why this method does nothing.- Specified by:
setOutin interfaceInterpreter- Parameters:
out- the new outWriter.
-
getLocale
Returns the current locale or null if the locale currently used is the default one.- Specified by:
getLocalein interfaceLocalizable
-
setLocale
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:
setLocalein interfaceLocalizable- Parameters:
locale- The locale to set.
-
formatMessage
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:
formatMessagein interfaceLocalizable- 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.
-