Package net.sourceforge.jnlp.util
Class XDesktopEntry
- java.lang.Object
-
- net.sourceforge.jnlp.util.XDesktopEntry
-
- All Implemented Interfaces:
GenericDesktopEntry
public class XDesktopEntry extends java.lang.Object implements GenericDesktopEntry
This class builds a (freedesktop.org) desktop entry out of aJNLPFile. This entry can be used to install desktop shortcuts. See xdg-desktop-icon (1) and http://standards.freedesktop.org/desktop-entry-spec/latest/ for more information
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classXDesktopEntry.NonFileProtocolException
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String[]BROWSERSstatic java.lang.StringFAVICONprivate JNLPFilefileprivate static java.lang.StringGIFprivate java.lang.StringiconLocationprivate inticonSizeprivate static java.lang.StringJPEGprivate static java.lang.StringJPGprivate static LoggerLOGprivate static java.lang.StringMICprivate static java.lang.StringPNGprivate static int[]VALID_ICON_SIZES(package private) static java.lang.StringXDG_DESKTOP_DIR
-
Constructor Summary
Constructors Constructor Description XDesktopEntry(JNLPFile file)Create a XDesktopEntry for the given JNLP file
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) java.lang.StringcacheAndGetIconLocation()private voidcacheIcon()Cache the icon for the desktop entryprivate voidcantCache()private java.io.FileconvertToIco(java.io.File source, java.lang.String targetName)voidcreateDesktopShortcuts(AccessWarningPaneComplexReturn.ShortcutResult menu, AccessWarningPaneComplexReturn.ShortcutResult desktop)Create a desktop shortcut for this desktop entryvoidcreateShortcutOnWindowsDesktop()voidcreateWindowsMenu()private static java.io.FiledownloadFavIcon(JNLPFile file)private static java.lang.StringevaluateLinuxVariables(java.lang.String orig)private static java.lang.StringevaluateLinuxVariables(java.lang.String orig, java.util.Map<java.lang.String,java.lang.String> variables)private static java.net.URLfavUrl(java.lang.String delimiter, java.lang.String path, JNLPFile file)private static java.lang.StringfilterQuotes(java.lang.String string)private static java.lang.StringfindAndVerifyBasicDir(java.io.File f, java.lang.String message)private static java.lang.StringfindAndVerifyGeneratedJnlpDir()private static java.lang.StringfindAndVerifyJavawsMenuDir()private static java.lang.StringfindFreedesktopOrgDesktopPath()Instead of having all this parsing of user-dirs.dirs and replacing variables we can execute `echo $(xdg-user-dir DESKTOP)` and it will do all the job in case approaches below become failingstatic java.lang.StringfindFreedesktopOrgDesktopPathCatch()static java.lang.StringgetBrowserBin()(package private) java.lang.StringgetContent(boolean menu, AccessWarningPaneComplexReturn.ShortcutResult info)Returns the contents of theXDesktopEntryas a String.(package private) static java.io.FilegetDesktop()java.io.FilegetDesktopIconFile()(package private) static java.lang.StringgetFreedesktopOrgDesktopPathFrom(java.io.BufferedReader r)private static java.lang.StringgetFreedesktopOrgDesktopPathFrom(java.io.File userDirs)java.io.FilegetGeneratedJnlpFileName()java.io.FilegetLinuxMenuIconFile()private java.lang.StringgetShortcutFileName()private java.lang.StringgetShortcutName()(package private) java.io.FilegetShortcutTmpFile()private java.lang.StringgetUniqueIconName(java.lang.String iconName)private voidinstallDesktopLauncher(AccessWarningPaneComplexReturn.ShortcutResult info)Install this XDesktopEntry into the user's desktop as a launcher.private voidinstallMenuLauncher(AccessWarningPaneComplexReturn.ShortcutResult info)Install this XDesktopEntry into the user's menu.(package private) static java.util.List<java.lang.String>possibleFavIconLocations(java.lang.String path)voidrefreshExistingShortcuts(boolean desktop, boolean menu)private static java.lang.Stringsanitize(java.lang.String input)Sanitizes a string so that it can be used safely in a key=value pair in a desktop entry file.
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
file
private JNLPFile file
-
iconSize
private int iconSize
-
iconLocation
private java.lang.String iconLocation
-
VALID_ICON_SIZES
private static final int[] VALID_ICON_SIZES
-
GIF
private static final java.lang.String GIF
- See Also:
- Constant Field Values
-
JPG
private static final java.lang.String JPG
- See Also:
- Constant Field Values
-
JPEG
private static final java.lang.String JPEG
- See Also:
- Constant Field Values
-
PNG
private static final java.lang.String PNG
- See Also:
- Constant Field Values
-
BROWSERS
public static final java.lang.String[] BROWSERS
-
FAVICON
public static final java.lang.String FAVICON
- See Also:
- Constant Field Values
-
XDG_DESKTOP_DIR
static final java.lang.String XDG_DESKTOP_DIR
- See Also:
- Constant Field Values
-
MIC
private static final java.lang.String MIC
- See Also:
- Constant Field Values
-
-
Method Detail
-
getContent
java.lang.String getContent(boolean menu, AccessWarningPaneComplexReturn.ShortcutResult info)Returns the contents of theXDesktopEntryas a String.- Parameters:
menu- whether to create this icon to menuinfo- result of user's interference- Returns:
- string with desktop shortcut specification
-
getBrowserBin
public static java.lang.String getBrowserBin()
-
sanitize
private static java.lang.String sanitize(java.lang.String input)
Sanitizes a string so that it can be used safely in a key=value pair in a desktop entry file.- Parameters:
input- a String to sanitize- Returns:
- a string safe to use as either the key or the value in the key=value pair in a desktop entry file
-
getShortcutTmpFile
java.io.File getShortcutTmpFile()
-
createDesktopShortcuts
public void createDesktopShortcuts(AccessWarningPaneComplexReturn.ShortcutResult menu, AccessWarningPaneComplexReturn.ShortcutResult desktop)
Create a desktop shortcut for this desktop entry- Specified by:
createDesktopShortcutsin interfaceGenericDesktopEntry- Parameters:
menu- how to create in menudesktop- how to create on desktop
-
installMenuLauncher
private void installMenuLauncher(AccessWarningPaneComplexReturn.ShortcutResult info)
Install this XDesktopEntry into the user's menu.
-
installDesktopLauncher
private void installDesktopLauncher(AccessWarningPaneComplexReturn.ShortcutResult info)
Install this XDesktopEntry into the user's desktop as a launcher.
-
refreshExistingShortcuts
public void refreshExistingShortcuts(boolean desktop, boolean menu)- Specified by:
refreshExistingShortcutsin interfaceGenericDesktopEntry
-
getGeneratedJnlpFileName
public java.io.File getGeneratedJnlpFileName()
- Specified by:
getGeneratedJnlpFileNamein interfaceGenericDesktopEntry
-
cacheIcon
private void cacheIcon() throws java.io.IOException, XDesktopEntry.NonFileProtocolExceptionCache the icon for the desktop entry- Throws:
java.io.IOExceptionXDesktopEntry.NonFileProtocolException
-
getUniqueIconName
private java.lang.String getUniqueIconName(java.lang.String iconName)
-
convertToIco
private java.io.File convertToIco(java.io.File source, java.lang.String targetName)
-
cacheAndGetIconLocation
java.lang.String cacheAndGetIconLocation()
-
possibleFavIconLocations
static java.util.List<java.lang.String> possibleFavIconLocations(java.lang.String path)
-
favUrl
private static java.net.URL favUrl(java.lang.String delimiter, java.lang.String path, JNLPFile file) throws java.net.MalformedURLException- Throws:
java.net.MalformedURLException
-
downloadFavIcon
private static java.io.File downloadFavIcon(JNLPFile file)
-
cantCache
private void cantCache() throws XDesktopEntry.NonFileProtocolException
-
getShortcutName
private java.lang.String getShortcutName()
-
getDesktopIconFile
public java.io.File getDesktopIconFile()
- Specified by:
getDesktopIconFilein interfaceGenericDesktopEntry
-
getDesktop
static java.io.File getDesktop()
-
getLinuxMenuIconFile
public java.io.File getLinuxMenuIconFile()
- Specified by:
getLinuxMenuIconFilein interfaceGenericDesktopEntry
-
getShortcutFileName
private java.lang.String getShortcutFileName()
-
findAndVerifyGeneratedJnlpDir
private static java.lang.String findAndVerifyGeneratedJnlpDir()
-
findAndVerifyJavawsMenuDir
private static java.lang.String findAndVerifyJavawsMenuDir()
-
findAndVerifyBasicDir
private static java.lang.String findAndVerifyBasicDir(java.io.File f, java.lang.String message)
-
findFreedesktopOrgDesktopPathCatch
public static java.lang.String findFreedesktopOrgDesktopPathCatch()
-
findFreedesktopOrgDesktopPath
private static java.lang.String findFreedesktopOrgDesktopPath() throws java.io.IOExceptionInstead of having all this parsing of user-dirs.dirs and replacing variables we can execute `echo $(xdg-user-dir DESKTOP)` and it will do all the job in case approaches below become failing- Returns:
- variables (if declared) and quotation marks (unless escaped) free path
- Throws:
java.io.IOException- if no file do not exists or key with desktop do not exists
-
getFreedesktopOrgDesktopPathFrom
private static java.lang.String getFreedesktopOrgDesktopPathFrom(java.io.File userDirs) throws java.io.IOException- Throws:
java.io.IOException
-
getFreedesktopOrgDesktopPathFrom
static java.lang.String getFreedesktopOrgDesktopPathFrom(java.io.BufferedReader r) throws java.io.IOException- Throws:
java.io.IOException
-
filterQuotes
private static java.lang.String filterQuotes(java.lang.String string)
-
evaluateLinuxVariables
private static java.lang.String evaluateLinuxVariables(java.lang.String orig)
-
evaluateLinuxVariables
private static java.lang.String evaluateLinuxVariables(java.lang.String orig, java.util.Map<java.lang.String,java.lang.String> variables)
-
createShortcutOnWindowsDesktop
public void createShortcutOnWindowsDesktop()
- Specified by:
createShortcutOnWindowsDesktopin interfaceGenericDesktopEntry
-
createWindowsMenu
public void createWindowsMenu()
- Specified by:
createWindowsMenuin interfaceGenericDesktopEntry
-
-