View Javadoc

1   /*
2    * Copyright (c) 2010 Commsen International. All rights reserved.
3    * 
4    * This file is part of JWebThumb library.
5    *	
6    * JWebThumb library is free software: you can redistribute it and/or modify 
7    * it under the terms of the GNU Lesser General Public License as published by
8    * the Free Software Foundation, either version 2 of the License, or
9    * (at your option) any later version.
10   * 
11   * JWebThumb library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Lesser General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Lesser General Public License
17   * along with JWebThumb library.  If not, see <http://www.gnu.org/licenses/lgpl.html>.
18   */
19  
20  package com.commsen.jwebthumb.simplexml;
21  
22  import java.text.SimpleDateFormat;
23  import java.util.Date;
24  
25  import org.simpleframework.xml.transform.Transform;
26  
27  /***
28   * Implementation of {@link Transform} which transforms dates according to
29   * <code>yyyy-MM-dd HH:mm:ss</code> format.
30   * 
31   * @author <a href="mailto:MilenDyankov@gmail.com">Milen Dyankov</a>
32   * @since 0.3
33   */
34  public class DateTransformer implements Transform<Date> {
35  
36  	public final SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
37  
38  
39  	/***
40  	 * @see org.simpleframework.xml.transform.Transform#read(java.lang.String)
41  	 */
42  	public Date read(String value) throws Exception {
43  		return timeFormat.parse(value);
44  	}
45  
46  
47  	/***
48  	 * @see org.simpleframework.xml.transform.Transform#write(java.lang.Object)
49  	 */
50  	public String write(Date value) throws Exception {
51  		return timeFormat.format(value);
52  	}
53  
54  }