18 package org.turro.elephant.impl.util;
20 import java.text.DecimalFormat;
21 import java.text.NumberFormat;
22 import java.text.SimpleDateFormat;
23 import org.turro.string.ObjectString;
24 import org.turro.elephant.context.IConstructor;
25 import org.turro.i18n.I_;
46 if(format ==
null) format = inFormat;
47 if(
"date".equals(type)) {
48 SimpleDateFormat sdfi =
new SimpleDateFormat(
49 (format ==
null ? ObjectString.DEFAULT_DATE : format)
51 return parseValue(type, outFormat, sdfi.parse(value));
53 else if(
"number".equals(type)) {
54 Number number = (Number)ObjectString.parseNativeString(value, Double.class,
true);
57 else if(
"bytes".equals(type)) {
58 Long bytes = (Long)ObjectString.parseNativeString(value, Long.class,
true);
63 }
catch(Exception ex) {
74 if(format ==
null) format = inFormat;
75 if(
"date".equals(type)) {
76 SimpleDateFormat sdfi =
new SimpleDateFormat(
77 (format ==
null ? ObjectString.DEFAULT_DATE : format)
79 return sdfi.parse(value);
81 else if(
"number".equals(type)) {
82 Number number = (Number)ObjectString.parseNativeString(value, Double.class,
true);
85 else if(
"bytes".equals(type)) {
86 Long bytes = (Long)ObjectString.parseNativeString(value, Long.class,
true);
91 }
catch(Exception ex) {
101 if(
"date".equals(type)) {
103 SimpleDateFormat sdfo =
new SimpleDateFormat(
104 (outFormat ==
null ? ObjectString.DATE_PATTERN : outFormat),
107 return sdfo.format(value);
109 else if(
"number".equals(type)) {
111 NumberFormat dfo = NumberFormat.getInstance(
114 if(dfo instanceof DecimalFormat) {
115 ((DecimalFormat)dfo).applyPattern(
116 (outFormat ==
null ? ObjectString.DEFAULT_NUMBER : outFormat)
119 return dfo.format(value);
121 else if(
"bytes".equals(type)) {
122 return new org.turro.formatter.BytesFormatter(((Long)value).longValue()).toString();
125 return value.toString();
126 }
catch(Exception ex) {
Localizer(IConstructor constructor)
Object parseString(String type, String inFormat, String value)
String parseValue(String type, String outFormat, Object value)
String parseString(String type, String inFormat, String outFormat, String value)
static I18nCompatibilityWrapper compatibility()