Class ApplicationUtil
- java.lang.Object
-
- ch.supertomcat.supertomcatutils.application.ApplicationUtil
-
public final class ApplicationUtil extends Object
Utility class to initialize an application
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intcompareVersions(String v1, String v2)Compares two Version-Stringsstatic JFramecreateInvisibleFrame(String title)Create invisible frame, which can be used as parent for JOptionPane dialogs, so that the message is displayed in the taskbarstatic JFramecreateInvisibleFrame(String title, Image icon)Create invisible frame, which can be used as parent for JOptionPane dialogs, so that the message is displayed in the taskbarstatic voiddeleteOldBackupFiles(File folder, String filename, int daysToKeepBackup)Deletes old backup filesstatic voiddeleteOldLogFiles(int days, String logFileName, String logPath)static StringformatStackTrace(Throwable throwable)Format Stacktrace to Stringstatic FileLockgetLockFile()static StringgetThisApplicationsJarFilename(Class<?> classInJarFile)Returns the filename of this application's Jar File or an empty string, if the filename could not be detectedstatic StringgetThisApplicationsPath(String jarFilename)Returns the path of this applicationstatic voidinitializeSLF4JUncaughtExceptionHandler()Sets the default UncaughtExceptionHandler to a handler, which logs exceptions to SLF4Jstatic booleanlockLockFile(String strLockFilePath, String strLockFilename)Try to lock the lockfilestatic voidlogApplicationInfo()Logs application infostatic booleanreleaseLockFile()Release lock filestatic voidwriteBasicErrorLogfile(File file, String errorMessage)Writes an error logfile for the case when no Loggers are initialized.
-
-
-
Method Detail
-
getThisApplicationsPath
public static String getThisApplicationsPath(String jarFilename)
Returns the path of this application- Parameters:
jarFilename- Filename of the Jar- Returns:
- Path
-
getThisApplicationsJarFilename
public static String getThisApplicationsJarFilename(Class<?> classInJarFile)
Returns the filename of this application's Jar File or an empty string, if the filename could not be detected- Parameters:
classInJarFile- Class which is in Jar File- Returns:
- Jar Filename or an empty String
-
compareVersions
public static int compareVersions(String v1, String v2)
Compares two Version-Strings- Parameters:
v1- First Version-Stringv2- Second Version-String- Returns:
- 0 or less than 0 or more than 0
-
lockLockFile
public static boolean lockLockFile(String strLockFilePath, String strLockFilename)
Try to lock the lockfile- Parameters:
strLockFilePath- Lockfile PathstrLockFilename- Lockfile Filename- Returns:
- True if successful
-
releaseLockFile
public static boolean releaseLockFile()
Release lock file- Returns:
- True if successful, false otherwise
-
getLockFile
public static FileLock getLockFile()
- Returns:
- FileLock or null
-
deleteOldLogFiles
public static void deleteOldLogFiles(int days, String logFileName, String logPath)- Parameters:
days- DayslogFileName- Logfile NamelogPath- Logfile Path
-
initializeSLF4JUncaughtExceptionHandler
public static void initializeSLF4JUncaughtExceptionHandler()
Sets the default UncaughtExceptionHandler to a handler, which logs exceptions to SLF4J
-
logApplicationInfo
public static void logApplicationInfo()
Logs application info
-
writeBasicErrorLogfile
public static void writeBasicErrorLogfile(File file, String errorMessage)
Writes an error logfile for the case when no Loggers are initialized. If an Exception occurs while writing the file, the Stacktrace is printed to the console.- Parameters:
file- FileerrorMessage- Error Message
-
deleteOldBackupFiles
public static void deleteOldBackupFiles(File folder, String filename, int daysToKeepBackup)
Deletes old backup files- Parameters:
folder- Folderfilename- FilenamedaysToKeepBackup- Days to keep backups
-
createInvisibleFrame
public static JFrame createInvisibleFrame(String title)
Create invisible frame, which can be used as parent for JOptionPane dialogs, so that the message is displayed in the taskbar- Parameters:
title- Window Title- Returns:
- Invisible Frame
-
createInvisibleFrame
public static JFrame createInvisibleFrame(String title, Image icon)
Create invisible frame, which can be used as parent for JOptionPane dialogs, so that the message is displayed in the taskbar- Parameters:
title- Window Titleicon- Icon- Returns:
- Invisible Frame
-
-