本文整理汇总了Java中org.springframework.format.Formatter类的典型用法代码示例。如果您正苦于以下问题:Java Formatter类的具体用法?Java Formatter怎么用?Java Formatter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Formatter类属于org.springframework.format包,在下文中一共展示了Formatter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureFormatterFrom
import org.springframework.format.Formatter; //导入依赖的package包/类
private Formatter<Number> configureFormatterFrom(NumberFormat annotation) {
if (StringUtils.hasLength(annotation.pattern())) {
return new NumberFormatter(resolveEmbeddedValue(annotation.pattern()));
}
else {
Style style = annotation.style();
if (style == Style.PERCENT) {
return new PercentFormatter();
}
else if (style == Style.CURRENCY) {
return new CurrencyFormatter();
}
else {
return new NumberFormatter();
}
}
}
示例2: registerFormatters
import org.springframework.format.Formatter; //导入依赖的package包/类
private void registerFormatters() {
if (this.formatters != null) {
for (Object formatter : this.formatters) {
if (formatter instanceof Formatter<?>) {
this.conversionService.addFormatter((Formatter<?>) formatter);
}
else if (formatter instanceof AnnotationFormatterFactory<?>) {
this.conversionService.addFormatterForFieldAnnotation((AnnotationFormatterFactory<?>) formatter);
}
else {
throw new IllegalArgumentException(
"Custom formatters must be implementations of Formatter or AnnotationFormatterFactory");
}
}
}
if (this.formatterRegistrars != null) {
for (FormatterRegistrar registrar : this.formatterRegistrars) {
registrar.registerFormatters(this.conversionService);
}
}
installFormatters(this.conversionService);
}
示例3: configureFormatterFrom
import org.springframework.format.Formatter; //导入依赖的package包/类
private Formatter<Number> configureFormatterFrom(NumberFormat annotation) {
if (StringUtils.hasLength(annotation.pattern())) {
return new NumberStyleFormatter(resolveEmbeddedValue(annotation.pattern()));
}
else {
Style style = annotation.style();
if (style == Style.CURRENCY) {
return new CurrencyStyleFormatter();
}
else if (style == Style.PERCENT) {
return new PercentStyleFormatter();
}
else {
return new NumberStyleFormatter();
}
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:NumberFormatAnnotationFormatterFactory.java
示例4: configureFormatterFrom
import org.springframework.format.Formatter; //导入依赖的package包/类
private Formatter<MonetaryAmount> configureFormatterFrom(NumberFormat annotation) {
if (StringUtils.hasLength(annotation.pattern())) {
return new PatternDecoratingFormatter(resolveEmbeddedValue(annotation.pattern()));
}
else {
Style style = annotation.style();
if (style == Style.NUMBER) {
return new NumberDecoratingFormatter(new NumberStyleFormatter());
}
else if (style == Style.PERCENT) {
return new NumberDecoratingFormatter(new PercentStyleFormatter());
}
else {
return new NumberDecoratingFormatter(new CurrencyStyleFormatter());
}
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:Jsr354NumberFormatAnnotationFormatterFactory.java
示例5: registerFormatters
import org.springframework.format.Formatter; //导入依赖的package包/类
private void registerFormatters() {
if (this.formatters != null) {
for (Object formatter : this.formatters) {
if (formatter instanceof Formatter<?>) {
this.conversionService.addFormatter((Formatter<?>) formatter);
}
else if (formatter instanceof AnnotationFormatterFactory<?>) {
this.conversionService.addFormatterForFieldAnnotation((AnnotationFormatterFactory<?>) formatter);
}
else {
throw new IllegalArgumentException(
"Custom formatters must be implementations of Formatter or AnnotationFormatterFactory");
}
}
}
if (this.formatterRegistrars != null) {
for (FormatterRegistrar registrar : this.formatterRegistrars) {
registrar.registerFormatters(this.conversionService);
}
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:FormattingConversionServiceFactoryBean.java
示例6: getHandledMetatypes
import org.springframework.format.Formatter; //导入依赖的package包/类
/**
* Extract handled types from all possible sources (annotation and interface).
* @param formatter
* @return
*/
@SuppressWarnings("unchecked")
public static Set<Key<?>> getHandledMetatypes(Formatter<?> formatter) {
Assert.notNull(formatter, "formatter is null");
Set<Key<?>> set = new HashSet<>();
if(formatter instanceof SelfDescribedFormatter) {
set.addAll(((SelfDescribedFormatter) formatter).getHandledMetatypes());
}
FormatterInfo formatterInfo = AnnotationUtils.findAnnotation(formatter.getClass(), FormatterInfo.class);
if(formatterInfo != null) {
for(MetatypeInfo metatypeInfo: formatterInfo.metatypes()) {
set.add(MetatypeUtils.toKey(metatypeInfo));
}
}
return set;
}
示例7: registerFormatters
import org.springframework.format.Formatter; //导入依赖的package包/类
private void registerFormatters() {
if (this.formatters != null) {
for (Object formatter : this.formatters) {
if (formatter instanceof Formatter<?>) {
this.conversionService
.addFormatter((Formatter<?>) formatter);
} else if (formatter instanceof AnnotationFormatterFactory<?>) {
this.conversionService
.addFormatterForFieldAnnotation((AnnotationFormatterFactory<?>) formatter);
} else {
throw new IllegalArgumentException(
"Custom formatters must be implementations of Formatter or AnnotationFormatterFactory");
}
}
}
if (this.formatterRegistrars != null) {
for (FormatterRegistrar registrar : this.formatterRegistrars) {
registrar.registerFormatters(this.conversionService);
}
}
installFormatters(this.conversionService);
}
示例8: getFormatter
import org.springframework.format.Formatter; //导入依赖的package包/类
/**
* Get a formatter for class and property name
* @param clazz the class
* @param propertyName the property name
* @return the formatter or null if none
*/
public static Formatter<?> getFormatter(Class<?> clazz, String propertyName) {
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(clazz, propertyName);
if (pd != null) {
NumberFormat format = getAnnotation(pd, NumberFormat.class);
if (format != null) {
return (Formatter<?>) numberFormatFactory.getPrinter(format, pd.getPropertyType());
}
PeriodFormat periodFormat = getAnnotation(pd, PeriodFormat.class);
if (periodFormat != null)
return new PeriodFormatter();
}
return null;
}
示例9: addFormatter
import org.springframework.format.Formatter; //导入依赖的package包/类
@Override
public void addFormatter(Formatter<?> formatter) {
Class<?> fieldType = GenericTypeResolver.resolveTypeArgument(formatter.getClass(), Formatter.class);
if (fieldType == null) {
throw new IllegalArgumentException("Unable to extract parameterized field type argument from Formatter [" +
formatter.getClass().getName() + "]; does the formatter parameterize the <T> generic type?");
}
addFormatterForFieldType(fieldType, formatter);
}
示例10: getFormatter
import org.springframework.format.Formatter; //导入依赖的package包/类
protected Formatter<Date> getFormatter(DateTimeFormat annotation, Class<?> fieldType) {
DateFormatter formatter = new DateFormatter();
formatter.setStylePattern(resolveEmbeddedValue(annotation.style()));
formatter.setIso(annotation.iso());
formatter.setPattern(resolveEmbeddedValue(annotation.pattern()));
return formatter;
}
示例11: mvcConversionService
import org.springframework.format.Formatter; //导入依赖的package包/类
@Bean
@Autowired // L'ho spostato qui per risolvere il problema "Requested bean is currently in creation"
// Questo registra un Date Formatter
public FormattingConversionService mvcConversionService(YadaDateFormatter yadaDateFormatter) {
FormattingConversionServiceFactoryBean result = new FormattingConversionServiceFactoryBean();
Set<Formatter<Date>> formatters = new HashSet<Formatter<Date>>();
formatters.add(yadaDateFormatter);
result.setFormatters(formatters);
result.afterPropertiesSet();
return result.getObject();
}
示例12: addCustomFormatter
import org.springframework.format.Formatter; //导入依赖的package包/类
/**
* Add a custom formatter for the field type specified in {@link Formatter} class,
* applying it to the specified fields only, if any, or otherwise to all fields.
* <p>Registers a corresponding {@link PropertyEditor} adapter underneath the covers.
* @param formatter the formatter to add, generically declared for a specific type
* @param fields the fields to apply the formatter to, or none if to be applied to all
* @since 4.2
* @see #registerCustomEditor(Class, String, PropertyEditor)
*/
public void addCustomFormatter(Formatter<?> formatter, String... fields) {
FormatterPropertyEditorAdapter adapter = new FormatterPropertyEditorAdapter(formatter);
Class<?> fieldType = adapter.getFieldType();
if (ObjectUtils.isEmpty(fields)) {
getPropertyEditorRegistry().registerCustomEditor(fieldType, adapter);
}
else {
for (String field : fields) {
getPropertyEditorRegistry().registerCustomEditor(fieldType, field, adapter);
}
}
}
示例13: getFieldType
import org.springframework.format.Formatter; //导入依赖的package包/类
static Class<?> getFieldType(Formatter<?> formatter) {
Class<?> fieldType = GenericTypeResolver.resolveTypeArgument(formatter.getClass(), Formatter.class);
if (fieldType == null) {
throw new IllegalArgumentException("Unable to extract parameterized field type argument from Formatter [" +
formatter.getClass().getName() + "]; does the formatter parameterize the <T> generic type?");
}
return fieldType;
}
示例14: getFormatter
import org.springframework.format.Formatter; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <T> Formatter<T> getFormatter(Key<T> key) {
Assert.notNull(key, "key is null");
Formatter<?> formatter = map.get(key);
if(formatter == null) {
throw new RuntimeException("No registered formatters for: " + key);
}
return (Formatter<T>) formatter;
}
示例15: parse
import org.springframework.format.Formatter; //导入依赖的package包/类
/**
* Do invocation of specified formatter on text with default locale.
* @param formatter
* @param text allow null
* @param <T>
* @return parsed object or null if text is null
*/
public static <T> T parse(Formatter<T> formatter, String text) {
if(text == null) {
return null;
}
try {
return formatter.parse(text, Locale.getDefault());
} catch (ParseException e) {
throw new IllegalArgumentException("Can not parse:'" + text + "'", e);
}
}