Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6255196
Votes 0
Synopsis API to launch desktop helper applications
Category java:classes_awt
Reported Against 1.4.1 , 1.4.2 , 1.1.7a
Release Fixed mustang(b49)
State 10-Fix Delivered, Verified, request for enhancement
Priority: 3-Medium
Related Bugs 4915908 , 4210168
Submit Date 14-APR-2005
Description
This RFE is the implementation of http://jplan.sfbay/feature/239.
See the proposed API at 
http://sceri.prc/desktop/MH/java_integration/download/desktop_api_tuning/javadoc/
  xxxxx@xxxxx   2005-04-14 10:58:01 GMT
Work Around
N/A
Evaluation
The API is being developed and implemented by JDIC engineers, current contact is Armin Chen.
  xxxxx@xxxxx   2005-04-14 11:01:29 GMT

CCC: http://ccc.sfbay/6255196
  xxxxx@xxxxx   2005-04-14 11:01:43 GMT

As of the latest JCG meeting, we don't plan to release it in Mustang.
  xxxxx@xxxxx   2005-05-26 12:10:19 GMT

Actually, we decided to persue this feature for Mustang.  The planned API looks as follows:
package java.awt;

/** 
 * The {@code Desktop} class allows a Java application to launch 
 * associated applications registered on the native desktop to handle a 
 * {@link java.net.URI} or a file. 
 * <p>
 * Supported operations include:
 * <ul>
 *   <li>launching the user-default browser to show a specified URI;</li>
 *   <li>launching the user-default mail client with an optional {@code mailto} URI;</li>
 *   <li>launching a registered application to open, edit or print a specified file.</li>
 * </ul>
 *
 * <p> This class provides methods corresponding to these operations. The methods 
 * look for the associated application registered on the current platform, and 
 * launch it to handle a URI or file. If there is no associated 
 * application or the associated application fails to be launched, an exception 
 * is thrown.  
 *
 * <p> An application is registered to a URI or file type; for
 * example, the {@code "sxi"} file extension is typically registered
 * to StarOffice.  The mechanism of registereing, accessing, and
 * launching the associated application is platform-dependent.
 *
 * <p>
 * Each operation is an action type represented by the {@link Desktop.Action} 
 * class.
 * <p> 
 * Note: when some action is invoked and the associated application is
 * executed, it will be executed on the same system as the one on which the
 * Java application was launched.
 *
 * @since 1.6
 * @author Armin Chen
 * @author George Zhang
 */
public class Desktop {

    /**
     * Represents an action type.  Each platform supports a different
     * set of actions.  You may use the {@link Desktop#isSupported}
     * method to determine if the given action is supported by the
     * current platform.
     * @see java.awt.Desktop#isSupported(java.awt.Desktop.Action)
     * @since 1.6
     */
    public static enum Action {
        /**
         * Represents an "open" action. 
         * @see Desktop#open(java.io.File)
         */
        OPEN,
        /**
         * Represents an "edit" action.
         * @see Desktop#edit(java.io.File)
         */
        EDIT,
        /**
         * Represents a "print" action.
         * @see Desktop#print(java.io.File)
         */
        PRINT,
        /**
         * Represents a "mail" action. 
         * @see Desktop#mail()
         * @see Desktop#mail(java.net.URI) 
         */
        MAIL,
        /**
         * Represents a "browse" action.
         * @see Desktop#browse(java.net.URI)
         */
        BROWSE
    };
        
    /**
     * Returns the <code>Desktop</code> instance of the current
     * browser context.  On some platforms the Desktop API may not be
     * supported; use the {@link #isDesktopSupported} method to
     * determine if the current desktop is supported.
     * @return the Desktop instance of the current browser context
     * @throws HeadlessException if {@link GraphicsEnvironment#isHeadless()} 
     *         returns {@code true}
     * @throws UnsupportedOperationException if this class is not supported 
     *         on the current platform
     * @see #isDesktopSupported()
     * @see java.awt.GraphicsEnvironment#isHeadless
     */
    public static synchronized Desktop getDesktop()
    
    /**
     * Tests whether this class is supported on the current platform.
     * If it's supported, use {@link #getDesktop()} to retrieve an
     * instance.
     *   
     * @return <code>true</code> if this class is supported on the 
     *         current platform; <code>false</code> otherwise
     * @see #getDesktop()
     */
    public static boolean isDesktopSupported()
    
