Revision 1999

View differences:

org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/impl/coercion/CoerceToDateTime.java
45 45
    protected DateFormat[] getFormatters(Locale locale) {
46 46
        return new DateFormat[] {
47 47
            DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.MEDIUM, locale),
48
            DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT, locale)
48
            DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT, locale),
49
            DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.LONG, locale)
49 50
        };
50 51
    }
51 52

  
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/impl/coercion/CoerceToString.java
23 23
 */
24 24
package org.gvsig.tools.dataTypes.impl.coercion;
25 25

  
26
import java.sql.Time;
26 27
import java.text.NumberFormat;
27 28
import java.util.Date;
28 29
import java.util.Locale;
......
32 33

  
33 34
public class CoerceToString implements CoercionWithLocale {
34 35

  
35
    @Override
36
    public Object coerce(Object value) throws CoercionException {
37
        if (value == null) {
38
            return null;
39
        }
40
        try {
41
            if (value instanceof Date) {
42
                Locale locale = Locale.getDefault();
43
                DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG, locale);
44
                value = df.format(value);
45
            } else if (!(value instanceof String)) {
46
                value = value.toString();
47
            }
48
            return value;
49
        } catch (Exception e) {
50
            throw new CoercionException(e);
51
        }
36
	@Override
37
	public Object coerce(Object value) throws CoercionException {
38
		if (value == null) {
39
			return null;
40
		}
41
		try {
42
			if (value instanceof Time) {
43
				Locale locale = Locale.getDefault();
44
				DateFormat df = DateFormat.getTimeInstance(DateFormat.LONG, locale);
45
				value = df.format(value);
46
			} else if (value instanceof Date) {
47
				Locale locale = Locale.getDefault();
48
				DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG, locale);
49
				value = df.format(value);
50
			} else if (!(value instanceof String)) {
51
				Locale locale = Locale.getDefault();
52
				if (value instanceof Float || value instanceof Double) {
53
					NumberFormat nf = NumberFormat.getInstance(locale);
54
					value = nf.format(((Number) value).doubleValue());
55
				} else {
56
					value = value.toString();
57
				}
58
			}
59
			return value;
60
		} catch (Exception e) {
61
			throw new CoercionException(e);
62
		}
52 63

  
53
    }
64
	}
54 65

  
55
    @Override
56
    public Object coerce(Object value, Locale locale) throws CoercionException {
57
        if (value == null) {
58
            return null;
59
        }
60
        try {
61
            if (value instanceof Date) {
62
                if (locale == null) {
63
                    locale = Locale.getDefault();
64
                }
65
                DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG, locale);
66
                value = df.format(value);
67
            } else if (!(value instanceof String)) {
68
                if (value instanceof Float || value instanceof Double) {
69
                    NumberFormat nf = NumberFormat.getInstance(locale);
70
                    value = nf.format(((Number) value).doubleValue());
71
                } else {
72
                    value = value.toString();
73
                }
74
            }
75
            return value;
76
        } catch (Exception e) {
77
            throw new CoercionException(e);
78
        }
79
    }
66
	@Override
67
	public Object coerce(Object value, Locale locale) throws CoercionException {
68
		if (value == null) {
69
			return null;
70
		}
71
		try {
72
			if (value instanceof Date) {
73
				if (locale == null) {
74
					locale = Locale.getDefault();
75
				}
76
				DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG, locale);
77
				value = df.format(value);
78
			} else if (!(value instanceof String)) {
79
				if (value instanceof Float || value instanceof Double) {
80
					NumberFormat nf = NumberFormat.getInstance(locale);
81
					value = nf.format(((Number) value).doubleValue());
82
				} else {
83
					value = value.toString();
84
				}
85
			}
86
			return value;
87
		} catch (Exception e) {
88
			throw new CoercionException(e);
89
		}
90
	}
80 91

  
81 92
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/impl/coercion/CoerceToDate.java
28 28
import java.util.Date;
29 29
import java.util.Locale;
30 30

  
31

  
32 31
/**
33 32
 * Coerces a value to a {@link Date}. If the value is not a {@link Date}, it
34
 * will use the {@link Object#toString()} method to convert the
35
 * resulting {@link String} to a Date object using the current locale default
36
 * formatter for Date through the {@link DateFormat#getDateInstance(int)} method
37
 * and the {@link DateFormat#SHORT} style.
33
 * will use the {@link Object#toString()} method to convert the resulting
34
 * {@link String} to a Date object using the current locale default formatter
35
 * for Date through the {@link DateFormat#getDateInstance(int)} method and the
36
 * {@link DateFormat#SHORT} style.
38 37
 *
39 38
 * @author gvSIG Team
40 39
 * @version $Id$
......
44 43

  
45 44
    @Override
46 45
    protected DateFormat[] getFormatters(Locale locale) {
47
        return new DateFormat[] {
46
        return new DateFormat[]{
48 47
            DateFormat.getDateInstance(DateFormat.SHORT, locale),
49 48
            DateFormat.getDateInstance(DateFormat.MEDIUM, locale),
50 49
            DateFormat.getDateInstance(DateFormat.LONG, locale),
50
            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG, locale),
51 51
            new SimpleDateFormat("yyyy-MM-dd") // PostgreSQL format
52 52
        };
53 53
    }

Also available in: Unified diff