001    package org.apache.myfaces.tobago.util;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (the "License"); you may not use this file except in compliance with
009     * the License.  You may obtain a copy of the License at
010     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
021    
022    import java.util.ArrayList;
023    import java.util.List;
024    import java.util.Locale;
025    import java.util.StringTokenizer;
026    
027    public class StringUtils {
028    
029      private StringUtils() {
030      }
031    
032      /**
033       * @deprecated Use commons-lang StringUtils.capitalize() instead.
034       */
035      @Deprecated
036      public static String firstToUpperCase(String string) {
037        if (Deprecation.LOG.isWarnEnabled()) {
038          Deprecation.LOG.warn("use commons-lang please");
039        }
040        if (string == null) {
041          return null;
042        }
043        switch (string.length()) {
044          case 0:
045            return string;
046          case 1:
047            return string.toUpperCase(Locale.ENGLISH);
048          default:
049            return string.substring(0, 1).toUpperCase(Locale.ENGLISH) + string.substring(1);
050        }
051      }
052    
053      public static List<Integer> parseIntegerList(String integerList)
054          throws NumberFormatException {
055        List<Integer> list = new ArrayList<Integer>();
056    
057        StringTokenizer tokenizer = new StringTokenizer(integerList, ", ");
058        while (tokenizer.hasMoreElements()) {
059          String token = tokenizer.nextToken().trim();
060          if (token.length() > 0) {
061            list.add(new Integer(token));
062          }
063        }
064    
065        return list;
066      }
067    
068      public static <T> String toString(List<T> list) {
069        StringBuilder buffer = new StringBuilder(",");
070        for (T t : list) {
071          buffer.append(t);
072          buffer.append(",");
073        }
074        return buffer.toString();
075      }
076    
077      @Deprecated
078      public static String escapeAccessKeyIndicator(String label) {
079        if (Deprecation.LOG.isWarnEnabled()) {
080          Deprecation.LOG.warn(label);
081        }
082        return org.apache.commons.lang.StringUtils.replace(label,
083            String.valueOf(LabelWithAccessKey.INDICATOR), LabelWithAccessKey.ESCAPED_INDICATOR);
084      }
085    
086    }