Coverage Report - org.seasar.cubby.util.CubbyFunctions
 
Classes in this File Line Coverage Branch Coverage Complexity
CubbyFunctions
52%
14/27
43%
6/14
0
 
 1  
 /*
 2  
  * Copyright 2004-2008 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.cubby.util;
 17  
 
 18  
 import java.text.SimpleDateFormat;
 19  
 import java.util.Arrays;
 20  
 import java.util.Collection;
 21  
 import java.util.Date;
 22  
 import java.util.Map;
 23  
 
 24  
 import org.seasar.framework.util.StringUtil;
 25  
 
 26  0
 public class CubbyFunctions {
 27  
 
 28  
         public static Boolean contains(Object c, Object value) {
 29  2
                 if (c instanceof Collection) {
 30  2
                         return _contains((Collection<?>) c, value);
 31  0
                 } else if (c != null && c.getClass().isArray()) {
 32  0
                         return _contains(Arrays.asList((Object[]) c), value);
 33  
                 } else {
 34  0
                         return false;
 35  
                 }
 36  
         }
 37  
 
 38  
         public static Boolean _contains(Collection<?> c, Object value) {
 39  2
                 return c.contains(value);
 40  
         }
 41  
 
 42  
         public static Boolean containsKey(Map<?, ?> m, Object value) {
 43  0
                 return m.containsKey(value);
 44  
         }
 45  
 
 46  
         public static Boolean containsValue(Map<?, ?> m, Object value) {
 47  0
                 return m.containsValue(value);
 48  
         }
 49  
 
 50  
         public static String odd(Integer index, String classnames) {
 51  0
                 String[] c = classnames.split(",");
 52  0
                 return c[index % c.length];
 53  
         }
 54  
 
 55  
         public static String out(Object value) {
 56  102
                 return value == null ? "" : escapeHtml(value.toString());
 57  
         }
 58  
 
 59  
         public static String escapeHtml(Object value) {
 60  108
                 if (value == null) {
 61  0
                         return "";
 62  
                 }
 63  
                 String text;
 64  108
                 if (value instanceof String) {
 65  107
                         text = (String) value;
 66  
                 } else {
 67  1
                         text = value.toString();
 68  
                 }
 69  108
                 text = StringUtil.replace(text, "&", "&amp;");
 70  108
                 text = StringUtil.replace(text, "<", "&lt;");
 71  108
                 text = StringUtil.replace(text, ">", "&gt;");
 72  108
                 text = StringUtil.replace(text, "\"", "&quot;");
 73  108
                 text = StringUtil.replace(text, "'", "&#39;");
 74  108
                 return text;
 75  
         }
 76  
 
 77  
         public static String dateFormat(Object date, String pattern) {
 78  0
                 if (date instanceof Date) {
 79  0
                         SimpleDateFormat format = new SimpleDateFormat(pattern);
 80  0
                         return format.format(date);
 81  
                 } else {
 82  0
                         return "";
 83  
                 }
 84  
         }
 85  
 
 86  
 }