|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.faceless.pdf2.JSEngine
public final class JSEngine
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.
| 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 |
|---|
public JSEngine(JSCoreMethods core)
core - the JSCoreMethods implementation to use| Method Detail |
|---|
public String getImplementationDescription()
public String getImplementationType()
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.
public static void checkPermission(Permission permission)
SecurityException.
public boolean runEvent(JSEvent event)
event.rc - true if the event succeeded, false otherwisepublic static SecurityManager getFallbackSecurityManager()
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);
}
}
};
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||