1 package org.tigris.scarab.attribute; 2 3 import java.text.ParseException ; 4 import java.text.SimpleDateFormat ; 5 import java.util.Collection ; 6 import java.util.Iterator ; 7 8 import org.apache.torque.TorqueException; 9 import org.tigris.scarab.om.AttributeValue; 10 11 56 57 62 public class DateAttribute extends StringAttribute 63 { 64 private static SimpleDateFormat internalFormat = new SimpleDateFormat ("yyyyMMddHHmmssSS"); 65 66 74 public static String dateFormat(String value, String mask) 75 { 76 SimpleDateFormat sdf = new SimpleDateFormat (mask); 77 String val = value; 78 try 79 { 80 if (val == null) 81 val = ""; 82 else 83 val = sdf.format(internalFormat.parse(value)); 84 } 85 catch (ParseException e) 86 { 87 } 89 return val; 90 } 91 99 public static String internalDateFormat(String value, String mask) 100 { 101 SimpleDateFormat sdf = new SimpleDateFormat (mask); 102 String val = value; 103 try 104 { 105 if (val == null) 106 val = ""; 107 else 108 val = internalFormat.format(sdf.parse(value)); 109 } 110 catch (ParseException e) 111 { 112 } 114 return val; 115 } 116 117 124 public static void convertDateAttributes(Collection attributeValues, String mask) throws TorqueException 125 { 126 for (Iterator iter = attributeValues.iterator(); iter.hasNext(); ) 127 { 128 AttributeValue av = (AttributeValue)iter.next(); 129 if (av instanceof DateAttribute) 130 { 131 av.setValue(internalDateFormat(av.getValue(), mask)); 132 } 133 } 134 } 135 } 136 | Popular Tags |