com.izforge.izpack.util.os
Class Unix_Shortcut

java.lang.Object
  extended by com.izforge.izpack.util.os.Shortcut
      extended by com.izforge.izpack.util.os.Unix_Shortcut
All Implemented Interfaces:
Unix_ShortcutConstants

public class Unix_Shortcut
extends Shortcut
implements Unix_ShortcutConstants

This is the Implementation of the RFC-Based Desktop-Link. Used in KDE and GNOME.

Author:
marc.eppelmann@reddot.de

Field Summary
private static java.lang.String C
          C = Comment = H+S = "# "
private  java.lang.String createdDirectory
          internal String createdDirectory
private static java.lang.String DESKTOP_EXT
          DESKTOP_EXT = ".desktop"
private  java.lang.Boolean forAll
          forAll = new Boolean(false): A flag to indicate that this should created for all users.
 java.lang.String FS
          Internal Constant: FS = File.separator //
private static java.lang.String H
          H = "#"
 java.lang.StringBuffer hlp
          Internal Help Buffer
private  java.lang.String itsApplnkFolder
          internal String itsApplnkFolder = "applnk"
private  java.lang.String itsFileName
          internal String itsFileName
private  java.lang.String itsGroupName
          internal String itsGroupName
private  java.lang.String itsName
          internal String itsName
private  int itsUserType
          internal int itsUserType
 java.lang.String myHome
          Internal Constant: myHome = System.getProperty("user.home")
 ShellScript myInstallScript
          my Install ShellScript
 java.lang.String myXdgDesktopIconCmd
           
 java.lang.String myXdgDesktopIconScript
           
private static java.lang.String N
          N = "\n"
private  java.util.Properties props
          internal Properties Set
private static java.lang.String QM
          QM = "\"" : QuotationMark
private static java.lang.String rev
          rev = "$Revision$"
private static ShellScript rootScript
           
private static java.lang.String S
          S = " "
private  int ShortcutType
           
 java.lang.String su
          Internal Constant: su = UnixHelper.getSuCommand()
private static java.lang.String template
          template = ""
private static ShellScript uninstallScript
           
private  java.util.List users
           
private static java.lang.String version
          version = "$Id$"
private  java.lang.String writtenFileName
           
 java.lang.String xdgDesktopIconCmd
          Internal Constant: xdgDesktopIconCmd = UnixHelper.getCustomCommand("xdg-desktop-icon")
 
Fields inherited from class com.izforge.izpack.util.os.Shortcut
ALL_USERS, APPLICATIONS, CURRENT_USER, DESKTOP, HIDE, MAXIMIZED, MINIMIZED, NORMAL, START_MENU, START_UP, uninstaller
 
Fields inherited from interface com.izforge.izpack.util.os.Unix_ShortcutConstants
$$LANG_Comment, $$LANG_GenericName, $$LANG_Name, $Arguments, $Categories, $Comment, $E_QUOT, $Encoding, $Exec, $GenericName, $Icon, $MimeType, $Name, $Options_For_Terminal, $P_QUOT, $Path, $ServiceTypes, $SwallowExec, $SwallowTitle, $Terminal, $TryExec, $Type, $URL, $X_KDE_SubstituteUID, $X_KDE_Username
 
Constructor Summary
Unix_Shortcut()
          Creates a new Unix_Shortcut object.
 
Method Summary
private  void copyDesktopFileToAllUsersDesktop(java.io.File writtenDesktopFile)
           
static void copyTo(java.io.File inFile, java.io.File outFile)
          Copies the inFile file to outFile using cbuff as buffer.
 void createExtXdgDesktopIconCmd(java.io.File shortCutLocation)
          Ceates Extended Locale Enabled XdgDesktopIcon Command script.
 void execPostAction()
          Post Exec Action especially for the Unix Root User.
 java.lang.String getDirectoryCreated()
          Dummy
 java.lang.String getFileName()
          Dummy
private  java.lang.String getKdeApplinkFolderName()
          Gets the name of the applink folder for the currently used distribution.
private  java.io.File getKdeBase(int userType)
          Gets the KDEBasedir for the given User.
private  java.io.File getKdeShareApplnkFolder(int userType)
          Gets the XDG path to place the menu shortcuts
 int getLinkType()
          Gets the type of link types are:
Shortcut.DESKTOP Shortcut.APPLICATIONS Shortcut.START_MENU Shortcut.START_UP
 java.util.Vector<java.lang.String> getProgramGroups(int userType)
          Overridden compatibility method.
 java.lang.String getProgramsFolder(int current_user)
          Gets the Programsfolder for the given User (non-Javadoc).
