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

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

Introduction

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

Prototype

public static String defaultIfBlank(String str, String defaultStr) 

Source Link

Document

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

Usage

From source file:net.ymate.platform.persistence.mongodb.impl.MongoSession.java

protected <T extends IEntity> MongoCollection<Document> __doGetCollection(Class<T> entity) {
    String _collectionName = StringUtils.defaultIfBlank(__collectionPrefix, "")
            .concat(EntityMeta.createAndGet(entity).getEntityName());
    return __databaseHolder.getDatabase().getCollection(_collectionName);
}

From source file:net.ymate.platform.persistence.redis.impl.RedisModuleCfg.java

public RedisModuleCfg(YMP owner) throws Exception {
    Map<String, String> _moduleCfgs = owner.getConfig().getModuleConfigs(IRedis.MODULE_NAME);
    ///*  w  ww .j a  va 2s  .  c  o  m*/
    this.dataSourceDefaultName = StringUtils.defaultIfBlank(_moduleCfgs.get("ds_default_name"), "default");
    //
    this.dataSourceCfgMetas = new HashMap<String, RedisDataSourceCfgMeta>();
    String _dsNameStr = StringUtils.defaultIfBlank(_moduleCfgs.get("ds_name_list"), "default");
    if (StringUtils.contains(_dsNameStr, this.dataSourceDefaultName)) {
        String[] _dsNameList = StringUtils.split(_dsNameStr, "|");
        for (String _dsName : _dsNameList) {
            RedisDataSourceCfgMeta _meta = __doParserDataSourceCfgMeta(_dsName, _moduleCfgs);
            if (_meta != null) {
                this.dataSourceCfgMetas.put(_dsName, _meta);
            }
        }
    } else {
        throw new IllegalArgumentException("The default datasource name does not match");
    }
}

From source file:net.ymate.platform.persistence.redis.impl.RedisModuleCfg.java

