KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > ui > common > converter > XMLDateConverter


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.web.ui.common.converter;
18
19 import java.util.Date JavaDoc;
20 import java.util.TimeZone JavaDoc;
21
22 import javax.faces.component.UIComponent;
23 import javax.faces.context.FacesContext;
24 import javax.faces.convert.DateTimeConverter;
25
26 import org.alfresco.util.ISO8601DateFormat;
27
28 /**
29  * Converter class to convert an XML date representation into a Date
30  *
31  * @author gavinc
32  */

33 public class XMLDateConverter extends DateTimeConverter
34 {
35    /**
36     * <p>The standard converter id for this converter.</p>
37     */

38    public static final String JavaDoc CONVERTER_ID = "org.alfresco.faces.XMLDataConverter";
39
40    /**
41     * @see javax.faces.convert.Converter#getAsObject(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.String)
42     */

43    public Object JavaDoc getAsObject(FacesContext context, UIComponent component, String JavaDoc value)
44    {
45       return ISO8601DateFormat.parse(value);
46    }
47
48    /**
49     * @see javax.faces.convert.Converter#getAsString(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
50     */

51    public String JavaDoc getAsString(FacesContext context, UIComponent component, Object JavaDoc value)
52    {
53       String JavaDoc str = null;
54       
55       if (value instanceof String JavaDoc)
56       {
57          Date JavaDoc date = ISO8601DateFormat.parse((String JavaDoc)value);
58          str = super.getAsString(context, component, date);
59       }
60       else
61       {
62          str = super.getAsString(context, component, value);
63       }
64       
65       return str;
66    }
67
68    /*
69     * (non-Javadoc)
70     * @see javax.faces.convert.DateTimeConverter#getTimeZone()
71     */

72    public TimeZone JavaDoc getTimeZone()
73    {
74        // Note: this forces the display of the date to the server's timezone - it does not
75
// take into account any client specific timezone
76
return TimeZone.getDefault();
77    }
78    
79 }
80
Popular Tags