private  java.util.List getUsers()
           
 int getUserType()
          Gets the Usertype of the Shortcut.
 java.lang.String getWrittenFileName()
           
 void initialize(int aType, java.lang.String aName)
          Overridden Method
private  void initProps()
          This initialisizes all Properties Values with "".
private  void installDesktopFileToAllUsersDesktop(java.io.File writtenDesktopFile)
          Calls and creates the Install/Unistall Script which installs Desktop Icons using xdgDesktopIconCmd un-/install
static void main(java.lang.String[] args)
          Test Method
 boolean multipleUsers()
          overridden method
 java.lang.String replace()
          Creates the Shortcut String which will be stored as File.
 void save()
          Creates and stores the shortcut-files.
 void setArguments(java.lang.String args)
          Set the Commandline Arguments
 void setCategories(java.lang.String theCategories)
          Sets the Categories Field
 void setDescription(java.lang.String description)
          Sets the Description
 void setEncoding(java.lang.String aEncoding)
          Sets The Encoding
 void setIconLocation(java.lang.String path, int index)
          Sets The Icon Path
 void setKdeSubstUID(java.lang.String trueFalseOrNothing)
          Sets The KDE Specific subst UID property
 void setKdeUserName(java.lang.String aUserName)
          Sets The KDE Specific subst UID property
 void setLinkName(java.lang.String aName)
          Sets the Name of this Shortcut
 void setLinkType(int aType)
          Sets the type of this Shortcut
 void setMimetype(java.lang.String aMimetype)
          Sets the MimeType
 void setProgramGroup(java.lang.String aGroupName)
          Sets the ProgramGroup
 void setShowCommand(int show)
          Sets the ShowMode
 void setTargetPath(java.lang.String aPath)
          Sets The TargetPath
 void setTerminal(java.lang.String trueFalseOrNothing)
          Sets the terminal
 void setTerminalOptions(java.lang.String someTerminalOptions)
          Sets the terminal options
 void setTryExec(java.lang.String aTryExec)
          Sets the TryExecField.
 void setType(java.lang.String aType)
          Sets the Shortcut type (one of Application, Link or Device)
 void setURL(java.lang.String anUrl)
          Sets the Url for type Link.
 void setUserType(int aUserType)
          Sets the usertype.
 void setWorkingDirectory(java.lang.String aDirectory)
          Sets the working-directory
protected  void setWrittenFileName(java.lang.String s)
           
 boolean supported()
          This indicates that Unix will be supported.
 java.lang.String toString()
          Dumps the Name to console.
private  java.io.File writeAppShortcut(java.lang.String targetPath, java.lang.String shortcutName, java.lang.String shortcutDef)
          Write the given ShortDefinition in a File $ShortcutName-$timestamp.desktop in the given TargetPath.
private  java.io.File writeAppShortcutWithOutSpace(java.lang.String targetPath, java.lang.String shortcutName, java.lang.String shortcutDef)
          Write the given ShortDefinition in a File $ShortcutName-$timestamp.desktop in the given TargetPath.
private  java.io.File writeAppShortcutWithSimpleSpacehandling(java.lang.String targetPath, java.lang.String shortcutName, java.lang.String shortcutDef, boolean replaceSpacesWithMinus)
          Write the given ShortDefinition in a File $ShortcutName-$timestamp.desktop in the given TargetPath.
private  java.io.File writeShortCut(java.lang.String target, java.lang.String shortCutDef)
          Writes the given Shortcutdefinition to the given Target.
 
Methods inherited from class com.izforge.izpack.util.os.Shortcut
cleanUp, getBasePath, getCreateForAll, getHotkey, getIconLocation, getShowCommand, getWorkingDirectory, setCreateForAll, setHotkey, setUninstaller
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

version

private static java.lang.String version
version = "$Id$"


rev

private static java.lang.String rev
rev = "$Revision$"


DESKTOP_EXT

private static java.lang.String DESKTOP_EXT
DESKTOP_EXT = ".desktop"


template

private static java.lang.String template
template = ""


N

private static final java.lang.String N
N = "\n"

See Also:
Constant Field Values

H

private static final java.lang.String H
H = "#"

See Also:
Constant Field Values

S

private static final java.lang.String S
S = " "

See Also:
Constant Field Values

C

private static final java.lang.String C
C = Comment = H+S = "# "

See Also:
Constant Field Values

QM

