Example usage for org.apache.commons.lang StringUtils defaultIfEmpty

List of usage examples for org.apache.commons.lang StringUtils defaultIfEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultIfEmpty.

Prototype

public static String defaultIfEmpty(String str, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is empty or null, the value of defaultStr.

Usage

From source file:net.ymate.platform.mvc.web.DispatcherFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    __filterConfig = filterConfig;/*from  w ww.  j a v  a2 s .  c  om*/
    String _regx = StringUtils.defaultIfEmpty(__filterConfig.getInitParameter("ignore"), IGNORE);
    if (!"false".equalsIgnoreCase(_regx)) {
        ignorePatern = Pattern.compile(_regx, Pattern.CASE_INSENSITIVE);
    }
    __dispHelper = new DispatchHelper(filterConfig);
}

From source file:net.ymate.platform.mvc.web.impl.WebRequestProcessor.java

protected void addControllerMetaToMap(IControllerBeanMeta beanMeta) {
    for (RequestMeta _meta : beanMeta.getRequestMetas()) {
        if (WebMVC.getConfig().isRestfulModel()) {
            Set<HttpMethod> _allowMethods = ((HttpRequestMeta) _meta).getAllowHttpMethods();
            if (_allowMethods.isEmpty()) {
                __RESTFUL_MAPPING_MAP.get(HttpMethod.GET).put(_meta.getRequestMapping(), _meta);
            } else {
                for (HttpMethod _method : _allowMethods) {
                    __RESTFUL_MAPPING_MAP.get(_method).put(_meta.getRequestMapping(), _meta);
                }//  w w w.java 2 s .co  m
            }
        } else {
            if (_meta.getRequestMapping().contains("{")) {
                __REQUEST_MAPPING_MAP.put(_meta.getRequestMapping(), _meta);
            } else {
                __CONSTANT_REQUEST_MAPPING_MAP.put(_meta.getRequestMapping(), _meta);
            }
        }
        _LOG.info(I18N.formatMessage(YMP.__LSTRING_FILE, null, null, "ymp.mvc.register_controller",
                _meta.getRequestMapping(),
                _meta.getTarget().getClass().getName() + "#" + _meta.getMethod().getName()));
        // 
        for (PairObject<Class<IFilter>, String> _c : _meta.getFilters()) {
            _LOG.info(I18N.formatMessage(YMP.__LSTRING_FILE, null, null, "ymp.mvc.register_filter",
                    _meta.getRequestMapping(), _c.getKey().getSimpleName(),
                    StringUtils.defaultIfEmpty(_c.getValue(), "null")));
            this.getControllerBeanFactory().add(_c.getKey());
        }
    }
}

From source file:net.ymate.platform.mvc.web.support.DispatchHelper.java

/**
 * //from  ww w  . java2 s .c  o m
 *
 * @param config
 */
public DispatchHelper(FilterConfig config) {
    prefix = StringUtils.defaultIfEmpty(config.getInitParameter("prefix"), "");
    methodParam = StringUtils.defaultIfEmpty(config.getInitParameter("methodParam"), DEFAULT_METHOD_PARAM);
    baseViewFilePath = RuntimeUtils.getRootPath()
            + StringUtils.substringAfter(TemplateHelper.getRootViewPath(), "/WEB-INF/");
}

From source file:net.ymate.platform.mvc.web.support.DispatchHelper.java

/**
 * /*from   w  w  w.  ja va 2  s . com*/
 *
 * @param config
 */
public DispatchHelper(ServletConfig config) {
    prefix = StringUtils.defaultIfEmpty(config.getInitParameter("prefix"), "");
    methodParam = StringUtils.defaultIfEmpty(config.getInitParameter("methodParam"), DEFAULT_METHOD_PARAM);
    baseViewFilePath = RuntimeUtils.getRootPath()
            + StringUtils.substringAfter(TemplateHelper.getRootViewPath(), "/WEB-INF/");
}

