protected <C> String convertToString(C object, Locale locale) { @SuppressWarnings("unchecked") Class<C> type = (Class<C>)object.getClass(); IConverter<C> converterForObj = converterSupplier.getConverter(type); return converterForObj.convertToString(object, locale); } }
protected <C> String convertToString(C object, Locale locale) { @SuppressWarnings("unchecked") Class<C> type = (Class<C>)object.getClass(); IConverter<C> converterForObj = converterSupplier.getConverter(type); return converterForObj.convertToString(object, locale); } }
/** * Use an {@link IConverter} to convert the given value to a String. * * @param value * the value, never {@code null} * * @return converted value */ @Override @SuppressWarnings({ "rawtypes", "unchecked" }) protected String toString(Object value) { IConverter converter = locator.getConverter(value.getClass()); return converter.convertToString(value, locale); } }
/** * Use an {@link IConverter} to convert the given value to a String. * * @param value * the value, never {@code null} * * @return converted value */ @Override @SuppressWarnings({ "rawtypes", "unchecked" }) protected String toString(Object value) { IConverter converter = locator.getConverter(value.getClass()); return converter.convertToString(value, locale); } }
/** * Gets the converter that should be used by this component. * * @param type * The type to convert to * * @return The converter that should be used by this component */ public IConverter getConverter(Class/* <?> */type) { return getApplication().getConverterLocator().getConverter(type); }
/** * Gets the converter that should be used by this component. * * @param type * The type to convert to * * @return The converter that should be used by this component */ public IConverter getConverter(Class<?> type) { return getApplication().getConverterLocator().getConverter(type); }
/** * @param buffer */ private void overrideDateType(AppendingStringBuffer buffer) { if (!addedDateInfo) { IConverter converter = Application.get().getConverterLocator().getConverter(Date.class); if (DateConverter.class.isAssignableFrom(converter.getClass())) { DateFormat dateFormat = ((DateConverter) converter).getDateFormat(Session.get().getLocale()); if (SimpleDateFormat.class.isAssignableFrom(dateFormat.getClass())) { SimpleDateFormat sdf = (SimpleDateFormat) dateFormat; String pattern = sdf.toPattern(); if (pattern.indexOf("yyyy") == -1) { pattern = pattern.replace("yy", "yyyy"); } buffer.append("yav_config.DATE_FORMAT='" + pattern + "';\n"); } } addedDateInfo = true; } }
private static String resolveDatePattern() { Application app = Application.get(); if (app != null) { IConverter converter = app.getConverterLocator().getConverter(DateTime.class); if (!(converter instanceof DateConverter)) { converter = app.getConverterLocator().getConverter(Date.class); } Session session = Session.get(); if (session != null) { return ((SimpleDateFormat) ((org.apache.wicket.util.convert.converters.DateConverter) converter) .getDateFormat(session.getLocale())).toPattern(); } } return "d-M-yy"; }
/** * @param buffer */ private void overrideDateType(AppendingStringBuffer buffer) { if (!addedDateInfo) { IConverter<Date> converter = Application.get() .getConverterLocator() .getConverter(Date.class); if (DateConverter.class.isAssignableFrom(converter.getClass())) { DateFormat dateFormat = ((DateConverter)converter).getDateFormat(Session.get() .getLocale()); if (SimpleDateFormat.class.isAssignableFrom(dateFormat.getClass())) { SimpleDateFormat sdf = (SimpleDateFormat)dateFormat; String pattern = sdf.toPattern(); if (pattern.indexOf("yyyy") == -1) { pattern = pattern.replace("yy", "yyyy"); } buffer.append("yav_config.DATE_FORMAT='" + pattern + "';\n"); } } addedDateInfo = true; } }
private static String resolveDatePattern() { Application app = Application.get(); if (app != null) { IConverter converter = app.getConverterLocator().getConverter(DateTime.class); if (!(converter instanceof DateConverter)) { converter = app.getConverterLocator().getConverter(Date.class); } Session session = Session.get(); if (session != null) { return ((SimpleDateFormat) ((org.apache.wicket.util.convert.converters.DateConverter) converter) .getDateFormat(session.getLocale())).toPattern(); } } return "d-M-yy"; }
/** * Get the converter that should be used by this component, delegates to * {@link #createConverter(Class)} and then to the application's * {@link IConverterLocator}. * * @param type * The type to convert to * * @return The converter that should be used by this component */ @SuppressWarnings("unchecked") @Override public <C> IConverter<C> getConverter(Class<C> type) { IConverter<?> converter = createConverter(type); if (converter != null) { return (IConverter<C>) converter; } return getApplication().getConverterLocator().getConverter(type); }
@Test public void providesConverterLocatorRegistersIsisSpecificConverters() { final IConverterLocator converterLocator = application.newConverterLocator(); assertThat(converterLocator.getConverter(ObjectAdapter.class), is(not(nullValue()))); assertThat(converterLocator.getConverter(ObjectAdapterMemento.class), is(not(nullValue()))); }
@Test public void providesConverterLocatorRegistersIsisSpecificConverters() { final IConverterLocator converterLocator = application.newConverterLocator(); assertThat(converterLocator.getConverter(ObjectAdapter.class), is(not(nullValue()))); assertThat(converterLocator.getConverter(ObjectAdapterMemento.class), is(not(nullValue()))); }
/** * Safe method to get String representation of an object. * Wicket convertions are also has been used * @param data * @return */ @SuppressWarnings("unchecked") public static String toString(Object data) { if(data==null) return "null"; else if (data instanceof CharSequence) return data.toString(); else { IConverter<Object> converter = (IConverter<Object>)OrienteerWebApplication.lookupApplication() .getConverterLocator().getConverter(data.getClass()); if(converter!=null) { return converter.convertToString(data, Session.exists()?Session.get().getLocale():Locale.getDefault()); } else { return data.toString(); } } } }
/** * Get the converter that should be used by this component, delegates to * {@link #createConverter(Class)} and then to the application's * {@link IConverterLocator}. * * @param type * The type to convert to * * @return The converter that should be used by this component */ @SuppressWarnings("unchecked") @Override public <C> IConverter<C> getConverter(Class<C> type) { IConverter<?> converter = createConverter(type); if (converter != null) { return (IConverter<C>) converter; } return getApplication().getConverterLocator().getConverter(type); }
/** * Converts the object to its string representation using the appropriate converter, if defined. * * @param <T> the object type * @param object the object * @return the string representation using the appropriate converter, if defined. #toString() otherwise. */ public static <T> String toString(T object) { String value = null; @SuppressWarnings("unchecked") IConverter<T> converter = (IConverter<T>) Application.get().getConverterLocator().getConverter(object.getClass()); if (converter != null) { value = converter.convertToString(object, Session.get().getLocale()); } else { value = object.toString(); } return value; } }
/** * Converts the object to its string representation using the appropriate converter, if defined. * * @param <T> the object type * @param object the object * @return the string representation using the appropriate converter, if defined. #toString() otherwise. */ public static <T> String toString(T object) { String value = null; @SuppressWarnings("unchecked") IConverter<T> converter = (IConverter<T>) Application.get().getConverterLocator().getConverter(object.getClass()); if (converter != null) { value = converter.convertToString(object, Session.get().getLocale()); } else { value = object.toString(); } return value; } }
/** * Convert given object to localized string * Uses Wicket {@link IConverter} * @param value {@link Object} value which need convert to string * @param defaultValue {@link String} default value if can't convert value to string or value is null * @return {@link String} value converted into string */ public static final String objectToString(Object value, String defaultValue) { String ret = null; if(value!=null) { final Class<?> objectClass = value.getClass(); final IConverter converter = OrienteerWebApplication.get().getConverterLocator().getConverter(objectClass); ret = converter.convertToString(value, OrienteerWebSession.get().getLocale()); } return ret!=null?ret:defaultValue; }
if (converter == null && result != null) converter = Application.get().getConverterLocator().getConverter(result.getClass());
IConverter converter = getConverterLocator().getConverter(c);