Changeset 578
- Timestamp:
- 12/06/13 11:40:01 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Misc.java
r577 r578 1238 1238 private static ScriptEngine se = sem.getEngineByMimeType("application/javascript"); 1239 1239 1240 private static String getScript(Frame frame) throws Exception { 1241 1242 StringBuffer sb = new StringBuffer(); 1243 1244 List<Item> y_ordered_items = (List<Item>)frame.getNonAnnotationItems(true); 1245 XGroupItem toplevel_xgroup = new XGroupItem(frame,y_ordered_items); 1246 1247 // ... following on from Steps 1 and 2 in the Constructor in XGroupItem ... 1248 1249 // Step 3: Reposition any 'out-of-flow' XGroupItems 1250 toplevel_xgroup.repositionOutOfFlowGroups(toplevel_xgroup); 1251 1252 // Step 4: Now add in the remaining (nested) XGroupItems 1253 List<XGroupItem> grouped_item_list = toplevel_xgroup.getGroupedItemList(); 1254 toplevel_xgroup.mapInXGroupItemsRecursive(grouped_item_list); 1255 1256 // Finally, retrieve linear list of all Items, (ordered, Y by X, allowing for overlap, nested-boxing, and arrow flow) 1257 1258 List<Item> overlapping_y_ordered_items = toplevel_xgroup.getYXOverlappingItemList(); 1259 1260 for(Item i : overlapping_y_ordered_items) { 1261 if(i instanceof Text) { 1262 sb.append(((Text)i).getText() + "\n"); 1263 } 1264 } 1265 1266 System.out.println("*****\n" + sb.toString() + "\n*****"); 1267 return sb.toString(); 1240 private static class JSParser { 1241 private List<Frame> seen = new LinkedList<Frame>(); 1242 private StringBuffer sb = new StringBuffer(); 1243 1244 public JSParser(Frame frame, boolean followLinks) throws Exception { 1245 parseScript(frame, followLinks); 1246 } 1247 1248 private void parseScript(Frame frame, boolean followLinks) throws Exception { 1249 1250 if(frame == null) { 1251 return; 1252 } 1253 1254 // make sure we don't get into an infinite loop 1255 // TODO: find a smarter way to do this that allows reusing frames but still stops infinite loops? 1256 seen.add(frame); 1257 1258 // get all items on the frame 1259 List<Item> y_ordered_items = (List<Item>)frame.getItems(); 1260 // remove the title item 1261 y_ordered_items.remove(frame.getTitleItem()); 1262 1263 XGroupItem toplevel_xgroup = new XGroupItem(frame,y_ordered_items); 1264 // ... following on from Steps 1 and 2 in the Constructor in XGroupItem ... 1265 1266 // Step 3: Reposition any 'out-of-flow' XGroupItems 1267 toplevel_xgroup.repositionOutOfFlowGroups(toplevel_xgroup); 1268 1269 // Step 4: Now add in the remaining (nested) XGroupItems 1270 List<XGroupItem> grouped_item_list = toplevel_xgroup.getGroupedItemList(); 1271 toplevel_xgroup.mapInXGroupItemsRecursive(grouped_item_list); 1272 1273 // Finally, retrieve linear list of all Items, (ordered, Y by X, allowing for overlap, nested-boxing, and arrow flow) 1274 List<Item> overlapping_y_ordered_items = toplevel_xgroup.getYXOverlappingItemList(); 1275 1276 // Loop through the items looking for code and links to new frames 1277 for(Item i : overlapping_y_ordered_items) { 1278 if(followLinks && i.hasLink()) { 1279 Frame child = i.getChild(); 1280 if(child != null && !seen.contains(child)) { 1281 this.parseScript(child, true); 1282 } 1283 } 1284 if(i instanceof Text && !i.isAnnotation()) { 1285 sb.append(((Text)i).getText() + "\n"); 1286 } 1287 } 1288 } 1289 1290 public String getScript() { 1291 System.out.println("*****\n" + sb.toString() + "\n*****"); 1292 return sb.toString(); 1293 } 1268 1294 } 1269 1295 1270 1296 public static void runJSFrame(Frame frame) throws Exception { 1271 se.eval( getScript(frame));1297 se.eval(new JSParser(frame, true).getScript()); 1272 1298 } 1273 1299 … … 1310 1336 FrameIO.SaveFrame(frame); 1311 1337 } else { 1312 se.eval(getScript(frame));1338 runJSFrame(frame); 1313 1339 } 1314 1340 }
Note:
See TracChangeset
for help on using the changeset viewer.