Kaydet (Commit) 73ee44c0 authored tarafından Tomas O'Connor's avatar Tomas O'Connor

Changes from code review, BeanShell document scripts can now be edited,

Rhino document scripts cannot.
üst 9b4ee751
import java.io.*; import java.io.File;
import java.net.URL; import java.io.InputStream;
import java.net.URLDecoder; import java.io.IOException;
import drafts.com.sun.star.script.framework.runtime.XScriptContext; import java.net.URL;
import java.net.URLDecoder;
public class DebugRunner {
import com.sun.star.uno.XComponentContext;
private static final String FILE_URL_PREFIX = import com.sun.star.scripting.runtime.java.PathUtils;
System.getProperty("os.name").startsWith("Windows") == true ? import drafts.com.sun.star.script.framework.runtime.XScriptContext;
"file:///" : "file://";
public class DebugRunner {
public void go(final XScriptContext xsctxt, String language, String uri,
String filename) { private static final String FILE_URL_PREFIX =
System.getProperty("os.name").startsWith("Windows") == true ?
OOScriptDebugger debugger; "file:///" : "file://";
InputStream is = null;
String path = ""; public void go(final XScriptContext xsctxt, String language, String uri,
String filename) {
System.out.println("uri: " + uri + ", language: " + language);
OOScriptDebugger debugger;
if (language.equals("Rhino")) String path = "";
debugger = new OORhinoDebugger();
else if (language.equals("BeanShell")) if (language.equals("Rhino")) {
debugger = new OOBeanShellDebugger(); debugger = new OORhinoDebugger();
else }
return; else if (language.equals("BeanShell")) {
debugger = new OOBeanShellDebugger();
if (uri.startsWith(FILE_URL_PREFIX)) { }
uri = URLDecoder.decode(uri); else {
String s = uri.substring(FILE_URL_PREFIX.length()); return;
File f = new File(s); }
if (f.exists()) { if (uri.startsWith(FILE_URL_PREFIX)) {
if (f.isDirectory()) { uri = URLDecoder.decode(uri);
if (!filename.equals("")) { String s = uri.substring(FILE_URL_PREFIX.length());
path = new File(f, filename).getAbsolutePath(); File f = new File(s);
}
} if (f.exists()) {
else { if (f.isDirectory()) {
path = f.getAbsolutePath(); if (!filename.equals("")) {
} path = new File(f, filename).getAbsolutePath();
} }
} }
else if (uri.startsWith("http://")) { else {
try { path = f.getAbsolutePath();
if (!filename.equals("")) }
uri = uri + "/" + filename; }
debugger.go(xsctxt, path);
URL url = new URL(uri); }
is = url.openStream(); else {
} if (!uri.endsWith("/")) {
catch (IOException ioe) { uri += "/";
ioe.printStackTrace(); }
}
} String script = uri + filename;
System.out.println("path: " + path); InputStream is;
debugger.go(xsctxt, path);
} try {
} is = PathUtils.getScriptFileStream(
script, xsctxt.getComponentContext());
if (is != null) {
debugger.go(xsctxt, is);
}
}
catch (IOException ioe) {
System.out.println("Error loading script: " + script);
}
}
}
}
import drafts.com.sun.star.script.framework.runtime.XScriptContext;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import org.mozilla.javascript.*; import java.io.InputStream;
import org.mozilla.javascript.tools.debugger.*;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ImporterTopLevel;
import org.mozilla.javascript.tools.debugger.Main;
import org.mozilla.javascript.tools.debugger.ScopeProvider;
import drafts.com.sun.star.script.framework.runtime.XScriptContext;
public class OORhinoDebugger implements OOScriptDebugger { public class OORhinoDebugger implements OOScriptDebugger {
// This code is based on the main method of the Rhino Debugger Main class
// We pass in the XScriptContext in the global scope for script execution
public void go(final XScriptContext xsctxt, String filename) { public void go(final XScriptContext xsctxt, String filename) {
try { try {
final Main sdb = new Main("Rhino JavaScript Debugger"); final Main sdb = new Main("Rhino JavaScript Debugger");
...@@ -31,12 +39,17 @@ public class OORhinoDebugger implements OOScriptDebugger { ...@@ -31,12 +39,17 @@ public class OORhinoDebugger implements OOScriptDebugger {
return scope; return scope;
} }
}); });
// This is the method we've added to open a file when starting
// the Rhino debugger
sdb.openFile(filename); sdb.openFile(filename);
} catch (Exception exc) { } catch (Exception exc) {
exc.printStackTrace(); exc.printStackTrace();
} }
} }
public void go(final XScriptContext xsctxt, InputStream in) {
}
static void swingInvoke(Runnable f) { static void swingInvoke(Runnable f) {
if (SwingUtilities.isEventDispatchThread()) { if (SwingUtilities.isEventDispatchThread()) {
f.run(); f.run();
......
import java.io.InputStream;
import drafts.com.sun.star.script.framework.runtime.XScriptContext; import drafts.com.sun.star.script.framework.runtime.XScriptContext;
public interface OOScriptDebugger { public interface OOScriptDebugger {
public void go(XScriptContext ctxt, String filename); public void go(XScriptContext ctxt, String filename);
public void go(XScriptContext ctxt, InputStream in);
} }
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
<script language="Java"> <script language="Java">
<locale lang="en"> <locale lang="en">
<displayname value="asdf.doMethod" /> <displayname value="Scripting Framework Debugger" />
<description>asdf.doMethod</description> <description>Script that starts debuggers for Rhino and BeanShell
</description>
</locale> </locale>
<logicalname value="DebugRunner.Debug" /> <logicalname value="_$DebugRunner.Debug" />
<functionname value="DebugRunner.go" /> <functionname value="DebugRunner.go" />
<languagedepprops> <languagedepprops>
<prop name="classpath" value="debugger.jar"/> <prop name="classpath" value="debugger.jar"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment