KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > designer > elements > date > DayOfYearAttribute


1 /*
2  * (c) Rob Gordon 2005.
3  */

4 package org.oddjob.designer.elements.date;
5
6 import java.text.ParseException JavaDoc;
7 import java.text.SimpleDateFormat JavaDoc;
8 import java.util.Date JavaDoc;
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 /**
17  *
18  */

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 JavaDoc attribute) {
27         if (attribute != null && attribute.trim().length() > 0) {
28             try {
29                 new SimpleDateFormat JavaDoc("dd-MMM").parse(attribute);
30             } catch (ParseException JavaDoc e) {
31                 try {
32                     Date JavaDoc date = DateHelper.parseDate(attribute);
33                     attribute = new SimpleDateFormat JavaDoc("dd-MMM").format(date);
34                 } catch (ParseException JavaDoc e2) {
35                     throw new OddjobConfigException("Date does not parse [" + attribute + "]");
36                 }
37             }
38         }
39         super.attribute(attribute);
40     }
41
42 }
43
Popular Tags