private static final java.lang.String QM
QM = "\"" : QuotationMark

See Also:
Constant Field Values

ShortcutType

private int ShortcutType

rootScript

private static ShellScript rootScript

uninstallScript

private static ShellScript uninstallScript

users

private java.util.List users

createdDirectory

private java.lang.String createdDirectory
internal String createdDirectory


itsUserType

private int itsUserType
internal int itsUserType


itsGroupName

private java.lang.String itsGroupName
internal String itsGroupName


itsName

private java.lang.String itsName
internal String itsName


itsFileName

private java.lang.String itsFileName
internal String itsFileName


itsApplnkFolder

private java.lang.String itsApplnkFolder
internal String itsApplnkFolder = "applnk"


props

private java.util.Properties props
internal Properties Set


forAll

private java.lang.Boolean forAll
forAll = new Boolean(false): A flag to indicate that this should created for all users.


hlp

public java.lang.StringBuffer hlp
Internal Help Buffer


myInstallScript

public ShellScript myInstallScript
my Install ShellScript


FS

public final java.lang.String FS
Internal Constant: FS = File.separator //


myHome

public final java.lang.String myHome
Internal Constant: myHome = System.getProperty("user.home")


su

public final java.lang.String su
Internal Constant: su = UnixHelper.getSuCommand()


xdgDesktopIconCmd

public final java.lang.String xdgDesktopIconCmd
Internal Constant: xdgDesktopIconCmd = UnixHelper.getCustomCommand("xdg-desktop-icon")


myXdgDesktopIconScript

public java.lang.String myXdgDesktopIconScript

myXdgDesktopIconCmd

public java.lang.String myXdgDesktopIconCmd

writtenFileName

private java.lang.String writtenFileName
Constructor Detail

Unix_Shortcut

public Unix_Shortcut()
Creates a new Unix_Shortcut object.

Method Detail

initProps

private void initProps()
This initialisizes all Properties Values with "".


initialize

public void initialize(int aType,
                       java.lang.String aName)
                throws java.lang.Exception
Overridden Method

Overrides:
initialize in class Shortcut
Parameters:
aType - the type or classification of the program group in which the link should exist.
aName - the name of the shortcut.
Throws:
java.lang.Exception
See Also:
Shortcut.initialize(int, java.lang.String)

supported

public boolean supported()
This indicates that Unix will be supported.

Overrides:
supported in class Shortcut
Returns:
true if the creation of shortcuts is supported, false if this is not supported.
See Also:
Shortcut.supported()

getDirectoryCreated

public java.lang.String getDirectoryCreated()
Dummy

Overrides:
getDirectoryCreated in class Shortcut
Returns:
this implementation returns always null.
See Also:
Shortcut.getDirectoryCreated()

getFileName

public java.lang.String getFileName()
Dummy

Overrides:
getFileName in class Shortcut
Returns:
an empty String
See Also:
Shortcut.getFileName()

getProgramGroups

public java.util.Vector<java.lang.String> getProgramGroups(int userType)
Overridden compatibility method. Returns all directories in $USER/.kde/share/applink.

Overrides:
getProgramGroups in class Shortcut
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:
Shortcut.getProgramGroups(int)

getProgramsFolder

public java.lang.String getProgramsFolder(int current_user)
Gets the Programsfolder for the given User (non-Javadoc).

Overrides:
getProgramsFolder in class Shortcut
Parameters:
current_user - one of current or all
Returns:
The Foldername or null on unsupported platforms.
See Also:
Shortcut.getProgramsFolder(int)

getKdeShareApplnkFolder

private java.io.File getKdeShareApplnkFolder(int userType)
Gets the XDG path to place the menu shortcuts

Parameters:
userType - to get for.
Returns:
handle to the directory

getKdeApplinkFolderName

private java.lang.String getKdeApplinkFolderName()
Gets the name of the applink folder for the currently used distribution. Currently "applnk-redhat for RedHat, "applnk-mdk" for Mandrake, and simply "applnk" for all others.

Returns:
result

getKdeBase

private java.io.File getKdeBase(int userType)
Gets the KDEBasedir for the given User.

Parameters:
userType - one of root or regular user
Returns:
the basedir

multipleUsers

public boolean multipleUsers()
overridden method

Overrides:
multipleUsers in class Shortcut
Returns:
true
See Also:
Shortcut.multipleUsers()

save

public void save()
          throws java.lang.Exception
Creates and stores the shortcut-files.

Overrides:
save in class Shortcut
Throws:
java.lang.Exception - if problems are encountered
See Also:
Shortcut.save()

