KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > datatypes > processors > FormatDateTime


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.datatypes.processors;
11
12 import org.mmbase.bridge.*;
13 import org.mmbase.datatypes.*;
14 import java.util.*;
15 import org.mmbase.util.logging.*;
16
17 /**
18  * This can be used as getProcessor for String on DateTime fields. Then, the 'getStringValue' will
19  * use a localized String as customized in datatypes.xml
20  *
21  * @author Michiel Meeuwissen
22  * @version $Id: FormatDateTime.java,v 1.3 2005/12/10 14:33:36 michiel Exp $
23  * @since MMBase-1.8
24  */

25
26 public class FormatDateTime implements Processor {
27     private static final Logger log = Logging.getLoggerInstance(FormatDateTime.class);
28
29     private static final long serialVersionUID = 1L;
30
31     public Object JavaDoc process(Node node, Field field, Object JavaDoc value) {
32         Locale locale = node.getCloud().getLocale();
33         DataType dataType = field.getDataType();
34         Object JavaDoc date = node.getValue(field.getName());
35         if (dataType instanceof DateTimeDataType) {
36             DateTimeDataType dateType = (DateTimeDataType) dataType;
37             if (date == null) {
38                 return "";
39             } else {
40                 return dateType.getPattern().getDateFormat(locale).format(node.getDateValue(field.getName()));
41             }
42         } else { // backwards compatibility
43
if (date == null) {
44                 return "";
45             } else {
46                 return org.mmbase.util.Casting.ISO_8601_LOOSE.format(node.getDateValue(field.getName()));
47             }
48         }
49     }
50
51     public String JavaDoc toString() {
52         return "format_datetime";
53     }
54
55 }
56
Popular Tags