com.izforge.izpack.util.os
Class Shortcut

java.lang.Object
  extended bycom.izforge.izpack.util.os.Shortcut
Direct Known Subclasses:
Unix_Shortcut, Win_Shortcut

public class Shortcut
extends java.lang.Object

This class represents a shortcut in a operating system independent way. OS specific subclasses are used to implement the necessary mapping from this generic API to the classes that reflect the system dependent AIP.

Version:
0.0.1 / 3/4/02
Author:
Elmar Grom
See Also:
TargetFactory

Field Summary
static int ALL_USERS
          identifies the user type as valid for all users
static int APPLICATIONS
           
private  java.lang.Boolean createForAll
          indicates that this shortcut should be created for all users or only me
static int CURRENT_USER
          identifies the user type as the current user
static int DESKTOP
           
static int HIDE
          Hide the window when starting.
static int MAXIMIZED
          Show the window maximized when starting.
static int MINIMIZED
           
static int NORMAL
          Show the window 'normal' when starting.
static int START_MENU
           
static int START_UP
           
 
Constructor Summary
Shortcut()
           
 
Method Summary
 java.lang.String getBasePath()
          Returns the base path of the shortcut depending on type.
 java.lang.Boolean getCreateForAll()
          Gets the create for All Flag
 java.lang.String getDirectoryCreated()
          Subclass implementations return the path of the directory where the link file is stored, if it was necessary during the previous save operation to create the directory.
 java.lang.String getFileName()
          Subclass implementations return the fully qualified file name under which the link is saved on disk.
 int getHotkey()
          Gets the link hotKey
 java.lang.String getIconLocation()
          returns icon Location
 int getLinkType()
          Gets the type of link types are:
DESKTOP APPLICATIONS START_MENU START_UP
 java.util.Vector getProgramGroups(int userType)
          Returns a list of currently existing program groups, based on the requested type.
 java.lang.String getProgramsFolder(int current_user)
          Gets the Programs Folder for the given User.
 int getShowCommand()
           
 int getUserType()
          Gets the user type for the link
 java.lang.String getWorkingDirectory()
          Gets the working directory for the link target.
 void initialize(int type, java.lang.String name)
          This method initializes the object.
 boolean multipleUsers()
          Returns true if the target OS supports current user and all users.
 void save()
          Saves this link.
 void setArguments(java.lang.String arguments)
          Sets the command line arguments that will be passed to the target when the link is activated.
 void setCreateForAll(java.lang.Boolean aCreateForAll)
          Sets the flag which indicates, that this should created for all.
 void setDescription(java.lang.String description)
          Sets the description string that is used to identify the link in a menu or on the desktop.
 void setEncoding(java.lang.String string)
          Sets the Encoding
 void setHotkey(int hotkey)
          Sets the link hotKey
 void setIconLocation(java.lang.String path, int index)
          Sets the location of the icon that is shown for the shortcut on the desktop.
 void setKdeSubstUID(java.lang.String string)
          This sets the KdeSubstUID
 void setLinkName(java.lang.String name)
          Sets the name shown in a menu or on the desktop for the link.
 void setLinkType(int type)
          Sets the type of link
 void setMimetype(java.lang.String string)
          This sets the Mimetype
 void setProgramGroup(java.lang.String groupName)
          Sets the name of the program group this ShellLinbk should be placed in.
 void setShowCommand(int show)
          Sets the show command that is passed to the target application when the link is activated.
 void setTargetPath(java.lang.String path)
          Sets the absolute path to the shortcut target.
 void setTerminal(java.lang.String string)
          Sets the terminal
 void setTerminalOptions(java.lang.String string)
          This sets the terminals-options
 void setType(java.lang.String string)
          This sets the shortcut type
 void setURL(java.lang.String string)
          This sets the URL
 void setUserType(int type)
          Sets the user type for the link
 void setWorkingDirectory(java.lang.String dir)
          Sets the working directory for the link target.
 boolean supported()
          Determines if a specific instance of this class supports the creation of shortcuts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

APPLICATIONS

