From 2f0eae9753f396ac7fcd4af63ff057448b605eb9 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 14 Sep 2018 14:48:58 -0700 Subject: [PATCH] Excise additional samskivert code. --- .../threerings/getdown/util/MessageUtil.java | 76 ++++++++++++++++--- .../getdown/launcher/AbortPanel.java | 2 +- .../threerings/getdown/launcher/Getdown.java | 7 +- .../getdown/launcher/GetdownApp.java | 10 +-- .../getdown/launcher/ProxyPanel.java | 2 +- .../getdown/launcher/StatusPanel.java | 14 ++-- 6 files changed, 82 insertions(+), 29 deletions(-) diff --git a/core/src/main/java/com/threerings/getdown/util/MessageUtil.java b/core/src/main/java/com/threerings/getdown/util/MessageUtil.java index 1ecc828..41d9e9e 100644 --- a/core/src/main/java/com/threerings/getdown/util/MessageUtil.java +++ b/core/src/main/java/com/threerings/getdown/util/MessageUtil.java @@ -7,6 +7,34 @@ package com.threerings.getdown.util; public class MessageUtil { + /** + * Returns whether or not the provided string is tainted. See {@link #taint}. Null strings + * are considered untainted. + */ + public static boolean isTainted (String text) + { + return text != null && text.startsWith(TAINT_CHAR); + } + + /** + * Call this to "taint" any string that has been entered by an entity outside the application + * so that the translation code knows not to attempt to translate this string when doing + * recursive translations. + */ + public static String taint (Object text) + { + return TAINT_CHAR + text; + } + + /** + * Removes the tainting character added to a string by {@link #taint}. If the provided string + * is not tainted, this silently returns the originally provided string. + */ + public static String untaint (String text) + { + return isTainted(text) ? text.substring(TAINT_CHAR.length()) : text; + } + /** * Composes a message key with an array of arguments. The message can subsequently be * decomposed and translated without prior knowledge of how many arguments were provided. @@ -46,16 +74,6 @@ public class MessageUtil { return compose(key, (Object[]) args); } - /** - * Call this to "taint" any string that has been entered by an entity outside the application - * so that the translation code knows not to attempt to translate this string when doing - * recursive translations. - */ - public static String taint (Object text) - { - return TAINT_CHAR + text; - } - /** * A convenience method for calling {@link #compose(String,Object[])} with an array of * arguments that will be automatically tainted (see {@link #taint}). @@ -82,6 +100,44 @@ public class MessageUtil { return compose(key, args); } + /** + * Used to escape single quotes so that they are not interpreted by MessageFormat. + * As we assume all single quotes are to be escaped, we cannot use the characters + * { and } in our translation strings, but this is a small price to + * pay to have to differentiate between messages that will and won't eventually be parsed by a + * MessageFormat instance. + */ + public static String escape (String message) + { + return message.replace("'", "''"); + } + + /** + * Unescapes characters that are escaped in a call to compose. + */ + public static String unescape (String value) + { + int bsidx = value.indexOf('\\'); + if (bsidx == -1) { + return value; + } + + StringBuilder buf = new StringBuilder(); + int vlength = value.length(); + for (int ii = 0; ii < vlength; ii++) { + char ch = value.charAt(ii); + if (ch != '\\' || ii == vlength-1) { + buf.append(ch); + } else { + // look at the next character + ch = value.charAt(++ii); + buf.append((ch == '!') ? '|' : ch); + } + } + + return buf.toString(); + } + /** Text prefixed by this character will be considered tainted when doing recursive * translations and won't be translated. */ protected static final String TAINT_CHAR = "~"; diff --git a/launcher/src/main/java/com/threerings/getdown/launcher/AbortPanel.java b/launcher/src/main/java/com/threerings/getdown/launcher/AbortPanel.java index ff7fe68..16b2eb2 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/AbortPanel.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/AbortPanel.java @@ -21,8 +21,8 @@ import javax.swing.JPanel; import com.samskivert.swing.GroupLayout; import com.samskivert.swing.Spacer; import com.samskivert.swing.VGroupLayout; -import com.samskivert.text.MessageUtil; +import com.threerings.getdown.util.MessageUtil; import static com.threerings.getdown.Log.log; /** diff --git a/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java b/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java index 48e7ff3..1718107 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java @@ -41,9 +41,6 @@ import ca.beq.util.win32.registry.RegistryValue; import ca.beq.util.win32.registry.RootKey; import com.samskivert.swing.util.SwingUtil; -import com.samskivert.text.MessageUtil; -import com.samskivert.util.RunAnywhere; -import com.samskivert.util.StringUtil; import com.threerings.getdown.data.Application.UpdateInterface.Step; import com.threerings.getdown.data.Application; @@ -57,8 +54,10 @@ import com.threerings.getdown.util.Config; import com.threerings.getdown.util.ConnectionUtil; import com.threerings.getdown.util.FileUtil; import com.threerings.getdown.util.LaunchUtil; +import com.threerings.getdown.util.MessageUtil; import com.threerings.getdown.util.ProgressAggregator; import com.threerings.getdown.util.ProgressObserver; +import com.threerings.getdown.util.StringUtil; import com.threerings.getdown.util.VersionUtil; import static com.threerings.getdown.Log.log; @@ -239,7 +238,7 @@ public abstract class Getdown extends Thread } // look in the Vinders registry - if (RunAnywhere.isWindows()) { + if (LaunchUtil.isWindows()) { try { String host = null, port = null; boolean enabled = false; diff --git a/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java b/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java index 90ab720..2dbb507 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java @@ -29,11 +29,9 @@ import javax.swing.JFrame; import javax.swing.WindowConstants; import com.samskivert.swing.util.SwingUtil; -import com.samskivert.util.ArrayUtil; -import com.samskivert.util.RunAnywhere; - import com.threerings.getdown.data.Digest; import com.threerings.getdown.data.SysProps; +import com.threerings.getdown.util.LaunchUtil; import com.threerings.getdown.util.StringUtil; import static com.threerings.getdown.Log.log; @@ -79,7 +77,7 @@ public class GetdownApp // pass along anything after that as app args String[] appArgs = (aidx >= args.size()) ? null : - args.subList(aidx, args.size()).toArray(ArrayUtil.EMPTY_STRING); + args.subList(aidx, args.size()).toArray(new String[0]); // ensure a valid directory was supplied File appDir = new File(adarg); @@ -200,7 +198,7 @@ public class GetdownApp return; } String[] cmdarray; - if (RunAnywhere.isWindows()) { + if (LaunchUtil.isWindows()) { String osName = System.getProperty("os.name", ""); if (osName.indexOf("9") != -1 || osName.indexOf("Me") != -1) { cmdarray = new String[] { @@ -209,7 +207,7 @@ public class GetdownApp cmdarray = new String[] { "cmd.exe", "/c", "start", "\"\"", "\"" + url + "\"" }; } - } else if (RunAnywhere.isMacOS()) { + } else if (LaunchUtil.isMacOS()) { cmdarray = new String[] { "open", url }; } else { // Linux, Solaris, etc. cmdarray = new String[] { "firefox", url }; diff --git a/launcher/src/main/java/com/threerings/getdown/launcher/ProxyPanel.java b/launcher/src/main/java/com/threerings/getdown/launcher/ProxyPanel.java index 0982c15..341bff4 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/ProxyPanel.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/ProxyPanel.java @@ -22,8 +22,8 @@ import javax.swing.JTextField; import com.samskivert.swing.GroupLayout; import com.samskivert.swing.Spacer; import com.samskivert.swing.VGroupLayout; -import com.samskivert.text.MessageUtil; +import com.threerings.getdown.util.MessageUtil; import static com.threerings.getdown.Log.log; /** diff --git a/launcher/src/main/java/com/threerings/getdown/launcher/StatusPanel.java b/launcher/src/main/java/com/threerings/getdown/launcher/StatusPanel.java index cfaa21e..b171861 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/StatusPanel.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/StatusPanel.java @@ -15,6 +15,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.ImageObserver; import java.text.MessageFormat; +import java.util.Arrays; import java.util.MissingResourceException; import java.util.ResourceBundle; @@ -24,12 +25,12 @@ import javax.swing.Timer; import com.samskivert.swing.Label; import com.samskivert.swing.LabelStyleConstants; import com.samskivert.swing.util.SwingUtil; -import com.samskivert.text.MessageUtil; -import com.samskivert.util.StringUtil; import com.samskivert.util.Throttle; import com.threerings.getdown.data.Application.UpdateInterface; +import com.threerings.getdown.util.MessageUtil; import com.threerings.getdown.util.Rectangle; +import com.threerings.getdown.util.StringUtil; import static com.threerings.getdown.Log.log; @@ -323,7 +324,7 @@ public final class StatusPanel extends JComponent } else { String key = compoundKey.substring(0, tidx); String argstr = compoundKey.substring(tidx+1); - String[] args = StringUtil.split(argstr, "|"); + String[] args = argstr.split("\\|"); // unescape and translate the arguments for (int i = 0; i < args.length; i++) { // if the argument is tainted, do no further translation @@ -339,12 +340,11 @@ public final class StatusPanel extends JComponent } /** Used by {@link #setStatus}. */ - protected String get (String key, Object[] args) + protected String get (String key, String[] args) { String msg = get(key); - return (msg != null) ? - MessageFormat.format(MessageUtil.escape(msg), args) - : (key + StringUtil.toString(args)); + if (msg != null) return MessageFormat.format(MessageUtil.escape(msg), (Object[])args); + return key + String.valueOf(Arrays.asList(args)); } /** Used by {@link #setStatus}, and {@link #setProgress}. */