@SuppressWarnings("unchecked")
protected RedisDataSourceCfgMeta __doParserDataSourceCfgMeta(String dsName, Map<String, String> _moduleCfgs)
        throws Exception {
    RedisDataSourceCfgMeta _meta = null;
    ///*from  ww  w. j  a  v a 2 s  .  c o  m*/
    Map<String, String> _dataSourceCfgs = __doGetCfgs(_moduleCfgs, "ds." + dsName + ".");
    //
    //        if (!_dataSourceCfgs.isEmpty()) {
    String _connectionType = StringUtils.defaultIfBlank(_dataSourceCfgs.get("connection_type"), "default");
    String _masterServerName = StringUtils.defaultIfBlank(_dataSourceCfgs.get("master_server_name"), "default");
    List<ServerMeta> _servers = new ArrayList<ServerMeta>();
    String[] _serverNames = StringUtils
            .split(StringUtils.defaultIfBlank(_dataSourceCfgs.get("server_name_list"), "default"), "|");
    Map<String, String> _tmpCfgs = null;
    if (_serverNames != null) {
        for (String _serverName : _serverNames) {
            _tmpCfgs = __doGetCfgs(_dataSourceCfgs, "server." + _serverName + ".");
            if (!_tmpCfgs.isEmpty()) {
                ServerMeta _servMeta = new ServerMeta();
                _servMeta.setName(_serverName);
                _servMeta.setHost(StringUtils.defaultIfBlank(_tmpCfgs.get("host"), "localhost"));
                _servMeta.setPort(
                        BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("port"), "6379")).toIntValue());
                _servMeta.setTimeout(BlurObject
                        .bind(StringUtils.defaultIfBlank(_tmpCfgs.get("timeout"), "2000")).toIntValue());
                _servMeta.setWeight(
                        BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("weight"), "1")).toIntValue());
                _servMeta.setDatabase(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("database"), "0"))
                        .toIntValue());
                _servMeta.setClientName(StringUtils.trimToNull(_tmpCfgs.get("client_name")));
                _servMeta.setPassword(StringUtils.trimToNull(_tmpCfgs.get("password")));
                //
                boolean _pwdEncrypted = new BlurObject(_tmpCfgs.get("password_encrypted")).toBooleanValue();
                //
                if (_pwdEncrypted && StringUtils.isNotBlank(_servMeta.getPassword())
                        && StringUtils.isNotBlank(_tmpCfgs.get("password_class"))) {
                    IPasswordProcessor _proc = ClassUtils.impl(_dataSourceCfgs.get("password_class"),
                            IPasswordProcessor.class, this.getClass());
                    if (_proc != null) {
                        _servMeta.setPassword(_proc.decrypt(_servMeta.getPassword()));
                    }
                }
                //
                _servers.add(_servMeta);
            }
        }
    }
    //
    GenericObjectPoolConfig _poolConfig = new GenericObjectPoolConfig();
    _tmpCfgs = __doGetCfgs(_dataSourceCfgs, "pool.");
    if (!_tmpCfgs.isEmpty()) {
        _poolConfig.setMinIdle(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("min_idle"),
                GenericObjectPoolConfig.DEFAULT_MIN_IDLE + "")).toIntValue());
        _poolConfig.setMaxIdle(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("max_idle"),
                GenericObjectPoolConfig.DEFAULT_MAX_IDLE + "")).toIntValue());
        _poolConfig.setMaxTotal(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("max_total"),
                GenericObjectPoolConfig.DEFAULT_MAX_TOTAL + "")).toIntValue());
        _poolConfig
                .setBlockWhenExhausted(
                        BlurObject
                                .bind(StringUtils.defaultIfBlank(_tmpCfgs.get("block_when_exhausted"),
                                        GenericObjectPoolConfig.DEFAULT_BLOCK_WHEN_EXHAUSTED + ""))
                                .toBooleanValue());
        _poolConfig.setFairness(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("fairness"),
                GenericObjectPoolConfig.DEFAULT_FAIRNESS + "")).toBooleanValue());
        _poolConfig.setJmxEnabled(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("jmx_enabled"),
                GenericObjectPoolConfig.DEFAULT_JMX_ENABLE + "")).toBooleanValue());
        _poolConfig.setJmxNameBase(StringUtils.defaultIfBlank(_tmpCfgs.get("jmx_name_base"),
                GenericObjectPoolConfig.DEFAULT_JMX_NAME_BASE));
        _poolConfig.setJmxNamePrefix(StringUtils.defaultIfBlank(_tmpCfgs.get("jmx_name_prefix"),
                GenericObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX));
        _poolConfig.setEvictionPolicyClassName(
                StringUtils.defaultIfBlank(_tmpCfgs.get("eviction_policy_class_name"),
                        GenericObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME));
        _poolConfig.setLifo(BlurObject.bind(
                StringUtils.defaultIfBlank(_tmpCfgs.get("lifo"), GenericObjectPoolConfig.DEFAULT_LIFO + ""))
                .toBooleanValue());
        _poolConfig.setMaxWaitMillis(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("max_wait_millis"),
                GenericObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS + "")).toLongValue());
        _poolConfig
                .setMinEvictableIdleTimeMillis(BlurObject
                        .bind(StringUtils.defaultIfBlank(_tmpCfgs.get("min_evictable_idle_time_millis"),
                                GenericObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS + ""))
                        .toLongValue());
        _poolConfig.setSoftMinEvictableIdleTimeMillis(BlurObject
                .bind(StringUtils.defaultIfBlank(_tmpCfgs.get("soft_min_evictable_idle_time_millis"),
                        GenericObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS + ""))
                .toLongValue());
        _poolConfig.setTestOnBorrow(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("test_on_borrow"),
                GenericObjectPoolConfig.DEFAULT_TEST_ON_BORROW + "")).toBooleanValue());
        _poolConfig.setTestOnReturn(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("test_on_return"),
                GenericObjectPoolConfig.DEFAULT_TEST_ON_RETURN + "")).toBooleanValue());
        _poolConfig.setTestOnCreate(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("test_on_create"),
                GenericObjectPoolConfig.DEFAULT_TEST_ON_CREATE + "")).toBooleanValue());
        _poolConfig
                .setTestWhileIdle(
                        BlurObject
                                .bind(StringUtils.defaultIfBlank(_tmpCfgs.get("test_while_idle"),
                                        GenericObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE + ""))
                                .toBooleanValue());
        _poolConfig
                .setNumTestsPerEvictionRun(
                        BlurObject
                                .bind(StringUtils.defaultIfBlank(_tmpCfgs.get("num_tests_per_eviction_run"),
                                        GenericObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN + ""))
                                .toIntValue());
        _poolConfig
                .setTimeBetweenEvictionRunsMillis(BlurObject
                        .bind(StringUtils.defaultIfBlank(_tmpCfgs.get("time_between_eviction_runs_millis"),
                                GenericObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS + ""))
                        .toLongValue());
    }
    _meta = new RedisDataSourceCfgMeta(dsName, _connectionType, _masterServerName, _servers, _poolConfig);
    //        }
    return _meta;
}

From source file:net.ymate.platform.persistence.support.EntityMeta.java

/**
 * /*  w  ww . j  a v  a2s.  c  om*/
 * @param entityClass 
 * @param prefix ?
 * @param simple ??trueentityClass???
 */
