bump product version to 5.0.4.1
[LibreOffice.git] / scripting / examples / java / debugger / DebugRunner.java
bloba3b4869fe93e07720b180d2a1e522f891beefc7e
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.provider.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();
45 } else if (language.equals("BeanShell")) {
46 debugger = new OOBeanShellDebugger();
47 } else {
48 return;
51 if (uri.startsWith(FILE_URL_PREFIX)) {
52 uri = URLDecoder.decode(uri);
53 String s = uri.substring(FILE_URL_PREFIX.length());
54 File f = new File(s);
56 if (f.exists()) {
57 if (f.isDirectory()) {
58 if (!filename.equals("")) {
59 path = new File(f, filename).getAbsolutePath();
61 } else {
62 path = f.getAbsolutePath();
66 debugger.go(xsctxt, path);
67 } else {
68 if (!uri.endsWith("/")) {
69 uri += "/";
72 String script = uri + filename;
73 InputStream is;
75 try {
76 is = PathUtils.getScriptFileStream(
77 script, xsctxt.getComponentContext());
79 if (is != null) {
80 debugger.go(xsctxt, is);
82 } catch (IOException ioe) {
83 System.out.println("Error loading script: " + script);