KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webdav > lib > properties > DateProperty


1 /*
2  * $Header: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/properties/DateProperty.java,v 1.1.2.1 2004/09/26 14:19:20 luetzkendorf Exp $
3  * $Revision: 1.1.2.1 $
4  * $Date: 2004/09/26 14:19:20 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.webdav.lib.properties;
25
26 import java.text.ParseException JavaDoc;
27 import java.text.SimpleDateFormat JavaDoc;
28 import java.util.Date JavaDoc;
29 import java.util.Locale JavaDoc;
30
31 import org.apache.webdav.lib.BaseProperty;
32 import org.apache.webdav.lib.ResponseEntity;
33 import org.apache.webdav.lib.util.DOMUtils;
34 import org.w3c.dom.Element JavaDoc;
35
36 /**
37  * Base for all properties that contain date values.
38  */

39 public abstract class DateProperty extends BaseProperty
40 {
41     
42     private static final SimpleDateFormat JavaDoc FORMATS[] = {
43         new SimpleDateFormat JavaDoc("EEE, d MMM yyyy kk:mm:ss z", Locale.US),
44         new SimpleDateFormat JavaDoc("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
45         new SimpleDateFormat JavaDoc("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US),
46         new SimpleDateFormat JavaDoc("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
47         new SimpleDateFormat JavaDoc("EEE MMMM d HH:mm:ss yyyy", Locale.US),
48         new SimpleDateFormat JavaDoc("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US),
49         new SimpleDateFormat JavaDoc("yyyy-MM-dd'T'HH:mm:ss.sss'Z'", Locale.US)
50     };
51
52     public DateProperty(ResponseEntity response, Element JavaDoc element) {
53         super(response, element);
54     }
55     
56     /**
57      * Returns the date value.
58      */

59     public Date JavaDoc getDate()
60     {
61         String JavaDoc dateString = DOMUtils.getTextValue(element);
62         for(int i = 0; i < FORMATS.length; i++) {
63             try {
64                 return FORMATS[i].parse(dateString);
65             } catch (ParseException JavaDoc e) {
66                 // try next
67
}
68         }
69         return null;
70     }
71 }
72
Popular Tags