Ejemplo n.º 1
0
 public static Object parseGeneric(Class<?> clazz, String string) throws Exception {
   if (clazz.equals(String.class)) return string;
   else if (clazz.equals(Character.class)) return Character.valueOf(string.charAt(0));
   else if (clazz.equals(Integer.class)) return Integer.valueOf(string);
   else if (clazz.equals(Long.class)) return Long.valueOf(string);
   else if (clazz.equals(Boolean.class)) return StringUtils.parseBoolean(string);
   else if (clazz.equals(Double.class)) return Double.valueOf(string);
   else if (clazz.equals(BigDecimal.class)) return BigDecimal.valueOf(Double.parseDouble(string));
   else if (clazz.equals(java.util.Date.class)) return StringUtils.parseDate(string);
   else if (clazz.equals(java.sql.Date.class))
     return new java.sql.Date(StringUtils.parseDate(string).getTime());
   else if (clazz.equals(Timestamp.class))
     return new Timestamp(StringUtils.parseDate(string).getTime());
   else throw new Exception("Unsupported type: '" + clazz.getName() + "'");
 }
Ejemplo n.º 2
0
 public static String encodeMD5(String string) throws Exception {
   try {
     MessageDigest messageDigest = MessageDigest.getInstance("MD5");
     byte buffer[] = string.getBytes();
     messageDigest.update(buffer);
     return StringUtils.convertToHex(messageDigest.digest());
   } catch (Exception ex) {
     return null;
   }
 }