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.module.LogModule.java

public void initialize(final Map<String, String> moduleCfgs) throws Exception {
    Logs.initialize(new ILogConfig() {

        public String getLogCfgFile() {
            String _logCfgF = moduleCfgs.get("xml_cfg_file");
            if (StringUtils.isBlank(_logCfgF)) {
                if (Cfgs.isInited()) {
                    _logCfgF = Cfgs.smartSearch("cfgs/log4j.xml");
                } else {
                    _logCfgF = RuntimeUtils.getRootPath() + "cfgs/log4j.xml";
                }// w  w  w. ja v a  2  s .  co  m
            } else if (_logCfgF.contains("${user.dir}")) {
                _logCfgF = doParseVariableUserDir(_logCfgF);
            }
            return _logCfgF;
        }

        public String getLogOutputDir() {
            String _logOutputF = moduleCfgs.get("output_path");
            if (StringUtils.isBlank(_logOutputF)) {
                if (Cfgs.isInited()) {
                    _logOutputF = Cfgs.smartSearch("logs");
                } else {
                    _logOutputF = RuntimeUtils.getRootPath() + "logs";
                }
            }
            if (StringUtils.isBlank(_logOutputF)) {
                _logOutputF = "${user.dir}/logs";
            }
            if (_logOutputF.contains("${user.dir}")) {
                _logOutputF = doParseVariableUserDir(_logOutputF);
            }
            return _logOutputF;
        }

        public String getLoggerName() {
            return StringUtils.defaultIfEmpty(moduleCfgs.get("name"), DEFAULT_LOGGER_NAME);
        }

        public LogLevel getLogLevel() {
            return LogLevel.parse(moduleCfgs.get("level"));
        }

        public boolean allowPrintConsole() {
            return new BlurObject(moduleCfgs.get("allow_print_console")).toBooleanValue();
        }

        public ILogger getLoggerClassImpl() {
            return ClassUtils.impl(StringUtils.defaultIfEmpty(moduleCfgs.get("impl_class"),
                    DefaultLog4JLogger.class.getName()), ILogger.class, LogModule.class);
        }

    });
}

From source file:net.ymate.platform.module.search.support.DefaultSearchConfig.java

/**
 * /*from  w w  w.  j  ava  2s . com*/
 * 
 * @param directoryPath
 * @param luceneVersion
 * @param analyzerImpl
 * @param threadPoolSize
 * @param bufferSize
 * @param scheduledPeriod
 */
public DefaultSearchConfig(String directoryPath, Version luceneVersion, Analyzer analyzerImpl,
        int threadPoolSize, double bufferSize, int scheduledPeriod) {
    this.directoryPath = doParseVariableUserDir(StringUtils.defaultIfEmpty(directoryPath, ""));
    this.luceneVersion = luceneVersion;
    this.analyzerImpl = analyzerImpl;
    this.threadPoolSize = threadPoolSize;
    this.bufferSize = bufferSize;
    this.scheduledPeriod = scheduledPeriod;
}

From source file:net.ymate.platform.module.search.support.DefaultSearchConfig.java

public void setDirectoryPath(String directoryPath) {
    this.directoryPath = doParseVariableUserDir(StringUtils.defaultIfEmpty(directoryPath, ""));
}

From source file:net.ymate.platform.module.search.support.IndexedMeta.java

/**
 * //ww w . ja v a  2  s.c o m
 * 
 * @param searchableClass
 */
public IndexedMeta(Class<? extends ISearchable> searchableClass) {
    if (!ClassUtils.isInterfaceOf(searchableClass, ISearchable.class)) {
        throw new RuntimeException(I18N.formatMessage(YMP.__LSTRING_FILE, null, null,
                "ymp.search.searchable_class_need_impl", searchableClass.getName()));
    }
    Indexed _idx = searchableClass.getAnnotation(Indexed.class);
    if (null != _idx) {
        __indexName = StringUtils.defaultIfEmpty(_idx.name(), searchableClass.getSimpleName());
        this.__init(searchableClass);
    } else {
        throw new RuntimeException(I18N.formatMessage(YMP.__LSTRING_FILE, null, null,
                "ymp.search.searchable_class_need_anno_indexed", searchableClass.getName()));
    }
}

From source file:net.ymate.platform.module.SearchModule.java

