add split/join methods. no StringUtils is complete without them. taken from
authormh <mh>
Tue, 26 Feb 2002 12:08:41 +0000 (12:08 +0000)
committermh <mh>
Tue, 26 Feb 2002 12:08:41 +0000 (12:08 +0000)
Jakarta Turbine StringUtils

source/mir/misc/StringUtil.java

index a59b84a..24de3ab 100755 (executable)
@@ -185,6 +185,49 @@ public final class StringUtil {
                return returnDate.toString();
        }
 
+    /**
+     * Splits the provided CSV text into a list. stolen wholesale from 
+     * from Jakarta Turbine StrinUtils.java -mh
+     *
+     * @param text      The CSV list of values to split apart.
+     * @param separator The separator character.
+     * @return          The list of values.
+     */
+    public static String[] split(String text, String separator)
+    {
+        StringTokenizer st = new StringTokenizer(text, separator);
+        String[] values = new String[st.countTokens()];
+        int pos = 0;
+        while (st.hasMoreTokens())
+        {
+            values[pos++] = st.nextToken();
+        }
+        return values;
+    }
+
+    /**
+     * Joins the elements of the provided array into a single string
+     * containing a list of CSV elements. Stolen wholesale from Jakarta
+     * Turbine StringUtils.java. -mh
+     *
+     * @param list      The list of values to join together.
+     * @param separator The separator character.
+     * @return          The CSV text.
+     */
+    public static String join(String[] list, String separator)
+    {
+        StringBuffer csv = new StringBuffer();
+        for (int i = 0; i < list.length; i++)
+        {
+            if (i > 0)
+            {
+                csv.append(separator);
+            }
+            csv.append(list[i]);
+        }
+        return csv.toString();
+    }
+
 
        /**
         * schließt einen String in Anführungsszeichen ein, falls er Leerzeichen o.ä. enthält
@@ -946,12 +989,25 @@ public final class StringUtil {
         * @param width, width of the image
         * @return a String containing the url
         */
-       public static String createIMGLinks(String haystack, String title, String height,String width) {
+       public static String createIMGLinks(String haystack, String title,
+                                        String height,String width) {
+        String wh="";
+        if ( (height != null) && (width != null) ) 
+        {
+            wh = "width=\""+width+"\" height=\""+height+"\""; 
+        }
                if (title != null) {
                        title = removeHTMLTags(title);
-                       return re_url.substituteAll(haystack,"<img hspace=\"10\" vspace=\"6\" align=\"left\" src=\"$0\" width=\""+width+"\" height=\""+height+"\" alt=\""+title+"\"/>&#160;<br><i>"+title+"</i>");
+                       return re_url.substituteAll(haystack,
+                                        "<img hspace=\"10\" vspace=\"6\" "+
+                                        "align=\"left\" src=\"$0\" "+wh+
+                                        " alt=\""+title+"\"/>&#160;<br><i>"+
+                                        title+"</i>");
                } else {
-                       return re_url.substituteAll(haystack,"<img hspace=\"10\" vspace=\"6\" align=\"left\" src=\"$0\" width=\""+width+"\" height=\""+height+"\" alt=\"\"/>&#160;");
+                       return re_url.substituteAll(haystack,
+                                        "<img hspace=\"10\" vspace=\"6\" "+
+                                        "align=\"left\" src=\"$0\" "+wh+
+                                        " alt=\"\"/>&#160;");
                }
        }