public EntityMeta(Class<?> entityClass, String prefix, boolean simple) {
    if (simple) {
        this.__isSimple = true;
        this.__init(entityClass);
    } else {
        // ???
        if (!ClassUtils.isInterfaceOf(entityClass, IEntity.class)) {
            throw new RuntimeException(I18N.formatMessage(YMP.__LSTRING_FILE, null, null,
                    "ymp.jdbc.entity_class_need_impl", entityClass.getName()));
        }
        Entity t = entityClass.getAnnotation(Entity.class);
        if (null != t) {
            this.__tableName = StringUtils.defaultIfBlank(prefix, "") + t.name();
            this.__init(entityClass);
        } else {
            throw new RuntimeException(I18N.formatMessage(YMP.__LSTRING_FILE, null, null,
                    "ymp.jdbc.entity_class_need_anno_table", entityClass.getName()));
        }
    }
}

From source file:net.ymate.platform.plugin.handle.PluginHandler.java

@SuppressWarnings("unchecked")
public Object handle(Class<?> targetClass) throws Exception {
    if (ClassUtils.isInterfaceOf(targetClass, IPlugin.class)) {
        Plugin _plugin = targetClass.getAnnotation(Plugin.class);
        PluginMeta _meta = new PluginMeta(targetClass.getClassLoader());
        ///*from w  w w .ja v a  2  s .  c  o m*/
        _meta.setId(StringUtils.defaultIfBlank(_plugin.id(), DigestUtils.md5Hex(targetClass.getName())));
        _meta.setName(StringUtils.defaultIfBlank(_plugin.name(), targetClass.getSimpleName()));
        _meta.setAlias(_plugin.alias());
        _meta.setInitClass((Class<? extends IPlugin>) targetClass);
        _meta.setVersion(_plugin.version());
        _meta.setAuthor(_plugin.version());
        _meta.setEmail(_plugin.email());
        _meta.setAutomatic(_plugin.automatic());
        _meta.setDescription(_plugin.description());
        //
        if (targetClass.getClassLoader() instanceof PluginClassLoader) {
            _meta.setPath(((PluginClassLoader) targetClass.getClassLoader()).getPluginHome());
        }
        //
        return _meta;
    }
    return null;
}

From source file:net.ymate.platform.plugin.Plugins.java

public void init(YMP owner) throws Exception {
    if (!__inited) {
        Map<String, String> _moduleCfgs = owner.getConfig().getModuleConfigs(MODULE_NAME);
        __owner = owner;/*from   w  w  w  .ja  v  a 2  s .co m*/
        __owner.getEvents().registerEvent(PluginEvent.class);
        //
        _LOG.info("Initializing ymate-platform-plugin-" + VERSION);
        //
        DefaultPluginConfig _config = new DefaultPluginConfig();
        _config.setPluginHome(new File(RuntimeUtils.replaceEnvVariable(
                StringUtils.defaultIfBlank(_moduleCfgs.get("plugin_home"), "${root}/plugins"))));
        _config.setAutoscanPackages(new ArrayList<String>(Arrays.asList(
                StringUtils.split(StringUtils.trimToEmpty(_moduleCfgs.get("autoscan_packages")), "|"))));
        //
        for (String _package : __owner.getConfig().getAutoscanPackages()) {
            if (!_config.getAutoscanPackages().contains(_package)) {
                _config.getAutoscanPackages().add(_package);
            }
        }
        //
        _config.setAutomatic(BlurObject.bind(StringUtils.defaultIfBlank(_moduleCfgs.get("automatic"), "true"))
                .toBooleanValue());
        _config.setIncludedClassPath(
                BlurObject.bind(StringUtils.defaultIfBlank(_moduleCfgs.get("included_classpath"), "true"))
                        .toBooleanValue());
        //
        _config.setPluginEventListener(new IPluginEventListener() {
            public void onInited(IPluginContext context, IPlugin plugin) {
                __owner.getEvents().fireEvent(Events.MODE.NORMAL,
                        new PluginEvent(plugin, PluginEvent.EVENT.PLUGIN_INITED));
            }

            public void onStarted(IPluginContext context, IPlugin plugin) {
                __owner.getEvents().fireEvent(Events.MODE.NORMAL,
                        new PluginEvent(plugin, PluginEvent.EVENT.PLUGIN_STARTED));
            }

            public void onShutdown(IPluginContext context, IPlugin plugin) {
                __owner.getEvents().fireEvent(Events.MODE.NORMAL,
                        new PluginEvent(plugin, PluginEvent.EVENT.PLUGIN_SHUTDOWN));
            }

            public void onDestroy(IPluginContext context, IPlugin plugin) {
                __owner.getEvents().fireEvent(Events.MODE.NORMAL,
                        new PluginEvent(plugin, PluginEvent.EVENT.PLUGIN_DESTROYED));
            }
        });
        //
        __pluginFactory = new DefaultPluginFactory(__owner);
        __pluginFactory.init(_config);
        //
        __inited = true;
    }
}

From source file:net.ymate.platform.serv.impl.DefaultClientCfg.java

