1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
|
--- misc/rhino1_5R5/src/org/mozilla/javascript/DefiningClassLoader.java Thu Mar 25 21:54:34 2004
+++ misc/build/rhino1_5R5/src/org/mozilla/javascript/DefiningClassLoader.java Fri Mar 28 17:24:23 2008
@@ -38,6 +38,7 @@
package org.mozilla.javascript;
import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
/**
* Load generated classes.
@@ -48,11 +49,34 @@
implements GeneratedClassLoader
{
public DefiningClassLoader() {
- this.parentLoader = getClass().getClassLoader();
+ init(getClass().getClassLoader());
}
public DefiningClassLoader(ClassLoader parentLoader) {
+
+ init(parentLoader);
+ }
+
+ private void init(ClassLoader parentLoader) {
+
this.parentLoader = parentLoader;
+
+ this.contextLoader = null;
+ if (method_getContextClassLoader != null) {
+ try {
+ this.contextLoader = (ClassLoader)
+ method_getContextClassLoader.invoke(
+ Thread.currentThread(),
+ ScriptRuntime.emptyArgs);
+ } catch (IllegalAccessException ex) {
+ } catch (InvocationTargetException ex) {
+ } catch (SecurityException ex) {
+ }
+ if (this.contextLoader == this.parentLoader) {
+ this.contextLoader = null;
+ }
+ }
+
}
public Class defineClass(String name, byte[] data) {
@@ -68,10 +92,20 @@
{
Class cl = findLoadedClass(name);
if (cl == null) {
- if (parentLoader != null) {
- cl = parentLoader.loadClass(name);
+ // First try parent class loader and if that does not work, try
+ // contextLoader, but that will be null if
+ // Thread.getContextClassLoader() == parentLoader
+ // or on JDK 1.1 due to lack Thread.getContextClassLoader().
+ // To avoid catching and rethrowing ClassNotFoundException
+ // in this cases, use try/catch check only if contextLoader != null.
+ if (contextLoader == null) {
+ cl = loadFromParent(name);
} else {
- cl = findSystemClass(name);
+ try {
+ cl = loadFromParent(name);
+ } catch (ClassNotFoundException ex) {
+ cl = contextLoader.loadClass(name);
+ }
}
}
if (resolve) {
@@ -80,5 +114,37 @@
return cl;
}
+ private Class loadFromParent(String name)
+ throws ClassNotFoundException
+ {
+ if (parentLoader != null) {
+ return parentLoader.loadClass(name);
+ } else {
+ return findSystemClass(name);
+ }
+
+ }
+
private ClassLoader parentLoader;
+
+ private ClassLoader contextLoader;
+
+ // We'd like to use "Thread.getContextClassLoader", but
+ // that's only available on Java2.
+ private static Method method_getContextClassLoader;
+
+ static {
+ try {
+ // Don't use "Thread.class": that performs the lookup
+ // in the class initializer, which doesn't allow us to
+ // catch possible security exceptions.
+ Class threadClass = Class.forName("java.lang.Thread");
+ method_getContextClassLoader =
+ threadClass.getDeclaredMethod("getContextClassLoader",
+ new Class[0]);
+ } catch (ClassNotFoundException e) {
+ } catch (NoSuchMethodException e) {
+ } catch (SecurityException e) {
+ }
+ }
}
--- misc/rhino1_5R5/toolsrc/build.xml 2004-03-25 21:54:34.000000000 +0100
+++ misc/build/rhino1_5R5/toolsrc/build.xml 2009-01-17 20:46:44.000000000 +0100
@@ -6,6 +6,24 @@
-->
<project name="toolsrc" default="compile" basedir=".">
+ <condition property="boot_refID" value="macPath" else="nonMacPath">
+ <and>
+ <os family="mac"/>
+ <os family="unix"/>
+ </and>
+ </condition>
+ <path id="macPath" location="${java.home}/../Classes/classes.jar"/>
+ <!-- rhino.jar from OpenJDK breaks build -->
+ <path id="nonMacPath">
+ <fileset dir="${java.home}/">
+ <include name="jre/lib/*.jar"/>
+ <include name="lib/*.jar"/>
+ <exclude name="jre/lib/rhino.jar"/>
+ <exclude name="lib/rhino.jar"/>
+ </fileset>
+ </path>
+ <path id="my.bootstrap.classpath" refID="${boot_refID}"/>
+
<target name="properties">
<property name="nest" value=".."/>
<property name="build.dir" value="./build"/>
@@ -20,46 +38,10 @@
<!-- Download source from Sun's site, unzip it, remove
the files we don't need, and change the package
-->
- <get src="http://java.sun.com/products/jfc/tsc/articles/treetable2/downloads/src.zip" dest="${nest}/${build.dir}/swingExSrc.zip"/>
- <unzip src="${nest}/${build.dir}/swingExSrc.zip" dest="${src.debugger}"/>
+ <unzip src="../../../../../download/swingExSrc.zip" dest="${src.debugger}"/>
<delete file="${src.debugger}/FileSystemModel2.java" />
<delete file="${src.debugger}/MergeSort.java" />
<delete file="${src.debugger}/TreeTableExample2.java" />
- <replace file="${src.debugger}/AbstractCellEditor.java">
- <replacetoken>import java.awt.Component;</replacetoken>
- <replacevalue>
- package org.mozilla.javascript.tools.debugger;
- import java.awt.Component;
- </replacevalue>
- </replace>
- <replace file="${src.debugger}/AbstractTreeTableModel.java">
- <replacetoken>import javax.swing.tree.*;</replacetoken>
- <replacevalue>
- package org.mozilla.javascript.tools.debugger;
- import javax.swing.tree.*;
- </replacevalue>
- </replace>
- <replace file="${src.debugger}/JTreeTable.java">
- <replacetoken>import javax.swing.*;</replacetoken>
- <replacevalue>
- package org.mozilla.javascript.tools.debugger;
- import javax.swing.*;
- </replacevalue>
- </replace>
- <replace file="${src.debugger}/TreeTableModel.java">
- <replacetoken>import javax.swing.tree.TreeModel;</replacetoken>
- <replacevalue>
- package org.mozilla.javascript.tools.debugger;
- import javax.swing.tree.TreeModel;
- </replacevalue>
- </replace>
- <replace file="${src.debugger}/TreeTableModelAdapter.java">
- <replacetoken>import javax.swing.JTree;</replacetoken>
- <replacevalue>
- package org.mozilla.javascript.tools.debugger;
- import javax.swing.JTree;
- </replacevalue>
- </replace>
</target>
<target name="compile" depends="properties,get-swing-ex">
@@ -68,6 +50,7 @@
includes="org/**/*.java"
deprecation="on"
debug="${debug}">
+ <compilerarg value="-Xbootclasspath:${toString:my.bootstrap.classpath}"/>
</javac>
<copy todir="${nest}/${classes}">
<fileset dir="." includes="org/**/*.properties" />
--- misc/rhino1_5R5/toolsrc/org/mozilla/javascript/tools/debugger/Main.java 2004-03-25 21:54:34.000000000 +0100
+++ misc/build/rhino1_5R5/toolsrc/org/mozilla/javascript/tools/debugger/Main.java 2009-01-17 20:44:22.000000000 +0100
@@ -470,15 +470,21 @@
case KeyEvent.VK_BACK_SPACE:
case KeyEvent.VK_ENTER:
case KeyEvent.VK_DELETE:
+ if (w.isEditable() == false) {
e.consume();
+ }
break;
}
}
public void keyTyped(KeyEvent e) {
+ if (w.isEditable() == false) {
e.consume();
+ }
}
public void keyReleased(KeyEvent e) {
+ if (w.isEditable() == false) {
e.consume();
+ }
}
}
@@ -879,7 +885,7 @@
}
};
-class FileWindow extends JInternalFrame implements ActionListener {
+class FileWindow extends JInternalFrame implements ActionListener, DocumentListener {
Main db;
SourceInfo sourceInfo;
@@ -888,15 +894,16 @@
JScrollPane p;
int currentPos;
JLabel statusBar;
+ boolean isModified = false;
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if (cmd.equals("Cut")) {
- // textArea.cut();
+ textArea.cut();
} else if (cmd.equals("Copy")) {
textArea.copy();
} else if (cmd.equals("Paste")) {
- // textArea.paste();
+ textArea.paste();
}
}
@@ -910,17 +917,73 @@
}
void load() {
- Scriptable scope = db.getScope();
+ //Scriptable scope = db.getScope();
+ Scriptable scope = db.officeScripts.getScriptScope( getUrl() );
+ if ( scope == null )
+ {
+ scope = db.getScope();
+ }
if (scope == null) {
MessageDialogWrapper.showMessageDialog(db, "Can't load scripts: no scope available", "Run", JOptionPane.ERROR_MESSAGE);
} else {
String url = getUrl();
if (url != null) {
- new Thread(new LoadFile(db,scope,url)).start();
+ new Thread(new LoadFile(db,scope, url, new StringReader(textArea.getText()))).start();
}
}
}
+ void save() {
+ if (getUrl() != null) {
+ OutputStream os = null;
+ try {
+ if ( getUrl().startsWith("vnd.sun.star") )
+ {
+ URL scriptUrl = db.officeScripts.getScriptUrl( getUrl() );
+ if ( scriptUrl == null )
+ {
+ throw new IOException("Can't optain stream for " + getUrl() );
+ }
+ os = scriptUrl.openConnection().getOutputStream();
+ }
+ else
+ {
+ os = new FileOutputStream( getUrl() );
+ }
+ String s = textArea.getText();
+ os.write(s.getBytes(), 0, s.length());
+
+ this.isModified = false;
+ }
+ catch (IOException ioe) {
+ JOptionPane.showMessageDialog(this,
+ "Error saving file: " + ioe.getMessage(),
+ "Error", JOptionPane.ERROR_MESSAGE);
+ }
+ finally
+ {
+ if ( os != null )
+ {
+ try
+ {
+ os.close();
+ os = null;
+ }
+ catch( IOException ioe )
+ {
+ System.err.println("Error closing stream: " + ioe.getMessage() );
+ ioe.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+ public boolean isEditable() {
+ return db.isSourceEditingEnabled();
+ }
+
+
public int getPosition(int line) {
int result = -1;
try {
@@ -953,7 +1016,7 @@
fileHeader.repaint();
}
}
-
+ public Main getDB() { return db; }
FileWindow(Main db, SourceInfo sourceInfo) {
super(SourceInfo.getShortName(sourceInfo.getUrl()),
true, true, true, true);
@@ -972,6 +1035,14 @@
pack();
updateText();
textArea.select(0);
+ addInternalFrameListener( new InternalFrameAdapter() {
+ public void internalFrameClosed(InternalFrameEvent e) {
+ // clean up scriptItems and sourceNames hashes
+ getDB().removeScript( getUrl() );
+ // remove scripts for officeScripts
+ getDB().officeScripts.deleteScript( getUrl() );
+ }
+ } );
}
private void updateToolTip() {
@@ -990,7 +1061,10 @@
void updateText() {
String newText = sourceInfo.getSource();
if (!textArea.getText().equals(newText)) {
+ textArea.getDocument().removeDocumentListener(this);
textArea.setText(newText);
+ this.isModified = false;
+ textArea.getDocument().addDocumentListener(this);
int pos = 0;
if (currentPos != -1) {
pos = currentPos;
@@ -1001,6 +1075,31 @@
fileHeader.repaint();
}
+ /* Implementation of DocumentListener interface */
+ public void insertUpdate(DocumentEvent e) {
+ doChanged(e);
+ }
+
+ public void removeUpdate(DocumentEvent e) {
+ doChanged(e);
+ }
+
+ public void changedUpdate(DocumentEvent e) {
+ doChanged(e);
+ }
+
+ public void doChanged(DocumentEvent e) {
+ this.isModified = true;
+ }
+
+ public boolean isModified() {
+ return this.isModified;
+ }
+
+ public String getText() {
+ return textArea.getText();
+ }
+
void setPosition(int pos) {
textArea.select(pos);
currentPos = pos;
@@ -1618,7 +1717,7 @@
if (line != -1) {
db.currentWindow = w;
}
- db.menubar.addFile(url);
+ // db.menubar.addFile(url);
w.setVisible(true);
if (activate) {
try {
@@ -1752,8 +1851,10 @@
Menubar(Main db) {
super();
this.db = db;
- String[] fileItems = {"Open...", "Run...", "", "Exit"};
- String[] fileCmds = {"Open", "Load", "", "Exit"};
+ // String[] fileItems = {"Open...", "Run...", "", "Exit"};
+ // String[] fileCmds = {"Open", "Load", "", "Exit"};
+ String[] fileItems = {"Run", "Save", "", "Exit"};
+ String[] fileCmds = {"Run", "Save", "", "Exit"};
char[] fileShortCuts = {'0', 'N', '\0', 'X'};
int[] fileAccelerators = {KeyEvent.VK_O,
KeyEvent.VK_N,
@@ -1795,6 +1896,9 @@
KeyStroke k = KeyStroke.getKeyStroke(fileAccelerators[i], Event.CTRL_MASK);
item.setAccelerator(k);
}
+ if (fileItems[i].equals("Save")) {
+ saveItem = item;
+ }
}
}
for (int i = 0; i < editItems.length; ++i) {
@@ -1849,9 +1953,9 @@
item.addActionListener(this);
windowMenu.add(item = new JMenuItem("Tile", 'T'));
item.addActionListener(this);
- windowMenu.addSeparator();
- windowMenu.add(item = new JMenuItem("Console", 'C'));
- item.addActionListener(this);
+// windowMenu.addSeparator();
+// windowMenu.add(item = new JMenuItem("Console", 'C'));
+// item.addActionListener(this);
add(windowMenu);
}
@@ -1925,11 +2029,16 @@
item.addActionListener(this);
}
+ public void setSaveEnabled(boolean state) {
+ saveItem.setEnabled(state);
+ }
+
Main db;
JMenu windowMenu;
JCheckBoxMenuItem breakOnExceptions;
JCheckBoxMenuItem breakOnEnter;
JCheckBoxMenuItem breakOnReturn;
+ JMenuItem saveItem;
};
class EnterInterrupt implements Runnable {
@@ -1942,6 +2051,13 @@
public void run() {
JMenu menu = db.getJMenuBar().getMenu(0);
//menu.getItem(0).setEnabled(false); // File->Load
+
+ // disable Edit menu Cut, Copy, Paste items
+ menu = db.getJMenuBar().getMenu(1);
+ for (int i = 0; i < 3; i++) {
+ menu.getItem(i).setEnabled(false);
+ }
+
menu = db.getJMenuBar().getMenu(2);
menu.getItem(0).setEnabled(false); // Debug->Break
int count = menu.getItemCount();
@@ -1954,6 +2070,10 @@
b = true;
}
db.toolBar.setEnabled(true);
+
+ // set flag to disable source editing
+ db.setSourceEditingEnabled(false);
+
// raise the debugger window
db.toFront();
}
@@ -1967,6 +2087,13 @@
public void run() {
JMenu menu = db.getJMenuBar().getMenu(0);
menu.getItem(0).setEnabled(true); // File->Load
+
+ // enable Edit menu items
+ menu = db.getJMenuBar().getMenu(1);
+ for (int i = 0; i < 3; i++) {
+ menu.getItem(i).setEnabled(true);
+ }
+
menu = db.getJMenuBar().getMenu(2);
menu.getItem(0).setEnabled(true); // Debug->Break
int count = menu.getItemCount() - 1;
@@ -1980,6 +2107,10 @@
db.toolBar.getComponent(ci).setEnabled(b);
b = false;
}
+
+ // set flag to enable source editing
+ db.setSourceEditingEnabled(true);
+
//db.console.consoleTextArea.requestFocus();
}
};
@@ -1988,17 +2119,24 @@
{
String fileName;
Main db;
+ Reader reader = null;
OpenFile(Main db, String fileName)
{
this.fileName = fileName;
this.db = db;
}
+ OpenFile(Main db, String fileName, Reader reader) {
+ this(db, fileName);
+ this.reader = reader;
+ }
public void run() {
Context cx = Context.enter();
ContextData contextData = ContextData.get(cx);
contextData.breakNextLine = true;
try {
- cx.compileReader(new FileReader(fileName), fileName, 1, null);
+ cx.compileReader(
+ reader == null ? new FileReader(fileName) : reader,
+ fileName, 1, null);
} catch (Exception exc) {
String msg = exc.getMessage();
if (exc instanceof EcmaError) {
@@ -2019,29 +2157,79 @@
Scriptable scope;
String fileName;
Main db;
+ Reader reader = null;
+ Object result = null;
+ Exception exception = null;
+ int lineNum = -1;
+ boolean sfExecute = false;
+
LoadFile(Main db, Scriptable scope, String fileName) {
this.scope = scope;
this.fileName = fileName;
this.db = db;
}
+
+ LoadFile(Main db, Scriptable scope, String fileName, Reader reader) {
+ this(db, scope, fileName);
+ this.reader = reader;
+ }
+ LoadFile(Main db, Scriptable scope, String fileName, Reader reader, boolean sfExecute ) {
+ this(db, scope, fileName);
+ this.reader = reader;
+ this.sfExecute = sfExecute;
+ }
+
public void run() {
+ if ( db.officeScripts.isScriptRunning( fileName ) )
+ {
+ exception = new Exception("The script is already executing");
+ if ( !sfExecute ) {
+ MessageDialogWrapper.showMessageDialog(db,
+ "Script already executing",
+ "Run",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ return;
+ }
+ db.officeScripts.setScriptRunning( fileName, true );
Context cx = Context.enter();
ContextData contextData = ContextData.get(cx);
+ if ( sfExecute )
+ {
+ contextData.breakNextLine = false;
+ }
+ else
+ {
contextData.breakNextLine = true;
+ }
+ /*
+ FileWindow w = (FileWindow)db.getSelectedFrame();
+ if ( sfExecute )
+ {
+ db.swingInvoke(new SetFilePosition(db, w, -1 ) );
+ }*/
try {
- cx.evaluateReader(scope, new FileReader(fileName),
+ result = cx.evaluateReader(scope,
+ reader == null ? new FileReader(fileName) : reader,
fileName, 1, null);
} catch (Exception exc) {
+ exception = exc;
String msg = exc.getMessage();
if (exc instanceof EcmaError) {
EcmaError err = (EcmaError)exc;
msg = err.getSourceName() + ", line " + err.getLineNumber() + ": " + msg;
- }
+
+ int lineNum = err.getLineNumber() ;
+ //db.swingInvoke(new SetFilePosition(db, w, lineNum ) );
+ if ( !sfExecute ) {
MessageDialogWrapper.showMessageDialog(db,
msg,
"Run",
JOptionPane.ERROR_MESSAGE);
+ }
+ }
} finally {
+ db.officeScripts.setScriptRunning( fileName, false );
cx.exit();
}
}
@@ -2416,13 +2604,13 @@
super.setVisible(b);
if (b) {
// this needs to be done after the window is visible
- console.consoleTextArea.requestFocus();
+ // console.consoleTextArea.requestFocus();
context.split.setDividerLocation(0.5);
try {
- console.setMaximum(true);
- console.setSelected(true);
- console.show();
- console.consoleTextArea.requestFocus();
+ // console.setMaximum(true);
+ // console.setSelected(true);
+ // console.show();
+ // console.consoleTextArea.requestFocus();
} catch (Exception exc) {
}
}
@@ -2449,35 +2637,6 @@
Hashtable functionNames = new Hashtable();
- ScriptItem getScriptItem(DebuggableScript fnOrScript) {
- ScriptItem item = (ScriptItem)scriptItems.get(fnOrScript);
- if (item == null) {
- String url = getNormilizedUrl(fnOrScript);
- SourceInfo si = (SourceInfo)sourceNames.get(url);
- if (si == null) {
- if (!fnOrScript.isGeneratedScript()) {
- // Not eval or Function, try to load it from URL
- String source = null;
- try {
- InputStream is = openSource(url);
- try { source = readSource(is); }
- finally { is.close(); }
- } catch (IOException ex) {
- System.err.println
- ("Failed to load source from "+url+": "+ ex);
- }
- if (source != null) {
- si = registerSource(url, source);
- }
- }
- }
- if (si != null) {
- item = registerScript(si, fnOrScript);
- }
- }
- return item;
- }
-
/* Debugger Interface */
public void handleCompilationDone(Context cx, DebuggableScript fnOrScript,
@@ -2490,7 +2649,7 @@
String getNormilizedUrl(DebuggableScript fnOrScript) {
String url = fnOrScript.getSourceName();
- if (url == null) { url = "<stdin>"; }
+ if (url == null) { url = "document"; }
else {
// Not to produce window for eval from different lines,
// strip line numbers, i.e. replace all #[0-9]+\(eval\) by (eval)
@@ -2601,7 +2760,7 @@
if (si == null) {
si = new SourceInfo(sourceUrl, source);
sourceNames.put(sourceUrl, si);
- } else {
+ } else if (!source.equals(si.getSource())) {
si.setSource(source);
}
}
@@ -2762,7 +2921,7 @@
desk = new JDesktopPane();
desk.setPreferredSize(new Dimension(600, 300));
desk.setMinimumSize(new Dimension(150, 50));
- desk.add(console = new JSInternalConsole("JavaScript Console"));
+ // desk.add(console = new JSInternalConsole("JavaScript Console"));
context = new ContextWindow(this);
context.setPreferredSize(new Dimension(600, 120));
context.setMinimumSize(new Dimension(50, 50));
@@ -2871,7 +3030,7 @@
FrameHelper frame = contextData.getFrame(frameIndex);
String sourceName = frame.getUrl();
if (sourceName == null || sourceName.equals("<stdin>")) {
- console.show();
+ // console.show();
helper.reset();
return;
}
@@ -2895,6 +3054,19 @@
int dispatcherIsWaiting = 0;
Context currentContext = null;
+ // Flag used to establish whether source code editing is allowed in
+ // the debugger, switched on and off depending on whether a debug session
+ // is active
+ boolean sourceEditingEnabled = true;
+
+ public boolean isSourceEditingEnabled() {
+ return sourceEditingEnabled;
+ }
+
+ void setSourceEditingEnabled(boolean b) {
+ sourceEditingEnabled = b;
+ }
+
Context getCurrentContext() {
return currentContext;
}
@@ -3028,14 +3200,14 @@
swingInvoke(CreateFileWindow.action(this, si, line));
}
} else {
- if (console.isVisible()) {
+ /* if (console.isVisible()) {
final JSInternalConsole finalConsole = console;
swingInvoke(new Runnable() {
public void run() {
finalConsole.show();
}
});
- }
+ } */
}
swingInvoke(new EnterInterrupt(this, cx));
swingInvoke(new UpdateContext(this, cx));
@@ -3217,6 +3389,14 @@
fileName)).start();
}
}
+ } else if (cmd.equals("Run")) {
+ FileWindow w = (FileWindow)getSelectedFrame();
+ if (w != null)
+ w.load();
+ } else if (cmd.equals("Save")) {
+ FileWindow w = (FileWindow)getSelectedFrame();
+ if (w != null)
+ w.save();
} else if (cmd.equals("More Windows...")) {
MoreWindows dlg = new MoreWindows(this, fileWindows,
"Window", "Files");
@@ -3509,6 +3689,60 @@
}
}
+ JInternalFrame getFrameForUrl( URL url )
+ {
+ JInternalFrame[] frames = desk.getAllFrames();
+ for (int i = 0; i < frames.length; i++) {
+ FileWindow w = (FileWindow)frames[i];
+ if ( url.toString().equals( w.getUrl() ) ) {
+ return w;
+ }
+ }
+ return null;
+ }
+ public void highlighLineInSelectedWindow(URL url, int lineNum ){
+ //FileWindow w = (FileWindow)getFrameForUrl( url );
+ FileWindow w = (FileWindow)getSelectedFrame();
+ if (w != null)
+ {
+ if ( lineNum > -1 )
+ swingInvoke(new SetFilePosition(this, w, lineNum ) );
+ }
+ }
+ public Object runSelectedWindow( URL scriptUrl ) throws Exception
+ {
+ Object result = null;
+ FileWindow w = (FileWindow)getSelectedFrame();
+ //FileWindow w = (FileWindow)getFrameForUrl( scriptUrl );
+ w.toFront();
+ if (w != null)
+ {
+ Scriptable scope = w.db.getScope();
+ if (scope == null)
+ {
+ MessageDialogWrapper.showMessageDialog(w.db, "Can't load scripts: no scope available", "Run", JOptionPane.ERROR_MESSAGE);
+ result = null;
+ }
+ else
+ {
+ String url = w.getUrl();
+ Thread executorThread = null;
+ if (url != null)
+ {
+ LoadFile executor = new LoadFile(w.db,scope, url, new StringReader(w.textArea.getText()), true );
+ executor.run();
+ result = executor.result;
+ if ( executor.exception != null )
+ {
+ throw executor.exception;
+ }
+ }
+ }
+ }
+ return result;
+
+ }
+
//
// public interface
//
@@ -3604,6 +3838,69 @@
return console.getErr();
}
+ public void openFile(URL scriptUrl, Scriptable scope, Runnable closeCallback ) {
+ if (scope == null) {
+ MessageDialogWrapper.showMessageDialog(this,
+ "Can't compile scripts: no scope available",
+ "Open", JOptionPane.ERROR_MESSAGE);
+ } else {
+ if (scriptUrl != null) {
+ try
+ {
+ InputStreamReader reader = new InputStreamReader(scriptUrl.openStream());
+ String fileName = null;
+ if ( scriptUrl.getProtocol().startsWith("vnd.sun.star.") )
+ {
+ fileName = scriptUrl.toString();
+ }
+ else
+ {
+ fileName = scriptUrl.getPath();
+ }
+ officeScripts.addScript( fileName, scriptUrl, scope, closeCallback );
+ //new Thread(new OpenFile(this, scope, fileName, reader )).start();
+ swingInvoke( new OpenFile(this, fileName, reader ));
+ }
+ catch ( IOException e )
+ {
+ MessageDialogWrapper.showMessageDialog(this,
+ "Can't open stream for script: " + e.toString(),
+ "Open", JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ }
+ split1.setDividerLocation(1.0);
+ }
+
+ public void openFile(String fileName) {
+ Scriptable scope = getScope();
+ if (scope == null) {
+ MessageDialogWrapper.showMessageDialog(this,
+ "Can't compile scripts: no scope available",
+ "Open", JOptionPane.ERROR_MESSAGE);
+ } else {
+ if (fileName != null) {
+ new Thread(new OpenFile(this, fileName)).start();
+ }
+ }
+ split1.setDividerLocation(1.0);
+ }
+
+ public void openStream(InputStream in) {
+ Scriptable scope = getScope();
+ if (scope == null) {
+ MessageDialogWrapper.showMessageDialog(this,
+ "Can't compile scripts: no scope available",
+ "Open", JOptionPane.ERROR_MESSAGE);
+ } else {
+ if (in != null) {
+ new Thread(new OpenFile(this, null, new InputStreamReader(in))).start();
+ }
+ }
+ split1.setDividerLocation(1.0);
+ menubar.setSaveEnabled(false);
+ }
+
public static void main(String[] args) {
try {
mainThread = Thread.currentThread();
@@ -3635,5 +3932,162 @@
}
}
+ // patched Office specific interface
+
+ OfficeScriptInfo officeScripts = new OfficeScriptInfo();
+
+ void removeScript( String url )
+ {
+ // Remove the FileWindow from list of open sources
+ fileWindows.remove( url );
+
+ // Remove sourceInfo from sourceNames, ensures that
+ // breakpoints etc are deleted
+ synchronized (sourceNames) {
+ sourceNames.remove( url );
+ }
+ // Removes scriptItems for the script, ensures that a new open ( from openFile )
+ // will succeed, openFile should open file but fails due to fact that
+ synchronized ( scriptItems )
+ {
+ Iterator iter = scriptItems.entrySet().iterator();
+ while ( iter.hasNext() )
+ {
+ Map.Entry me = ( Map.Entry )iter.next();
+ ScriptItem item = (ScriptItem)me.getValue();
+ SourceInfo si = item.getSourceInfo();
+ if ( si.getUrl().equals( url ) )
+ {
+ //match
+ scriptItems.remove( me.getKey() );
+ break;
+ }
+ }
+ }
+ officeScripts.deleteScript( url );
+ }
+
+
+ ScriptItem getScriptItem(DebuggableScript fnOrScript) {
+ ScriptItem item = (ScriptItem)scriptItems.get(fnOrScript);
+ if (item == null) {
+ String url = getNormilizedUrl(fnOrScript);
+ SourceInfo si = (SourceInfo)sourceNames.get(url);
+ if (si == null) {
+ if (!fnOrScript.isGeneratedScript()) {
+ // Not eval or Function, try to load it from URL
+ String source = null;
+ try {
+ InputStream is = openSource(url);
+ try { source = readSource(is); }
+ finally { is.close(); }
+ } catch (IOException ex) {
+ System.err.println
+ ("Failed to load source from "+url+": "+ ex);
+ }
+ if (source != null) {
+ si = registerSource(url, source);
+ }
+ }
+ }
+ if (si != null) {
+ item = registerScript(si, fnOrScript);
+ }
+ }
+
+ return item;
+ }
+
+ public void showScriptWindow(URL url ){
+ String key = url.getPath();
+ if ( url.getProtocol().startsWith("vnd.sun.star") )
+ {
+ key = url.toString();
+ }
+ FileWindow w = (FileWindow)getFileWindow( key );
+ if ( w != null )
+ {
+ //w.maximize();
+ desk.getDesktopManager().deiconifyFrame(w);
+ desk.getDesktopManager().activateFrame(w);
+ w.show();
+ w.toFront();
+ }
+ }
+
+ public void highlighLineInScriptWindow(URL url, int lineNum ){
+ String key = url.getPath();
+ if ( url.getProtocol().startsWith("vnd.sun.star") )
+ {
+ key = url.getPath();
+ }
+ FileWindow w = (FileWindow)getFileWindow( key );
+ if (w != null)
+ {
+ if ( lineNum > -1 )
+ swingInvoke(new SetFilePosition(this, w, lineNum ) );
+ }
+ }
+ public Object runScriptWindow( URL scriptUrl ) throws Exception
+ {
+ String key = scriptUrl.getPath();
+ if ( scriptUrl.getProtocol().startsWith("vnd.sun.star") )
+ {
+ key = scriptUrl.toString();
+ }
+ FileWindow w = (FileWindow)getFileWindow( key );
+ Object result = null;
+ w.toFront();
+ if (w != null)
+ {
+ //Scriptable scope = w.db.getScope();
+ Scriptable scope = w.db.officeScripts.getScriptScope( key );
+ if (scope == null)
+ {
+ MessageDialogWrapper.showMessageDialog(w.db, "Can't load scripts: no scope available", "Run", JOptionPane.ERROR_MESSAGE);
+ result = null;
+ }
+ else
+ {
+ String url = w.getUrl();
+ Thread executorThread = null;
+ if (url != null)
+ {
+ LoadFile executor = new LoadFile(w.db,scope, url, new StringReader(w.textArea.getText()), true );
+ executor.run();
+ result = executor.result;
+ if ( executor.exception != null )
+ {
+ throw executor.exception;
+ }
+ }
+ }
+ }
+ return result;
+
+ }
+
+ public boolean isModified( URL url )
+ {
+ String key = url.getPath();
+ if ( url.getProtocol().startsWith("vnd.sun.star") )
+ {
+ key = url.toString();
+ }
+ FileWindow w = (FileWindow)getFileWindow( key );
+ return w.isModified();
+ }
+
+ public String getText( URL url )
+ {
+ String key = url.toString();
+ if ( url.getProtocol().startsWith("vnd.sun.star") )
+ {
+ key = url.toString();
+ }
+ FileWindow w = (FileWindow)getFileWindow( key );
+ return w.getText();
+ }
+
}
--- misc/rhino1_5R5/toolsrc/org/mozilla/javascript/tools/shell/JavaPolicySecurity.java Thu Mar 25 21:54:34 2004
+++ misc/build/rhino1_5R5/toolsrc/org/mozilla/javascript/tools/shell/JavaPolicySecurity.java Fri Mar 28 17:24:23 2008
@@ -36,6 +36,7 @@
package org.mozilla.javascript.tools.shell;
import java.security.*;
+import java.security.cert.Certificate;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Hashtable;
@@ -124,7 +125,7 @@
public JavaPolicySecurity() {
// To trigger error on jdk-1.1 with lazy load
- new CodeSource(null, null);
+ new CodeSource(null, (Certificate [])null);
}
protected void callProcessFileSecure(final Context cx,
@@ -167,7 +168,7 @@
}
private ProtectionDomain getUrlDomain(URL url) {
- CodeSource cs = new CodeSource(url, null);
+ CodeSource cs = new CodeSource(url, (Certificate [])null);
PermissionCollection pc = Policy.getPolicy().getPermissions(cs);
return new ProtectionDomain(cs, pc);
}
|