Coverage Report - org.seasar.cubby.util.CubbyFunctions
 
Classes in this File Line Coverage Branch Coverage Complexity
CubbyFunctions
100%
14/14
N/A
0
 
 1  
 package org.seasar.cubby.util;
 2  
 
 3  
 import java.text.SimpleDateFormat;
 4  
 import java.util.Arrays;
 5  
 import java.util.Collection;
 6  
 import java.util.Date;
 7  
 import java.util.Map;
 8  
 
 9  
 import org.seasar.framework.util.StringUtil;
 10  
 
 11  
 public class CubbyFunctions {
 12  
 
 13  
         public static Boolean contains(Object c, Object value) {
 14  2
                 if (c instanceof Collection) {
 15  2
                         return _contains((Collection<?>) c, value);
 16  
                 } else if (c != null && c.getClass().isArray()) {
 17  
                         return _contains(Arrays.asList((Object[]) c), value);
 18  
                 } else {
 19  
                         return false;
 20  
                 }
 21  
         }
 22  
 
 23  
         public static Boolean _contains(Collection<?> c, Object value) {
 24  2
                 return c.contains(value);
 25  
         }
 26  
 
 27  
         public static Boolean containsKey(Map<?, ?> m, Object value) {
 28  
                 return m.containsKey(value);
 29  
         }
 30  
 
 31  
         public static Boolean containsValue(Map<?, ?> m, Object value) {
 32  
                 return m.containsValue(value);
 33  
         }
 34  
 
 35  
         public static String odd(Integer index, String classnames) {
 36  
                 String[] c = classnames.split(",");
 37  
                 return c[index % c.length];
 38  
         }
 39  
 
 40  
         public static String out(Object value) {
 41  98
                 return value == null ? "" : escapeHtml(value.toString());
 42  
         }
 43  
 
 44  
         public static String escapeHtml(Object value) {
 45  129
                 if (value == null) {
 46  
                         return "";
 47  
                 }
 48  
                 String text;
 49  129
                 if (value instanceof String) {
 50  129
                         text = (String) value;
 51  129
                 } else {
 52  
                         text = value.toString();
 53  
                 }
 54  129
                 text = StringUtil.replace(text, "&", "&amp;");
 55  129
                 text = StringUtil.replace(text, "<", "&lt;");
 56  129
                 text = StringUtil.replace(text, ">", "&gt;");
 57  129
                 text = StringUtil.replace(text, "\"", "&quot;");
 58  129
                 text = StringUtil.replace(text, "'", "&#39;");
 59  129
                 return text;
 60  
         }
 61  
 
 62  
         public static String dateFormat(Object date, String pattern) {
 63  
                 if (date instanceof Date) {
 64  
                         SimpleDateFormat format = new SimpleDateFormat(pattern);
 65  
                         return format.format(date);
 66  
                 } else {
 67  
                         return "";
 68  
                 }
 69  
         }
 70  
 
 71  
 }