public DefaultClientCfg(IServModuleCfg moduleCfg, String clientName) {
    __clientName = StringUtils.defaultIfBlank(clientName, "default");
    ////  w w w.  ja  va  2s.  c o m
    Map<String, String> _clientCfgs = moduleCfg.getClientCfg(__clientName);
    //
    __remoteHost = StringUtils.defaultIfBlank(_clientCfgs.get("host"), "0.0.0.0");
    __port = BlurObject.bind(StringUtils.defaultIfBlank(_clientCfgs.get("port"), "8281")).toIntValue();
    __charset = StringUtils.defaultIfBlank(_clientCfgs.get("charset"), "UTF-8");
    __executorCount = BlurObject.bind(StringUtils.defaultIfBlank(_clientCfgs.get("executor_count"),
            Runtime.getRuntime().availableProcessors() + "")).toIntValue();
    __bufferSize = BlurObject.bind(StringUtils.defaultIfBlank(_clientCfgs.get("buffer_size"), "4096"))
            .toIntValue();
    __connectionTimeout = BlurObject
            .bind(StringUtils.defaultIfBlank(_clientCfgs.get("connection_timeout"), "0")).toIntValue();
    __heartbeatInterval = BlurObject
            .bind(StringUtils.defaultIfBlank(_clientCfgs.get("heartbeat_interval"), "0")).toIntValue();
    __params = new HashMap<String, String>();
    for (Map.Entry<String, String> _entry : _clientCfgs.entrySet()) {
        if (_entry.getKey().startsWith("params.")) {
            String _paramKey = StringUtils.substring(_entry.getKey(), ("params.").length());
            __params.put(_paramKey, _entry.getValue());
        }
    }
}

From source file:net.ymate.platform.serv.impl.DefaultHeartbeatService.java

@Override
public synchronized void start() {
    __flag = true;/*from  w w w.jav  a 2  s  .co  m*/
    setName("HeartbeatService-" + __client.listener().getClass().getSimpleName());
    if (__client.clientCfg().getHeartbeatInterval() > 0) {
        __heartbeatInterval = __client.clientCfg().getHeartbeatInterval();
    }
    __heartbeatMessage = StringUtils.defaultIfBlank(__client.clientCfg().getParam("heartbeat_message"), "0");
    super.start();
}

From source file:net.ymate.platform.serv.impl.DefaultModuleCfg.java

public DefaultModuleCfg(YMP owner) throws Exception {
    Map<String, String> _moduleCfgs = owner.getConfig().getModuleConfigs(IServ.MODULE_NAME);
    ///*from   w w  w.  j  a  v  a2s .  co  m*/
    String[] _serverNames = StringUtils
            .split(StringUtils.defaultIfBlank(_moduleCfgs.get("server.name_list"), "default"), "|");
    __serverCfgs = new HashMap<String, Map<String, String>>(_serverNames.length);
    for (String _name : _serverNames) {
        __doConfigMapLoad("server", _name, _moduleCfgs, __serverCfgs);
    }
    //
    String[] _clientNames = StringUtils
            .split(StringUtils.defaultIfBlank(_moduleCfgs.get("client.name_list"), "default"), "|");
    __clientCfgs = new HashMap<String, Map<String, String>>(_clientNames.length);
    for (String _name : _clientNames) {
        __doConfigMapLoad("client", _name, _moduleCfgs, __clientCfgs);
    }
}

From source file:net.ymate.platform.serv.impl.DefaultServerCfg.java

public DefaultServerCfg(IServModuleCfg moduleCfg, String serverName) {
    __serverName = StringUtils.defaultIfBlank(serverName, "default");
    Map<String, String> _serverCfgs = moduleCfg.getServerCfg(__serverName);
    ////from w  ww.j av a2s  . c  o m
    __serverHost = StringUtils.defaultIfBlank(_serverCfgs.get("host"), "0.0.0.0");
    __port = BlurObject.bind(StringUtils.defaultIfBlank(_serverCfgs.get("port"), "8281")).toIntValue();
    __charset = StringUtils.defaultIfBlank(_serverCfgs.get("charset"), "UTF-8");
    __bufferSize = BlurObject.bind(StringUtils.defaultIfBlank(_serverCfgs.get("buffer_size"), "4096"))
            .toIntValue();
    __executorCount = BlurObject.bind(StringUtils.defaultIfBlank(_serverCfgs.get("executor_count"),
            Runtime.getRuntime().availableProcessors() + "")).toIntValue();
    __params = new HashMap<String, String>();
    for (Map.Entry<String, String> _entry : _serverCfgs.entrySet()) {
        if (_entry.getKey().startsWith("params.")) {
            String _paramKey = StringUtils.substring(_entry.getKey(), ("params.").length());
            __params.put(_paramKey, _entry.getValue());
        }
    }
}