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    import org.apache.commons.lang.StringUtils;
022    
023    import java.util.ArrayList;
024    import java.util.List;
025    import java.util.StringTokenizer;
026    import java.util.Locale;
027    
028    public class StringUtil {
029    
030      private StringUtil() {
031      }
032    
033      public static String firstToUpperCase(String string) {
034        if (string == null) {
035          return null;
036        }
037        switch (string.length()) {
038          case 0:
039            return string;
040          case 1:
041            return string.toUpperCase(Locale.ENGLISH);
042          default:
043            return string.substring(0, 1).toUpperCase(Locale.ENGLISH) + string.substring(1);
044        }
045      }
046    
047      public static List<Integer> parseIntegerList(String integerList)
048          throws NumberFormatException {
049        List<Integer> list = new ArrayList<Integer>();
050    
051        StringTokenizer tokenizer = new StringTokenizer(integerList, ", ");
052        while (tokenizer.hasMoreElements()) {
053          String token = tokenizer.nextToken().trim();
054          if (token.length() > 0) {
055            list.add(new Integer(token));
056          }
057        }
058    
059        return list;
060      }
061    
062      public static <T> String toString(List<T> list) {
063        StringBuilder buffer = new StringBuilder(",");
064        for (T t : list) {
065          buffer.append(t);
066          buffer.append(",");
067        }
068        return buffer.toString();
069      }
070    
071      public static String escapeAccessKeyIndicator(String label) {
072        return StringUtils.replace(label,
073            String.valueOf(LabelWithAccessKey.INDICATOR), LabelWithAccessKey.ESCAPED_INDICATOR);
074      }
075    
076    }