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; }
/** * 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); }
/** * 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; }
/** * 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); }
/** * 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();