dsto.dfc.swt.util
Class Documents

java.lang.Object
  extended by dsto.dfc.swt.util.Documents

public final class Documents
extends Object

General utilities for opening document files/URL's using local applications or the system browser.

Author:
Matthew Phillips
See Also:
BrowserControl

Method Summary
static String getExtension(String uri, String defaultExt)
          Get the nominal extension of a URL/URI.
static boolean looksLikeDOSFile(String name)
           
static boolean looksLikeUNCFile(String name)
           
static String makeUrl(String filename)
          Convert a reference that's probably a URL or a filename into a guaranteed bona fide URL.
static void open(String name)
          Open a filename/URL with the system default application.
static void openWithBrowserControl(String command, String url)
          Open a URL using BrowserControl.
static String urlToFilename(String url)
          Convert "file:" URL's to their platform filenames.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

open

public static void open(String name)
                 throws IOException
Open a filename/URL with the system default application. Tries to use the SWT Program class to open based on extension (works well with filenames and file:// URL's), then falls back on whatever handles HTML then falls back on BrowserControl as a last resort.

Parameters:
name - The URL/filename to open.
Throws:
IOException - if the URL could not be opened or an error occurred opening it.

openWithBrowserControl

public static void openWithBrowserControl(String command,
                                          String url)
                                   throws IOException
Open a URL using BrowserControl.

Parameters:
command - The command to execute. May be null.
url - The URL.
Throws:
IOException - if an error occurs.

urlToFilename

public static String urlToFilename(String url)
Convert "file:" URL's to their platform filenames. Does nothing for non-file URL's.


getExtension

public static String getExtension(String uri,
                                  String defaultExt)
Get the nominal extension of a URL/URI.

Parameters:
uri - The URI.
defaultExt - The extension to return when there is none (eg URL is http://www.frob.com/)

makeUrl

public static String makeUrl(String filename)
Convert a reference that's probably a URL or a filename into a guaranteed bona fide URL. Does nothing if filename appears to be a URL already. This may add "file:" as a prefix if needed or expand a Windows ".url" file.


looksLikeUNCFile

public static boolean looksLikeUNCFile(String name)

looksLikeDOSFile

public static boolean looksLikeDOSFile(String name)


Copyright © 2008 Commonwealth of Australia