createExtXdgDesktopIconCmd

public void createExtXdgDesktopIconCmd(java.io.File shortCutLocation)
                                throws java.io.IOException,
                                       ResourceNotFoundException
Ceates Extended Locale Enabled XdgDesktopIcon Command script. Fills the File myXdgDesktopIconScript with the content of com/izforge/izpack/util/os/unix/xdgscript.sh and uses this to creates User Desktop icons

Parameters:
shortCutLocation - in which folder should this stored.
Throws:
java.io.IOException
ResourceNotFoundException

installDesktopFileToAllUsersDesktop

private void installDesktopFileToAllUsersDesktop(java.io.File writtenDesktopFile)
Calls and creates the Install/Unistall Script which installs Desktop Icons using xdgDesktopIconCmd un-/install

Parameters:
writtenDesktopFile - An applications desktop file, which should be installed.

copyDesktopFileToAllUsersDesktop

private void copyDesktopFileToAllUsersDesktop(java.io.File writtenDesktopFile)
                                       throws java.io.IOException
Parameters:
writtenDesktopFile -
Throws:
java.io.IOException

execPostAction

public void execPostAction()
Post Exec Action especially for the Unix Root User. which executes the Root ShortCut Shellscript. to copy all ShellScripts to the users Desktop.

Overrides:
execPostAction in class Shortcut

copyTo

public static void copyTo(java.io.File inFile,
                          java.io.File outFile)
                   throws java.io.IOException
Copies the inFile file to outFile using cbuff as buffer.

Parameters:
inFile - The File to read from.
outFile - The targetFile to write to.
Throws:
java.io.IOException - If an IO Error occurs

getWrittenFileName

public java.lang.String getWrittenFileName()

setWrittenFileName

protected void setWrittenFileName(java.lang.String s)

writeAppShortcut

private java.io.File writeAppShortcut(java.lang.String targetPath,
                                      java.lang.String shortcutName,
                                      java.lang.String shortcutDef)
Write the given ShortDefinition in a File $ShortcutName-$timestamp.desktop in the given TargetPath.

Parameters:
targetPath - The Path in which the files should be written.
shortcutName - The Name for the File
shortcutDef - The Shortcut FileContent
Returns:
The written File

writeAppShortcutWithOutSpace

private java.io.File writeAppShortcutWithOutSpace(java.lang.String targetPath,
                                                  java.lang.String shortcutName,
                                                  java.lang.String shortcutDef)
Write the given ShortDefinition in a File $ShortcutName-$timestamp.desktop in the given TargetPath. ALSO all WhiteSpaces in the ShortCutName will be repalced with "-"

Parameters:
targetPath - The Path in which the files should be written.
shortcutName - The Name for the File
shortcutDef - The Shortcut FileContent
Returns:
The written File

writeAppShortcutWithSimpleSpacehandling

private java.io.File writeAppShortcutWithSimpleSpacehandling(java.lang.String targetPath,
                                                             java.lang.String shortcutName,
                                                             java.lang.String shortcutDef,
                                                             boolean replaceSpacesWithMinus)
Write the given ShortDefinition in a File $ShortcutName-$timestamp.desktop in the given TargetPath. If the given replaceSpaces was true ALSO all WhiteSpaces in the ShortCutName will be replaced with "-"

Parameters:
targetPath - The Path in which the files should be written.
shortcutName - The Name for the File
shortcutDef - The Shortcut FileContent
Returns:
The written File

writeShortCut

private java.io.File writeShortCut(java.lang.String target,
                                   java.lang.String shortCutDef)
Writes the given Shortcutdefinition to the given Target. Returns the written File.

Parameters:
target -
shortCutDef -
Returns:
the File of the written shortcut.

setArguments

public void setArguments(java.lang.String args)
Set the Commandline Arguments

Overrides:
setArguments in class Shortcut
Parameters:
args - the command line arguments
See Also:
Shortcut.setArguments(java.lang.String)

setDescription

public void setDescription(java.lang.String description)
Sets the Description

Overrides:
setDescription in class Shortcut
Parameters:
description - the descriptiojn string
See Also:
Shortcut.setDescription(java.lang.String)

setIconLocation

public void setIconLocation(java.lang.String path,
                            int index)
Sets The Icon Path

Overrides:
setIconLocation in class Shortcut
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.
See Also:
Shortcut.setIconLocation(java.lang.String, int)

setLinkName

public void setLinkName(java.lang.String aName)
Sets the Name of this Shortcut

