Paren fix for Ubu 10.04 build (and fdo#58417 ?)
[LibreOffice.git] / rhino / rhino1_5R5.patch
blob5b10c320d0150286de74b0b672cfd6d2767709b1
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,24 @@
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 + </and>
120 + </condition>
121 + <path id="macPath" location="${java.home}/../Classes/classes.jar"/>
122 + <!-- rhino.jar from OpenJDK breaks build -->
123 + <path id="nonMacPath">
124 + <fileset dir="${java.home}/">
125 + <include name="jre/lib/*.jar"/>
126 + <include name="lib/*.jar"/>
127 + <exclude name="jre/lib/rhino.jar"/>
128 + <exclude name="lib/rhino.jar"/>
129 + </fileset>
130 + </path>
131 + <path id="my.bootstrap.classpath" refID="${boot_refID}"/>
133 <target name="properties">
134 <property name="nest" value=".."/>
135 <property name="build.dir" value="./build"/>
136 @@ -20,46 +38,10 @@
137 <!-- Download source from Sun's site, unzip it, remove
138 the files we don't need, and change the package
140 - <get src="http://java.sun.com/products/jfc/tsc/articles/treetable2/downloads/src.zip" dest="${nest}/${build.dir}/swingExSrc.zip"/>
141 - <unzip src="${nest}/${build.dir}/swingExSrc.zip" dest="${src.debugger}"/>
142 + <unzip src="../../../../../download/swingExSrc.zip" dest="${src.debugger}"/>
143 <delete file="${src.debugger}/FileSystemModel2.java" />
144 <delete file="${src.debugger}/MergeSort.java" />
145 <delete file="${src.debugger}/TreeTableExample2.java" />
146 - <replace file="${src.debugger}/AbstractCellEditor.java">
147 - <replacetoken>import java.awt.Component;</replacetoken>
148 - <replacevalue>
149 - package org.mozilla.javascript.tools.debugger;
150 - import java.awt.Component;
151 - </replacevalue>
152 - </replace>
153 - <replace file="${src.debugger}/AbstractTreeTableModel.java">
154 - <replacetoken>import javax.swing.tree.*;</replacetoken>
155 - <replacevalue>
156 - package org.mozilla.javascript.tools.debugger;
157 - import javax.swing.tree.*;
158 - </replacevalue>
159 - </replace>
160 - <replace file="${src.debugger}/JTreeTable.java">
161 - <replacetoken>import javax.swing.*;</replacetoken>
162 - <replacevalue>
163 - package org.mozilla.javascript.tools.debugger;
164 - import javax.swing.*;
165 - </replacevalue>
166 - </replace>
167 - <replace file="${src.debugger}/TreeTableModel.java">
168 - <replacetoken>import javax.swing.tree.TreeModel;</replacetoken>
169 - <replacevalue>
170 - package org.mozilla.javascript.tools.debugger;
171 - import javax.swing.tree.TreeModel;
172 - </replacevalue>
173 - </replace>
174 - <replace file="${src.debugger}/TreeTableModelAdapter.java">
175 - <replacetoken>import javax.swing.JTree;</replacetoken>
176 - <replacevalue>
177 - package org.mozilla.javascript.tools.debugger;
178 - import javax.swing.JTree;
179 - </replacevalue>
180 - </replace>
181 </target>
183 <target name="compile" depends="properties,get-swing-ex">
184 @@ -68,6 +50,7 @@
185 includes="org/**/*.java"
186 deprecation="on"
187 debug="${debug}">
188 + <compilerarg value="-Xbootclasspath:${toString:my.bootstrap.classpath}"/>
189 </javac>
190 <copy todir="${nest}/${classes}">
191 <fileset dir="." includes="org/**/*.properties" />
192 --- misc/rhino1_5R5/toolsrc/org/mozilla/javascript/tools/debugger/Main.java 2004-03-25 21:54:34.000000000 +0100
193 +++ misc/build/rhino1_5R5/toolsrc/org/mozilla/javascript/tools/debugger/Main.java 2009-01-17 20:44:22.000000000 +0100
194 @@ -470,15 +470,21 @@
195 case KeyEvent.VK_BACK_SPACE:
196 case KeyEvent.VK_ENTER:
197 case KeyEvent.VK_DELETE:
198 + if (w.isEditable() == false) {
199 e.consume();
201 break;
204 public void keyTyped(KeyEvent e) {
205 + if (w.isEditable() == false) {
206 e.consume();
209 public void keyReleased(KeyEvent e) {
210 + if (w.isEditable() == false) {
211 e.consume();
216 @@ -879,7 +885,7 @@
220 -class FileWindow extends JInternalFrame implements ActionListener {
221 +class FileWindow extends JInternalFrame implements ActionListener, DocumentListener {
223 Main db;
224 SourceInfo sourceInfo;
225 @@ -888,15 +894,16 @@
226 JScrollPane p;
227 int currentPos;
228 JLabel statusBar;
229 + boolean isModified = false;
231 public void actionPerformed(ActionEvent e) {
232 String cmd = e.getActionCommand();
233 if (cmd.equals("Cut")) {
234 - // textArea.cut();
235 + textArea.cut();
236 } else if (cmd.equals("Copy")) {
237 textArea.copy();
238 } else if (cmd.equals("Paste")) {
239 - // textArea.paste();
240 + textArea.paste();
244 @@ -910,17 +917,73 @@
247 void load() {
248 - Scriptable scope = db.getScope();
249 + //Scriptable scope = db.getScope();
250 + Scriptable scope = db.officeScripts.getScriptScope( getUrl() );
251 + if ( scope == null )
253 + scope = db.getScope();
255 if (scope == null) {
256 MessageDialogWrapper.showMessageDialog(db, "Can't load scripts: no scope available", "Run", JOptionPane.ERROR_MESSAGE);
257 } else {
258 String url = getUrl();
259 if (url != null) {
260 - new Thread(new LoadFile(db,scope,url)).start();
261 + new Thread(new LoadFile(db,scope, url, new StringReader(textArea.getText()))).start();
266 + void save() {
267 + if (getUrl() != null) {
268 + OutputStream os = null;
269 + try {
270 + if ( getUrl().startsWith("vnd.sun.star") )
272 + URL scriptUrl = db.officeScripts.getScriptUrl( getUrl() );
273 + if ( scriptUrl == null )
275 + throw new IOException("Can't optain stream for " + getUrl() );
277 + os = scriptUrl.openConnection().getOutputStream();
279 + else
281 + os = new FileOutputStream( getUrl() );
283 + String s = textArea.getText();
284 + os.write(s.getBytes(), 0, s.length());
286 + this.isModified = false;
288 + catch (IOException ioe) {
289 + JOptionPane.showMessageDialog(this,
290 + "Error saving file: " + ioe.getMessage(),
291 + "Error", JOptionPane.ERROR_MESSAGE);
293 + finally
295 + if ( os != null )
297 + try
299 + os.close();
300 + os = null;
302 + catch( IOException ioe )
304 + System.err.println("Error closing stream: " + ioe.getMessage() );
305 + ioe.printStackTrace();
312 + public boolean isEditable() {
313 + return db.isSourceEditingEnabled();
317 public int getPosition(int line) {
318 int result = -1;
319 try {
320 @@ -953,7 +1016,7 @@
321 fileHeader.repaint();
325 + public Main getDB() { return db; }
326 FileWindow(Main db, SourceInfo sourceInfo) {
327 super(SourceInfo.getShortName(sourceInfo.getUrl()),
328 true, true, true, true);
329 @@ -972,6 +1035,14 @@
330 pack();
331 updateText();
332 textArea.select(0);
333 + addInternalFrameListener( new InternalFrameAdapter() {
334 + public void internalFrameClosed(InternalFrameEvent e) {
335 + // clean up scriptItems and sourceNames hashes
336 + getDB().removeScript( getUrl() );
337 + // remove scripts for officeScripts
338 + getDB().officeScripts.deleteScript( getUrl() );
340 + } );
343 private void updateToolTip() {
344 @@ -990,7 +1061,10 @@
345 void updateText() {
346 String newText = sourceInfo.getSource();
347 if (!textArea.getText().equals(newText)) {
348 + textArea.getDocument().removeDocumentListener(this);
349 textArea.setText(newText);
350 + this.isModified = false;
351 + textArea.getDocument().addDocumentListener(this);
352 int pos = 0;
353 if (currentPos != -1) {
354 pos = currentPos;
355 @@ -1001,6 +1075,31 @@
356 fileHeader.repaint();
359 + /* Implementation of DocumentListener interface */
360 + public void insertUpdate(DocumentEvent e) {
361 + doChanged(e);
364 + public void removeUpdate(DocumentEvent e) {
365 + doChanged(e);
368 + public void changedUpdate(DocumentEvent e) {
369 + doChanged(e);
372 + public void doChanged(DocumentEvent e) {
373 + this.isModified = true;
376 + public boolean isModified() {
377 + return this.isModified;
380 + public String getText() {
381 + return textArea.getText();
384 void setPosition(int pos) {
385 textArea.select(pos);
386 currentPos = pos;
387 @@ -1618,7 +1717,7 @@
388 if (line != -1) {
389 db.currentWindow = w;
391 - db.menubar.addFile(url);
392 + // db.menubar.addFile(url);
393 w.setVisible(true);
394 if (activate) {
395 try {
396 @@ -1752,8 +1851,10 @@
397 Menubar(Main db) {
398 super();
399 this.db = db;
400 - String[] fileItems = {"Open...", "Run...", "", "Exit"};
401 - String[] fileCmds = {"Open", "Load", "", "Exit"};
402 + // String[] fileItems = {"Open...", "Run...", "", "Exit"};
403 + // String[] fileCmds = {"Open", "Load", "", "Exit"};
404 + String[] fileItems = {"Run", "Save", "", "Exit"};
405 + String[] fileCmds = {"Run", "Save", "", "Exit"};
406 char[] fileShortCuts = {'0', 'N', '\0', 'X'};
407 int[] fileAccelerators = {KeyEvent.VK_O,
408 KeyEvent.VK_N,
409 @@ -1795,6 +1896,9 @@
410 KeyStroke k = KeyStroke.getKeyStroke(fileAccelerators[i], Event.CTRL_MASK);
411 item.setAccelerator(k);
413 + if (fileItems[i].equals("Save")) {
414 + saveItem = item;
418 for (int i = 0; i < editItems.length; ++i) {
419 @@ -1849,9 +1953,9 @@
420 item.addActionListener(this);
421 windowMenu.add(item = new JMenuItem("Tile", 'T'));
422 item.addActionListener(this);
423 - windowMenu.addSeparator();
424 - windowMenu.add(item = new JMenuItem("Console", 'C'));
425 - item.addActionListener(this);
426 +// windowMenu.addSeparator();
427 +// windowMenu.add(item = new JMenuItem("Console", 'C'));
428 +// item.addActionListener(this);
429 add(windowMenu);
432 @@ -1925,11 +2029,16 @@
433 item.addActionListener(this);
436 + public void setSaveEnabled(boolean state) {
437 + saveItem.setEnabled(state);
440 Main db;
441 JMenu windowMenu;
442 JCheckBoxMenuItem breakOnExceptions;
443 JCheckBoxMenuItem breakOnEnter;
444 JCheckBoxMenuItem breakOnReturn;
445 + JMenuItem saveItem;
448 class EnterInterrupt implements Runnable {
449 @@ -1942,6 +2051,13 @@
450 public void run() {
451 JMenu menu = db.getJMenuBar().getMenu(0);
452 //menu.getItem(0).setEnabled(false); // File->Load
454 + // disable Edit menu Cut, Copy, Paste items
455 + menu = db.getJMenuBar().getMenu(1);
456 + for (int i = 0; i < 3; i++) {
457 + menu.getItem(i).setEnabled(false);
460 menu = db.getJMenuBar().getMenu(2);
461 menu.getItem(0).setEnabled(false); // Debug->Break
462 int count = menu.getItemCount();
463 @@ -1954,6 +2070,10 @@
464 b = true;
466 db.toolBar.setEnabled(true);
468 + // set flag to disable source editing
469 + db.setSourceEditingEnabled(false);
471 // raise the debugger window
472 db.toFront();
474 @@ -1967,6 +2087,13 @@
475 public void run() {
476 JMenu menu = db.getJMenuBar().getMenu(0);
477 menu.getItem(0).setEnabled(true); // File->Load
479 + // enable Edit menu items
480 + menu = db.getJMenuBar().getMenu(1);
481 + for (int i = 0; i < 3; i++) {
482 + menu.getItem(i).setEnabled(true);
485 menu = db.getJMenuBar().getMenu(2);
486 menu.getItem(0).setEnabled(true); // Debug->Break
487 int count = menu.getItemCount() - 1;
488 @@ -1980,6 +2107,10 @@
489 db.toolBar.getComponent(ci).setEnabled(b);
490 b = false;
493 + // set flag to enable source editing
494 + db.setSourceEditingEnabled(true);
496 //db.console.consoleTextArea.requestFocus();
499 @@ -1988,17 +2119,24 @@
501 String fileName;
502 Main db;
503 + Reader reader = null;
504 OpenFile(Main db, String fileName)
506 this.fileName = fileName;
507 this.db = db;
509 + OpenFile(Main db, String fileName, Reader reader) {
510 + this(db, fileName);
511 + this.reader = reader;
513 public void run() {
514 Context cx = Context.enter();
515 ContextData contextData = ContextData.get(cx);
516 contextData.breakNextLine = true;
517 try {
518 - cx.compileReader(new FileReader(fileName), fileName, 1, null);
519 + cx.compileReader(
520 + reader == null ? new FileReader(fileName) : reader,
521 + fileName, 1, null);
522 } catch (Exception exc) {
523 String msg = exc.getMessage();
524 if (exc instanceof EcmaError) {
525 @@ -2019,29 +2157,79 @@
526 Scriptable scope;
527 String fileName;
528 Main db;
529 + Reader reader = null;
530 + Object result = null;
531 + Exception exception = null;
532 + int lineNum = -1;
533 + boolean sfExecute = false;
535 LoadFile(Main db, Scriptable scope, String fileName) {
536 this.scope = scope;
537 this.fileName = fileName;
538 this.db = db;
541 + LoadFile(Main db, Scriptable scope, String fileName, Reader reader) {
542 + this(db, scope, fileName);
543 + this.reader = reader;
545 + LoadFile(Main db, Scriptable scope, String fileName, Reader reader, boolean sfExecute ) {
546 + this(db, scope, fileName);
547 + this.reader = reader;
548 + this.sfExecute = sfExecute;
551 public void run() {
552 + if ( db.officeScripts.isScriptRunning( fileName ) )
553 + {
554 + exception = new Exception("The script is already executing");
555 + if ( !sfExecute ) {
556 + MessageDialogWrapper.showMessageDialog(db,
557 + "Script already executing",
558 + "Run",
559 + JOptionPane.ERROR_MESSAGE);
561 + return;
562 + }
563 + db.officeScripts.setScriptRunning( fileName, true );
564 Context cx = Context.enter();
565 ContextData contextData = ContextData.get(cx);
566 + if ( sfExecute )
568 + contextData.breakNextLine = false;
570 + else
572 contextData.breakNextLine = true;
574 + /*
575 + FileWindow w = (FileWindow)db.getSelectedFrame();
576 + if ( sfExecute )
578 + db.swingInvoke(new SetFilePosition(db, w, -1 ) );
579 + }*/
580 try {
581 - cx.evaluateReader(scope, new FileReader(fileName),
582 + result = cx.evaluateReader(scope,
583 + reader == null ? new FileReader(fileName) : reader,
584 fileName, 1, null);
585 } catch (Exception exc) {
586 + exception = exc;
587 String msg = exc.getMessage();
588 if (exc instanceof EcmaError) {
589 EcmaError err = (EcmaError)exc;
590 msg = err.getSourceName() + ", line " + err.getLineNumber() + ": " + msg;
593 + int lineNum = err.getLineNumber() ;
594 + //db.swingInvoke(new SetFilePosition(db, w, lineNum ) );
595 + if ( !sfExecute ) {
596 MessageDialogWrapper.showMessageDialog(db,
597 msg,
598 "Run",
599 JOptionPane.ERROR_MESSAGE);
602 } finally {
603 + db.officeScripts.setScriptRunning( fileName, false );
604 cx.exit();
607 @@ -2416,13 +2604,13 @@
608 super.setVisible(b);
609 if (b) {
610 // this needs to be done after the window is visible
611 - console.consoleTextArea.requestFocus();
612 + // console.consoleTextArea.requestFocus();
613 context.split.setDividerLocation(0.5);
614 try {
615 - console.setMaximum(true);
616 - console.setSelected(true);
617 - console.show();
618 - console.consoleTextArea.requestFocus();
619 + // console.setMaximum(true);
620 + // console.setSelected(true);
621 + // console.show();
622 + // console.consoleTextArea.requestFocus();
623 } catch (Exception exc) {
626 @@ -2449,35 +2637,6 @@
628 Hashtable functionNames = new Hashtable();
630 - ScriptItem getScriptItem(DebuggableScript fnOrScript) {
631 - ScriptItem item = (ScriptItem)scriptItems.get(fnOrScript);
632 - if (item == null) {
633 - String url = getNormilizedUrl(fnOrScript);
634 - SourceInfo si = (SourceInfo)sourceNames.get(url);
635 - if (si == null) {
636 - if (!fnOrScript.isGeneratedScript()) {
637 - // Not eval or Function, try to load it from URL
638 - String source = null;
639 - try {
640 - InputStream is = openSource(url);
641 - try { source = readSource(is); }
642 - finally { is.close(); }
643 - } catch (IOException ex) {
644 - System.err.println
645 - ("Failed to load source from "+url+": "+ ex);
647 - if (source != null) {
648 - si = registerSource(url, source);
652 - if (si != null) {
653 - item = registerScript(si, fnOrScript);
656 - return item;
659 /* Debugger Interface */
661 public void handleCompilationDone(Context cx, DebuggableScript fnOrScript,
662 @@ -2490,7 +2649,7 @@
664 String getNormilizedUrl(DebuggableScript fnOrScript) {
665 String url = fnOrScript.getSourceName();
666 - if (url == null) { url = "<stdin>"; }
667 + if (url == null) { url = "document"; }
668 else {
669 // Not to produce window for eval from different lines,
670 // strip line numbers, i.e. replace all #[0-9]+\(eval\) by (eval)
671 @@ -2601,7 +2760,7 @@
672 if (si == null) {
673 si = new SourceInfo(sourceUrl, source);
674 sourceNames.put(sourceUrl, si);
675 - } else {
676 + } else if (!source.equals(si.getSource())) {
677 si.setSource(source);
680 @@ -2762,7 +2921,7 @@
681 desk = new JDesktopPane();
682 desk.setPreferredSize(new Dimension(600, 300));
683 desk.setMinimumSize(new Dimension(150, 50));
684 - desk.add(console = new JSInternalConsole("JavaScript Console"));
685 + // desk.add(console = new JSInternalConsole("JavaScript Console"));
686 context = new ContextWindow(this);
687 context.setPreferredSize(new Dimension(600, 120));
688 context.setMinimumSize(new Dimension(50, 50));
689 @@ -2871,7 +3030,7 @@
690 FrameHelper frame = contextData.getFrame(frameIndex);
691 String sourceName = frame.getUrl();
692 if (sourceName == null || sourceName.equals("<stdin>")) {
693 - console.show();
694 + // console.show();
695 helper.reset();
696 return;
698 @@ -2895,6 +3054,19 @@
699 int dispatcherIsWaiting = 0;
700 Context currentContext = null;
702 + // Flag used to establish whether source code editing is allowed in
703 + // the debugger, switched on and off depending on whether a debug session
704 + // is active
705 + boolean sourceEditingEnabled = true;
707 + public boolean isSourceEditingEnabled() {
708 + return sourceEditingEnabled;
711 + void setSourceEditingEnabled(boolean b) {
712 + sourceEditingEnabled = b;
715 Context getCurrentContext() {
716 return currentContext;
718 @@ -3028,14 +3200,14 @@
719 swingInvoke(CreateFileWindow.action(this, si, line));
721 } else {
722 - if (console.isVisible()) {
723 + /* if (console.isVisible()) {
724 final JSInternalConsole finalConsole = console;
725 swingInvoke(new Runnable() {
726 public void run() {
727 finalConsole.show();
731 + } */
733 swingInvoke(new EnterInterrupt(this, cx));
734 swingInvoke(new UpdateContext(this, cx));
735 @@ -3217,6 +3389,14 @@
736 fileName)).start();
739 + } else if (cmd.equals("Run")) {
740 + FileWindow w = (FileWindow)getSelectedFrame();
741 + if (w != null)
742 + w.load();
743 + } else if (cmd.equals("Save")) {
744 + FileWindow w = (FileWindow)getSelectedFrame();
745 + if (w != null)
746 + w.save();
747 } else if (cmd.equals("More Windows...")) {
748 MoreWindows dlg = new MoreWindows(this, fileWindows,
749 "Window", "Files");
750 @@ -3509,6 +3689,60 @@
754 + JInternalFrame getFrameForUrl( URL url )
755 + {
756 + JInternalFrame[] frames = desk.getAllFrames();
757 + for (int i = 0; i < frames.length; i++) {
758 + FileWindow w = (FileWindow)frames[i];
759 + if ( url.toString().equals( w.getUrl() ) ) {
760 + return w;
763 + return null;
764 + }
765 + public void highlighLineInSelectedWindow(URL url, int lineNum ){
766 + //FileWindow w = (FileWindow)getFrameForUrl( url );
767 + FileWindow w = (FileWindow)getSelectedFrame();
768 + if (w != null)
770 + if ( lineNum > -1 )
771 + swingInvoke(new SetFilePosition(this, w, lineNum ) );
774 + public Object runSelectedWindow( URL scriptUrl ) throws Exception
776 + Object result = null;
777 + FileWindow w = (FileWindow)getSelectedFrame();
778 + //FileWindow w = (FileWindow)getFrameForUrl( scriptUrl );
779 + w.toFront();
780 + if (w != null)
782 + Scriptable scope = w.db.getScope();
783 + if (scope == null)
785 + MessageDialogWrapper.showMessageDialog(w.db, "Can't load scripts: no scope available", "Run", JOptionPane.ERROR_MESSAGE);
786 + result = null;
787 + }
788 + else
790 + String url = w.getUrl();
791 + Thread executorThread = null;
792 + if (url != null)
794 + LoadFile executor = new LoadFile(w.db,scope, url, new StringReader(w.textArea.getText()), true );
795 + executor.run();
796 + result = executor.result;
797 + if ( executor.exception != null )
799 + throw executor.exception;
804 + return result;
809 // public interface
811 @@ -3604,6 +3838,69 @@
812 return console.getErr();
815 + public void openFile(URL scriptUrl, Scriptable scope, Runnable closeCallback ) {
816 + if (scope == null) {
817 + MessageDialogWrapper.showMessageDialog(this,
818 + "Can't compile scripts: no scope available",
819 + "Open", JOptionPane.ERROR_MESSAGE);
820 + } else {
821 + if (scriptUrl != null) {
822 + try
824 + InputStreamReader reader = new InputStreamReader(scriptUrl.openStream());
825 + String fileName = null;
826 + if ( scriptUrl.getProtocol().startsWith("vnd.sun.star.") )
828 + fileName = scriptUrl.toString();
830 + else
832 + fileName = scriptUrl.getPath();
834 + officeScripts.addScript( fileName, scriptUrl, scope, closeCallback );
835 + //new Thread(new OpenFile(this, scope, fileName, reader )).start();
836 + swingInvoke( new OpenFile(this, fileName, reader ));
838 + catch ( IOException e )
840 + MessageDialogWrapper.showMessageDialog(this,
841 + "Can't open stream for script: " + e.toString(),
842 + "Open", JOptionPane.ERROR_MESSAGE);
846 + split1.setDividerLocation(1.0);
849 + public void openFile(String fileName) {
850 + Scriptable scope = getScope();
851 + if (scope == null) {
852 + MessageDialogWrapper.showMessageDialog(this,
853 + "Can't compile scripts: no scope available",
854 + "Open", JOptionPane.ERROR_MESSAGE);
855 + } else {
856 + if (fileName != null) {
857 + new Thread(new OpenFile(this, fileName)).start();
860 + split1.setDividerLocation(1.0);
863 + public void openStream(InputStream in) {
864 + Scriptable scope = getScope();
865 + if (scope == null) {
866 + MessageDialogWrapper.showMessageDialog(this,
867 + "Can't compile scripts: no scope available",
868 + "Open", JOptionPane.ERROR_MESSAGE);
869 + } else {
870 + if (in != null) {
871 + new Thread(new OpenFile(this, null, new InputStreamReader(in))).start();
874 + split1.setDividerLocation(1.0);
875 + menubar.setSaveEnabled(false);
878 public static void main(String[] args) {
879 try {
880 mainThread = Thread.currentThread();
881 @@ -3635,5 +3932,162 @@
885 + // patched Office specific interface
887 + OfficeScriptInfo officeScripts = new OfficeScriptInfo();
889 + void removeScript( String url )
891 + // Remove the FileWindow from list of open sources
892 + fileWindows.remove( url );
894 + // Remove sourceInfo from sourceNames, ensures that
895 + // breakpoints etc are deleted
896 + synchronized (sourceNames) {
897 + sourceNames.remove( url );
899 + // Removes scriptItems for the script, ensures that a new open ( from openFile )
900 + // will succeed, openFile should open file but fails due to fact that
901 + synchronized ( scriptItems )
902 + {
903 + Iterator iter = scriptItems.entrySet().iterator();
904 + while ( iter.hasNext() )
906 + Map.Entry me = ( Map.Entry )iter.next();
907 + ScriptItem item = (ScriptItem)me.getValue();
908 + SourceInfo si = item.getSourceInfo();
909 + if ( si.getUrl().equals( url ) )
911 + //match
912 + scriptItems.remove( me.getKey() );
913 + break;
917 + officeScripts.deleteScript( url );
921 + ScriptItem getScriptItem(DebuggableScript fnOrScript) {
922 + ScriptItem item = (ScriptItem)scriptItems.get(fnOrScript);
923 + if (item == null) {
924 + String url = getNormilizedUrl(fnOrScript);
925 + SourceInfo si = (SourceInfo)sourceNames.get(url);
926 + if (si == null) {
927 + if (!fnOrScript.isGeneratedScript()) {
928 + // Not eval or Function, try to load it from URL
929 + String source = null;
930 + try {
931 + InputStream is = openSource(url);
932 + try { source = readSource(is); }
933 + finally { is.close(); }
934 + } catch (IOException ex) {
935 + System.err.println
936 + ("Failed to load source from "+url+": "+ ex);
938 + if (source != null) {
939 + si = registerSource(url, source);
943 + if (si != null) {
944 + item = registerScript(si, fnOrScript);
948 + return item;
951 + public void showScriptWindow(URL url ){
952 + String key = url.getPath();
953 + if ( url.getProtocol().startsWith("vnd.sun.star") )
955 + key = url.toString();
957 + FileWindow w = (FileWindow)getFileWindow( key );
958 + if ( w != null )
960 + //w.maximize();
961 + desk.getDesktopManager().deiconifyFrame(w);
962 + desk.getDesktopManager().activateFrame(w);
963 + w.show();
964 + w.toFront();
968 + public void highlighLineInScriptWindow(URL url, int lineNum ){
969 + String key = url.getPath();
970 + if ( url.getProtocol().startsWith("vnd.sun.star") )
972 + key = url.getPath();
974 + FileWindow w = (FileWindow)getFileWindow( key );
975 + if (w != null)
977 + if ( lineNum > -1 )
978 + swingInvoke(new SetFilePosition(this, w, lineNum ) );
981 + public Object runScriptWindow( URL scriptUrl ) throws Exception
983 + String key = scriptUrl.getPath();
984 + if ( scriptUrl.getProtocol().startsWith("vnd.sun.star") )
986 + key = scriptUrl.toString();
988 + FileWindow w = (FileWindow)getFileWindow( key );
989 + Object result = null;
990 + w.toFront();
991 + if (w != null)
993 + //Scriptable scope = w.db.getScope();
994 + Scriptable scope = w.db.officeScripts.getScriptScope( key );
995 + if (scope == null)
997 + MessageDialogWrapper.showMessageDialog(w.db, "Can't load scripts: no scope available", "Run", JOptionPane.ERROR_MESSAGE);
998 + result = null;
999 + }
1000 + else
1002 + String url = w.getUrl();
1003 + Thread executorThread = null;
1004 + if (url != null)
1006 + LoadFile executor = new LoadFile(w.db,scope, url, new StringReader(w.textArea.getText()), true );
1007 + executor.run();
1008 + result = executor.result;
1009 + if ( executor.exception != null )
1011 + throw executor.exception;
1016 + return result;
1020 + public boolean isModified( URL url )
1022 + String key = url.getPath();
1023 + if ( url.getProtocol().startsWith("vnd.sun.star") )
1025 + key = url.toString();
1027 + FileWindow w = (FileWindow)getFileWindow( key );
1028 + return w.isModified();
1031 + public String getText( URL url )
1033 + String key = url.toString();
1034 + if ( url.getProtocol().startsWith("vnd.sun.star") )
1036 + key = url.toString();
1038 + FileWindow w = (FileWindow)getFileWindow( key );
1039 + return w.getText();
1044 --- misc/rhino1_5R5/toolsrc/org/mozilla/javascript/tools/shell/JavaPolicySecurity.java Thu Mar 25 21:54:34 2004
1045 +++ misc/build/rhino1_5R5/toolsrc/org/mozilla/javascript/tools/shell/JavaPolicySecurity.java Fri Mar 28 17:24:23 2008
1046 @@ -36,6 +36,7 @@
1047 package org.mozilla.javascript.tools.shell;
1049 import java.security.*;
1050 +import java.security.cert.Certificate;
1051 import java.net.MalformedURLException;
1052 import java.net.URL;
1053 import java.util.Hashtable;
1054 @@ -124,7 +125,7 @@
1056 public JavaPolicySecurity() {
1057 // To trigger error on jdk-1.1 with lazy load
1058 - new CodeSource(null, null);
1059 + new CodeSource(null, (Certificate [])null);
1062 protected void callProcessFileSecure(final Context cx,
1063 @@ -167,7 +168,7 @@
1066 private ProtectionDomain getUrlDomain(URL url) {
1067 - CodeSource cs = new CodeSource(url, null);
1068 + CodeSource cs = new CodeSource(url, (Certificate [])null);
1069 PermissionCollection pc = Policy.getPolicy().getPermissions(cs);
1070 return new ProtectionDomain(cs, pc);