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.webmvc.impl.DefaultRequestContext.java
public DefaultRequestContext(HttpServletRequest request, String prefix) { this.requestMapping = this.originalUrl = StringUtils.defaultIfBlank(request.getPathInfo(), request.getServletPath());/*from ww w . j ava 2s .c o m*/ if (StringUtils.isNotBlank(prefix)) { this.requestMapping = StringUtils.substringAfter(this.requestMapping, prefix); this.prefix = prefix; } int _pos = 0; if (!this.requestMapping.endsWith("/")) { _pos = this.requestMapping.lastIndexOf('.'); if (_pos < this.requestMapping.lastIndexOf('/')) { _pos = -1; } } else { // (:'/'?'/'?) this.requestMapping = this.requestMapping.substring(0, this.requestMapping.length() - 1); } if (_pos > 0) { this.suffix = this.requestMapping.substring(_pos + 1); this.requestMapping = this.requestMapping.substring(0, _pos); } else { this.suffix = ""; } __httpMethod = Type.HttpMethod.valueOf(request.getMethod()); // __attributes = new HashMap<String, Object>(); }
From source file:net.ymate.platform.webmvc.impl.DefaultRequestProcessor.java
protected Object __doSafeGetParamValue(IWebMvc owner, String paramName, Class<?> paramType, String paramValue, String defaultValue, boolean fullScope) { Object _returnValue = null;/* w w w . ja v a2 s .c o m*/ try { if (paramValue == null) { if (fullScope) { _returnValue = new BlurObject(WebContext.getRequest().getParameter(paramName)) .toObjectValue(paramType); if (_returnValue == null) { _returnValue = new BlurObject(WebContext.getContext().getSession().get(paramName)) .toObjectValue(paramType); if (_returnValue == null) { _returnValue = new BlurObject(WebContext.getContext().getApplication().get(paramName)) .toObjectValue(paramType); } } } } if (_returnValue == null) { _returnValue = new BlurObject(StringUtils.defaultIfBlank(paramValue, defaultValue)) .toObjectValue(paramType); } } catch (Throwable e) { if (owner.getOwner().getConfig().isDevelopMode()) { _LOG.warn("Invalid '" + paramName + "' value: " + paramValue, RuntimeUtils.unwrapThrow(e)); } } return _returnValue; }
From source file:net.ymate.platform.webmvc.impl.JSONRequestProcessor.java
private JSONObject __doGetProtocol(IWebMvc owner) { JSONObject _protocol = WebContext.getRequestContext().getAttribute(JSONRequestProcessor.class.getName()); if (_protocol == null) { try {/*from ww w . ja v a 2 s . c o m*/ _protocol = JSON.parseObject( StringUtils.defaultIfBlank(IOUtils.toString(WebContext.getRequest().getInputStream(), owner.getModuleCfg().getDefaultCharsetEncoding()), "{}")); } catch (Exception e) { _protocol = JSON.parseObject("{}"); // if (WebContext.getContext().getOwner().getOwner().getConfig().isDevelopMode()) { _LOG.warn("Invalid protocol", RuntimeUtils.unwrapThrow(e)); } } WebContext.getRequestContext().addAttribute(JSONRequestProcessor.class.getName(), _protocol); } return _protocol; }
From source file:net.ymate.platform.webmvc.ParameterMeta.java
private boolean __doParseAnnotation(Annotation anno) { boolean _flag = false; if (anno != null) { if (anno instanceof CookieVariable) { CookieVariable _anno = (CookieVariable) anno; this.paramAnno = _anno; this.paramName = doBuildParamName(StringUtils.defaultIfBlank(_anno.prefix(), prefix), _anno.value(), fieldName);// w w w. j a va2 s . co m _flag = true; } else if (anno instanceof PathVariable) { PathVariable _anno = (PathVariable) anno; this.paramAnno = _anno; this.paramName = doBuildParamName("", _anno.value(), fieldName); _flag = true; } else if (anno instanceof RequestHeader) { RequestHeader _anno = (RequestHeader) anno; this.paramAnno = _anno; this.paramName = doBuildParamName(StringUtils.defaultIfBlank(_anno.prefix(), prefix), _anno.value(), fieldName); _flag = true; } else if (anno instanceof RequestParam) { RequestParam _anno = (RequestParam) anno; this.paramAnno = _anno; this.paramName = doBuildParamName(StringUtils.defaultIfBlank(_anno.prefix(), prefix), _anno.value(), fieldName); _flag = true; } else if (anno instanceof ModelBind) { ModelBind _mBind = (ModelBind) anno; this.paramAnno = anno; this.prefix = _mBind.prefix(); this.isModelBind = true; _flag = true; } } return _flag; }
From source file:net.ymate.platform.webmvc.ParameterMeta.java
/** * @param prefix ?/*from w w w. j a v a 2s . c o m*/ * @param paramName ??? * @param defaultName ?? * @return ?????? */ public String doBuildParamName(String prefix, String paramName, String defaultName) { String _name = StringUtils.defaultIfBlank(paramName, defaultName); if (StringUtils.isNotBlank(prefix)) { _name = prefix.trim().concat(".").concat(_name); } return _name; }
From source file:net.ymate.platform.webmvc.RequestMeta.java
public RequestMeta(IWebMvc owner, Class<?> targetClass, Method method) throws Exception { this.targetClass = targetClass; this.method = method; ///* w w w. jav a2 s . c o m*/ this.allowMethods = new HashSet<Type.HttpMethod>(); this.allowHeaders = new HashMap<String, String>(); this.allowParams = new HashMap<String, String>(); // Controller _controller = targetClass.getAnnotation(Controller.class); this.name = StringUtils.defaultIfBlank(_controller.name(), targetClass.getName()); this.singleton = _controller.singleton(); // this.responseCache = method.getAnnotation(ResponseCache.class); if (this.responseCache == null) { this.responseCache = targetClass.getAnnotation(ResponseCache.class); } // this.parameterEscape = method.getAnnotation(ParameterEscape.class); if (this.parameterEscape == null) { this.parameterEscape = targetClass.getAnnotation(ParameterEscape.class); if (this.parameterEscape == null && owner.getModuleCfg().isParameterEscapeMode()) { this.parameterEscape = this.getClass().getAnnotation(ParameterEscape.class); } } if (this.parameterEscape != null && this.parameterEscape.skiped()) { this.parameterEscape = null; } // this.responseView = method.getAnnotation(ResponseView.class); if (this.responseView == null) { this.responseView = targetClass.getAnnotation(ResponseView.class); } // this.responseHeaders = new HashSet<Header>(); ResponseHeader _respHeader = targetClass.getAnnotation(ResponseHeader.class); if (_respHeader != null) { Collections.addAll(this.responseHeaders, _respHeader.value()); } _respHeader = method.getAnnotation(ResponseHeader.class); if (_respHeader != null) { Collections.addAll(this.responseHeaders, _respHeader.value()); } // RequestMapping _reqMapping = targetClass.getAnnotation(RequestMapping.class); String _root = null; if (_reqMapping != null) { _root = _reqMapping.value(); __doSetAllowValues(_reqMapping); } _reqMapping = method.getAnnotation(RequestMapping.class); __doSetAllowValues(_reqMapping); // if (this.allowMethods.isEmpty()) { this.allowMethods.add(Type.HttpMethod.GET); } // this.mapping = __doBuildRequestMapping(_root, _reqMapping); // RequestProcessor _reqProcessor = method.getAnnotation(RequestProcessor.class); if (_reqProcessor != null) { this.processor = _reqProcessor.value(); } if (this.processor == null) { _reqProcessor = targetClass.getAnnotation(RequestProcessor.class); if (_reqProcessor != null) { this.processor = _reqProcessor.value(); } } // Map<String, ParameterMeta> _targetClassParameterMetas = __CLASS_PARAMETER_METAS.get(targetClass); if (_targetClassParameterMetas == null) { ClassUtils.BeanWrapper<?> _wrapper = ClassUtils.wrapper(targetClass); if (_wrapper != null) { _targetClassParameterMetas = new HashMap<String, ParameterMeta>(); // for (String _fieldName : _wrapper.getFieldNames()) { if (!_targetClassParameterMetas.containsKey(_fieldName)) { ParameterMeta _meta = new ParameterMeta(this, _wrapper.getField(_fieldName)); if (_meta.isParamField()) { _targetClassParameterMetas.put(_fieldName, _meta); } } } __CLASS_PARAMETER_METAS.put(targetClass, _targetClassParameterMetas); } } // this.__methodParameterMetas = new ArrayList<ParameterMeta>(); this.methodParamNames = Arrays.asList(ClassUtils.getMethodParamNames(method)); if (!this.methodParamNames.isEmpty()) { Class<?>[] _paramTypes = method.getParameterTypes(); Annotation[][] _paramAnnotations = method.getParameterAnnotations(); for (int _idx = 0; _idx < this.methodParamNames.size(); _idx++) { ParameterMeta _meta = new ParameterMeta(this, _paramTypes[_idx], this.methodParamNames.get(_idx), _paramAnnotations[_idx]); if (_meta.isParamField()) { this.__methodParameterMetas.add(_meta); } } } }
From source file:net.ymate.platform.webmvc.support.I18NWebEventHandler.java
public InputStream onLoad(String resourceName) throws IOException { if (__i18nHome == null) { __i18nHome = RuntimeUtils.replaceEnvVariable(StringUtils.defaultIfBlank( WebMVC.get().getOwner().getConfig().getParam("i18n_resources_home"), "${root}/i18n/")); }//w w w. j a va2s . c o m if (StringUtils.trimToNull(resourceName) != null) { File _resFile = new File(__i18nHome, resourceName); if (_resFile.exists() && _resFile.isFile() && _resFile.canRead()) { return new FileInputStream(_resFile); } } return null; }
From source file:net.ymate.platform.webmvc.support.MultipartRequestWrapper.java
public MultipartRequestWrapper(IWebMvc owner, HttpServletRequest request) throws IOException, FileUploadException { super(request); // ?/*from www . j ava 2s. c om*/ __formWarpper = FileUploadHelper.bind(owner, request) .setUploadTempDir(new File(StringUtils.defaultIfBlank(owner.getModuleCfg().getUploadTempDir(), System.getProperty("java.io.tmpdir")))) .setFileSizeMax(owner.getModuleCfg().getUploadTotalSizeMax()) .setSizeMax(owner.getModuleCfg().getUploadFileSizeMax()) .setSizeThreshold(owner.getModuleCfg().getUploadSizeThreshold()) .setFileUploadListener(owner.getModuleCfg().getUploadFileListener()).processUpload(); }
From source file:net.ymate.platform.webmvc.support.RequestMethodWrapper.java
public RequestMethodWrapper(HttpServletRequest request, String methodParam) { super(request); if ("POST".equals(request.getMethod())) { String _methodName = request.getParameter(StringUtils.defaultIfBlank(methodParam, "_method")); if (StringUtils.isNotBlank(_methodName)) { method = _methodName.toUpperCase(); } else {// ww w . j a v a 2s . c o m method = null; } } else { method = null; } }
From source file:nl.knaw.huygens.facetedsearch.LocalSolrServer.java
public LocalSolrServer(String solrDir, String coreName, QueryComposer queryComposer) { super(queryComposer); this.solrDir = StringUtils.defaultIfBlank(solrDir, SOLR_DIRECTORY); this.coreName = StringUtils.defaultIfBlank(coreName, "core1"); setServer();//from w w w.jav a 2 s .c o m }