public static final int APPLICATIONS
See Also:
Constant Field Values

START_MENU

public static final int START_MENU
See Also:
Constant Field Values

DESKTOP

public static final int DESKTOP
See Also:
Constant Field Values

START_UP

public static final int START_UP
See Also:
Constant Field Values

HIDE

public static final int HIDE
Hide the window when starting.

See Also:
Constant Field Values

NORMAL

public static final int NORMAL
Show the window 'normal' when starting. Usually restores the window properties at the last shut-down.

See Also:
Constant Field Values

MINIMIZED

public static final int MINIMIZED
See Also:
Constant Field Values

MAXIMIZED

public static final int MAXIMIZED
Show the window maximized when starting.

See Also:
Constant Field Values

CURRENT_USER

public static final int CURRENT_USER
identifies the user type as the current user

See Also:
Constant Field Values

ALL_USERS

public static final int ALL_USERS
identifies the user type as valid for all users

See Also:
Constant Field Values

createForAll

private java.lang.Boolean createForAll
indicates that this shortcut should be created for all users or only me

Constructor Detail

Shortcut

public Shortcut()
Method Detail

initialize

public void initialize(int type,
                       java.lang.String name)
                throws java.lang.Exception
This method initializes the object. It is used as a replacement for the contructor because of the way it is instantiated through the TargetFactory.

Parameters:
type - the type or classification of the program group in which the link should exist.
name - the name of the shortcut.
Throws:
java.lang.Exception

getBasePath

public java.lang.String getBasePath()
                             throws java.lang.Exception
Returns the base path of the shortcut depending on type. The base path is the directory that the short cut, (or its program group) will be created in. For instance, on Windows NT, a shortcut with user-type ALL_USERS, and link-type DESKTOP might have the base path "C:\Program Files\All Users\Desktop"

Throws:
java.lang.Exception
See Also:
setLinkType(int), setUserType(int)

getProgramGroups

public java.util.Vector getProgramGroups(int userType)
Returns a list of currently existing program groups, based on the requested type. For example if the type is APPLICATIONS then all the names of the program groups in the Start Menu\Programs menu would be returned.

Parameters:
userType - the type of user for the program group set.
Returns:
a Vector of String objects that represent the names of the existing program groups. It is theoretically possible that this list is empty.
See Also:
APPLICATIONS, START_MENU

getFileName

public java.lang.String getFileName()
Subclass implementations return the fully qualified file name under which the link is saved on disk. Note: this method returns valid results only if the instance was created from a file on disk or after a successful save operation. An instance of this class returns an empty string.

Returns:
an empty String

getDirectoryCreated

public java.lang.String getDirectoryCreated()
Subclass implementations return the path of the directory where the link file is stored, if it was necessary during the previous save operation to create the directory. This method returns null if no save operation was carried out or there was no need to create a directory during the previous save operation.

Returns:
this implementation returns always null.

multipleUsers

public boolean multipleUsers()
Returns true if the target OS supports current user and all users.

Returns:
true if the target OS supports current and all users.

supported

public boolean supported()
Determines if a specific instance of this class supports the creation of shortcuts. The use of this method might seem odd, since one would not implement a flavor of this class that does not actually support the creation of shortcuts. In other words all flavors will in all probability return true. The only version that can be expected to return false is this class itself, since it has no actual implementation for shortcut creation. This is left to OS specific flavors. If the installer is launched on a unsupported OS there will be no appropriate flavor of this class, which will cause this class itself to be instantiated. The client code can now determine by calling this method if the active OS is supported and take appropriate action.

Returns:
true if the creation of shortcuts is supported, false if this is not supported.

setArguments

public void setArguments(java.lang.String arguments)
Sets the command line arguments that will be passed to the target when the link is activated.

Parameters:
arguments - the command line arguments

setDescription

public void setDescription(java.lang.String description)
Sets the description string that is used to identify the link in a menu or on the desktop.

Parameters:
description - the descriptiojn string

setIconLocation

public void setIconLocation(java.lang.String path,
                            int index)
