You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2001/10/29 09:58:17 UTC

cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/util StringUtils.java

taylor      01/10/29 00:58:17

  Modified:    src/java/org/apache/jetspeed/util StringUtils.java
  Log:
  Add new methods for removing spaces from strings (necessary for customization of stocks ui), and
   converting tokenized strings to arrays and visa versa.
  
  Revision  Changes    Path
  1.4       +93 -1     jakarta-jetspeed/src/java/org/apache/jetspeed/util/StringUtils.java
  
  Index: StringUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/util/StringUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StringUtils.java	2001/03/07 06:50:06	1.3
  +++ StringUtils.java	2001/10/29 08:58:17	1.4
  @@ -55,13 +55,14 @@
   package org.apache.jetspeed.util;
   
   import org.apache.turbine.util.Log;
  +import java.util.StringTokenizer;
   
   /**
    * This class provides static util methods for String manaipulation that 
    * aren't part of the default JDK functionalities.
    *
    * @author <a href="mailto:raphael@apache.org">Rapha�l Luta</a>
  - * @version $Id: StringUtils.java,v 1.3 2001/03/07 06:50:06 taylor Exp $
  + * @version $Id: StringUtils.java,v 1.4 2001/10/29 08:58:17 taylor Exp $
    */
   public class StringUtils 
   {
  @@ -138,6 +139,97 @@
           //No more matches
           return buffer;
               
  +    }
  +
  +   /**
  +     *  Takes an array of tokens and converts into separator-separated string.
  +     *
  +     * @param String[] The array of strings input.
  +     * @param String The string separator.
  +     * @returns String A string containing tokens separated by seperator.
  +     */
  +    public static final String arrayToString(String[] array, String separators)
  +    {
  +        StringBuffer sb = new StringBuffer("");
  +        String empty = "";
  +        
  +        if (array == null)
  +            return empty;
  +
  +        if (separators == null)
  +            separators = ",";
  +
  +        for (int ix=0; ix < array.length; ix++) 
  +        {
  +            if (array[ix] != null && !array[ix].equals("")) 
  +            {
  +                sb.append(array[ix] + separators);
  +            }
  +        }
  +        String str = sb.toString();
  +        if (!str.equals("")) 
  +        {
  +            str = str.substring(0, (str.length() - separators.length()));
  +        }
  +        return str;
  +    }
  +
  +    /**
  +      *  Converts a delimited string into an array of string tokens.
  +      *                    
  +      * @param String[] The 'separator' separated string.
  +      * @param String The string separator.
  +      * @returns String A string array of the original tokens.
  +      */
  +    public static final String[] stringToArray(String str, String separators)
  +    {
  +        StringTokenizer tokenizer;
  +        String[] array = null;
  +        int count = 0;
  +
  +        if (str == null)
  +            return array;
  +
  +        if (separators == null)
  +            separators = ",";
  +
  +        tokenizer = new StringTokenizer(str, separators);
  +        if ((count = tokenizer.countTokens()) <= 0) {
  +            return array;
  +        }
  +        
  +        array = new String[count];
  +        
  +        int ix = 0;
  +        while (tokenizer.hasMoreTokens()) 
  +        {
  +            array[ix] = tokenizer.nextToken();
  +            ix++;
  +        }
  +
  +        return array;
  +    }
  +
  +    /**
  +     * Remove a given set of characters from a String.
  +     *
  +     * @param String The input string to be cleansed of 'removeChars'.
  +     * @param String The characters to be removed.
  +     * @returns String The new string cleansed of 'removeChars'.
  +     */
  +    public static String removeChars (String data, String removeChars)
  +    {
  +        String temp = null;
  +        StringBuffer out = new StringBuffer();
  +        temp = data;
  +
  +        StringTokenizer st = new StringTokenizer(temp, removeChars);
  +        while (st.hasMoreTokens())
  +        {
  +            String element = (String) st.nextElement();
  +            out.append(element);
  +        }
  +        return out.toString();
       }
   
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>