From source file:net.ymate.platform.mvc.web.support.HttpRequestExecutor.java

protected Object parseCookieValueAnnotation(String paramName, String defaultValue, boolean required,
        Class<?> type, String defaultParamName) {
    String _paramName = StringUtils.defaultIfEmpty(paramName, defaultParamName);
    String _value = StringUtils.defaultIfEmpty(CookieHelper.create().getCookie(_paramName).toStringValue(),
            defaultValue);/*from  w  ww .ja  va2  s  .co  m*/
    _LOG.info(I18N.formatMessage(YMP.__LSTRING_FILE, null, null, "ymp.mvc.request_parameter_process",
            _paramName, _value, "Cookies"));
    // ??
    if (!hasValidation() && required && StringUtils.isBlank(_value)) {
        throw new NullPointerException(I18N.formatMessage(YMP.__LSTRING_FILE, null, null,
                "ymp.mvc.request_parameter_null", _paramName));
    }
    validateFieldValues.put(_paramName, _value);
    return new BlurObject(_value).toObjectValue(type);
}

From source file:net.ymate.platform.mvc.web.support.HttpRequestExecutor.java

protected Object parsePathVariableAnnotation(String paramName, String defaultValue, boolean required,
        Class<?> type, String defaultParamName) {
    String _paramName = StringUtils.defaultIfEmpty(paramName, defaultParamName);
    String _value = StringUtils.defaultIfEmpty((String) WebContext.getContext().get(_paramName), defaultValue);
    _LOG.info(I18N.formatMessage(YMP.__LSTRING_FILE, null, null, "ymp.mvc.request_parameter_process",
            _paramName, _value, "PathVariable"));
    if (!hasValidation() && required && StringUtils.isBlank(_value)) {
        throw new NullPointerException(I18N.formatMessage(YMP.__LSTRING_FILE, null, null,
                "ymp.mvc.request_parameter_null", _paramName));
    }/*  www . j  av  a2  s. c om*/
    validateFieldValues.put(_paramName, _value);
    return new BlurObject(_value).toObjectValue(type);
}

From source file:net.ymate.platform.mvc.web.support.HttpRequestExecutor.java

protected Object parseRequestHeaderAnnotation(String paramName, String defaultValue, boolean required,
        Class<?> type, String defaultParamName) {
    String _paramName = StringUtils.defaultIfEmpty(paramName, defaultParamName);
    String _value = StringUtils.defaultIfEmpty(WebContext.getRequest().getHeader(_paramName), defaultValue);
    _LOG.info(I18N.formatMessage(YMP.__LSTRING_FILE, null, null, "ymp.mvc.request_parameter_process",
            _paramName, _value, "Header"));
    if (!hasValidation() && required && StringUtils.isBlank(_value)) {
        throw new NullPointerException(I18N.formatMessage(YMP.__LSTRING_FILE, null, null,
                "ymp.mvc.request_parameter_null", _paramName));
    }//w  w  w .  j ava2s . c  o m
    validateFieldValues.put(_paramName, _value);
    return new BlurObject(_value).toObjectValue(type);
}

From source file:net.ymate.platform.mvc.web.support.HttpRequestExecutor.java

