1 | /**
|
---|
2 | * Javascript2.java
|
---|
3 | * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
|
---|
4 | *
|
---|
5 | * This program is free software: you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 | package org.expeditee.actions;
|
---|
20 |
|
---|
21 | import javax.script.Invocable;
|
---|
22 |
|
---|
23 | import org.expeditee.gui.Frame;
|
---|
24 | import org.expeditee.gui.MessageBay;
|
---|
25 | import org.expeditee.items.Item;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Javascript parser.
|
---|
29 | * Works differently to the other Javascript class in that it
|
---|
30 | * parses a frame as a whole rather than parsing individual text items as separate statements
|
---|
31 | *
|
---|
32 | * @author jts21
|
---|
33 | */
|
---|
34 | public class Javascript2 extends ScriptBase {
|
---|
35 |
|
---|
36 | protected void init() {
|
---|
37 | ERROR_FRAMESET = "JavascriptErrors";
|
---|
38 | scriptEngine = scriptEngineManager.getEngineByMimeType("application/javascript");
|
---|
39 | scriptEngine.put("invocable", (Invocable) scriptEngine);
|
---|
40 | }
|
---|
41 |
|
---|
42 | public static void printJSFrame(Item item) {
|
---|
43 | if(item.getChild() == null) {
|
---|
44 | // if the user clicked on the action without an item on their cursor
|
---|
45 | if(item.hasAction()) {
|
---|
46 | boolean isThis = false;
|
---|
47 | for(String s : item.getAction()) {
|
---|
48 | if(s.equalsIgnoreCase("printJSFrame")) {
|
---|
49 | isThis = true;
|
---|
50 | break;
|
---|
51 | }
|
---|
52 | }
|
---|
53 | if(isThis) {
|
---|
54 | System.out.println(new Javascript2(item.getParentOrCurrentFrame(), true));
|
---|
55 | return;
|
---|
56 | }
|
---|
57 | }
|
---|
58 | MessageBay.warningMessage("Requires either an item with a link to a frame, or no item (will run the current frame)");
|
---|
59 | } else {
|
---|
60 | System.out.println(new Javascript2(item.getChild(), true));
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | public static void runJSFrame(Item item) throws Exception {
|
---|
65 | if(item.getChild() == null) {
|
---|
66 | // if the user clicked on the action without an item on their cursor
|
---|
67 | if(item.hasAction()) {
|
---|
68 | boolean isThis = false;
|
---|
69 | for(String s : item.getAction()) {
|
---|
70 | if(s.equalsIgnoreCase("runJSFrame")) {
|
---|
71 | isThis = true;
|
---|
72 | break;
|
---|
73 | }
|
---|
74 | }
|
---|
75 | if(isThis) {
|
---|
76 | Javascript2.runFrameFollow(item.getParentOrCurrentFrame());
|
---|
77 | return;
|
---|
78 | }
|
---|
79 | }
|
---|
80 | MessageBay.warningMessage("Requires either an item with a link to a frame, or no item (will run the current frame)");
|
---|
81 | } else {
|
---|
82 | Javascript2.runFrameFollow(item.getChild());
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 |
|
---|
87 | private static synchronized void runFrameFollow(Frame frame) throws Exception {
|
---|
88 | Javascript2 js = new Javascript2(frame, true);
|
---|
89 | js.runFrame(frame,true);
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | private Javascript2(Frame frame, boolean followLinks) {
|
---|
94 | super(frame,followLinks);
|
---|
95 | }
|
---|
96 |
|
---|
97 | }
|
---|