Excise additional samskivert code.

This commit is contained in:
Michael Bayne
2018-09-14 14:48:58 -07:00
parent 24a23637a7
commit 2f0eae9753
6 changed files with 82 additions and 29 deletions
@@ -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 <code>MessageFormat</code>.
* As we assume all single quotes are to be escaped, we cannot use the characters
* <code>{</code> and <code>}</code> 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
* <code>MessageFormat</code> 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 = "~";
@@ -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;
/**
@@ -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;
@@ -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 };
@@ -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;
/**
@@ -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}. */