protected Object parseRequestParamAnnotation(String prefix, String paramName, String defaultValue,
        boolean required, Class<?> type, String defaultParamName) {
    String _paramName = prefix + StringUtils.defaultIfEmpty(paramName, defaultParamName);
    if (type.isArray()) {
        if (type.equals(IUploadFileWrapper[].class)) {
            if (WebContext.getRequest() instanceof MultipartRequestWrapper) {
                IUploadFileWrapper[] _value = ((MultipartRequestWrapper) WebContext.getRequest())
                        .getFiles(_paramName);
                _LOG.info(I18N.formatMessage(YMP.__LSTRING_FILE, null, null,
                        "ymp.mvc.request_parameter_process", _paramName, _value, "RequestParameter"));
                validateFieldValues.put(_paramName, _value);
                return ((MultipartRequestWrapper) WebContext.getRequest()).getFiles(_paramName);
            }/* w  w w  .  jav  a 2s . c  o  m*/
            validateFieldValues.put(_paramName, null);
            return null;
        }
        String[] _values = (String[]) WebContext.getRequest().getParameterMap().get(_paramName);
        if (_values == null || _values.length == 0) {
            _values = StringUtils.split(defaultValue, ",");
        }
        if (_values != null && _values.length > 0) {
            Class<?> _arrayClassType = ClassUtils.getArrayClassType(type);
            Object[] _tempParams = (Object[]) Array.newInstance(_arrayClassType, _values.length);
            for (int _tempIdx = 0; _tempIdx < _values.length; _tempIdx++) {
                _tempParams[_tempIdx] = new BlurObject(_values[_tempIdx]).toObjectValue(_arrayClassType);
            }
            _LOG.info(I18N.formatMessage(YMP.__LSTRING_FILE, null, null, "ymp.mvc.request_parameter_process",
                    _paramName, (_tempParams != null ? _tempParams.toString() : ""), "RequestParameter"));
            validateFieldValues.put(_paramName, _tempParams);
            return _tempParams;
        } else if (!hasValidation() && required) {
            throw new NullPointerException(I18N.formatMessage(YMP.__LSTRING_FILE, null, null,
                    "ymp.mvc.request_parameter_null", _paramName));
        }
        validateFieldValues.put(_paramName, null);
        return null;
    } else if (type.equals(IUploadFileWrapper.class)) {
        if (WebContext.getRequest() instanceof MultipartRequestWrapper) {
            IUploadFileWrapper _value = ((MultipartRequestWrapper) WebContext.getRequest()).getFile(_paramName);
            _LOG.info(I18N.formatMessage(YMP.__LSTRING_FILE, null, null, "ymp.mvc.request_parameter_process",
                    _paramName, (_value != null ? _value.getName() : ""), "RequestParameter"));
            validateFieldValues.put(_paramName, _value);
            return _value;
        }
        validateFieldValues.put(_paramName, null);
        return null;
    }
    String _value = StringUtils.defaultIfEmpty(WebContext.getRequest().getParameter(_paramName), defaultValue);
    _LOG.info(I18N.formatMessage(YMP.__LSTRING_FILE, null, null, "ymp.mvc.request_parameter_process",
            _paramName, _value, "RequestParameter"));
    if (!hasValidation() && required && StringUtils.isBlank(_value)) {
        throw new NullPointerException(I18N.formatMessage(YMP.__LSTRING_FILE, null, null,
                "ymp.mvc.request_parameter_null", _paramName));
    }
    validateFieldValues.put(_paramName, _value);
    return new BlurObject(_value).toObjectValue(type);
}

From source file:net.ymate.platform.mvc.web.support.HttpRequestExecutor.java

