jdk/src/java.desktop/share/classes/java/awt/Desktop.java
author serb
Wed, 17 Sep 2014 16:14:12 +0400
changeset 26749 b6598aa90114
parent 25859 3317bb8137f4
child 30471 c1568a2416a8
permissions -rw-r--r--
8055326: Fix typos in client-related packages Reviewed-by: prr, azvegint, alexsch Contributed-by: pavel.rappo@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.URISyntaxException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.URI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.AWTPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.HeadlessException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.peer.DesktopPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.awt.HeadlessToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.FilePermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.security.util.SecurityConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * The {@code Desktop} class allows a Java application to launch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * associated applications registered on the native desktop to handle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * a {@link java.net.URI} or a file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p> Supported operations include:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *   <li>launching the user-default browser to show a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *       URI;</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *   <li>launching the user-default mail client with an optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *       {@code mailto} URI;</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *   <li>launching a registered application to open, edit or print a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *       specified file.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <p> This class provides methods corresponding to these
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * operations. The methods look for the associated application
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * registered on the current platform, and launch it to handle a URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * or file. If there is no associated application or the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * application fails to be launched, an exception is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p> An application is registered to a URI or file type; for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * example, the {@code "sxi"} file extension is typically registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * to StarOffice.  The mechanism of registering, accessing, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * launching the associated application is platform-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <p> Each operation is an action type represented by the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * Desktop.Action} class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <p> Note: when some action is invoked and the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * application is executed, it will be executed on the same system as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * the one on which the Java application was launched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * @author Armin Chen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @author George Zhang
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
public class Desktop {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Represents an action type.  Each platform supports a different
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * set of actions.  You may use the {@link Desktop#isSupported}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * method to determine if the given action is supported by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * current platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @see java.awt.Desktop#isSupported(java.awt.Desktop.Action)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static enum Action {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
         * Represents an "open" action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
         * @see Desktop#open(java.io.File)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        OPEN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
         * Represents an "edit" action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
         * @see Desktop#edit(java.io.File)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        EDIT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
         * Represents a "print" action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
         * @see Desktop#print(java.io.File)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        PRINT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         * Represents a "mail" action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
         * @see Desktop#mail()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
         * @see Desktop#mail(java.net.URI)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        MAIL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
         * Represents a "browse" action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
         * @see Desktop#browse(java.net.URI)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        BROWSE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private DesktopPeer peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Suppresses default constructor for noninstantiability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private Desktop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        peer = Toolkit.getDefaultToolkit().createDesktopPeer(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Returns the <code>Desktop</code> instance of the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * browser context.  On some platforms the Desktop API may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * supported; use the {@link #isDesktopSupported} method to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * determine if the current desktop is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @return the Desktop instance of the current browser context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @throws HeadlessException if {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * GraphicsEnvironment#isHeadless()} returns {@code true}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @throws UnsupportedOperationException if this class is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * supported on the current platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @see #isDesktopSupported()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public static synchronized Desktop getDesktop(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (GraphicsEnvironment.isHeadless()) throw new HeadlessException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (!Desktop.isDesktopSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            throw new UnsupportedOperationException("Desktop API is not " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                                    "supported on the current platform");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        sun.awt.AppContext context = sun.awt.AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        Desktop desktop = (Desktop)context.get(Desktop.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (desktop == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            desktop = new Desktop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            context.put(Desktop.class, desktop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return desktop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Tests whether this class is supported on the current platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * If it's supported, use {@link #getDesktop()} to retrieve an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @return <code>true</code> if this class is supported on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *         current platform; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @see #getDesktop()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public static boolean isDesktopSupported(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (defaultToolkit instanceof SunToolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            return ((SunToolkit)defaultToolkit).isDesktopSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Tests whether an action is supported on the current platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * <p>Even when the platform supports an action, a file or URI may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * not have a registered application for the action.  For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * most of the platforms support the {@link Desktop.Action#OPEN}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * action.  But for a specific file, there may not be an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * application registered to open it.  In this case, {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * #isSupported} may return {@code true}, but the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * action method will throw an {@link IOException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @param action the specified {@link Action}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @return <code>true</code> if the specified action is supported on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *         the current platform; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @see Desktop.Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public boolean isSupported(Action action) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return peer.isSupported(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Checks if the file is a valid file and readable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @throws SecurityException If a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *         {@link SecurityManager#checkRead(java.lang.String)} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *         denies read access to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @throws NullPointerException if file is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @throws IllegalArgumentException if file doesn't exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    private static void checkFileValidation(File file){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (file == null) throw new NullPointerException("File must not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if (!file.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            throw new IllegalArgumentException("The file: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                               + file.getPath() + " doesn't exist.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        file.canRead();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Checks if the action type is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @param actionType the action type in question
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @throws UnsupportedOperationException if the specified action type is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *         supported on the current platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    private void checkActionSupport(Action actionType){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (!isSupported(actionType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            throw new UnsupportedOperationException("The " + actionType.name()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                                                    + " action is not supported on the current platform!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *  Calls to the security manager's <code>checkPermission</code> method with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *  an <code>AWTPermission("showWindowWithoutWarningBanner")</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *  permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    private void checkAWTPermission(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            sm.checkPermission(new AWTPermission(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                   "showWindowWithoutWarningBanner"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Launches the associated application to open the file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * <p> If the specified file is a directory, the file manager of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * the current platform is launched to open it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @param file the file to be opened with the associated application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @throws NullPointerException if {@code file} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @throws IllegalArgumentException if the specified file doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @throws UnsupportedOperationException if the current platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * does not support the {@link Desktop.Action#OPEN} action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @throws IOException if the specified file has no associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * application or the associated application fails to be launched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @throws SecurityException if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * {@link java.lang.SecurityManager#checkRead(java.lang.String)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * method denies read access to the file, or it denies the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * <code>AWTPermission("showWindowWithoutWarningBanner")</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * permission, or the calling thread is not allowed to create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @see java.awt.AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public void open(File file) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        checkAWTPermission();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        checkExec();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        checkActionSupport(Action.OPEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        checkFileValidation(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        peer.open(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Launches the associated editor application and opens a file for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param file the file to be opened for editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @throws NullPointerException if the specified file is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @throws IllegalArgumentException if the specified file doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @throws UnsupportedOperationException if the current platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * does not support the {@link Desktop.Action#EDIT} action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @throws IOException if the specified file has no associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * editor, or the associated application fails to be launched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @throws SecurityException if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * {@link java.lang.SecurityManager#checkRead(java.lang.String)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * method denies read access to the file, or {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * java.lang.SecurityManager#checkWrite(java.lang.String)} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * denies write access to the file, or it denies the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * <code>AWTPermission("showWindowWithoutWarningBanner")</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * permission, or the calling thread is not allowed to create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @see java.awt.AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public void edit(File file) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        checkAWTPermission();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        checkExec();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        checkActionSupport(Action.EDIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        file.canWrite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        checkFileValidation(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        peer.edit(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Prints a file with the native desktop printing facility, using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * the associated application's print command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @param file the file to be printed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @throws NullPointerException if the specified file is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @throws IllegalArgumentException if the specified file doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @throws UnsupportedOperationException if the current platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *         does not support the {@link Desktop.Action#PRINT} action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @throws IOException if the specified file has no associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * application that can be used to print it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @throws SecurityException if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * {@link java.lang.SecurityManager#checkRead(java.lang.String)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * method denies read access to the file, or its {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * java.lang.SecurityManager#checkPrintJobAccess()} method denies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * the permission to print the file, or the calling thread is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * allowed to create a subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    public void print(File file) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        checkExec();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            sm.checkPrintJobAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        checkActionSupport(Action.PRINT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        checkFileValidation(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        peer.print(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * Launches the default browser to display a {@code URI}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * If the default browser is not able to handle the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * {@code URI}, the application registered for handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * {@code URIs} of the specified type is invoked. The application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * is determined from the protocol and path of the {@code URI}, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * defined by the {@code URI} class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * If the calling thread does not have the necessary permissions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * and this is invoked from within an applet,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * {@code AppletContext.showDocument()} is used. Similarly, if the calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * does not have the necessary permissions, and this is invoked from within
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * a Java Web Started application, {@code BasicService.showDocument()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @param uri the URI to be displayed in the user default browser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @throws NullPointerException if {@code uri} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @throws UnsupportedOperationException if the current platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * does not support the {@link Desktop.Action#BROWSE} action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @throws IOException if the user default browser is not found,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * or it fails to be launched, or the default handler application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * failed to be launched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @throws SecurityException if a security manager exists and it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * denies the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * <code>AWTPermission("showWindowWithoutWarningBanner")</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * permission, or the calling thread is not allowed to create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * subprocess; and not invoked from within an applet or Java Web Started
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @throws IllegalArgumentException if the necessary permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * are not available and the URI can not be converted to a {@code URL}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @see java.net.URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @see java.awt.AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @see java.applet.AppletContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public void browse(URI uri) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        SecurityException securityException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            checkAWTPermission();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            checkExec();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        } catch (SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            securityException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        checkActionSupport(Action.BROWSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (uri == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        if (securityException == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            peer.browse(uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
   390
        // Calling thread doesn't have necessary privileges.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        // Delegate to DesktopBrowse so that it can work in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        // applet/webstart.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        URL url = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            url = uri.toURL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            throw new IllegalArgumentException("Unable to convert URI to URL", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        sun.awt.DesktopBrowse db = sun.awt.DesktopBrowse.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (db == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            // Not in webstart/applet, throw the exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            throw securityException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        db.browse(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * Launches the mail composing window of the user default mail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * client.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @throws UnsupportedOperationException if the current platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * does not support the {@link Desktop.Action#MAIL} action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @throws IOException if the user default mail client is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * found, or it fails to be launched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @throws SecurityException if a security manager exists and it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * denies the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * <code>AWTPermission("showWindowWithoutWarningBanner")</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * permission, or the calling thread is not allowed to create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @see java.awt.AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    public void mail() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        checkAWTPermission();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        checkExec();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        checkActionSupport(Action.MAIL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        URI mailtoURI = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        try{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            mailtoURI = new URI("mailto:?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            peer.mail(mailtoURI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        } catch (URISyntaxException e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            // won't reach here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * Launches the mail composing window of the user default mail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * client, filling the message fields specified by a {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * mailto:} URI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * <p> A <code>mailto:</code> URI can specify message fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * including <i>"to"</i>, <i>"cc"</i>, <i>"subject"</i>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * <i>"body"</i>, etc.  See <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * href="http://www.ietf.org/rfc/rfc2368.txt">The mailto URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * scheme (RFC 2368)</a> for the {@code mailto:} URI specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @param mailtoURI the specified {@code mailto:} URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @throws NullPointerException if the specified URI is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @throws IllegalArgumentException if the URI scheme is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *         <code>"mailto"</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @throws UnsupportedOperationException if the current platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * does not support the {@link Desktop.Action#MAIL} action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @throws IOException if the user default mail client is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * found or fails to be launched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @throws SecurityException if a security manager exists and it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * denies the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * <code>AWTPermission("showWindowWithoutWarningBanner")</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * permission, or the calling thread is not allowed to create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @see java.net.URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @see java.awt.AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public  void mail(URI mailtoURI) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        checkAWTPermission();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        checkExec();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        checkActionSupport(Action.MAIL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        if (mailtoURI == null) throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        if (!"mailto".equalsIgnoreCase(mailtoURI.getScheme())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            throw new IllegalArgumentException("URI scheme is not \"mailto\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        peer.mail(mailtoURI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    private void checkExec() throws SecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            sm.checkPermission(new FilePermission("<<ALL FILES>>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                                                  SecurityConstants.FILE_EXECUTE_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
}