jApp.jdic
Class AssociationService

java.lang.Object
  extended by jApp.jdic.AssociationService

public class AssociationService
extends java.lang.Object

Provides a service to register file/document types and associate them with an application so that both the application and the files/documents have the correct appearance (icon) and can be launched/opened by double clicking at the icon on the Desktop.

Supports modern Windows (NT based, such as 2000 and XP) and Linux (at least KDE/Gnome 3.0) platforms. MacOS X does not require this service as this is best handled through '.app' and '.plist' packaging on that platform.

This is done in 100% pure Java as registration is done using command line interface to the underlaying operating system usin Runtime.getRuntime().exec() method. More specifically, using REG.EXE on Windows and XDG Util scripts on Linux. In Linux, the commands are 'sudo':ed if a root/admin password is provided.

Author:
Kustaa Nyholm

Constructor Summary
AssociationService()
           
 
Method Summary
static void copyResourceToFile(java.lang.Class clss, java.lang.String resource, java.io.File toFile)
          Copies a resorce to a file.
 void register(boolean install, boolean systemInstall, java.lang.String password, java.lang.Class mainClass, java.lang.Class resourceClass, java.lang.String applicationID, java.lang.String applicationName, java.lang.String description, java.lang.String applicationDir, java.lang.Iterable<Association> associations)
          Registers/unregister the application and file associations with the platforms Desktop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AssociationService

public AssociationService()
Method Detail

copyResourceToFile

public static void copyResourceToFile(java.lang.Class clss,
                                      java.lang.String resource,
                                      java.io.File toFile)
                               throws java.io.IOException
Copies a resorce to a file. A non essential but nonetheless usefull, hence public, helper function that copies a named resource from the given class to the given file.

Parameters:
clss -
resource -
toFile -
Throws:
java.io.IOException

register

public void register(boolean install,
                     boolean systemInstall,
                     java.lang.String password,
                     java.lang.Class mainClass,
                     java.lang.Class resourceClass,
                     java.lang.String applicationID,
                     java.lang.String applicationName,
                     java.lang.String description,
                     java.lang.String applicationDir,
                     java.lang.Iterable<Association> associations)
              throws java.lang.Exception
Registers/unregister the application and file associations with the platforms Desktop. Registers/unregisters the associations with the platforms Desktop Manager (Gnome/KDE/Finder/Explorer) so that both the application and the documents have the correct appearance (icon) and can be launched/opened by double clicking at the icon on the Desktop. the application lauched b

Parameters:
install - weather to install or uninstall
systemInstall - install into system or for the user (Linux only)
password - the root (admin) password for 'sudo'ing the regisration (Linux only)
mainClass - the mainClass of the application
resourceClass - the class that contains the resources (icons)
applicationID - the internal name for the application (used as key in regisration)
applicationName - the user name for the application
description - the user description of the application
applicationDir - the directory used to store registration related files, needs to be writable
associations - list of associations to register
Throws:
java.lang.Exception - if something goes wrong