List of usage examples for org.apache.commons.lang StringUtils substring
public static String substring(String str, int start)
Gets a substring from the specified String avoiding exceptions.
From source file:net.ymate.platform.persistence.mongodb.impl.MongoModuleCfg.java
@SuppressWarnings("unchecked") protected MongoDataSourceCfgMeta __doParserDataSourceCfgMeta(String dsName, Map<String, String> _moduleCfgs) throws Exception { MongoDataSourceCfgMeta _meta = null; ///*from w w w . ja v a 2s. c o m*/ Map<String, String> _dataSourceCfgs = new HashMap<String, String>(); for (Map.Entry<String, String> _cfgEntry : _moduleCfgs.entrySet()) { String _key = _cfgEntry.getKey(); String _prefix = "ds." + dsName + "."; if (StringUtils.startsWith(_key, _prefix)) { String _cfgKey = StringUtils.substring(_key, _prefix.length()); _dataSourceCfgs.put(_cfgKey, _cfgEntry.getValue()); } } // if (!_dataSourceCfgs.isEmpty()) { String _connectionUrl = StringUtils.trimToNull(_dataSourceCfgs.get("connection_url")); if (_connectionUrl != null) { _meta = new MongoDataSourceCfgMeta(dsName, _dataSourceCfgs.get("collection_prefix"), _connectionUrl, _dataSourceCfgs.get("database_name")); } else { List<ServerAddress> _servers = new ArrayList<ServerAddress>(); String[] _serversArr = StringUtils.split(_dataSourceCfgs.get("servers"), "|"); if (_serversArr != null) { for (String _serverStr : _serversArr) { String[] _server = StringUtils.split(_serverStr, ":"); if (_server.length > 1) { _servers.add(new ServerAddress(_server[0], Integer.parseInt(_server[1]))); } else { _servers.add(new ServerAddress(_server[0])); } } } // boolean _isPwdEncrypted = new BlurObject(_dataSourceCfgs.get("password_encrypted")) .toBooleanValue(); Class<? extends IPasswordProcessor> _passwordClass = null; if (_isPwdEncrypted) { _passwordClass = (Class<? extends IPasswordProcessor>) ClassUtils .loadClass(_dataSourceCfgs.get("password_class"), this.getClass()); } _meta = new MongoDataSourceCfgMeta(dsName, _dataSourceCfgs.get("collection_prefix"), _servers, _dataSourceCfgs.get("username"), _dataSourceCfgs.get("password"), _dataSourceCfgs.get("database_name"), _isPwdEncrypted, _passwordClass); } } return _meta; }
From source file:net.ymate.platform.persistence.redis.impl.RedisModuleCfg.java
private Map<String, String> __doGetCfgs(Map<String, String> _moduleCfgs, String keyPrefix) { Map<String, String> _returnValues = new HashMap<String, String>(); for (Map.Entry<String, String> _cfgEntry : _moduleCfgs.entrySet()) { String _key = _cfgEntry.getKey(); if (StringUtils.startsWith(_key, keyPrefix)) { String _cfgKey = StringUtils.substring(_key, keyPrefix.length()); _returnValues.put(_cfgKey, _cfgEntry.getValue()); }//w w w.j a v a 2 s . c om } return _returnValues; }
From source file:net.ymate.platform.serv.impl.DefaultClientCfg.java
public DefaultClientCfg(IServModuleCfg moduleCfg, String clientName) { __clientName = StringUtils.defaultIfBlank(clientName, "default"); ////from w w w. j a v a 2 s. co 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.DefaultModuleCfg.java
private void __doConfigMapLoad(String prefix, String name, Map<String, String> sources, Map<String, Map<String, String>> dst) { Map<String, String> _cfgs = new HashMap<String, String>(); String _key = prefix.concat(".").concat(name).concat("."); for (Map.Entry<String, String> _entry : sources.entrySet()) { if (_entry.getKey().startsWith(_key)) { String _paramKey = StringUtils.substring(_entry.getKey(), _key.length()); _cfgs.put(_paramKey, _entry.getValue()); }/*from w w w . j a v a2 s . co m*/ } dst.put(name, _cfgs); }
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 w w . j a v a2 s . 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()); } } }
From source file:org.apache.cocoon.acting.DatabaseAddAction.java
/** * Inserts a row or a set of rows into the given table based on the * request parameters// w ww .j ava 2 s. co m * * @param table the table's configuration * @param conn the database connection * @param request the request */ void processTable(Configuration table, Connection conn, Request request, Map results) throws SQLException, ConfigurationException, Exception { PreparedStatement statement = null; try { String query = this.getAddQuery(table); getLogger().debug("Add query: " + query); statement = conn.prepareStatement(query); Configuration[] keys = table.getChild("keys").getChildren("key"); Configuration[] values = table.getChild("values").getChildren("value"); int currentIndex = 1; boolean manyrows = false; int wildcardIndex = -1; String wildcardParam = null; for (int i = 0; i < keys.length; i++) { wildcardParam = keys[i].getAttribute("param"); if ((wildcardIndex = wildcardParam.indexOf('*')) != -1) { manyrows = true; break; } } if (manyrows) { /** * This table has a column with a wildcard, so we're going * to be inserting n rows, where 0 <= n */ String prefix = wildcardParam.substring(0, wildcardIndex); String suffix = StringUtils.substring(wildcardParam, wildcardIndex + 1); Enumeration names = request.getParameterNames(); SortedSet matchset = new TreeSet(); int prefixLength = prefix.length(); int length = prefixLength + suffix.length(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); if (name.startsWith(prefix) && name.endsWith(suffix)) { String wildcard = StringUtils.mid(name, prefixLength, name.length() - length); matchset.add(wildcard); } } int rowIndex = 1; Iterator iterator = matchset.iterator(); while (iterator.hasNext()) { String wildcard = (String) iterator.next(); currentIndex = 1; for (int j = 0; j < keys.length; j++) { String myparam = getActualParam(keys[j].getAttribute("param"), wildcard); currentIndex += setKey(table, keys[j], conn, statement, currentIndex, request, myparam, results); } for (int j = 0; j < values.length; j++) { String myparam = getActualParam(values[j].getAttribute("param"), wildcard); this.setColumn(statement, currentIndex, request, values[j], myparam, request.getParameter(myparam), rowIndex); currentIndex++; } statement.execute(); rowIndex++; } } else { /** * This table has no wildcard columns, so we're going to * be inserting 1 row. */ for (int i = 0; i < keys.length; i++) { currentIndex += setKey(table, keys[i], conn, statement, currentIndex, request, keys[i].getAttribute("param", ""), results); } for (int i = 0; i < values.length; i++, currentIndex++) { this.setColumn(statement, currentIndex, request, values[i]); } statement.execute(); /** Done processing table **/ } } finally { try { if (statement != null) { statement.close(); } } catch (SQLException e) { } } }
From source file:org.apache.maven.scm.provider.svn.svnexe.command.checkout.SvnCheckOutConsumer.java
/** * {@inheritDoc}/*from w w w .j a v a2 s . c o m*/ */ protected void parseLine(String line) { String statusString = line.substring(0, 1); String file = line.substring(3).trim(); //[SCM-368] if (file.startsWith(getWorkingDirectory().getAbsolutePath())) { file = StringUtils.substring(file, getWorkingDirectory().getAbsolutePath().length() + 1); } ScmFileStatus status; if (line.startsWith(CHECKED_OUT_REVISION_TOKEN)) { String revisionString = line.substring(CHECKED_OUT_REVISION_TOKEN.length() + 1, line.length() - 1); revision = parseInt(revisionString); return; } else if (statusString.equals("A")) { status = ScmFileStatus.ADDED; } else if (statusString.equals("U")) { status = ScmFileStatus.UPDATED; } else { //Do nothing return; } addFile(new ScmFile(file, status)); }
From source file:org.archfirst.bfoms.infra.fixtrading.converters.ClOrdIDConverter.java
public static Long toDomain(ClOrdID clOrdID) { return new Long(StringUtils.substring(clOrdID.getValue(), 5)); }
From source file:org.archfirst.bfoms.infra.fixtrading.converters.OrigClOrdIDConverter.java
public static Long toDomain(OrigClOrdID origClOrdID) { return new Long(StringUtils.substring(origClOrdID.getValue(), 5)); }
From source file:org.archfirst.bfoms.infra.jsontrading.converters.ClOrdIDConverter.java
public static Long toDomain(String clOrdID) { return new Long(StringUtils.substring(clOrdID, 5)); }