    /**
     * Tests whether an action is supported on the current platform.
     * 
     * <p>Even when the platform supports an action, a file or URI may
     * not have a registered application for the action.  For example,
     * most of the platforms support the {@link Desktop.Action#OPEN}
     * action.  But for a specific file, there may not be an
     * application registered to open it.  In this case, {@link
     * #isSupported} may return {@code true}, but the corresponding
     * action method will throw an {@link IOException}.
     * 
     * @param action the specified {@link #Action}
     * @return <code>true</code> if the specified action is supported on 
     *         the current platform; <code>false</code> otherwise
     * @see Desktop.Action
     */
    public boolean isSupported(Action action)
    
    /**
     * Launches the associated application to open the file.
     * <p>
     * If the specified file is a directory, the file manager of the current 
     * platform is launched to open it.   
     * 
     * @param file the file to be opened with the associated application
     * @throws NullPointerException if {@code file} is {@code null}
     * @throws IllegalArgumentException if the specified file dosen't exist
     * @throws UnsupportedOperationException if the current platform 
     *         does not support the {@link Desktop.Action#OPEN} action
     * @throws IOException if the specified file has no associated application, 
     *         or the associated application fails to be launched
     * @throws SecurityException if a security manager exists and its
     * {@link java.lang.SecurityManager#checkRead(java.lang.String)}
     * method denies read access to the file, or it denies the
     * <code>AWTPermission("showWindowWithoutWarningBanner")</code>
     * permission, or the calling thread is not allowed to create a
     * subprocess
     * @see java.awt.AWTPermission
     */
    public void open(File file) throws IOException
   
    /**
     * Launches the associated editor application and opens a file for editing.
     *
     * @param file the file to be opened for editing
     * @throws NullPointerException if the specified file is {@code null}
     * @throws IllegalArgumentException if the specified file doesn't exist
     * @throws UnsupportedOperationException if the current platform 
     *         does not support the {@link Desktop.Action#EDIT} action
     * @throws IOException if the specified file has no associated editor, or 
     *         the associated application fails to be launched
     * @throws SecurityException if a security manager exists and its
     * {@link java.lang.SecurityManager#checkRead(java.lang.String)}
     * method denies read access to the file, or {@link
     * java.lang.SecurityManager#checkWrite(java.lang.String)} method
     * denies write access to the file, or it denies the
     * <code>AWTPermission("showWindowWithoutWarningBanner")</code>
     * permission, or the calling thread is not allowed to create a
     * subprocess
     * @see java.awt.AWTPermission
     */
    public void edit(File file) throws IOException

    /**
     * Prints a file with the native desktop printing facility, using 
     * the associated application's print command.
     *
     * @param file the file to be printed
     * @throws NullPointerException if the specified file is {@code null}
     * @throws IllegalArgumentException if the specified file doesn't exist
     * @throws UnsupportedOperationException if the current platform 
     *         does not support the {@link Desktop.Action#PRINT} action
     * @throws IOException if the specified file has no associated application 
     *         that can be used to print it
     * @throws SecurityException if a security manager exists and its
     * {@link java.lang.SecurityManager#checkRead(java.lang.String)}
     * method denies read access to the file, or its {@link
     * java.lang.SecurityManager#checkPrintJobAccess()} method denies
     * the permission to print the file, or the calling thread is not
     * allowed to create a subprocess
     */
    public void print(File file) throws IOException
  
    /**
     * Launches the user default browser to display a URI if this is an URI the
     * browser can handle. Otherwise, launches the default handler application 
     * for the URI depending on the protocol and path (as defined in the  
     * <code>URI</code> class).
     *
     * @param uri the URI to be displayed in the user default browser
     * @throws NullPointerException if {@code uri} is {@code null}
     * @throws UnsupportedOperationException if the current platform does not
     *         support the {@link Desktop.Action#BROWSE} action
     * @throws IOException if the user default browser is not found, 
     *         or it fails to be launched, or the default handler application 
     *         failed to be launched
     * @throws SecurityException if a security manager exists and it
     * denies the
     * <code>AWTPermission("showWindowWithoutWarningBanner")</code>
     * permission, or the calling thread is not allowed to create a
     * subprocess
     * @see java.net.URI
     * @see java.awt.AWTPermission       
     */
    public void browse(URI uri) throws IOException
  
