1 4 package org.oddjob.designer.elements.date; 5 6 import java.text.ParseException ; 7 import java.text.SimpleDateFormat ; 8 import java.util.Date ; 9 10 import org.oddjob.designer.model.DateInput; 11 import org.oddjob.designer.model.DesignDefinition; 12 import org.oddjob.designer.model.SimpleAttribute; 13 import org.oddjob.util.DateHelper; 14 import org.oddjob.util.OddjobConfigException; 15 16 19 public class DayOfYearAttribute extends SimpleAttribute { 20 21 22 public DesignDefinition detail() { 23 return new DateInput("Date", this); 24 } 25 26 public void attribute(String attribute) { 27 if (attribute != null && attribute.trim().length() > 0) { 28 try { 29 new SimpleDateFormat ("dd-MMM").parse(attribute); 30 } catch (ParseException e) { 31 try { 32 Date date = DateHelper.parseDate(attribute); 33 attribute = new SimpleDateFormat ("dd-MMM").format(date); 34 } catch (ParseException e2) { 35 throw new OddjobConfigException("Date does not parse [" + attribute + "]"); 36 } 37 } 38 } 39 super.attribute(attribute); 40 } 41 42 } 43 | Popular Tags |