/** * Javascript2.java * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package org.expeditee.actions; import javax.script.Invocable; import org.expeditee.gui.Frame; import org.expeditee.gui.MessageBay; import org.expeditee.items.Item; /** * Javascript parser. * Works differently to the other Javascript class in that it * parses a frame as a whole rather than parsing individual text items as separate statements * * @author jts21 */ public class Javascript2 extends ScriptBase { protected void init() { ERROR_FRAMESET = "JavascriptErrors"; scriptEngine = scriptEngineManager.getEngineByMimeType("application/javascript"); scriptEngine.put("invocable", (Invocable) scriptEngine); } public static void printJSFrame(Item item) { if(item.getChild() == null) { // if the user clicked on the action without an item on their cursor if(item.hasAction()) { boolean isThis = false; for(String s : item.getAction()) { if(s.equalsIgnoreCase("printJSFrame")) { isThis = true; break; } } if(isThis) { System.out.println(new Javascript2(item.getParentOrCurrentFrame(), true)); return; } } MessageBay.warningMessage("Requires either an item with a link to a frame, or no item (will run the current frame)"); } else { System.out.println(new Javascript2(item.getChild(), true)); } } public static void runJSFrame(Item item) throws Exception { if(item.getChild() == null) { // if the user clicked on the action without an item on their cursor if(item.hasAction()) { boolean isThis = false; for(String s : item.getAction()) { if(s.equalsIgnoreCase("runJSFrame")) { isThis = true; break; } } if(isThis) { Javascript2.runFrameFollow(item.getParentOrCurrentFrame()); return; } } MessageBay.warningMessage("Requires either an item with a link to a frame, or no item (will run the current frame)"); } else { Javascript2.runFrameFollow(item.getChild()); } } private static synchronized void runFrameFollow(Frame frame) throws Exception { Javascript2 js = new Javascript2(frame, true); js.runFrame(frame,true); } private Javascript2(Frame frame, boolean followLinks) { super(frame,followLinks); } }