public void initialize(Map<String, String> moduleCfgs) throws Exception {
    DefaultSearchConfig _conf = new DefaultSearchConfig();
    _conf.setDirectoryPath(moduleCfgs.get("directory_path"));
    _conf.setLuceneVersion(//from  www  .j  ava 2s .  c  o m
            Version.valueOf(StringUtils.defaultIfEmpty(moduleCfgs.get("lucene_version"), "LUCENE_46")));
    _conf.setThreadPoolSize(new BlurObject(moduleCfgs.get("thread_pool_size")).toIntValue());
    _conf.setBufferSize(new BlurObject(moduleCfgs.get("buffer_size")).toDoubleValue());
    _conf.setScheduledPeriod(new BlurObject(moduleCfgs.get("scheduled_period")).toIntValue());
    _conf.setAnalyzerImpl(ClassUtils.impl(moduleCfgs.get("analyzer_impl"), Analyzer.class, SearchModule.class));
    //
    Searchs.initialize(_conf);
}

From source file:net.ymate.platform.module.WebMvcModule.java

@SuppressWarnings("unchecked")
public void initialize(Map<String, String> moduleCfgs) throws Exception {
    IWebEventHandler _eventHandler = ClassUtils.impl(moduleCfgs.get("base.event_handler_class"),
            IWebEventHandler.class, WebMvcModule.class);
    IPluginExtraParser _extraParser = ClassUtils.impl(moduleCfgs.get("base.plugin_extra_parser_class"),
            IPluginExtraParser.class, WebMvcModule.class);
    IWebErrorHandler _errorHandler = ClassUtils.impl(moduleCfgs.get("base.error_handler_class"),
            IWebErrorHandler.class, WebMvcModule.class);
    IWebMultipartHandler _multipartHandler = ClassUtils.impl(moduleCfgs.get("base.multipart_handler_class"),
            IWebMultipartHandler.class, WebMvcModule.class);
    ///*ww w. j a  v a 2  s  . c  om*/
    Locale _locale = MVC.localeFromStr(moduleCfgs.get("base.locale"), null);
    boolean _i18n = new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("base.i18n"), "false"))
            .toBooleanValue();
    String _charsetEncoding = StringUtils.defaultIfEmpty(moduleCfgs.get("base.charset_encoding"), "UTF-8");
    //
    List<Class<IFilter>> _extraFilters = new ArrayList<Class<IFilter>>();
    for (String _extraFilter : StringUtils.split(StringUtils.trimToEmpty(moduleCfgs.get("base.extra_filters")),
            "|")) {
        Class<?> _filterClass = ResourceUtils.loadClass(_extraFilter, WebMvcModule.class);
        if (_filterClass != null && ClassUtils.isInterfaceOf(_filterClass, IFilter.class)) {
            _extraFilters.add((Class<IFilter>) _filterClass);
        }
    }
    //
    Map<String, String> _extendParams = new HashMap<String, String>();
    for (String _cfgKey : moduleCfgs.keySet()) {
        if (_cfgKey.startsWith("params")) {
            _extendParams.put(StringUtils.substring(_cfgKey, 7), moduleCfgs.get(_cfgKey));
        }
    }
    //
    String _pluginHome = moduleCfgs.get("base.plugin_home");
    if (StringUtils.isNotBlank(_pluginHome)) {
        if (_pluginHome.startsWith("/WEB-INF/")) {
            File _pluginHomeFile = new File(RuntimeUtils.getRootPath(),
                    StringUtils.substringAfter(_pluginHome, "/WEB-INF/"));
            if (_pluginHomeFile.exists() && _pluginHomeFile.isDirectory()) {
                _pluginHome = _pluginHomeFile.getPath();
            }
        } else if (_pluginHome.contains("${user.dir}")) {
            _pluginHome = doParseVariableUserDir(_pluginHome);
        }
    }
    //
    WebMvcConfig _config = new WebMvcConfig(_eventHandler, _extraParser, _errorHandler, _locale, _i18n,
            _charsetEncoding, _pluginHome, _extendParams,
            StringUtils.split(moduleCfgs.get("base.controller_packages"), '|'));
    //
    _config.setMultipartHandlerClassImpl(_multipartHandler);
    _config.setRestfulModel(
            new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("base.restful_model"), "false"))
                    .toBooleanValue());
    _config.setConventionModel(
            new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("base.convention_model"), "true"))
                    .toBooleanValue());
    _config.setConventionUrlrewrite(
            new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("base.convention_urlrewrite"), "false"))
                    .toBooleanValue());
    _config.setUrlSuffix(StringUtils.defaultIfEmpty(moduleCfgs.get("base.url_suffix"), ""));
    _config.setViewPath(StringUtils.defaultIfEmpty(moduleCfgs.get("base.view_path"), ""));
    _config.setExtraFilters(_extraFilters);
    _config.setUploadTempDir(StringUtils.defaultIfEmpty(moduleCfgs.get("upload.temp_dir"),
            System.getProperty("java.io.tmpdir")));
    _config.setUploadFileSizeMax(
            new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("upload.file_size_max"), "-1"))
                    .toIntValue());
    _config.setUploadTotalSizeMax(
            new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("upload.total_size_max"), "-1"))
                    .toIntValue());
    _config.setUploadSizeThreshold(
            new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("upload.size_threshold"), "10240"))
                    .toIntValue());
    //
    _config.setCookiePrefix(StringUtils.defaultIfEmpty(moduleCfgs.get("cookie.prefix"), ""));
    _config.setCookieDomain(StringUtils.defaultIfEmpty(moduleCfgs.get("cookie.domain"), ""));
    _config.setCookiePath(StringUtils.defaultIfEmpty(moduleCfgs.get("cookie.path"), "/"));
    _config.setCookieAuthKey(StringUtils.defaultIfEmpty(moduleCfgs.get("cookie.auth_key"), ""));
    //
    WebMVC.initialize(_config);
}

