update credits
[LibreOffice.git] / scripting / examples / java / debugger / DebugRunner.java
blob4a5ee119608ea29e4ae9a0aa1c9dd4c4b27aad7d
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package org.libreoffice.example.java_scripts;
21 import java.io.File;
22 import java.io.InputStream;
23 import java.io.IOException;
24 import java.net.URL;
25 import java.net.URLDecoder;
27 import com.sun.star.uno.XComponentContext;
28 import com.sun.star.script.framework.provider.PathUtils;
29 import com.sun.star.script.framework.runtime.XScriptContext;
31 public class DebugRunner {
33 private static final String FILE_URL_PREFIX =
34 System.getProperty("os.name").startsWith("Windows") == true ?
35 "file:///" : "file://";
37 public void go(final XScriptContext xsctxt, String language, String uri,
38 String filename) {
40 OOScriptDebugger debugger;
41 String path = "";
43 if (language.equals("JavaScript")) {
44 debugger = new OORhinoDebugger();
46 else if (language.equals("BeanShell")) {
47 debugger = new OOBeanShellDebugger();
49 else {
50 return;
53 if (uri.startsWith(FILE_URL_PREFIX)) {
54 uri = URLDecoder.decode(uri);
55 String s = uri.substring(FILE_URL_PREFIX.length());
56 File f = new File(s);
58 if (f.exists()) {
59 if (f.isDirectory()) {
60 if (!filename.equals("")) {
61 path = new File(f, filename).getAbsolutePath();
64 else {
65 path = f.getAbsolutePath();
68 debugger.go(xsctxt, path);
70 else {
71 if (!uri.endsWith("/")) {
72 uri += "/";
75 String script = uri + filename;
76 InputStream is;
78 try {
79 is = PathUtils.getScriptFileStream(
80 script, xsctxt.getComponentContext());
82 if (is != null) {
83 debugger.go(xsctxt, is);
86 catch (IOException ioe) {
87 System.out.println("Error loading script: " + script);