package soph.collab.util;

import java.net.URLEncoder;

public final class StringUtils {

    /**
     * Escape the given as HTML.
     * Newlines are converted to <code>&lt;br/&gt;</code>.
     * Ampersands are converted to <code>&amp;amp;</code>.
     * Double quotes are converted to <code>&amp;quot;</code>.
     * Less than signs are converted to <code>&amp;lt;</code>.
     * Greater than signs are converted to <code>&amp;gt;</code>.
     *
     * @param s text to escape
     * @return empty string if given string is null, otherwise the converted
     *         version if the given string.
     */
    public static String htmlEncode(String s) {
        if (s == null)
            return "";

        StringBuilder sb = new StringBuilder();
        char c;
        for (int i = 0; i < s.length(); i++) {
            c = s.charAt(i);
            switch (c) {
                case '"':
                    sb.append("\"");
                    break;
                case '&':
                    sb.append("&");
                    break;
                case '<':
                    sb.append("<");
                    break;
                case '>':
                    sb.append(">");
                    break;
                case '\n':
                    sb.append("<br/>");
                    break;
                default:
                    sb.append(c);
                    break;
            }
        }
        return sb.toString();
    }

    public static String urlEncode(String s) {
        try {
            return URLEncoder.encode(s, "UTF-8");
        } catch (Exception e) {
            return s;
        }
    }
}

@@ -43,50 +43,535 @@
 .URL
-Encoder;%0A%0Apublic final class StringUtils %7B
+Decoder;%0Aimport java.net.URLEncoder;%0Aimport java.util.Collection;%0Aimport java.util.regex.Pattern;%0A%0Apublic final class StringUtils %7B%0A%0A    public static final String ENCODING = %22UTF-8%22;%0A    public static final String EMPTY = %22%22;%0A    public static final String SPACE = %22 %22;%0A    public static final String COMMA = %22,%22;%0A    public static final Pattern SPACE_PATTERN = Pattern.compile(SPACE);%0A    public static final Pattern COMMA_PATTERN = Pattern.compile(COMMA);%0A    public static final Pattern EOL_PATTERN = Pattern.compile(%22%5Cn%22);
 %0A%0A  
@@ -2049,81 +2049,689 @@
 (s, 
-%22UTF-8%22);%0A        %7D catch (Exception e) %7B%0A            return s;%0A        %7D
+ENCODING);%0A        %7D catch (Exception e) %7B%0A            return s;%0A        %7D%0A    %7D%0A%0A    public static String urlDecode(String url) %7B%0A        try %7B%0A            return URLDecoder.decode(url, ENCODING);%0A        %7D catch (Exception e) %7B%0A            return url;%0A        %7D%0A    %7D%0A%0A    public static boolean hasText(String s) %7B%0A        return org.springframework.util.StringUtils.hasText(s);%0A    %7D%0A%0A    public static String join(Collection%3CString%3E collection) %7B%0A        return join(collection, COMMA);%0A    %7D%0A    public static String join(Collection%3CString%3E collection, String delimiter) %7B%0A        return org.springframework.util.StringUtils.collectionToDelimitedString(collection, delimiter);
 %0A   

Add String utility methods for URL encoding and decoding.