merge the formfield patch from ooo-build
[ooovba.git] / scripting / examples / java / debugger / DebugRunner.java
blob4430b970b6bf542ff05d9ed3134efe7a1ccda737
1 import java.io.File;
2 import java.io.InputStream;
3 import java.io.IOException;
4 import java.net.URL;
5 import java.net.URLDecoder;
7 import com.sun.star.uno.XComponentContext;
8 import com.sun.star.script.framework.provider.PathUtils;
9 import com.sun.star.script.framework.runtime.XScriptContext;
11 public class DebugRunner {
13 private static final String FILE_URL_PREFIX =
14 System.getProperty("os.name").startsWith("Windows") == true ?
15 "file:///" : "file://";
17 public void go(final XScriptContext xsctxt, String language, String uri,
18 String filename) {
20 OOScriptDebugger debugger;
21 String path = "";
23 if (language.equals("JavaScript")) {
24 debugger = new OORhinoDebugger();
26 else if (language.equals("BeanShell")) {
27 debugger = new OOBeanShellDebugger();
29 else {
30 return;
33 if (uri.startsWith(FILE_URL_PREFIX)) {
34 uri = URLDecoder.decode(uri);
35 String s = uri.substring(FILE_URL_PREFIX.length());
36 File f = new File(s);
38 if (f.exists()) {
39 if (f.isDirectory()) {
40 if (!filename.equals("")) {
41 path = new File(f, filename).getAbsolutePath();
44 else {
45 path = f.getAbsolutePath();
48 debugger.go(xsctxt, path);
50 else {
51 if (!uri.endsWith("/")) {
52 uri += "/";
55 String script = uri + filename;
56 InputStream is;
58 try {
59 is = PathUtils.getScriptFileStream(
60 script, xsctxt.getComponentContext());
62 if (is != null) {
63 debugger.go(xsctxt, is);
66 catch (IOException ioe) {
67 System.out.println("Error loading script: " + script);