Class FileExecuteHelper
java.lang.Object
net.simplace.core.service.FileExecuteHelper
Opens files, URLs and e-mails in external applications and runs executables and scripts.
- Author:
- Andreas Enders
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringexecuteApplication(String aAppName, File aWorkingDir) Runs a command withcmd.exe /C(Windows only), waits until it has finished and returns its standard output.static ProcessexecuteExecutable(String aWholePathAndProgName) Starts an executable.static ProcessexecuteFile(File aFile) Opens a file in the application registered for its type.static ProcessexecuteFile(String aFileName) Opens a file in the application registered for its type.static ProcessexecuteFileExtern(File aFile) Opens a file in the application registered for its type.static ProcessexecuteFileExtern(File aFile, boolean aCreateTemporaryCopy) Opens a file in the application registered for its type.static ProcessexecuteFileExtern(String aFile) Opens a file in the application registered for its type.static voidexecuteScript(String aPath, String aExecutableName, String aParameterString) Runs a shell script (Linux:<path>/<name>.sh) or batch file (other systems:<path>/<name>.bat) with parameters, if it exists.static voidnewMailInStandardClient(List<String> aToAddrsList, String aSubject, String aBody, String aAttachementPath) Opens a new e-mail in the mail client.static voidshowInExternalBrowser(String aURL, boolean aNewWindows) Opens a URL in the default browser of the operating system.
-
Constructor Details
-
FileExecuteHelper
public FileExecuteHelper()
-
-
Method Details
-
showInExternalBrowser
public static void showInExternalBrowser(String aURL, boolean aNewWindows) throws ExecutionException Opens a URL in the default browser of the operating system.- Parameters:
aURL- URL to open; if it contains no slash,http://is prependedaNewWindows- ignored: java.awt.Desktop has no "new window" policy, the OS-registered browser decides- Throws:
ExecutionException- if no Desktop/BROWSE support is available or the browser could not be launched
-
executeFile
Opens a file in the application registered for its type.- Parameters:
aFile- file to open- Returns:
- the started process, or
null(seeexecuteFileExtern(File, boolean)) - Throws:
ExecutionException- if the file cannot be opened
-
executeFile
Opens a file in the application registered for its type. Errors are logged, not thrown.- Parameters:
aFileName- path of the file to open- Returns:
- the started process, or
nullif an error occurred (or seeexecuteFileExtern(File, boolean))
-
executeFileExtern
Opens a file in the application registered for its type.- Parameters:
aFile- file to open- Returns:
- the started process, or
null(seeexecuteFileExtern(File, boolean)) - Throws:
ExecutionException- if the file cannot be opened
-
executeFileExtern
Opens a file in the application registered for its type.- Parameters:
aFile- path of the file to open- Returns:
- the started process, or
null(seeexecuteFileExtern(File, boolean)) - Throws:
ExecutionException- if the file cannot be opened
-
executeFileExtern
public static Process executeFileExtern(File aFile, boolean aCreateTemporaryCopy) throws ExecutionException Opens a file in the application registered for its type. On Linuxkfmclient(KDE) orgnome-openis used, on Windows NT 4.0rundll32, on all other systems (Windows, macOS)Desktop.open(File).CAVEAT: Changes to this method must be tested against all supported operating systems.
- Parameters:
aFile- file to openaCreateTemporaryCopy- iftrue, the file is copied to a random temp directory and the copy is opened. This can be used to prevent the original document from being edited.- Returns:
- the started process;
nullon systems other than Linux and Windows NT 4.0 (no process handle available) - Throws:
ExecutionException- if the file cannot be copied or opened
-
executeExecutable
Starts an executable. Forward slashes in the path are replaced by backslashes (Windows only). Errors are logged, not thrown.- Parameters:
aWholePathAndProgName- full path of the executable- Returns:
- the started process, or
nullif an error occurred
-
executeApplication
Runs a command withcmd.exe /C(Windows only), waits until it has finished and returns its standard output.- Parameters:
aAppName- command line to run; forward slashes are replaced by backslashesaWorkingDir- working directory of the process- Returns:
- the standard output of the process
- Throws:
IOException- if the process cannot be started or its output cannot be read
-
executeScript
public static void executeScript(String aPath, String aExecutableName, String aParameterString) throws ExecutionException Runs a shell script (Linux:<path>/<name>.sh) or batch file (other systems:<path>/<name>.bat) with parameters, if it exists.- Parameters:
aPath- directory of the scriptaExecutableName- name of the script without extensionaParameterString- parameters appended to the command- Throws:
ExecutionException- if the script cannot be run
-
newMailInStandardClient
public static void newMailInStandardClient(List<String> aToAddrsList, String aSubject, String aBody, String aAttachementPath) throws IOException Opens a new e-mail in the mail client. Currently only implemented for Linux (except GNOME), where Thunderbird is started; on other systems only a log message is written.- Parameters:
aToAddrsList- list of recipient e-mail addressesaSubject- subject of the e-mailaBody- body text of the e-mailaAttachementPath- path of a file to attach, ornull- Throws:
IOException- if the mail client cannot be started
-