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
;
22 import java
.io
.InputStream
;
23 import java
.io
.IOException
;
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
,
40 OOScriptDebugger debugger
;
43 if (language
.equals("JavaScript")) {
44 debugger
= new OORhinoDebugger();
45 } else if (language
.equals("BeanShell")) {
46 debugger
= new OOBeanShellDebugger();
51 if (uri
.startsWith(FILE_URL_PREFIX
)) {
52 uri
= URLDecoder
.decode(uri
);
53 String s
= uri
.substring(FILE_URL_PREFIX
.length());
57 if (f
.isDirectory()) {
58 if (!filename
.equals("")) {
59 path
= new File(f
, filename
).getAbsolutePath();
62 path
= f
.getAbsolutePath();
66 debugger
.go(xsctxt
, path
);
68 if (!uri
.endsWith("/")) {
72 String script
= uri
+ filename
;
76 is
= PathUtils
.getScriptFileStream(
77 script
, xsctxt
.getComponentContext());
80 debugger
.go(xsctxt
, is
);
82 } catch (IOException ioe
) {
83 System
.out
.println("Error loading script: " + script
);