1 | package com.medias.xml.metadata; |
---|
2 | |
---|
3 | import com.medias.ConversionException; |
---|
4 | import com.medias.DateTime; |
---|
5 | import com.medias.utils.Entity; |
---|
6 | import org.jdom.Element; |
---|
7 | |
---|
8 | import java.sql.Timestamp; |
---|
9 | import java.util.Date; |
---|
10 | |
---|
11 | /** |
---|
12 | * @author combaz |
---|
13 | * |
---|
14 | * TODO To change the template for this generated type comment go to |
---|
15 | * Window - Preferences - Java - Code Style - Code Templates |
---|
16 | */ |
---|
17 | public class ExactTime implements Entity |
---|
18 | { |
---|
19 | /** |
---|
20 | * |
---|
21 | */ |
---|
22 | private static final long serialVersionUID = 1L; |
---|
23 | public static String date_format = "dd/MM/yyyy"; |
---|
24 | public static String heure_format = "HH:mm:ss"; |
---|
25 | |
---|
26 | private String date; |
---|
27 | private String heure; |
---|
28 | |
---|
29 | public ExactTime() { |
---|
30 | super(); |
---|
31 | this.date = ""; |
---|
32 | this.heure = ""; |
---|
33 | } |
---|
34 | |
---|
35 | /** |
---|
36 | * @return Returns the date. |
---|
37 | */ |
---|
38 | public String getDate() { |
---|
39 | return date; |
---|
40 | } |
---|
41 | /** |
---|
42 | * @param date The date to set. |
---|
43 | */ |
---|
44 | public void setDate(String date) { |
---|
45 | this.date = date; |
---|
46 | } |
---|
47 | /** |
---|
48 | * @return Returns the heure. |
---|
49 | */ |
---|
50 | public String getHeure() { |
---|
51 | return heure; |
---|
52 | } |
---|
53 | /** |
---|
54 | * @param heure The heure to set. |
---|
55 | */ |
---|
56 | public void setHeure(String heure) { |
---|
57 | this.heure = heure; |
---|
58 | } |
---|
59 | |
---|
60 | public Timestamp getTimestamp() { |
---|
61 | Date d = DateTime.getDate(this.date, date_format); |
---|
62 | Date h = DateTime.getDate(this.heure, heure_format); |
---|
63 | return DateTime.getTimeStamp(h,d); |
---|
64 | } |
---|
65 | |
---|
66 | public Element toXmlElement(String title) { |
---|
67 | Element d = new Element("date"); |
---|
68 | d.addContent(this.date); |
---|
69 | Element h = new Element("heure"); |
---|
70 | h.addContent(this.heure); |
---|
71 | |
---|
72 | Element time = new Element(title); |
---|
73 | time.addContent(d); |
---|
74 | time.addContent(h); |
---|
75 | return time; |
---|
76 | } |
---|
77 | |
---|
78 | public void fromXmlElement(Element el) throws ConversionException { |
---|
79 | Element d = el.getChild("date"); |
---|
80 | Element h = el.getChild("heure"); |
---|
81 | |
---|
82 | if((d==null)||(h==null)) |
---|
83 | throw new ConversionException(ConversionException.ERROR_fromXml + "ExactTime !"); |
---|
84 | |
---|
85 | else { |
---|
86 | this.setDate(d.getText()); |
---|
87 | this.setHeure(h.getText()); |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | /* public void reset() { |
---|
94 | this.date = null; |
---|
95 | this.heure = null; |
---|
96 | } */ |
---|
97 | |
---|
98 | } |
---|