org.apache.commons.beanutils.converters.DateConverter Java Examples

The following examples show how to use org.apache.commons.beanutils.converters.DateConverter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BeanUtil.java    From lutece-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * BeanUtil initialization, considering Lutèce availables locales and date format properties
 */
public static void init( )
{
    _mapBeanUtilsBeans = new HashMap<>( );

    for ( Locale locale : I18nService.getAdminAvailableLocales( ) )
    {
        BeanUtilsBean beanUtilsBean = new BeanUtilsBean( );
        beanUtilsBean.getPropertyUtils( ).addBeanIntrospector( SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS );

        DateConverter dateConverter = new DateConverter( null );
        dateConverter.setPattern( I18nService.getDateFormatShortPattern( locale ) );
        beanUtilsBean.getConvertUtils( ).register( dateConverter, Date.class );
        _mapBeanUtilsBeans.put( locale.getLanguage( ), beanUtilsBean );
    }
}
 
Example #2
Source File: ObjectMapper.java    From DWSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 定义Apache BeanUtils日期Converter的格式,可注册多个格式,以','分隔
 */
public static void registerDateConverter(String patterns) {
	DateConverter dc = new DateConverter();
	dc.setUseLocaleFormat(true);
	dc.setPatterns(StringUtils.split(patterns, ","));
	ConvertUtils.register(dc, Date.class);
}
 
Example #3
Source File: ConvertUtils.java    From lemon with Apache License 2.0 5 votes vote down vote up
/**
 * register date converter.
 */
