8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.javafx.application;
27
28 import java.io.File;
29 import java.lang.reflect.Method;
30 import java.net.URI;
31 import java.security.AccessController;
32 import java.security.PrivilegedActionException;
33 import java.security.PrivilegedExceptionAction;
34 import javafx.application.Application;
35 import netscape.javascript.JSObject;
36
37
38 public abstract class HostServicesDelegate {
39
40 private static Method getInstanceMeth = null;
41
42 public static HostServicesDelegate getInstance(final Application app) {
43 // Call into the deploy code to get the delegate class
44 HostServicesDelegate instance = null;
45 try {
46 instance = AccessController.doPrivileged(
47 (PrivilegedExceptionAction<HostServicesDelegate>) () -> {
153 // dump stack for debug purpose
154 e.printStackTrace();
155 }
156 return "";
157 }
158
159 @Override public String getDocumentBase() {
160 // If the application was launched in standalone mode,
161 // this method returns the URI of the current directory.
162 return toURIString(System.getProperty("user.dir"));
163 }
164
165 static final String[] browsers = {"google-chrome", "firefox", "opera",
166 "konqueror", "mozilla"};
167
168 @Override
169 public void showDocument(final String uri) {
170 String osName = System.getProperty("os.name");
171 try {
172 if (osName.startsWith("Mac OS")) {
173 Class.forName("com.apple.eio.FileManager").getDeclaredMethod(
174 "openURL", new Class[]{String.class}).invoke(null,
175 new Object[]{uri});
176 } else if (osName.startsWith("Windows")) {
177 Runtime.getRuntime().exec(
178 "rundll32 url.dll,FileProtocolHandler " + uri);
179 } else { //assume Unix or Linux
180 String browser = null;
181 for (String b : browsers) {
182 if (browser == null && Runtime.getRuntime().exec(
183 new String[]{"which", b}).getInputStream().read() != -1) {
184 Runtime.getRuntime().exec(new String[]{browser = b, uri});
185 }
186 }
187 if (browser == null) {
188 throw new Exception("No web browser found");
189 }
190 }
191 } catch (Exception e) {
192 // should not happen
193 // dump stack for debug purpose
194 e.printStackTrace();
195 }
|
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.javafx.application;
27
28 import java.awt.Desktop;
29 import java.io.File;
30 import java.lang.reflect.Method;
31 import java.net.URI;
32 import java.security.AccessController;
33 import java.security.PrivilegedActionException;
34 import java.security.PrivilegedExceptionAction;
35 import javafx.application.Application;
36 import netscape.javascript.JSObject;
37
38
39 public abstract class HostServicesDelegate {
40
41 private static Method getInstanceMeth = null;
42
43 public static HostServicesDelegate getInstance(final Application app) {
44 // Call into the deploy code to get the delegate class
45 HostServicesDelegate instance = null;
46 try {
47 instance = AccessController.doPrivileged(
48 (PrivilegedExceptionAction<HostServicesDelegate>) () -> {
154 // dump stack for debug purpose
155 e.printStackTrace();
156 }
157 return "";
158 }
159
160 @Override public String getDocumentBase() {
161 // If the application was launched in standalone mode,
162 // this method returns the URI of the current directory.
163 return toURIString(System.getProperty("user.dir"));
164 }
165
166 static final String[] browsers = {"google-chrome", "firefox", "opera",
167 "konqueror", "mozilla"};
168
169 @Override
170 public void showDocument(final String uri) {
171 String osName = System.getProperty("os.name");
172 try {
173 if (osName.startsWith("Mac OS")) {
174 Desktop.getDesktop().browse(URI.create(uri));
175 } else if (osName.startsWith("Windows")) {
176 Runtime.getRuntime().exec(
177 "rundll32 url.dll,FileProtocolHandler " + uri);
178 } else { //assume Unix or Linux
179 String browser = null;
180 for (String b : browsers) {
181 if (browser == null && Runtime.getRuntime().exec(
182 new String[]{"which", b}).getInputStream().read() != -1) {
183 Runtime.getRuntime().exec(new String[]{browser = b, uri});
184 }
185 }
186 if (browser == null) {
187 throw new Exception("No web browser found");
188 }
189 }
190 } catch (Exception e) {
191 // should not happen
192 // dump stack for debug purpose
193 e.printStackTrace();
194 }
|