private String createXDGDirectory(String menuName, String icon, String comment) { String menuDirectoryDescriptor = "[Desktop Entry]\n" + "Name=$Name\n" + "Comment=$Comment\n" + "Icon=$Icon\n" + "Type=Directory\n" + "Encoding=UTF-8"; menuDirectoryDescriptor = StringTool.replace(menuDirectoryDescriptor, "$Name", menuName); menuDirectoryDescriptor = StringTool.replace(menuDirectoryDescriptor, "$Comment", comment); menuDirectoryDescriptor = StringTool.replace(menuDirectoryDescriptor, "$Icon", icon); return menuDirectoryDescriptor; }
/** * Transforms a (Array)List of Strings into a line.separator="\n" separated Stringlist. * * @param aStringList * @return a printable list */ public static String listToString(List<?> aStringList) { return listToString(aStringList, null); }
/** * Normalizes a mixed Windows/Unix Path. Does Only work for Windows or Unix Pathes Reason: * Java.File accepts / or \ for Pathes. Batches or ShellScripts does it not! * * @param destination accepted mixed form by java.File like "C:/a/mixed\path\accepted/by\Java" * @return the normalized Path */ public static String normalizePath(String destination) { return (normalizePath(destination, null)); }
if (StringTool.startsWithIgnoreCase(name, OsVersionConstants.FREEBSD)) else if (StringTool.startsWithIgnoreCase(name, OsVersionConstants.LINUX)) else if (StringTool.startsWithIgnoreCase(name, OsVersionConstants.HP_UX)) else if (StringTool.startsWithIgnoreCase(name, OsVersionConstants.AIX)) else if (StringTool.startsWithIgnoreCase(name, OsVersionConstants.SUNOS) || StringTool.startsWithIgnoreCase(name, OsVersionConstants.SOLARIS)) else if (StringTool.startsWith(name, OsVersionConstants.OS_2)) else if (StringTool.startsWithIgnoreCase(name, OsVersionConstants.MACOSX)) else if (StringTool.startsWith(name, OsVersionConstants.MAC)) else if (StringTool.startsWith(name, OsVersionConstants.WINDOWS))
/** * Escapes all white Space Characters * * @param aPathString * @return */ public static String escapeSpaces(String aPathString) { return replaceOrEscapeAll(aPathString, null, null, true); }
StringTool.escapeSpaces(writtenDesktopFile.toString()) + "\""}); StringTool.escapeSpaces(writtenDesktopFile.toString()) + "\""});
/** * Escapes all white Space Characters * * @param aPathString * @return */ public static String replaceSpacesWithMinus(String aPathString) { return replaceSpaces(aPathString, "-"); }
try result = new String(shortcut.getLinkPath(USER).getBytes(StringTool.getPlatformEncoding()), StringTool.getPlatformEncoding());
/** * 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 "-" * * @param targetPath The Path in which the files should be written. * @param shortcutName The Name for the File * @param shortcutDef The Shortcut FileContent * @return The written File */ private File writeAppShortcutWithSimpleSpacehandling(String targetPath, String shortcutName, String shortcutDef, boolean replaceSpacesWithMinus) { File shortcutFile = new File( FilenameUtils.getFullPathNoEndSeparator(targetPath) + '/' + (replaceSpacesWithMinus ? StringTool.replaceSpacesWithMinus(shortcutName) : shortcutName) + DESKTOP_EXT); try { FileUtils.writeStringToFile(shortcutFile, shortcutDef); } catch (IOException e) { logger.warning("Application shortcut could not be created (" + e.getMessage() + ")"); } return shortcutFile; }
/** * Escapes all white Space Characters * * @param aPathString * @return */ public static String replaceSpaces(String aPathString, String replaceWith) { return replaceOrEscapeAll(aPathString, replaceWith, null, false); }
"install", "--novendor", StringTool.escapeSpaces(writtenDesktopFile.toString())}; String[] uninstallCmd = new String[]{ makeFilenameScriptable(myXdgDesktopIconCmd), "uninstall", "--novendor", StringTool.escapeSpaces(writtenDesktopFile.toString())}; StringTool.escapeSpaces(myDesktopFile.getPath())}); StringTool.escapeSpaces(myDesktopFile.getPath())});
/** * Replaces <b>from</b> with <b>to</b> in given String: <b>value</b> * * @param value original String * @param from Search Pattern * @param to Replace with this * @return the replaced String */ public static String replace(String value, String from, String to) { return replace(value, from, to, true); }
public int relaunchWithElevatedRights(String ... args) throws Exception { if(!platform.isA(WINDOWS)) { throw new Exception("Installer should be run as admin"); } String javaCommand = getJavaCommand(args); String installer = getInstallerJar(); ProcessBuilder builder = new ProcessBuilder(getElevator(javaCommand, installer, args)); if (logger.isLoggable(Level.INFO)) { logger.info("Relaunching: " + StringTool.listToString(builder.command(), " ")); } builder.environment().put("izpack.mode", "privileged"); Process process = builder.start(); return process.waitFor(); }
/** * Replaces all given white Space Characters with the replaceOrEscapeWith or Escapes with replaceOrEscapeWith * <p/> * If true was given as Escape-Flag , the Method escapes each whitespace with the replaceOrEscapeWith + replaceWhat[x] * Otherwise the replaces each replaceWhat[x] with the replaceOrEscapeWith. * * @param aPathString The input string in which the white space should be handled. * @param replaceOrEscapeWith The Repace or Escape Char Interpreted depended on the escape Flag * @param replaceWhat The atring array with the Characters, which should be replaced * @param escape The flag, wihch indeicates, how to handle the given replaceOrEscapeWith String. */ public static String replaceOrEscapeAll(String aPathString, String replaceOrEscapeWith, String[] replaceWhat, boolean escape) { if (replaceWhat == null) { replaceWhat = new String[]{" ", "\t", "\n"}; } if (replaceOrEscapeWith == null) { replaceOrEscapeWith = "\\"; } for (String aReplaceWhat : replaceWhat) { aPathString = replace(aPathString, aReplaceWhat, escape == true ? replaceOrEscapeWith + aReplaceWhat : replaceOrEscapeWith); } return aPathString; }
/** * Test main Method * * @param args from Commandline */ public static void main(String[] args) { System.out.println("UnixUsers:"); UnixUsers users = new UnixUsers(); // users.fromUsersArrayList(); for (Object user : users) { System.out.println(((UnixUser) user).getName()); } System.out.println(StringTool .listToString(getUsersWithValidShellsExistingHomesAndDesktops())); // getUsersWithValidShellsAndExistingHomes(); } }
/** * Normalizes a Windows or Unix Path. * <p/> * Reason: Javas File accepts / or \ for Pathes. Batches or ShellScripts does it not! * <p/> * TODO: implement support for MAC < MacOSX * * @param destination * @param fileSeparator a target-system fileseparator * @return the normalized path */ public static String normalizePath(String destination, String fileSeparator) { String FILESEP = (fileSeparator == null) ? File.separator : fileSeparator; destination = StringTool.replace(destination, "\\", "/"); // all occs of "//" by "/" destination = StringTool.replace(destination, "//", "/"); destination = StringTool.replace(destination, ":", ";"); destination = StringTool.replace(destination, ";", ":"); destination = StringTool.replace(destination, "/", FILESEP); if ("\\".equals(FILESEP)) { destination = StringTool.replace(destination, ":", ";"); // results in "C;\" instead of "C:\" // so correct it: destination = StringTool.replace(destination, ";\\", ":\\"); } // Convert the file separator characters return (destination); }
result = SUSE + SP + LINUX + NL + StringTool.listToString(FileUtil.getFileContent(getReleaseFileName())); result = REDHAT + SP + LINUX + NL + StringTool.listToString(FileUtil.getFileContent(getReleaseFileName())); + StringTool.listToString(FileUtil.getFileContent(getReleaseFileName())); + StringTool.listToString(FileUtil.getFileContent(getReleaseFileName())); + StringTool.listToString(FileUtil.getFileContent(getReleaseFileName())); + StringTool.listToString(FileUtil.getFileContent("/etc/debian_version")); + StringTool.listToString(FileUtil.getFileContent(getReleaseFileName()));
/** * Helper to format a message to create shortcuts for the current platform. * * @return a formatted message */ public String getCreateShortcutsPrompt() { Messages messages = installData.getMessages(); String menuKind = messages.get("ShortcutPanel.regular.StartMenu:Start-Menu"); if (installData.getPlatform().isA(UNIX) && UnixHelper.kdeIsInstalled()) { menuKind = messages.get("ShortcutPanel.regular.StartMenu:K-Menu"); } return StringTool.replace(messages.get("ShortcutPanel.regular.create"), "StartMenu", menuKind); }
rootScript.append(tempFile.toString()); rootScript.append(S); rootScript.append(StringTool.replace(dest.toString(), " ", "\\ ")); rootScript.appendln('"'); rootScript.append(user.getName()); rootScript.append(S); rootScript.appendln(StringTool.replace(dest.toString(), " ", "\\ ")); rootScript.append('\n'); rootScript.append('\n'); uninstallScript.append(rm); uninstallScript.append(S); uninstallScript.append(StringTool.replace(dest.toString(), " ", "\\ ")); uninstallScript.appendln('"'); uninstallScript.appendln();