Overrides:
setLinkName in class Shortcut
Parameters:
aName - The name that the link should display on a menu or on the desktop. Do not include a file extension.
See Also:
Shortcut.setLinkName(java.lang.String)

setLinkType

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

Overrides:
setLinkType in class Shortcut
Parameters:
aType - 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
See Also:
Shortcut.setLinkType(int)

setProgramGroup

public void setProgramGroup(java.lang.String aGroupName)
Sets the ProgramGroup

Overrides:
setProgramGroup in class Shortcut
Parameters:
aGroupName - the name of the program group
See Also:
Shortcut.setProgramGroup(java.lang.String)

setShowCommand

public void setShowCommand(int show)
Sets the ShowMode

Overrides:
setShowCommand in class Shortcut
Parameters:
show - the show command. Valid settings are:
See Also:
Shortcut.setShowCommand(int)

setTargetPath

public void setTargetPath(java.lang.String aPath)
Sets The TargetPath

Overrides:
setTargetPath in class Shortcut
Parameters:
aPath - the fully qualified file name of the target
See Also:
Shortcut.setTargetPath(java.lang.String)

setUserType

public void setUserType(int aUserType)
Sets the usertype.

Overrides:
setUserType in class Shortcut
Parameters:
aUserType - the type of user for the link.
See Also:
Shortcut.setUserType(int)

setWorkingDirectory

public void setWorkingDirectory(java.lang.String aDirectory)
Sets the working-directory

Overrides:
setWorkingDirectory in class Shortcut
Parameters:
aDirectory - the working directory
See Also:
Shortcut.setWorkingDirectory(java.lang.String)

toString

public java.lang.String toString()
Dumps the Name to console.

Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

replace

public java.lang.String replace()
Creates the Shortcut String which will be stored as File.

Returns:
contents of the shortcut file

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException,
                        ResourceNotFoundException
Test Method

Parameters:
args -
Throws:
java.io.IOException
ResourceNotFoundException

setEncoding

public void setEncoding(java.lang.String aEncoding)
Sets The Encoding

Overrides:
setEncoding in class Shortcut
See Also:
Shortcut.setEncoding(java.lang.String)

setKdeSubstUID

public void setKdeSubstUID(java.lang.String trueFalseOrNothing)
Sets The KDE Specific subst UID property

Overrides:
setKdeSubstUID in class Shortcut
Parameters:
trueFalseOrNothing - exactly "true" or "false" or nothing
See Also:
Shortcut.setKdeSubstUID(java.lang.String)

setKdeUserName

public void setKdeUserName(java.lang.String aUserName)
Sets The KDE Specific subst UID property

Overrides:
setKdeUserName in class Shortcut
Parameters:
aUserName - The UserName
See Also:
Shortcut.setKdeSubstUID(java.lang.String)

setMimetype

public void setMimetype(java.lang.String aMimetype)
Sets the MimeType

Overrides:
setMimetype in class Shortcut
See Also:
Shortcut.setMimetype(java.lang.String)

setTerminal

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

Overrides:
setTerminal in class Shortcut
See Also:
Shortcut.setTerminal(java.lang.String)

setTerminalOptions

public void setTerminalOptions(java.lang.String someTerminalOptions)
Sets the terminal options

Overrides:
setTerminalOptions in class Shortcut
See Also:
Shortcut.setTerminalOptions(java.lang.String)

setType

public void setType(java.lang.String aType)
Sets the Shortcut type (one of Application, Link or Device)

Overrides:
setType in class Shortcut
See Also:
Shortcut.setType(java.lang.String)

setURL

public void setURL(java.lang.String anUrl)
Sets the Url for type Link. Can be also a apsolute file/path

Overrides:
setURL in class Shortcut
See Also:
Shortcut.setURL(java.lang.String)

getUserType

public int getUserType()
Gets the Usertype of the Shortcut.

Overrides:
getUserType in class Shortcut
Returns:
userType
See Also:
Shortcut.getUserType()

setCategories

public void setCategories(java.lang.String theCategories)
Sets the Categories Field

Overrides:
setCategories in class Shortcut
Parameters:
theCategories - the categories

setTryExec

public void setTryExec(java.lang.String aTryExec)
Sets the TryExecField.

Overrides:
setTryExec in class Shortcut
Parameters:
aTryExec - the try exec command

getLinkType

public int getLinkType()
Description copied from class: Shortcut
Gets the type of link types are:

Overrides:
getLinkType in class Shortcut

getUsers

private java.util.List getUsers()