protected String getDateTimeFormattedValue(Object value, Locale locale) { return Datatypes.getNN(Date.class).format(value, locale); }
protected Datatype getDatatype(Class clazz) { if (clazz == Integer.TYPE || clazz == Byte.TYPE || clazz == Short.TYPE) return Datatypes.get(Integer.class); if (clazz == Long.TYPE) return Datatypes.get(Long.class); if (clazz == Boolean.TYPE) return Datatypes.get(Boolean.class); return Datatypes.get(clazz); }
@Override public String apply(Number value) { if (value == null) { return null; } String pattern = element != null ? element.attributeValue("format") : null; if (pattern == null) { Datatype datatype = Datatypes.getNN(value.getClass()); return datatype.format(value, userSessionSource.getLocale()); } else { if (pattern.startsWith("msg://")) { pattern = messages.getMainMessage(pattern.substring(6, pattern.length())); } FormatStrings formatStrings = Datatypes.getFormatStrings(userSessionSource.getLocale()); if (formatStrings == null) throw new IllegalStateException("FormatStrings are not defined for " + userSessionSource.getLocale()); DecimalFormat format = new DecimalFormat(pattern, formatStrings.getFormatSymbols()); return format.format(value); } } }
private void loadProperties(Element element, KeyValueContainer container) { Element propsEl = element.element("properties"); if (propsEl != null) { for (Element propEl : propsEl.elements()) { String name = propEl.attributeValue("name"); String className = propEl.attributeValue("class"); if (className != null) { container.addProperty(name, ReflectionHelper.getClass(className)); } else { String typeName = propEl.attributeValue("datatype"); Datatype datatype = typeName == null ? Datatypes.getNN(String.class) : Datatypes.get(typeName); container.addProperty(name, datatype); } } String idProperty = propsEl.attributeValue("idProperty"); if (idProperty != null) { if (container.getEntityMetaClass().getProperty(idProperty) == null) throw new DevelopmentException(String.format("Property '%s' is not defined", idProperty)); container.setIdName(idProperty); } } }
private Object tryDate(String value) { UserSessionSource userSession = AppBeans.get(UserSessionSource.NAME); FormatStrings formatStrings = Datatypes.getFormatStrings(userSession.getLocale()); SimpleDateFormat sdf = new SimpleDateFormat(formatStrings.getDateFormat()); try { Date date = sdf.parse(value); return date; } catch (ParseException e) { return null; } }
public String[] getAvailableBasicTypes() { Set<String> allAvailableTypes = Datatypes.getIds(); TreeSet<String> availableTypes = new TreeSet<>(); //byteArray is not supported as a GET parameter for (String type : allAvailableTypes) if (!"byteArray".equals(type)) availableTypes.add(type); return availableTypes.toArray(new String[availableTypes.size()]); } }
public static String formatParamValue(Param param, Object value) { //noinspection unchecked Datatype datatype = Datatypes.get(param.getJavaClass()); MetaProperty property = param.getProperty(); if (property != null) { TemporalType tt = (TemporalType) property.getAnnotations().get(MetadataTools.TEMPORAL_ANN_NAME); if (tt == TemporalType.DATE) { datatype = Datatypes.getNN(java.sql.Date.class); } } if (datatype != null) { UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.class); return datatype.format(value, userSessionSource.getLocale()); } return value.toString(); } }
private Object tryNumber(String value) { UserSessionSource userSession = AppBeans.get(UserSessionSource.NAME); FormatStrings formatStrings = Datatypes.getFormatStrings(userSession.getLocale()); char decimalSeparator = formatStrings.getFormatSymbols().getDecimalSeparator(); char groupingSeparator = formatStrings.getFormatSymbols().getGroupingSeparator(); if (decimalSeparator != '.') value = value.replace(decimalSeparator, '.'); if (groupingSeparator != ',') value = value.replace(groupingSeparator, ','); if (!Character.isDigit(value.charAt(0)) || value.startsWith("0")) return null; try { Number number = new BigDecimal(value); return number; } catch (NumberFormatException e) { return null; } } }
@Override public Component generateField(Datasource datasource, String propertyId) { LookupField lookup = AppConfig.getFactory().createComponent(LookupField.class); lookup.setDatasource(datasource, propertyId); lookup.setRequiredMessage(getMessage("datatypeMsg")); lookup.setRequired(true); lookup.setPageLength(15); Map<String, Object> options = new TreeMap<>(); String mainMessagePack = AppConfig.getMessagesPack(); for (String datatypeId : Datatypes.getIds()) { options.put(messages.getMessage(mainMessagePack, "Datatype." + datatypeId), datatypeId); } lookup.setOptionsMap(options); return lookup; } }
private static Object parseByDatatype(String value, Class<?> type) throws ParseException { Datatype datatype = Datatypes.getNN(type); return datatype.parse(value); }
protected Datatype getDatatype(Class clazz) { if (clazz == Integer.TYPE || clazz == Byte.TYPE || clazz == Short.TYPE) return Datatypes.get(Integer.class); if (clazz == Long.TYPE) return Datatypes.get(Long.class); if (clazz == Boolean.TYPE) return Datatypes.get(Boolean.class); return Datatypes.get(clazz); }
private void loadProperties(Element element, ValueDatasource datasource) { Element propsEl = element.element("properties"); if (propsEl != null) { for (Element propEl : Dom4j.elements(propsEl)) { String name = propEl.attributeValue("name"); String className = propEl.attributeValue("class"); if (className != null) { datasource.addProperty(name, ReflectionHelper.getClass(className)); } else { String typeName = propEl.attributeValue("datatype"); Datatype datatype = typeName == null ? Datatypes.getNN(String.class) : Datatypes.get(typeName); datasource.addProperty(name, datatype); } } String idProperty = propsEl.attributeValue("idProperty"); if (idProperty != null) { if (datasource.getMetaClass().getProperty(idProperty) == null) throw new DevelopmentException(String.format("Property '%s' is not defined", idProperty)); datasource.setIdName(idProperty); } } }
String type = element.attributeValue("type"); if (type != null) { FormatStrings formatStrings = Datatypes.getFormatStrings(userSessionSource.getLocale()); if (formatStrings == null) throw new IllegalStateException("FormatStrings are not defined for " + userSessionSource.getLocale());
protected String formatSingleValue(Object v) { switch (type) { case ENTITY: if (v instanceof UUID) return v.toString(); else if (v instanceof Entity) return ((Entity) v).getId().toString(); case ENUM: return ((Enum) v).name(); case RUNTIME_ENUM: case DATATYPE: case UNARY: if (isDateInterval) return (String) v; //noinspection unchecked Datatype<Object> datatype = Datatypes.getNN(javaClass); return datatype.format(v); default: throw new IllegalStateException("Param type unknown"); } }
public DateSerializer() { dateDatatype = Datatypes.get(Date.class); }
FormatStrings formatStrings = Datatypes.getFormatStrings(locale);
if (Integer.class == clazz || Integer.TYPE == clazz || Byte.class == clazz || Byte.TYPE == clazz || Short.class == clazz || Short.TYPE == clazz) return Datatypes.getNN(Integer.class).parse(value); if (Date.class == clazz) { try { return Datatypes.getNN(Date.class).parse(value); } catch (ParseException e) { try { return Datatypes.getNN(java.sql.Date.class).parse(value); } catch (ParseException e1) { return Datatypes.getNN(Time.class).parse(value); if (BigDecimal.class == clazz) return Datatypes.getNN(BigDecimal.class).parse(value); if (Boolean.class == clazz || Boolean.TYPE == clazz) return Datatypes.getNN(Boolean.class).parse(value); if (Long.class == clazz || Long.TYPE == clazz) return Datatypes.getNN(Long.class).parse(value); if (Double.class == clazz || Double.TYPE == clazz || Float.class == clazz || Float.TYPE == clazz) return Datatypes.getNN(Double.class).parse(value); if (UUID.class == clazz) return UUID.fromString(value); throw new IllegalArgumentException("Parameters of type " + clazz.getName() + " are not supported");
public DateDeserializer() { dateDatatype = Datatypes.get(Date.class); }
protected void setupFormatStrings(List<StockPanel> panels) { FormatStrings formatStrings = Datatypes.getFormatStrings(userSessionSource.getLocale()); if (formatStrings != null) { for (StockPanel panel : panels) { DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols(); if (panel.getPrecision() == null) { panel.setPrecision(-1); } if (panel.getPercentPrecision() == null) { panel.setPercentPrecision(2); } if (panel.getDecimalSeparator() == null) { panel.setDecimalSeparator(Character.toString(formatSymbols.getDecimalSeparator())); } if (panel.getThousandsSeparator() == null) { panel.setThousandsSeparator(Character.toString(formatSymbols.getGroupingSeparator())); } } } }
|| Byte.class == clazz || Byte.TYPE == clazz || Short.class == clazz || Short.TYPE == clazz) { return Datatypes.getNN(Integer.class).parse(value); return Datatypes.getNN(Date.class).parse(value); } catch (ParseException e) { try { return Datatypes.getNN(java.sql.Date.class).parse(value); } catch (ParseException e1) { return Datatypes.getNN(Time.class).parse(value); return Datatypes.getNN(BigDecimal.class).parse(value); return Datatypes.getNN(Boolean.class).parse(value); return Datatypes.getNN(Long.class).parse(value); return Datatypes.getNN(Double.class).parse(value);