📄 fixedpatterncalendarconverter.java
字号:
package xyz.frame.converter;import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.GregorianCalendar;import org.apache.log4j.Logger;import xyz.frame.LogicRequest;/** * Fixed Locale based calendar converter. Uses the error key invalid_date if * unable to parse its information. * * @author Guilherme Silveira */public class FixedPatternCalendarConverter implements Converter { private static final Logger logger = Logger .getLogger(FixedPatternCalendarConverter.class); private String pattern; /** * Simple constructor with pattern * * @param pattern * pattern */ public FixedPatternCalendarConverter(String pattern) { super(); this.pattern = pattern; } /** * * @see xyz.frame.converter.Converter#convert(java.lang.String, * java.lang.Class, xyz.frame.scope.LogicRequest) */ public Object convert(String value, Class<?> type, LogicRequest context) throws ConversionException { DateFormat df = new SimpleDateFormat(this.pattern); Calendar calendar = new GregorianCalendar(); try { calendar.setTime(df.parse(value)); } catch (ParseException e) { FixedPatternCalendarConverter.logger.error( "Unable to parse string " + value, e); throw new ConversionException("invalid_value", "Unable to parse string " + value, e); } return calendar; } /** * Returns the list of supported types * * @see xyz.frame.converter.Converter#getSupportedTypes() */ public Class<?>[] getSupportedTypes() { return new Class[] { Calendar.class }; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -