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