当前位置: 首页>>代码示例>>Java>>正文


Java Formatter类代码示例

本文整理汇总了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();
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:NumberFormatAnnotationFormatterFactory.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:FormattingConversionServiceFactoryBean.java

示例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;
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:21,代码来源:FormatterUtils.java

示例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);
}
 
开发者ID:yangjm,项目名称:winlet,代码行数:23,代码来源:WinletFormattingConversionServiceFactoryBean.java

示例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;
}
 
开发者ID:chelu,项目名称:jdal,代码行数:22,代码来源:FormatUtils.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:FormattingConversionService.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:DateTimeFormatAnnotationFormatterFactory.java

示例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();
}
 
开发者ID:xtianus,项目名称:yadaframework,代码行数:12,代码来源:YadaWebConfig.java

示例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);
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:DataBinder.java

示例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;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:FormattingConversionService.java

示例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;
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:11,代码来源:DefaultMetatypeFormatterRegistry.java

示例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);
    }
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:18,代码来源:FormatterUtils.java


注:本文中的org.springframework.format.Formatter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。