Sets the location of the icon that is shown for the shortcut on the desktop.

Parameters:
path - a fully qualified file name of a file that contains the icon.
index - the index of the specific icon to use in the file. If there is only one icon in the file, use an index of 0.

getIconLocation

public java.lang.String getIconLocation()
returns icon Location

Returns:
iconLocation

setProgramGroup

public void setProgramGroup(java.lang.String groupName)
Sets the name of the program group this ShellLinbk should be placed in.

Parameters:
groupName - the name of the program group

setShowCommand

public void setShowCommand(int show)
Sets the show command that is passed to the target application when the link is activated. The show command determines if the the window will be restored to the previous size, minimized, maximized or visible at all.

Note:
Using HIDE will cause the target window not to show at all. There is not even a button on the taskbar. This is a very useful setting when batch files are used to launch a Java application as it will then appear to run just like any native Windows application.

Parameters:
show - the show command. Valid settings are:
See Also:
getShowCommand()

getShowCommand

public int getShowCommand()

setTargetPath

public void setTargetPath(java.lang.String path)
Sets the absolute path to the shortcut target.

Parameters:
path - the fully qualified file name of the target

setWorkingDirectory

public void setWorkingDirectory(java.lang.String dir)
Sets the working directory for the link target.

Parameters:
dir - the working directory

getWorkingDirectory

public java.lang.String getWorkingDirectory()
Gets the working directory for the link target.

Returns:
the working directory.

setLinkName

public void setLinkName(java.lang.String name)
Sets the name shown in a menu or on the desktop for the link.

Parameters:
name - The name that the link should display on a menu or on the desktop. Do not include a file extension.

getLinkType

public int getLinkType()
Gets the type of link types are:


setLinkType

public void setLinkType(int type)
                 throws java.lang.IllegalArgumentException,
                        java.io.UnsupportedEncodingException
Sets the type of link

Parameters:
type - The type of link desired. The following values can be set:
Throws:
java.lang.IllegalArgumentException - if an an invalid type is passed
java.io.UnsupportedEncodingException

setUserType

public void setUserType(int type)
Sets the user type for the link

Parameters:
type - the type of user for the link.
See Also:
CURRENT_USER, ALL_USERS

getUserType

public int getUserType()
Gets the user type for the link

Returns:
userType
See Also:
CURRENT_USER, ALL_USERS

save

public void save()
          throws java.lang.Exception
Saves this link.

Throws:
java.lang.Exception - if problems are encountered

getHotkey

public int getHotkey()
Gets the link hotKey

Returns:
int hotKey

setHotkey

public void setHotkey(int hotkey)
Sets the link hotKey

Parameters:
hotkey -

setEncoding

public void setEncoding(java.lang.String string)
Sets the Encoding

Parameters:
string -

setMimetype

public void setMimetype(java.lang.String string)
This sets the Mimetype

Parameters:
string -

setTerminal

public void setTerminal(java.lang.String string)
Sets the terminal

Parameters:
string -

setTerminalOptions

public void setTerminalOptions(java.lang.String string)
This sets the terminals-options

Parameters:
string -

setType

public void setType(java.lang.String string)
This sets the shortcut type

Parameters:
string -

setKdeSubstUID

public void setKdeSubstUID(java.lang.String string)
This sets the KdeSubstUID

Parameters:
string -

setURL

public void setURL(java.lang.String string)
This sets the URL

Parameters:
string -

getProgramsFolder

public java.lang.String getProgramsFolder(int current_user)
Gets the Programs Folder for the given User. This is where to create subfolders or to place or create shortcuts.

Parameters:
current_user - one of current or all
Returns:
The Foldername or null on unsupported platforms.

setCreateForAll

public void setCreateForAll(java.lang.Boolean aCreateForAll)
Sets the flag which indicates, that this should created for all.

Parameters:
aCreateForAll - A Flag - Set to true, if to create for All.

getCreateForAll

public java.lang.Boolean getCreateForAll()
Gets the create for All Flag

Returns:
Returns True if this should be for all.