List of usage examples for org.springframework.util StringUtils delimitedListToStringArray
public static String[] delimitedListToStringArray(@Nullable String str, @Nullable String delimiter)
From source file:dev.argent.hive.SqlScriptLoader.java
@SuppressWarnings("unchecked") public static String[] getScripts(Class<?> clazz, String sqlFileName) { try {//w w w.jav a 2 s .com String fileName = clazz.getResource(sqlFileName).getFile(); String comments = stripComments((List<String>) FileUtils.readLines(new File(fileName))); return StringUtils.delimitedListToStringArray(comments, ";"); } catch (IOException e) { log.warn(e.getMessage(), e); throw new IllegalArgumentException("SqlFile load failed. fileName : " + sqlFileName, e); } }
From source file:com.codeabovelab.dm.cluman.cluster.docker.model.Bind.java
/** * Parses a bind mount specification to a {@link Bind}. * * @param serialized//from www . j a v a2 s . c o m * the specification, e.g. <code>/host:/container:ro</code> * @return a {@link Bind} matching the specification * @throws IllegalArgumentException * if the specification cannot be parsed */ public static Bind parse(String serialized) { try { String[] parts = StringUtils.delimitedListToStringArray(serialized, ":"); switch (parts.length) { case 2: { return new Bind(parts[0], new Volume(parts[1])); } case 3: { AccessMode accessMode = AccessMode.valueOf(parts[2].toLowerCase()); return new Bind(parts[0], new Volume(parts[1]), accessMode); } default: { throw new IllegalArgumentException(); } } } catch (Exception e) { throw new IllegalArgumentException("Error parsing Bind '" + serialized + "'"); } }
From source file:org.web4thejob.orm.PathMetadataImpl.java
public PathMetadataImpl(Class<? extends Entity> entityType, Path nodes) { this(entityType, StringUtils.delimitedListToStringArray(nodes.toString(), Path.DELIMITER)); }
From source file:io.cloudslang.lang.cli.converters.MapConverter.java
@Override public Map<String, String> convertFromText(String value, Class<?> targetType, String optionContext) { value = value.replace("\\,", ESCAPE_EXPRESSION); String[] values = StringUtils.commaDelimitedListToStringArray(value); Map<String, String> map = new HashMap<>(); for (String v : values) { String[] keyValue = StringUtils.delimitedListToStringArray(v, "="); if (keyValue.length == 2) { keyValue[1] = keyValue[1].replace(ESCAPE_EXPRESSION, ","); map.put(keyValue[0], keyValue[1]); } else {/* w w w . j a va 2 s . c o m*/ throw new RuntimeException( "Input should be in a key=value comma separated format, e.g. key1=val1,key2=val2 etc."); } } return map; }
From source file:org.springmodules.cache.util.SemicolonSeparatedPropertiesParser.java
/** * Creates a <code>java.util.Properties</code> from the specified String. * * @param text// w w w .jav a 2 s . c o m * the String to parse. * @throws IllegalArgumentException * if the specified property does not match the regular expression * pattern defined in <code>KEY_VALUE_REGEX</code>. * @throws IllegalArgumentException * if the set of properties already contains the property specified * by the given String. * @return a new instance of <code>java.util.Properties</code> created from * the given text. */ public static Properties parseProperties(String text) throws IllegalArgumentException { String newText = text; if (!StringUtils.hasText(newText)) { return null; } if (newText.endsWith(PROPERTY_DELIMITER)) { // remove ';' at the end of the text (if applicable) newText = newText.substring(0, newText.length() - PROPERTY_DELIMITER.length()); if (!StringUtils.hasText(newText)) { return null; } } Properties properties = new Properties(); String[] propertiesAsText = StringUtils.delimitedListToStringArray(newText, PROPERTY_DELIMITER); int propertyCount = propertiesAsText.length; for (int i = 0; i < propertyCount; i++) { String property = propertiesAsText[i]; Match match = KEY_VALUE_REGEX.match(property); if (!match.isSuccessful()) { String message = "The String " + StringUtils.quote(property) + " should match the regular expression pattern " + StringUtils.quote(KEY_VALUE_REGEX.getPattern()); throw new IllegalArgumentException(message); } String[] groups = match.getGroups(); String key = groups[1].trim(); String value = groups[2].trim(); if (properties.containsKey(key)) { throw new IllegalArgumentException( "The property " + StringUtils.quote(key) + " is specified more than once"); } properties.setProperty(key, value); } return properties; }
From source file:fr.xebia.springframework.security.core.userdetails.memory.ExtendedUserMapBuilder.java
/** * Build an {@link fr.xebia.springframework.security.core.userdetails.ExtendedUser} from user attributes. * Protected for test purpose.// w w w.ja v a 2 s .c om * @param userAttributes a list. * @return the build {@link fr.xebia.springframework.security.core.userdetails.ExtendedUser}. */ protected static ExtendedUser buildExtendedUser(String userAttributes) { if (userAttributes == null) { return null; } String[] userAttributesStringArray = StringUtils.delimitedListToStringArray(userAttributes, "="); if (userAttributesStringArray.length != 2) { return null; // we need a username and some attributes. } String username = userAttributesStringArray[0].trim(); Pattern pattern = Pattern.compile("(enabled|disabled){1}$"); Matcher matcher = pattern.matcher(userAttributesStringArray[1].trim()); // Check activated attribute boolean activated = true; if (matcher.find()) { activated = ENABLED.equals(matcher.group()); } // Check authorized IP addresses String allowedIpAddresses = ""; pattern = Pattern.compile("@\\(.*\\)"); matcher = pattern.matcher(userAttributesStringArray[1]); if (matcher.find()) { allowedIpAddresses = StringUtils.deleteAny(matcher.group(), "@() "); } // Get user password and roles : pattern = Pattern.compile("((,\\ *@\\(.*\\)){0,1}(\\ *,\\ *(enabled|disabled)\\ *){0,1})$"); String[] remainingAttributes = pattern.split(userAttributesStringArray[1]); if (remainingAttributes.length != 1) { return null; // password and role(s) must have been defined. } String[] attributes = StringUtils.commaDelimitedListToStringArray(remainingAttributes[0]); if (attributes.length < 2) { return null; // we need at least one password and one role. } String password = attributes[0].trim(); List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); for (int i = 1; i < attributes.length; i++) { authorities.add(new GrantedAuthorityImpl(attributes[i].trim())); } ExtendedUser extendedUser = new ExtendedUser(username, password, activated, true, true, true, authorities); extendedUser.setAllowedRemoteAddresses(allowedIpAddresses); return extendedUser; }
From source file:com.bxtel.security5.auth.impl.SecurityMetadataSourceImpl.java
protected void buildRequestMap() { LinkedHashMap<RequestMatcher, Collection<IConfigAttribute>> requestMap = null; requestMap = new LinkedHashMap<RequestMatcher, Collection<IConfigAttribute>>(); Iterable<SecurityData> resourceMap = dao.findAll(); for (SecurityData one : resourceMap) { String key = one.getPath(); String[] roles = StringUtils.delimitedListToStringArray(one.getRolelist(), ",");//role Collection<IConfigAttribute> roleslist = new ArrayList<IConfigAttribute>(); for (int i = 0; i < roles.length; i++) { ConfigAttributeImpl e = new ConfigAttributeImpl(roles[i]); roleslist.add((IConfigAttribute) e); }// w ww .j a va 2 s . c om requestMap.put(new AntPathRequestMatcher(key), roleslist); } this.requestMap = requestMap; }
From source file:org.jasig.portlet.contacts.adapters.impl.ldap.LdapSearchAdapter.java
public Contact getByURN(String urn) { String[] attr = StringUtils.delimitedListToStringArray(urn, ":"); String searchText = attr[2];/*from ww w . jav a 2 s . c om*/ String filter = attr[3]; String id = attr[4]; ContactSet contacts = search(searchText, filter); for (Contact contact : contacts) { if (contact.getId().equals(id)) return contact; } return null; }
From source file:net.opentsdb.contrib.tsquare.ExtendedTsdbMetricParser.java
private Metric parseSingleMetricWithoutTags(final String metricString) { Metric metric = null;//from w w w .j a v a 2s . c o m if (metricString.indexOf(':') < 0) { // EXTENSION: This is a metric only expression. We auto-detect the aggregator // based on the metric name, or use the default. Aggregator agg = aggregatorFactory.getAggregatorForMetric(metricString); metric = new Metric(metricString, metricString, (agg == null ? defaultAggregator : agg)); } else { // Otherwise, this might be a standard expression with some extra sauce... final String[] parts = StringUtils.delimitedListToStringArray(metricString, ":"); Preconditions.checkState(parts.length > 1, "Invalid metric: %s", metricString); // Metric name is always the last element, regardless of format. ASSUMING we've stripped // tag expressions off the end. final String metricName = parts[parts.length - 1]; // EXTENSION: Logic in determineAggregator() allows for empty or auto-detect // aggregators. See the doc on that method for details. metric = new Metric(metricString, metricName, determineAggregator(metricName, parts[0])); // Handle parsing of rate and downsampler. if (parts.length > 2 && parts.length <= 4) { for (int i = 1; i < parts.length - 1; i++) { final String p = parts[i]; if ("rate".equals(p)) { metric.setRate(true); } else if (Character.isDefined(p.charAt(0)) && p.indexOf('-') > 0) { // 1h-sum final String[] downsampleParts = StringUtils.split(p, "-"); long downsampleMillis = new DateTimeExpressionParser().setBaseTimeMillis(0) // ... parse a relative duration .setPositiveOffset(true).parseRequired(downsampleParts[0]); // Convert to epoch SECONDS. metric.setDownsampleIntervalSeconds( (int) TimeUnit.MILLISECONDS.toSeconds(downsampleMillis)); // EXTENSION: Again, determineAggregator() allows for empty or auto-detected // downsamplers. metric.setDownsampler(determineAggregator(metricName, downsampleParts[1])); } else { throw new IllegalStateException("Invalid characters in metric: " + p); } } } else if (parts.length != 2) { throw new IllegalStateException("Metric has invalid parsed length: " + parts.length); } } return metric; }
From source file:de.dlopes.stocks.facilitator.services.impl.StockInfoServiceImpl.java
@Override public void addStocks(AddStocksForm addStocksForm) { List<String> yahooSymbols = null; String url = addStocksForm.getUrl(); if (StringUtils.isEmpty(url)) { String yhooSymString = addStocksForm.getListOfYahooSymbols(); yhooSymString = yhooSymString.replace("\n", ","); yhooSymString = yhooSymString.replace("\r", ","); yhooSymString = yhooSymString.replace(",,", ","); yhooSymString = StringUtils.trimAllWhitespace(yhooSymString); yahooSymbols = Arrays.asList(StringUtils.delimitedListToStringArray(yhooSymString, ",")); } else {// w ww . j a v a2 s . c o m /* // get the ISINs FinanzenNetIndexHTMLExtractorImpl fn_isin_extr = new FinanzenNetIndexHTMLExtractorImpl(); List<String> isins = fn_isin_extr.getFinanceData(url); // TODO: remove ISINs which already exist in the DB from list log.info("ISINs extracted!"); // guard: abort when there is nothing to add if (isins.size() < 1) { throw new RuntimeException("no ISINs found!."); // TODO: propagate error message to UI } log.info("ISINs found!"); // receive the mapping Map<String,String> symbols2isins = null; try { symbols2isins = YahooFinanceDataCollectorImpl.getSymbols4ISINs(isins); } catch (SFApplicationException sfae) { throw new RuntimeException("Yahoo Symbols could not be loaded", sfae); } log.info("Yahoo symbols loaded!"); // when there was no mapping was found for one or more ISIN, the we // have to propagate this as a warning message if (symbols2isins.size() < isins.size()) { // remove all ISINs that returned a valid mapping and see what stays in the list for (String s : symbols2isins.keySet()) { String isin = symbols2isins.get(s); isins.remove(isin); } // TODO: propagate a message to the UI } log.info("Yahoo symbols cleaned up!"); // guard: do not proceed when we don't have new symbols to add if (symbols2isins.size() < 1) { throw new RuntimeException("no YAHOO symbols found!."); // TODO: propagate error message to UI } log.info("still have Yahoo symbols to load!"); */ FinanceDataExtractor finDataExtr = cs.getFinanceDataExtractor(); yahooSymbols = finDataExtr.getFinanceData(url); } // guard: abort when there is nothing to add if (yahooSymbols == null || yahooSymbols.isEmpty()) { throw new RuntimeException("no Yahoo Symbols found!."); // TODO: propagate error message to UI } // load stock details from yahoo finance api Map<String, Stock> stocks = null; try { stocks = YahooFinanceDataCollectorImpl.requestStocks(yahooSymbols); } catch (SFApplicationException sfae) { throw new RuntimeException("Stock details could not be loaded", sfae); } log.info("Stock info requested from Yahoo!"); for (String symbol : stocks.keySet()) { Stock stock = stocks.get(symbol); // TODO: refactor FinanznachrichtenOrderbuchExtractorImpl foei = new FinanznachrichtenOrderbuchExtractorImpl(); List<String> isins = foei.getFinanceData( FinanznachrichtenOrderbuchExtractorImpl.PREFIX + symbol.split("\\.")[0] + ".htm"); String isin = null; if (isins != null && isins.size() > 0) { isin = isins.get(0); } log.debug("creating StockInfo record for ISIN '" + isin + "'"); StockInfo si = new StockInfo(isin); Stock2StockInfoConverter.applyUpdates(stock, si); log.debug("yahoo data applied to StockInfo record for ISIN '" + isin + "'"); siRepo.save(si); log.debug("StockInfo record for ISIN '" + isin + "' saved"); } siRepo.flush(); log.info("Stock info committed to database!"); }