From source file:net.ymate.platform.module.wechat.web.WeChatFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    _LOG.debug("YMP Module WeChat Started");
    token = StringUtils.defaultIfEmpty(filterConfig.getInitParameter("token"), "wechat");
}

From source file:net.ymate.platform.module.wechat.web.WeChatFilter.java

private void __doGetProcess(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String _echoStr = "";
    String _signature = request.getParameter("signature");
    String _timestamp = request.getParameter("timestamp");
    String _nonce = request.getParameter("nonce");
    String _echostr = request.getParameter("echostr");
    // ???Token, ?
    String _token = StringUtils.defaultIfEmpty(request.getParameter("_t"), token);
    ///*from w  w w .j av  a  2s. c om*/
    if (WeChat.checkSignature(_token, _signature, _timestamp, _nonce)) {
        _echoStr = _echostr;
    }
    response.getWriter().write(_echoStr);
}

From source file:net.ymate.platform.module.wechat.WeChat.java

/**
 * @param accountId    ??ID/*from   www.  ja  v a 2  s. c  o  m*/
 * @param needUserInfo ???
 * @param state        ?(a-zA-Z0-9)
 * @param redirectURI  ???
 * @return ?URL?
 * @throws Exception
 */
public static String wxOAuthGetCodeURL(String accountId, boolean needUserInfo, String state, String redirectURI)
        throws Exception {
    __doCheckModuleInited();
    String _appId = __dataProvider.getAppId(accountId);
    if (StringUtils.isBlank(_appId)) {
        throw new NullArgumentException("appId");
    }
    if (StringUtils.isBlank(redirectURI)) {
        throw new NullArgumentException("redirectURI");
    }
    Map<String, Object> _params = new HashMap<String, Object>();
    _params.put("appid", _appId);
    _params.put("response_type", "code");
    _params.put("redirect_uri", URLEncoder.encode(redirectURI, HttpClientHelper.DEFAULT_CHARSET));
    _params.put("scope", needUserInfo ? "snsapi_userinfo" : "snsapi_base");
    _params.put("state", StringUtils.defaultIfEmpty(state, "") + "#wechat_redirect");
    return WX_API.OAUTH_GET_CODE.concat(__doParamSignatureSort(_params, false));
}

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

/**
 * //from   www  .j a  va  2 s  .  c  o  m
 * @param request 
 * @param prefix URL?
 */
public WebRequestContext(HttpServletRequest request, String prefix) {
    this.prefix = prefix;
    this.url = StringUtils.defaultIfEmpty(request.getPathInfo(), request.getServletPath());
    this.requestMapping = this.url;
    int _pos = 0;
    if (StringUtils.isNotBlank(prefix)) {
        this.requestMapping = StringUtils.substringAfter(this.requestMapping, this.prefix);
    }
    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 = "";
    }
}