KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > dictionary > M2XML


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.dictionary;
18
19 import java.text.ParseException JavaDoc;
20 import java.text.SimpleDateFormat JavaDoc;
21 import java.util.Date JavaDoc;
22
23 import org.alfresco.util.CachingDateFormat;
24
25
26 /**
27  * Support translating model from and to XML
28  *
29  * @author David Caruana
30  *
31  */

32 public class M2XML
33 {
34    
35     /**
36      * Convert XML date (of the form yyyy-MM-dd) to Date
37      *
38      * @param date the xml representation of the date
39      * @return the date
40      * @throws ParseException
41      */

42     public static Date JavaDoc deserialiseDate(String JavaDoc date)
43         throws ParseException JavaDoc
44     {
45         Date JavaDoc xmlDate = null;
46         if (date != null)
47         {
48             SimpleDateFormat JavaDoc df = CachingDateFormat.getDateOnlyFormat();
49             xmlDate = df.parse(date);
50         }
51         return xmlDate;
52     }
53
54     
55     /**
56      * Convert date to XML date (of the form yyyy-MM-dd)
57      *
58      * @param date the date
59      * @return the xml representation of the date
60      */

61     public static String JavaDoc serialiseDate(Date JavaDoc date)
62     {
63         String JavaDoc xmlDate = null;
64         if (date != null)
65         {
66             SimpleDateFormat JavaDoc df = CachingDateFormat.getDateOnlyFormat();
67             xmlDate = df.format(date);
68         }
69         return xmlDate;
70     }
71     
72 }
73
Popular Tags