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