org.faceless.pdf2
Class JSEngine

java.lang.Object
  extended by org.faceless.pdf2.JSEngine

public final class JSEngine
extends Object

This class handles the running of all JavaScript on the document. It's not required to read or edit the JavaScript actions the make up a document - it's used to actually run those actions, typically by an interactive application like the PDFViewer. This requires a JavaScript implementation, which means at least Java 1.6 or the use of Mozilla Rhino.

Although this class is public there is generally no reason to call the methods in this class directly, unless you're implementing your own PDF Viewer or modifying the JavaScript security permissions.

Since:
2.9

Constructor Summary
JSEngine(JSCoreMethods core)
          Create a new JSEngine
 
Method Summary
static void checkPermission(Permission permission)
          Check whether the specified permission will be accepted by the JavaScript engine.
static SecurityManager getFallbackSecurityManager()
          Return a SecurityManager which will allow any operation unless it originates from a JavaScript method, in which case it is processed like the default SecurityManager.
 String getImplementationDescription()
          Get a human-readable description of the JavaScript implementation
 String getImplementationType()
          Get a the type of JavaScript implementation
 boolean runEvent(JSEvent event)
          Raise and run the specified JavaScript event.
static void setPermissions(Permissions perms)
           Set the Permissions that are allowed for any JavaScript run by the PDF Library.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSEngine

public JSEngine(JSCoreMethods core)
Create a new JSEngine

Parameters:
core - the JSCoreMethods implementation to use
Method Detail

getImplementationDescription

public String getImplementationDescription()
Get a human-readable description of the JavaScript implementation


getImplementationType

public String getImplementationType()
Get a the type of JavaScript implementation


setPermissions

public static void setPermissions(Permissions perms)

Set the Permissions that are allowed for any JavaScript run by the PDF Library. The JavaScript engines supplied with most Java 1.6 implementations and Mozilla Rhino both allow access to the full Java class hierarchy, so it's important to place restrictions on what actions JavaScript in a PDF can perform, otherwise simply setting a field value with the PDF library could run any Java commands on your system.

By default, a minimal set of the permissions are in place. Passing a new set of permissions into this method will override them, and unless unless the setSecurityManager RuntimePermission is set the new Permissions will be unalterable.

Enforcing Permissions in Java requires a SecurityManager to be set, which is not always the case. If no SecurityManager is in place at the time the JavaScript is run, the SecurityManager returned by getFallbackSecurityManager() is installed.

Since:
2.11.4

checkPermission

public static void checkPermission(Permission permission)
Check whether the specified permission will be accepted by the JavaScript engine. Returns if it is, otherwise throws a SecurityException.

Since:
2.11.4

runEvent

public boolean runEvent(JSEvent event)
Raise and run the specified JavaScript event. Synchronized - JavaScript in PDF is single threaded

Returns:
the value of event.rc - true if the event succeeded, false otherwise

getFallbackSecurityManager

public static SecurityManager getFallbackSecurityManager()
Return a SecurityManager which will allow any operation unless it originates from a JavaScript method, in which case it is processed like the default SecurityManager. The SecurityManager returned by this method is installed automatically if no SecurityManager is present when a JavaScript operation is run. The source for this method is as follows:
  return new SecurityManager() {
    public void checkPermission(Permission p) {
      boolean fromjs = false;
      Class[] trace = getClassContext();
      for (int i=0;!fromjs && i1 && cn.startsWith("org.faceless.pdf2.")) return;
        fromjs |= cn.equals("org.mozilla.javascript.ScriptRuntime");
        fromjs |= cn.equals("sun.org.mozilla.javascript.internal.ScriptRuntime");
      }
      if (fromjs) {
        super.checkPermission(p);
      }
    }
  };
 

Since:
2.11.4


Copyright © 2001-2009 Big Faceless Organization