
com.jchanghong.core.convert.impl.LocaleConverter Maven / Gradle / Ivy
The newest version!
package com.jchanghong.core.convert.impl;
import java.util.Locale;
import com.jchanghong.core.convert.AbstractConverter;
import com.jchanghong.core.util.StrUtil;
/**
*
* {@link Locale}对象转换器
* 只提供String转换支持
*
* @author Looly
* @since 4.5.2
*/
public class LocaleConverter extends AbstractConverter {
private static final long serialVersionUID = 1L;
@Override
protected Locale convertInternal(Object value) {
try {
String str = convertToStr(value);
if (StrUtil.isEmpty(str)) {
return null;
}
final String[] items = str.split("_");
if (items.length == 1) {
return new Locale(items[0]);
}
if (items.length == 2) {
return new Locale(items[0], items[1]);
}
return new Locale(items[0], items[1], items[2]);
} catch (Exception e) {
// Ignore Exception
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy