List of usage examples for org.apache.commons.lang StringUtils defaultIfBlank
public static String defaultIfBlank(String str, String defaultStr)
Returns either the passed in String, or if the String is whitespace, empty ("") or null
, the value of defaultStr
.
From source file:net.ymate.platform.serv.nio.codec.NioStringCodec.java
public ICodec init(String charset) { __charset = StringUtils.defaultIfBlank(charset, "UTF-8"); return this; }
From source file:net.ymate.platform.serv.nio.server.NioServerCfg.java
public NioServerCfg(IServModuleCfg moduleCfg, String serverName) { super(moduleCfg, serverName); ///* w w w . j a v a 2 s . co m*/ __selectorCount = BlurObject.bind( StringUtils.defaultIfBlank(moduleCfg.getServerCfg(getServerName()).get("selector_count"), "1")) .toIntValue(); }
From source file:net.ymate.platform.validation.validate.CompareValidator.java
public ValidateResult validate(ValidateContext context) { Object _paramValue = context.getParamValue(); if (_paramValue != null && !_paramValue.getClass().isArray()) { VCompare _vCompare = (VCompare) context.getAnnotation(); boolean _matched = BlurObject.bind(_paramValue).toStringValue() .equals(BlurObject.bind(context.getParamValue(_vCompare.with())).toString()); String _condStr = "equals"; switch (_vCompare.cond()) { case NOT_EQ: _matched = !_matched;/*w ww . j a v a2 s.c om*/ _condStr = "not equals"; break; case EQ: } if (!_matched) { String _pName = StringUtils.defaultIfBlank(context.getParamLabel(), context.getParamName()); _pName = I18N.formatMessage(VALIDATION_I18N_RESOURCE, _pName, _pName); String _pLabel = StringUtils.defaultIfBlank(_vCompare.withLabel(), _vCompare.with()); _pLabel = I18N.formatMessage(VALIDATION_I18N_RESOURCE, _pLabel, _pLabel); // String _msg = StringUtils.trimToNull(_vCompare.msg()); if (_msg != null) { _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, _msg, _msg, _pName, _pLabel); } else { switch (_vCompare.cond()) { case NOT_EQ: String __COMPARE_NOT_EQ = "ymp.validation.compare_not_eq"; _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, __COMPARE_NOT_EQ, "{0} can not eq {1}.", _pName, _pLabel); break; case EQ: String __COMPARE_EQ = "ymp.validation.compare_eq"; _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, __COMPARE_EQ, "{0} must be eq {1}.", _pName, _pLabel); } if (StringUtils.trimToNull(_msg) == null) { _msg = I18N.formatMessage("{0} must be {1} {2}", _pName, _condStr, _pLabel); } } return new ValidateResult(context.getParamName(), _msg); } } return null; }
From source file:net.ymate.platform.validation.validate.DateTimeValidator.java
public ValidateResult validate(ValidateContext context) { Object _paramValue = context.getParamValue(); if (_paramValue != null) { if (!context.getParamValue().getClass().isArray()) { String _dateStr = BlurObject.bind(_paramValue).toStringValue(); if (StringUtils.isNotBlank(_dateStr)) { VDateTime _vDate = (VDateTime) context.getAnnotation(); try { DateTimeUtils.parseDateTime(_dateStr, _vDate.pattern()); } catch (Exception e) { String _pName = StringUtils.defaultIfBlank(context.getParamLabel(), context.getParamName()); _pName = I18N.formatMessage(VALIDATION_I18N_RESOURCE, _pName, _pName); // String _msg = StringUtils.trimToNull(_vDate.msg()); if (_msg != null) { _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, _msg, _msg, _pName); } else { String __DATETIME = "ymp.validation.datetime"; _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, __DATETIME, "{0} not a valid datetime.", _pName); }//from w w w . j av a2s .c o m return new ValidateResult(context.getParamName(), _msg); } } } } return null; }
From source file:net.ymate.platform.validation.validate.EmailValidator.java
public ValidateResult validate(ValidateContext context) { Object _paramValue = context.getParamValue(); if (_paramValue != null) { if (!context.getParamValue().getClass().isArray()) { String _value = BlurObject.bind(_paramValue).toStringValue(); if (StringUtils.isNotBlank(_value)) { if (!_value.matches("(?:\\w[-._\\w]*\\w@\\w[-._\\w]*\\w\\.\\w{2,3}$)")) { String _pName = StringUtils.defaultIfBlank(context.getParamLabel(), context.getParamName()); _pName = I18N.formatMessage(VALIDATION_I18N_RESOURCE, _pName, _pName); // String _msg = StringUtils.trimToNull(((VEmail) context.getAnnotation()).msg()); if (_msg != null) { _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, _msg, _msg, _pName); } else { String __EMAIL = "ymp.validation.email"; _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, __EMAIL, "{0} not a valid email address.", _pName); }// w ww . j a v a 2 s . c om return new ValidateResult(context.getParamName(), _msg); } } } } return null; }
From source file:net.ymate.platform.validation.validate.LengthValidator.java
public ValidateResult validate(ValidateContext context) { boolean _matched = false; VLength _vLength = (VLength) context.getAnnotation(); Object _paramValue = context.getParamValue(); if (_paramValue != null) { int _length = 0; if (!_paramValue.getClass().isArray()) { String _value = BlurObject.bind(_paramValue).toStringValue(); if (StringUtils.isNotBlank(_value)) { _length = _value.length(); }/* w w w.j av a 2 s .c om*/ } else { Object[] _values = (Object[]) _paramValue; _length = _values.length; } // if (_vLength.min() > 0 && _vLength.max() == _vLength.min() && _length != _vLength.max()) { _matched = true; } else if (_vLength.min() > 0 && _length < _vLength.min()) { _matched = true; } else if (_vLength.max() > 0 && _length > _vLength.max()) { _matched = true; } } if (_matched) { String _pName = StringUtils.defaultIfBlank(context.getParamLabel(), context.getParamName()); _pName = I18N.formatMessage(VALIDATION_I18N_RESOURCE, _pName, _pName); String _msg = StringUtils.trimToNull(_vLength.msg()); if (_msg != null) { _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, _msg, _msg, _pName); } else { if (_vLength.max() > 0 && _vLength.min() > 0) { if (_vLength.max() == _vLength.min()) { _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, "ymp.validation.length_eq", "{0} length must be eq {1}.", _pName, _vLength.max()); } else { _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, "ymp.validation.length_between", "{0} length must be between {1} and {2}.", _pName, _vLength.min(), _vLength.max()); } } else if (_vLength.max() > 0) { _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, "ymp.validation.length_max", "{0} length must be lt {1}.", _pName, _vLength.max()); } else { _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, "ymp.validation.length_min", "{0} length must be gt {1}.", _pName, _vLength.min()); } } return new ValidateResult(context.getParamName(), _msg); } return null; }
From source file:net.ymate.platform.validation.validate.NumericValidator.java
public ValidateResult validate(ValidateContext context) { Object _paramValue = context.getParamValue(); if (_paramValue != null) { boolean _matched = false; boolean _flag = false; VNumeric _vNumeric = (VNumeric) context.getAnnotation(); try {/* w w w.ja v a 2s . c o m*/ Number _number = NumberUtils.createNumber(BlurObject.bind(_paramValue).toStringValue()); if (_number == null) { _matched = true; _flag = true; } else { if (_vNumeric.min() > 0 && _number.doubleValue() < _vNumeric.min()) { _matched = true; } else if (_vNumeric.max() > 0 && _number.doubleValue() > _vNumeric.max()) { _matched = true; } } } catch (Exception e) { _matched = true; _flag = true; } if (_matched) { String _pName = StringUtils.defaultIfBlank(context.getParamLabel(), context.getParamName()); _pName = I18N.formatMessage(VALIDATION_I18N_RESOURCE, _pName, _pName); String _msg = StringUtils.trimToNull(_vNumeric.msg()); if (_msg != null) { _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, _msg, _msg, _pName); } else { if (_flag) { String __NUMERIC = "ymp.validation.numeric"; _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, __NUMERIC, "{0} not a valid numeric.", _pName); } else { if (_vNumeric.max() > 0 && _vNumeric.min() > 0) { String __NUMERIC_BETWEEN = "ymp.validation.numeric_between"; _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, __NUMERIC_BETWEEN, "{0} numeric must be between {1} and {2}.", _pName, _vNumeric.min(), _vNumeric.max()); } else if (_vNumeric.max() > 0) { String __NUMERIC_MAX = "ymp.validation.numeric_max"; _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, __NUMERIC_MAX, "{0} numeric must be lt {1}.", _pName, _vNumeric.max()); } else { String __NUMERIC_MIN = "ymp.validation.numeric_min"; _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, __NUMERIC_MIN, "{0} numeric must be gt {1}.", _pName, _vNumeric.min()); } } } return new ValidateResult(context.getParamName(), _msg); } } return null; }
From source file:net.ymate.platform.validation.validate.RegexValidator.java
public ValidateResult validate(ValidateContext context) { Object _paramValue = context.getParamValue(); if (_paramValue != null) { if (!_paramValue.getClass().isArray()) { String _value = BlurObject.bind(_paramValue).toStringValue(); if (StringUtils.isNotBlank(_value)) { VRegex _vRegex = (VRegex) context.getAnnotation(); if (!_value.matches(_vRegex.regex())) { String _pName = StringUtils.defaultIfBlank(context.getParamLabel(), context.getParamName()); _pName = I18N.formatMessage(VALIDATION_I18N_RESOURCE, _pName, _pName); // String _msg = StringUtils.trimToNull(_vRegex.msg()); if (_msg != null) { _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, _msg, _msg, _pName); } else { String __REGEX = "ymp.validation.regex"; _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, __REGEX, "{0} regex not match.", _pName); }//from w w w . j a v a 2 s . c o m return new ValidateResult(context.getParamName(), _msg); } } } } return null; }
From source file:net.ymate.platform.validation.validate.RequriedValidator.java
public ValidateResult validate(ValidateContext context) { boolean _matched = false; Object _paramValue = context.getParamValue(); if (_paramValue == null) { _matched = true;/* w w w . j ava2 s . co m*/ } else { if (!_paramValue.getClass().isArray()) { if (StringUtils.isBlank(BlurObject.bind(_paramValue).toStringValue())) { _matched = true; } } else { _matched = ArrayUtils.isEmpty((Object[]) _paramValue); } } if (_matched) { String _pName = StringUtils.defaultIfBlank(context.getParamLabel(), context.getParamName()); _pName = I18N.formatMessage(VALIDATION_I18N_RESOURCE, _pName, _pName); // String _msg = StringUtils.trimToNull(((VRequried) context.getAnnotation()).msg()); if (_msg != null) { _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, _msg, _msg, _pName); } else { String __REQURIED = "ymp.validation.requried"; _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, __REQURIED, "{0} must be requried.", _pName); } return new ValidateResult(context.getParamName(), _msg); } return null; }
From source file:net.ymate.platform.webmvc.impl.DefaultModuleCfg.java
public DefaultModuleCfg(YMP owner) throws Exception { Map<String, String> _moduleCfgs = owner.getConfig().getModuleConfigs(IWebMvc.MODULE_NAME); ///*from ww w . ja va2 s.co m*/ String _reqProcessorClass = StringUtils.defaultIfBlank(_moduleCfgs.get("request_processor_class"), "default"); Class<? extends IRequestProcessor> _requestProcessorClass = Type.REQUEST_PROCESSORS.get(_reqProcessorClass); if (_requestProcessorClass == null && StringUtils.isNotBlank(_reqProcessorClass)) { __requestProcessor = ClassUtils.impl(_reqProcessorClass, IRequestProcessor.class, this.getClass()); } else if (_requestProcessorClass != null) { __requestProcessor = _requestProcessorClass.newInstance(); } if (__requestProcessor == null) { __requestProcessor = new DefaultRequestProcessor(); } // String _errorProcessorClass = _moduleCfgs.get("error_processor_class"); if (StringUtils.isNotBlank(_errorProcessorClass)) { __errorProcessor = ClassUtils.impl(_errorProcessorClass, IWebErrorProcessor.class, this.getClass()); } // String _cacheProcessorClass = _moduleCfgs.get("cache_processor_class"); if (StringUtils.isNotBlank(_errorProcessorClass)) { __cacheProcessor = ClassUtils.impl(_cacheProcessorClass, IWebCacheProcessor.class, this.getClass()); } // __charsetEncoding = StringUtils.defaultIfBlank(_moduleCfgs.get("default_charset_encoding"), "UTF-8"); __requestIgnoreRegex = StringUtils.defaultIfBlank(_moduleCfgs.get("request_ignore_regex"), __IGNORE); __requestMethodParam = StringUtils.defaultIfBlank(_moduleCfgs.get("request_method_param"), "_method"); __requestPrefix = StringUtils.trimToEmpty(_moduleCfgs.get("request_prefix")); // __parameterEscapeMode = BlurObject.bind(_moduleCfgs.get("parameter_escape_mode")).toBooleanValue(); __parameterEscapeOrder = Type.EscapeOrder.valueOf( StringUtils.defaultIfBlank(_moduleCfgs.get("parameter_escape_order"), "after").toUpperCase()); // __baseViewPath = RuntimeUtils.replaceEnvVariable( StringUtils.defaultIfBlank(_moduleCfgs.get("base_view_path"), "/WEB-INF/templates/")); __abstractBaseViewPath = __baseViewPath; if (__abstractBaseViewPath.startsWith("/WEB-INF")) { __abstractBaseViewPath = new File(RuntimeUtils.getRootPath(false), __abstractBaseViewPath).getPath(); } // __cookiePrefix = StringUtils.trimToEmpty(_moduleCfgs.get("cookie_prefix")); __cookieDomain = StringUtils.trimToEmpty(_moduleCfgs.get("cookie_domain")); __cookiePath = StringUtils.defaultIfBlank(_moduleCfgs.get("cookie_path"), "/"); __cookieAuthKey = StringUtils.trimToEmpty(_moduleCfgs.get("cookie_auth_key")); __defaultEnabledCookieAuth = BlurObject.bind(_moduleCfgs.get("default_enabled_cookie_auth")) .toBooleanValue(); // __uploadTempDir = RuntimeUtils .replaceEnvVariable(StringUtils.trimToEmpty(_moduleCfgs.get("upload_temp_dir"))); __uploadFileSizeMax = Integer .parseInt(StringUtils.defaultIfBlank(_moduleCfgs.get("upload_file_size_max"), "10485760")); __uploadTotalSizeMax = Integer .parseInt(StringUtils.defaultIfBlank(_moduleCfgs.get("upload_total_size_max"), "10485760")); __uploadSizeThreshold = Integer .parseInt(StringUtils.defaultIfBlank(_moduleCfgs.get("upload_size_threshold"), "10240")); __uploadFileListener = ClassUtils.impl(_moduleCfgs.get("upload_file_listener_class"), ProgressListener.class, this.getClass()); // __conventionMode = BlurObject.bind(_moduleCfgs.get("convention_mode")).toBooleanValue(); __conventionUrlrewriteMode = BlurObject.bind(_moduleCfgs.get("convention_urlrewrite_mode")) .toBooleanValue(); __conventionInterceptorMode = BlurObject.bind(_moduleCfgs.get("convention_interceptor_mode")) .toBooleanValue(); // __conventionViewAllowPaths = new HashSet<String>(); __conventionViewNotAllowPaths = new HashSet<String>(); // String[] _cViewPaths = StringUtils .split(StringUtils.defaultIfBlank(_moduleCfgs.get("convention_view_paths"), ""), "|"); if (_cViewPaths != null) { for (String _cvPath : _cViewPaths) { _cvPath = StringUtils.trimToNull(_cvPath); if (_cvPath != null) { boolean _flag = true; if (_cvPath.length() > 1) { char _c = _cvPath.charAt(_cvPath.length() - 1); if (_c == '+') { _cvPath = StringUtils.substring(_cvPath, 0, _cvPath.length() - 1); } else if (_c == '-') { _cvPath = StringUtils.substring(_cvPath, 0, _cvPath.length() - 1); _flag = false; } } if (_cvPath.charAt(0) != '/') { _cvPath = "/" + _cvPath; } if (_flag) { __conventionViewAllowPaths.add(_cvPath); } else { __conventionViewNotAllowPaths.add(_cvPath); } } } } }