private static void registerDateConverter() {
    DateConverter dc = new DateConverter();
    dc.setUseLocaleFormat(true);
    dc.setPatterns(new String[] { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss" });
    org.apache.commons.beanutils.ConvertUtils.register(dc, Date.class);
}
 
Example #4
Source File: ConvertUtils.java    From base-framework with Apache License 2.0 5 votes vote down vote up
/**
 * 注册一个时间类型的转换器,当前默认的格式为:yyyy-MM-dd
 * 
 * @param patterns 日期格式
 */
public static void registerDateConverter(String... patterns) {
	DateConverter dc = new DateConverter();
	dc.setUseLocaleFormat(true);
	dc.setPatterns(patterns);
	register(dc, Date.class);
}
 
Example #5
Source File: StartedEventListener.java    From youkefu with Apache License 2.0 4 votes vote down vote up
@Override
  public void onApplicationEvent(ContextRefreshedEvent event) {
  	ConvertUtils.register(new DateConverter(null), java.util.Date.class);
  	if(UKDataContext.getContext() == null){
  		UKDataContext.setApplicationContext(event.getApplicationContext());
  	}
  	sysDicRes = event.getApplicationContext().getBean(SysDicRepository.class) ;
  	blackListRes = event.getApplicationContext().getBean(BlackListRepository.class) ;
  	List<SysDic> sysDicList = sysDicRes.findAll() ;
  	
  	for(SysDic dic : sysDicList){
  		CacheHelper.getSystemCacheBean().put(dic.getId(), dic, dic.getOrgi());
	if(dic.getParentid().equals("0")){
		List<SysDic> sysDicItemList = new ArrayList<SysDic>();
		for(SysDic item : sysDicList){
			if(item.getDicid()!=null && item.getDicid().equals(dic.getId())){
				sysDicItemList.add(item) ;
			}
		}
		CacheHelper.getSystemCacheBean().put(dic.getCode(), sysDicItemList, dic.getOrgi());
	}
}
  	List<BlackEntity> blackList = blackListRes.findByOrgi(UKDataContext.SYSTEM_ORGI) ;
  	for(BlackEntity black : blackList){
  		if(!StringUtils.isBlank(black.getUserid())) {
   		if(black.getEndtime()==null || black.getEndtime().after(new Date())){
   			CacheHelper.getSystemCacheBean().put(black.getUserid(), black, black.getOrgi());
   		}
  		}
  	}
  	/**
  	 * 加载系统全局配置
  	 */
  	SystemConfigRepository systemConfigRes = event.getApplicationContext().getBean(SystemConfigRepository.class) ;
  	SystemConfig config = systemConfigRes.findByOrgi(UKDataContext.SYSTEM_ORGI) ;
  	if(config != null){
  		CacheHelper.getSystemCacheBean().put("systemConfig", config, UKDataContext.SYSTEM_ORGI);
  	}
  	GenerationRepository generationRes = event.getApplicationContext().getBean(GenerationRepository.class) ;
  	List<Generation> generationList = generationRes.findAll() ;
  	for(Generation generation : generationList){
  		CacheHelper.getSystemCacheBean().setAtomicLong(UKDataContext.ModelType.WORKORDERS.toString(), generation.getStartinx());
  	}
  	
  	UKTools.initSystemArea();
  	
  	UKTools.initSystemSecField(event.getApplicationContext().getBean(TablePropertiesRepository.class));
  	//UKTools.initAdv();//初始化广告位
  }
 
Example #6
Source File: MailingImpl.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Object clone(ApplicationContext con) {
	Mailing tmpMailing = (Mailing) con.getBean("Mailing");
	MailingComponent compNew = null;
	TrackableLink linkNew = null;
	DynamicTag tagNew = null;
	DynamicTagContent contentNew = null;

	try {
		ConvertUtils.register(new DateConverter(null), Date.class);
		// copy components
		for (MailingComponent compOrg : components.values()) {
			compNew = (MailingComponent) con.getBean("MailingComponent");
			BeanUtils.copyProperties(compNew, compOrg);
			if (compOrg.getBinaryBlock() != null) {
				compNew.setBinaryBlock(compOrg.getBinaryBlock(), compOrg.getMimeType());
			} else {
				compNew.setEmmBlock(compOrg.getEmmBlock(), compOrg.getMimeType());
			}
			compNew.setId(0);
			compNew.setMailingID(0);
			tmpMailing.addComponent(compNew);
		}

		// copy dyntags
		for (DynamicTag tagOrg : dynTags.values()) {
			tagNew = (DynamicTag) con.getBean("DynamicTag");
			for (DynamicTagContent contentOrg : tagOrg.getDynContent().values()) {
				contentNew = (DynamicTagContent) con.getBean("DynamicTagContent");
				BeanUtils.copyProperties(contentNew, contentOrg);
				contentNew.setId(0);
				contentNew.setDynNameID(0);
				tagNew.addContent(contentNew);
			}
			tagNew.setCompanyID(tagOrg.getCompanyID());
			tagNew.setDynName(tagOrg.getDynName());
			tagNew.setDisableLinkExtension(tagOrg.isDisableLinkExtension());
			tmpMailing.addDynamicTag(tagNew);
		}

		// copy urls
		for (TrackableLink linkOrg : trackableLinks.values()) {
			linkNew = (TrackableLink) con.getBean("TrackableLink");
			BeanUtils.copyProperties(linkNew, linkOrg);
			linkNew.setId(0);
			linkNew.setMailingID(0);
			linkNew.setActionID(linkOrg.getActionID());
			tmpMailing.getTrackableLinks().put(linkNew.getFullUrl(), linkNew);
		}

		// copy active media types
		for (Entry<Integer, Mediatype> entry : mediatypes.entrySet()) {
			Mediatype mediatype = entry.getValue();
			if (mediatype.getStatus() == Mediatype.STATUS_ACTIVE) {
				Mediatype mediatypeCopy = mediatype.copy();
				tmpMailing.getMediatypes().put(entry.getKey(), mediatypeCopy);
			}
		}

		tmpMailing.setOpenActionID(openActionID);
		tmpMailing.setClickActionID(clickActionID);

		return tmpMailing;
	} catch (Exception e) {
		logger.error("could not copy", e);
		return null;
	}
}
 
Example #7
Source File: Application.java    From xiaoyaoji with GNU General Public License v3.0 4 votes vote down vote up
/**
 * beanutils 日期格式化
 */
private static void initializeBeanUtilsConfig(){
    DateConverter converter = new DateConverter();
    converter.setPattern("yyyy-MM-dd HH:mm:ss");
    ConvertUtils.register(converter, Date.class);
}
 
Example #8
Source File: RegexParser.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
public void processTuple(byte[] tuple)
{
  if (tuple == null) {
    if (err.isConnected()) {
      err.emit(new KeyValPair<String, String>(null, "Blank/null tuple"));
    }
    errorTupleCount++;
    return;
  }
  String incomingString = new String(tuple);
  if (StringUtils.isBlank(incomingString)) {
    if (err.isConnected()) {
      err.emit(new KeyValPair<String, String>(incomingString, "Blank tuple"));
    }
    errorTupleCount++;
    return;
  }
  try {
    if (out.isConnected() && clazz != null) {
      Matcher matcher = pattern.matcher(incomingString);
      boolean patternMatched = false;
      Constructor<?> ctor = clazz.getConstructor();
      Object object = ctor.newInstance();

      if (matcher.find()) {
        for (int i = 0; i <= matcher.groupCount() - 1; i++) {
          if (delimitedParserSchema.getFields().get(i).getType() == DelimitedSchema.FieldType.DATE) {
            DateTimeConverter dtConverter = new DateConverter();
            dtConverter.setPattern((String)delimitedParserSchema.getFields().get(i).getConstraints().get(DelimitedSchema.DATE_FORMAT));
            ConvertUtils.register(dtConverter, Date.class);
          }
          BeanUtils.setProperty(object, delimitedParserSchema.getFields().get(i).getName(), matcher.group(i + 1));
        }
        patternMatched = true;
      }
      if (!patternMatched) {
        throw new ConversionException("The incoming tuple do not match with the Regex pattern defined.");
      }

      out.emit(object);
      emittedObjectCount++;
    }

  } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | InstantiationException | ConversionException e) {
    if (err.isConnected()) {
      err.emit(new KeyValPair<String, String>(incomingString, e.getMessage()));
      logger.debug("Regex Expression : {} Incoming tuple : {}", splitRegexPattern, incomingString);
    }
    errorTupleCount++;
    logger.error("Tuple could not be parsed. Reason {}", e.getMessage());
  }
}