1 /* 2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 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 sun.awt.windows; 27 28 29 import java.awt.Desktop.Action; 30 import java.awt.peer.DesktopPeer; 31 import java.io.File; 32 import java.io.IOException; 33 import java.net.URI; 34 35 36 /** 37 * Concrete implementation of the interface <code>DesktopPeer</code> for 38 * the Windows platform. 39 * 40 * @see DesktopPeer 41 */ 42 final class WDesktopPeer implements DesktopPeer { 43 /* Contants for the operation verbs */ 44 private static String ACTION_OPEN_VERB = "open"; 45 private static String ACTION_EDIT_VERB = "edit"; 46 private static String ACTION_PRINT_VERB = "print"; 47 48 @Override 49 public boolean isSupported(Action action) { 50 // OPEN, EDIT, PRINT, MAIL, BROWSE all supported on windows. 51 return true; 52 } 53 54 @Override 55 public void open(File file) throws IOException { 56 this.ShellExecute(file, ACTION_OPEN_VERB); 57 } 58 59 @Override 60 public void edit(File file) throws IOException { 61 this.ShellExecute(file, ACTION_EDIT_VERB); 62 } 63 64 @Override 65 public void print(File file) throws IOException { 66 this.ShellExecute(file, ACTION_PRINT_VERB); 67 } 68 69 @Override 70 public void mail(URI uri) throws IOException { 71 this.ShellExecute(uri, ACTION_OPEN_VERB); 72 } 73 74 @Override 75 public void browse(URI uri) throws IOException { 76 this.ShellExecute(uri, ACTION_OPEN_VERB); 77 } 78 79 private void ShellExecute(File file, String verb) throws IOException { 80 String errMsg = ShellExecute(file.getAbsolutePath(), verb); 81 if (errMsg != null) { 82 throw new IOException("Failed to " + verb + " " + file + ". Error message: " + errMsg); 83 } 84 } 85 86 private void ShellExecute(URI uri, String verb) throws IOException { 87 String errmsg = ShellExecute(uri.toString(), verb); 88 89 if (errmsg != null) { 90 throw new IOException("Failed to " + verb + " " + uri 91 + ". Error message: " + errmsg); 92 } 93 } 94 95 private static native String ShellExecute(String fileOrUri, String verb); 96 97 }