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; 6 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; 10 11 public class DebugRunner { 12 13 private static final String FILE_URL_PREFIX = 14 System.getProperty("os.name").startsWith("Windows") == true ? 15 "file:///" : "file://"; 16 17 public void go(final XScriptContext xsctxt, String language, String uri, 18 String filename) { 19 20 OOScriptDebugger debugger; 21 String path = ""; 22 23 if (language.equals("JavaScript")) { 24 debugger = new OORhinoDebugger(); 25 } 26 else if (language.equals("BeanShell")) { 27 debugger = new OOBeanShellDebugger(); 28 } 29 else { 30 return; 31 } 32 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); 37 38 if (f.exists()) { 39 if (f.isDirectory()) { 40 if (!filename.equals("")) { 41 path = new File(f, filename).getAbsolutePath(); 42 } 43 } 44 else { 45 path = f.getAbsolutePath(); 46 } 47 } 48 debugger.go(xsctxt, path); 49 } 50 else { 51 if (!uri.endsWith("/")) { 52 uri += "/"; 53 } 54 55 String script = uri + filename; 56 InputStream is; 57 58 try { 59 is = PathUtils.getScriptFileStream( 60 script, xsctxt.getComponentContext()); 61 62 if (is != null) { 63 debugger.go(xsctxt, is); 64 } 65 } 66 catch (IOException ioe) { 67 System.out.println("Error loading script: " + script); 68 } 69 } 70 } 71 } 72