protected Object parseModelBindAnnotation(Class<?> type) {
    ClassBeanWrapper<?> _wrapper = ClassUtils.wrapper(type);
    for (String _fName : _wrapper.getFieldNames()) {
        Annotation[] _fieldAnnotations = _wrapper.getFieldAnnotations(_fName);
        for (Annotation _annotation : _fieldAnnotations) {
            if (_annotation instanceof CookieValue) {
                CookieValue _anno = (CookieValue) _annotation;
                Object _value = this.parseCookieValueAnnotation(_anno.value(),
                        StringUtils.defaultIfEmpty(_anno.defaultValue(), null), _anno.required(),
                        _wrapper.getFieldType(_fName), _fName);
                _wrapper.setValue(_fName, _value);
                break;
            } else if (_annotation instanceof PathVariable) {
                PathVariable _anno = (PathVariable) _annotation;
                Object _value = this.parsePathVariableAnnotation(_anno.value(),
                        StringUtils.defaultIfEmpty(_anno.defaultValue(), null), _anno.required(),
                        _wrapper.getFieldType(_fName), _fName);
                _wrapper.setValue(_fName, _value);
                break;
            } else if (_annotation instanceof RequestHeader) {
                RequestHeader _anno = (RequestHeader) _annotation;
                Object _value = this.parseRequestHeaderAnnotation(_anno.value(),
                        StringUtils.defaultIfEmpty(_anno.defaultValue(), null), _anno.required(),
                        _wrapper.getFieldType(_fName), _fName);
                _wrapper.setValue(_fName, _value);
                break;
            } else if (_annotation instanceof RequestParam) {
                RequestParam _anno = (RequestParam) _annotation;
                Object _value = this.parseRequestParamAnnotation(_anno.prefix(), _anno.value(),
                        StringUtils.defaultIfEmpty(_anno.defaultValue(), null), _anno.required(),
                        _wrapper.getFieldType(_fName), _fName);
                _wrapper.setValue(_fName, _value);
                break;
            } else if (_annotation instanceof ModelBind) {
                _wrapper.setValue(_fName, this.parseModelBindAnnotation(_wrapper.getFieldType(_fName)));
                break;
            }//  w  w  w  .  j  a va 2  s . c  o  m
        }
    }
    return _wrapper.getTarget();
}

From source file:net.ymate.platform.mvc.web.support.HttpRequestExecutor.java

protected Object[] getMethodParams() {
    Class<?>[] _paramTypes = this.requestMeta.getParameterTypes();
    Object[] _params = new Object[_paramTypes.length];
    if (_params.length > 0) {
        Annotation[][] _paramAnnotations = this.requestMeta.getMethod().getParameterAnnotations();
        for (int _idx = 0; _idx < _params.length; _idx++) {
            Annotation[] _annotations = _paramAnnotations[_idx];
            for (Annotation _annotation : _annotations) {
                if (_annotation instanceof CookieValue) {
                    CookieValue _anno = (CookieValue) _annotation;
                    _params[_idx] = this.parseCookieValueAnnotation(_anno.value(),
                            StringUtils.defaultIfEmpty(_anno.defaultValue(), null), _anno.required(),
                            _paramTypes[_idx], this.requestMeta.getMethodParamNames()[_idx]);
                    break;
                } else if (_annotation instanceof PathVariable) {
                    PathVariable _anno = (PathVariable) _annotation;
                    _params[_idx] = this.parsePathVariableAnnotation(_anno.value(),
                            StringUtils.defaultIfEmpty(_anno.defaultValue(), null), _anno.required(),
                            _paramTypes[_idx], this.requestMeta.getMethodParamNames()[_idx]);
                    break;
                } else if (_annotation instanceof RequestHeader) {
                    RequestHeader _anno = (RequestHeader) _annotation;
                    _params[_idx] = this.parseRequestHeaderAnnotation(_anno.value(),
                            StringUtils.defaultIfEmpty(_anno.defaultValue(), null), _anno.required(),
                            _paramTypes[_idx], this.requestMeta.getMethodParamNames()[_idx]);
                    break;
                } else if (_annotation instanceof RequestParam) {
                    RequestParam _anno = (RequestParam) _annotation;
                    _params[_idx] = this.parseRequestParamAnnotation(_anno.prefix(), _anno.value(),
                            StringUtils.defaultIfEmpty(_anno.defaultValue(), null), _anno.required(),
                            _paramTypes[_idx], this.requestMeta.getMethodParamNames()[_idx]);
                    break;
                } else if (_annotation instanceof ModelBind) {
                    _params[_idx] = this.parseModelBindAnnotation(_paramTypes[_idx]);
                    break;
                }/*from   ww w.j a v  a 2  s . c  o  m*/
            }
        }
    }
    return _params;
}