    /**
     * Launches the mail composing window of the user default mail client.
     * 
     * @throws UnsupportedOperationException if the current platform does not
     *         support the {@link Desktop.Action#MAIL} action
     * @throws IOException if the user default mail client is not found, 
     *         or it fails to be launched
     * @throws SecurityException if a security manager exists and it
     * denies the
     * <code>AWTPermission("showWindowWithoutWarningBanner")</code>
     * permission, or the calling thread is not allowed to create a
     * subprocess
     * @see java.awt.AWTPermission         
     */
    public void mail() throws IOException

    /**
     * Launches the mail composing window of the user default mail client, 
     * filling the message fields specified by a {@code mailto:} URI.
     * 
     * <p> A <code>mailto:</code> URI can specify message fields
     * including <i>"to"</i>, <i>"cc"</i>, <i>"subject"</i>,
     * <i>"body"</i>, etc.  See <a
     * href="http://www.ietf.org/rfc/rfc2368.txt">The mailto URL
     * scheme (RFC 2368)</a> for the {@code mailto:} URI specification details.
     * 
     * @param mailtoURI the specified {@code mailto:} URI
     * @throws NullPointerException if the specified URI is {@code null}
     * @throws IllegalArgumentException if the URI scheme is not 
     *         <code>"mailto"</code>
     * @throws UnsupportedOperationException if the current platform does not
     *         support the {@link Desktop.Action#MAIL} action
     * @throws IOException if the user default mail client is not found or 
     *         fails to be launched
     * @throws SecurityException if a security manager exists and it
     * denies the
     * <code>AWTPermission("showWindowWithoutWarningBanner")</code>
     * permission, or the calling thread is not allowed to create a
     * subprocess
     * @see java.net.URI
     * @see java.awt.AWTPermission         
     */
    public  void mail(URI mailtoURI) throws IOException
}

For other details, see CCC http://ccc.sfbay/6255196
  xxxxx@xxxxx   2005-06-26 04:28:49 GMT
Posted Date : 2005-06-26 04:28:49.0

- "The problem with this is that enums are not extensible."
this has been considered, and here is the answer from Peter von der Ahé:
------------------8<----------------------------------
"> > - is it safe to declare an enum with some set of values, and then
> > extend this set of values later, in a future release?
> 
> It is intended to work that way.  I will be relying on this feature
> myself in JSR 199 and a low level compiler API to be included in
> mustang.
> 
> A preliminary version of JLS's chapter 13 (Binary Compatibility) says:
> 
>         13.4.26 Evolution of Enums
>         
>         Adding or reordering constants from an enum type will not break
>         compatibility with pre-existing binaries.
>         If a precompiled binary attempts to access an enum constant that
>         no longer exists, the client will fail at runtime with a
>         NoSuchFieldError. Therefore such a change is not recommended for
>         widely distributed enums.
>         In all other respects, the binary compatibility rules for enums
>         are identical to those for classes.
> 
> I guess that the wording might change slightly, but this is considered a
> very important aspect of enums.
------------------8<----------------------------------

-  ... It would be useful to programatically have access to these verbs ...
This is already integrated in 6.0, as part of the JavaBeans Activation Framework.
http://java.sun.com/products/javabeans/jaf/index.jsp.  Javadoc has not been yet generated, 
however the code is there, you may find it by downloading source snapshot of the latest Mustang
build from mustang.dev.java.net, see package javax.activation
Posted Date : 2005-08-05 08:46:51.0
Comments
  
  Include a link with my name & email   

Submitted On 03-AUG-2005
eddiebenowitz
The problem with this is that enums are not extensible.  So if additional actions are needed, they can't be included.  Also, on windows, for example, if one right clicks a file in explorer, a menu with many configurable "verbs" appear, besides a simple print, open, etc.  It would be useful to programatically have access to these verbs, or to be able to pop up something like the native right click menu.  Instead , Windows offers a choice from among multiple editors.  The user should be able to query for a list of all appropriate editors and offer this choice programatically, rather than just using a default editor.  I believe a similar feature is available on linux as well.


Submitted On 06-MAY-2008
hay



PLEASE NOTE: JDK6 is formerly known as Project Mustang