Java Code Examples for org.springframework.util.StringUtils#delimitedListToStringArray()
The following examples show how to use
org.springframework.util.StringUtils#delimitedListToStringArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContextFunctionCatalogInitializerTests.java From spring-cloud-function with Apache License 2.0 | 6 votes |
private void create(ApplicationContextInitializer<GenericApplicationContext>[] types, String... props) { this.context = new GenericApplicationContext(); Map<String, Object> map = new HashMap<>(); for (String prop : props) { String[] array = StringUtils.delimitedListToStringArray(prop, "="); String key = array[0]; String value = array.length > 1 ? array[1] : ""; map.put(key, value); } if (!map.isEmpty()) { this.context.getEnvironment().getPropertySources() .addFirst(new MapPropertySource("testProperties", map)); } for (ApplicationContextInitializer<GenericApplicationContext> type : types) { type.initialize(this.context); } new ContextFunctionCatalogInitializer.ContextFunctionCatalogBeanRegistrar( this.context).postProcessBeanDefinitionRegistry(this.context); this.context.refresh(); this.catalog = this.context.getBean(FunctionCatalog.class); this.inspector = this.context.getBean(FunctionInspector.class); }
Example 2
Source File: ContainerCreator.java From haven-platform with Apache License 2.0 | 6 votes |
private Targets getBindedTargets(ContainerSource arg) { Targets targets = new Targets(); for (String binding : isEmpty(arg.getVolumeBinds()) ? Collections.<String>emptyList() : arg.getVolumeBinds()) { String[] arr = StringUtils.delimitedListToStringArray(binding, ":"); if (arr.length > 1) { String target = arr[1]; // remove trailing slashes while(target.endsWith("/") && target.length() > 1) { target = target.substring(0, target.length() - 1); } if (targets.bindTargets.add(target)) { targets.binds.add(binding); } } } return targets; }
Example 3
Source File: AbstractRememberMeServices.java From Lottery with GNU General Public License v2.0 | 6 votes |
/** * Decodes the cookie and splits it into a set of token strings using the * ":" delimiter. * * @param cookieValue * the value obtained from the submitted cookie * @return the array of tokens. * @throws InvalidCookieException * if the cookie was not base64 encoded. */ protected String[] decodeCookie(String cookieValue) throws InvalidCookieException { StringBuilder sb = new StringBuilder(cookieValue.length() + 3) .append(cookieValue); for (int j = 0; j < sb.length() % 4; j++) { sb.append("="); } cookieValue = sb.toString(); if (!Base64.isArrayByteBase64(cookieValue.getBytes())) { throw new InvalidCookieException( "Cookie token was not Base64 encoded; value was '" + cookieValue + "'"); } String cookieAsPlainText = new String(Base64.decodeBase64(cookieValue .getBytes())); return StringUtils.delimitedListToStringArray(cookieAsPlainText, DELIMITER); }
Example 4
Source File: ServletWebRequest.java From spring4-understanding with Apache License 2.0 | 6 votes |
private boolean isEtagNotModified(String etag) { if (StringUtils.hasLength(etag)) { String ifNoneMatch = getRequest().getHeader(HEADER_IF_NONE_MATCH); if (StringUtils.hasLength(ifNoneMatch)) { String[] clientEtags = StringUtils.delimitedListToStringArray(ifNoneMatch, ",", " "); for (String clientEtag : clientEtags) { // compare weak/strong ETag as per https://tools.ietf.org/html/rfc7232#section-2.3 if (StringUtils.hasLength(clientEtag) && (clientEtag.replaceFirst("^W/", "").equals(etag.replaceFirst("^W/", "")) || clientEtag.equals("*"))) { return true; } } } } return false; }
Example 5
Source File: CassandraConfiguration.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
@PostConstruct public void init() throws IOException { if (this.cassandraProperties.getInitScript() != null) { String scripts = new Scanner(this.cassandraProperties.getInitScript().getInputStream(), "UTF-8").useDelimiter("\\A").next(); CqlTemplate template = new CqlTemplate(this.session); for (String script : StringUtils.delimitedListToStringArray(scripts, ";", "\r\n\f")) { if (StringUtils.hasText(script)) { // an empty String after the last ';' template.execute(script + ";"); } } } }
Example 6
Source File: CronSequenceGenerator.java From lams with GNU General Public License v2.0 | 5 votes |
private int[] getRange(String field, int min, int max) { int[] result = new int[2]; if (field.contains("*")) { result[0] = min; result[1] = max - 1; return result; } if (!field.contains("-")) { result[0] = result[1] = Integer.valueOf(field); } else { String[] split = StringUtils.delimitedListToStringArray(field, "-"); if (split.length > 2) { throw new IllegalArgumentException("Range has more than two fields: '" + field + "' in expression \"" + this.expression + "\""); } result[0] = Integer.valueOf(split[0]); result[1] = Integer.valueOf(split[1]); } if (result[0] >= max || result[1] >= max) { throw new IllegalArgumentException("Range exceeds maximum (" + max + "): '" + field + "' in expression \"" + this.expression + "\""); } if (result[0] < min || result[1] < min) { throw new IllegalArgumentException("Range less than minimum (" + min + "): '" + field + "' in expression \"" + this.expression + "\""); } if (result[0] > result[1]) { throw new IllegalArgumentException("Invalid inverted range: '" + field + "' in expression \"" + this.expression + "\""); } return result; }
Example 7
Source File: DeploymentPropertiesUtils.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
/** * Parses a String comprised of 0 or more delimited key=value pairs where each key * has the format: {@code app.[appname].[key]} or {@code deployer.[appname].[key]}. Values * may themselves contain commas, since the split points will be based upon the key * pattern. * <p> * Logic of parsing key/value pairs from a string is based on few rules and assumptions 1. * keys will not have commas or equals. 2. First raw split is done by commas which will * need to be fixed later if value is a comma-delimited list. * * @param s the string to parse * @param delimiter delimiter used to split the string into pairs * @return the List key=value pairs */ public static List<String> parseParamList(String s, String delimiter) { ArrayList<String> pairs = new ArrayList<>(); // get raw candidates as simple comma split String[] candidates = StringUtils.delimitedListToStringArray(s, delimiter); for (int i = 0; i < candidates.length; i++) { if (i > 0 && !candidates[i].contains("=") || (i > 0 && candidates[i].contains("=") && !startsWithDeploymentPropertyPrefix(candidates[i]))) { // we don't have '=' so this has to be latter parts of // a comma delimited value, append it to previously added // key/value pair. // we skip first as we would not have anything to append to. this // would happen if dep prop string is malformed and first given // key/value pair is not actually a key/value. pairs.set(pairs.size() - 1, pairs.get(pairs.size() - 1) + delimiter + candidates[i]); } else { // we have a key/value pair having '=', or malformed first pair if (!startsWithDeploymentPropertyPrefix(candidates[i])) { throw new IllegalArgumentException( "Only deployment property keys starting with 'app.' or 'scheduler' or 'deployer.' or 'version.'" + " allowed."); } pairs.add(candidates[i]); } } return pairs; }
Example 8
Source File: NacosConfigHttpHandler.java From nacos-spring-project with Apache License 2.0 | 5 votes |
private Map<String, String> parseParams(String queryString) { Map<String, String> params = new HashMap<String, String>(); String[] parts = StringUtils.delimitedListToStringArray(queryString, "&"); for (String part : parts) { String[] nameAndValue = StringUtils.split(part, "="); params.put(StringUtils.trimAllWhitespace(nameAndValue[0]), StringUtils.trimAllWhitespace(nameAndValue[1])); } return params; }
Example 9
Source File: StringArrayPropertyEditor.java From java-technology-stack with MIT License | 5 votes |
@Override public void setAsText(String text) throws IllegalArgumentException { String[] array = StringUtils.delimitedListToStringArray(text, this.separator, this.charsToDelete); if (this.trimValues) { array = StringUtils.trimArrayElements(array); } if (this.emptyArrayAsNull && array.length == 0) { setValue(null); } else { setValue(array); } }
Example 10
Source File: RepoCommand.java From mojito with Apache License 2.0 | 5 votes |
/** * Extract {@link IntegrityChecker} Set from * {@link RepoCreateCommand#integrityCheckParam} to prep for * {@link Repository} creation * * @param integrityCheckParam * @param doPrint * @return */ protected Set<IntegrityChecker> extractIntegrityCheckersFromInput(String integrityCheckParam, boolean doPrint) throws CommandException { Set<IntegrityChecker> integrityCheckers = null; if (integrityCheckParam != null) { integrityCheckers = new HashSet<>(); Set<String> integrityCheckerParams = StringUtils.commaDelimitedListToSet(integrityCheckParam); if (doPrint) { consoleWriter.a("Extracted Integrity Checkers").println(); } for (String integrityCheckerParam : integrityCheckerParams) { String[] param = StringUtils.delimitedListToStringArray(integrityCheckerParam, ":"); if (param.length != 2) { throw new ParameterException("Invalid integrity checker format [" + integrityCheckerParam + "]"); } String fileExtension = param[0]; String checkerType = param[1]; IntegrityChecker integrityChecker = new IntegrityChecker(); integrityChecker.setAssetExtension(fileExtension); try { integrityChecker.setIntegrityCheckerType(IntegrityCheckerType.valueOf(checkerType)); } catch (IllegalArgumentException ex) { throw new ParameterException("Invalid integrity checker type [" + checkerType + "]"); } if (doPrint) { consoleWriter.fg(Ansi.Color.BLUE).a("-- file extension = ").fg(Ansi.Color.GREEN).a(integrityChecker.getAssetExtension()).println(); consoleWriter.fg(Ansi.Color.BLUE).a("-- checker type = ").fg(Ansi.Color.GREEN).a(integrityChecker.getIntegrityCheckerType().toString()).println(); } integrityCheckers.add(integrityChecker); } } return integrityCheckers; }
Example 11
Source File: MessageTag.java From java-technology-stack with MIT License | 5 votes |
/** * Resolve the given arguments Object into an arguments array. * @param arguments the specified arguments Object * @return the resolved arguments as array * @throws JspException if argument conversion failed * @see #setArguments */ @Nullable protected Object[] resolveArguments(@Nullable Object arguments) throws JspException { if (arguments instanceof String) { String[] stringArray = StringUtils.delimitedListToStringArray((String) arguments, this.argumentSeparator); if (stringArray.length == 1) { Object argument = stringArray[0]; if (argument != null && argument.getClass().isArray()) { return ObjectUtils.toObjectArray(argument); } else { return new Object[] {argument}; } } else { return stringArray; } } else if (arguments instanceof Object[]) { return (Object[]) arguments; } else if (arguments instanceof Collection) { return ((Collection<?>) arguments).toArray(); } else if (arguments != null) { // Assume a single argument object. return new Object[] {arguments}; } else { return null; } }
Example 12
Source File: MessageTag.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Resolve the given arguments Object into an arguments array. * @param arguments the specified arguments Object * @return the resolved arguments as array * @throws JspException if argument conversion failed * @see #setArguments */ protected Object[] resolveArguments(Object arguments) throws JspException { if (arguments instanceof String) { String[] stringArray = StringUtils.delimitedListToStringArray((String) arguments, this.argumentSeparator); if (stringArray.length == 1) { Object argument = stringArray[0]; if (argument != null && argument.getClass().isArray()) { return ObjectUtils.toObjectArray(argument); } else { return new Object[] {argument}; } } else { return stringArray; } } else if (arguments instanceof Object[]) { return (Object[]) arguments; } else if (arguments instanceof Collection) { return ((Collection<?>) arguments).toArray(); } else if (arguments != null) { // Assume a single argument object. return new Object[] {arguments}; } else { return null; } }
Example 13
Source File: ReflectUtil.java From Milkomeda with MIT License | 5 votes |
/** * 获取Field和值 * @param target 目标对象 * @param fieldPath 属性路径 * @return Field和值 * @since 3.7.1 */ public static Pair<Field, Object> getFieldBundlePath(Object target, String fieldPath) { if (target == null || StringUtils.isEmpty(fieldPath)) { return null; } String[] fieldNames = StringUtils.delimitedListToStringArray(fieldPath, "."); Field field = null; for (String fieldName : fieldNames) { field = ReflectionUtils.findField(Objects.requireNonNull(target).getClass(), fieldName); if (field == null) return null; ReflectionUtils.makeAccessible(field); target = ReflectionUtils.getField(field, target); } return Pair.of(field, target); }
Example 14
Source File: FreeMarkerMacroTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
private String fetchMacro(String name) throws Exception { ClassPathResource resource = new ClassPathResource("test.ftl", getClass()); assertTrue(resource.exists()); String all = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream())); all = all.replace("\r\n", "\n"); String[] macros = StringUtils.delimitedListToStringArray(all, "\n\n"); for (String macro : macros) { if (macro.startsWith(name)) { return macro.substring(macro.indexOf("\n")).trim(); } } return null; }
Example 15
Source File: StringArrayPropertyEditor.java From spring-analysis-note with MIT License | 5 votes |
@Override public void setAsText(String text) throws IllegalArgumentException { String[] array = StringUtils.delimitedListToStringArray(text, this.separator, this.charsToDelete); if (this.trimValues) { array = StringUtils.trimArrayElements(array); } if (this.emptyArrayAsNull && array.length == 0) { setValue(null); } else { setValue(array); } }
Example 16
Source File: VersionUtils.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
/** * Given a 3 or 4 part version return the 3 part version. Return empty string if supplied a * {@code null} value. If there are not 3 or 4 parts in the provided version, return empty string. * @param fourPartVersion The four part version of the string * @return the three part version number, */ public static String getThreePartVersion(String fourPartVersion) { String threePartVersion = ""; String[] versionTokens = StringUtils.delimitedListToStringArray(fourPartVersion, SEPARATOR); if (versionTokens.length == 3) { return fourPartVersion; } if (versionTokens.length != 4) { return threePartVersion; } return versionTokens[0] + SEPARATOR + versionTokens[1] + SEPARATOR + versionTokens[2]; }
Example 17
Source File: DelimitedStringToCollectionConverter.java From spring-cloud-gray with Apache License 2.0 | 4 votes |
private String[] getElements(String source, String delimiter) { return StringUtils.delimitedListToStringArray(source, Delimiter.NONE.equals(delimiter) ? null : delimiter); }
Example 18
Source File: ModifiedClassPathRunner.java From spring-cloud-commons with Apache License 2.0 | 4 votes |
private String[] getClassPath(URL booterJar) throws Exception { Attributes attributes = getManifestMainAttributesFromUrl(booterJar); return StringUtils.delimitedListToStringArray( attributes.getValue(Attributes.Name.CLASS_PATH), " "); }
Example 19
Source File: ResourceController.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
protected URL[] getRequestResourceUrls(String rawResourcePath, HttpServletRequest request) throws MalformedURLException { String appendedPaths = request.getParameter("appended"); // don't allow multiple resources if compression is off if (StringUtils.hasText(appendedPaths) && isCompressionAllowed()) { rawResourcePath = rawResourcePath + "," + appendedPaths; } String[] localResourcePaths = StringUtils.delimitedListToStringArray(rawResourcePath, ","); URL[] resources = new URL[localResourcePaths.length]; for (int i = 0; i < localResourcePaths.length; i++) { String localResourcePath = localResourcePaths[i]; if (!isAllowed(localResourcePath)) { if (log.isWarnEnabled()) { log.warn("An attempt to access a protected resource at " + localResourcePath + " was disallowed."); } return null; } URL resource = null; // try direct file access first (development mode) if (null != fileLocation) { File file = new File(fileLocation, localResourcePath); log.debug("trying to find {} ({})", file.getAbsolutePath(), file.exists()); if (file.exists()) { log.debug("found {} ({})", file.getAbsolutePath(), file.exists()); resource = file.toURI().toURL(); } } if (resource == null) { resource = servletContext.getResource(localResourcePath); } if (resource == null) { if (!isAllowed(localResourcePath)) { if (log.isWarnEnabled()) { log.warn("An attempt to access a protected resource at " + localResourcePath + " was disallowed."); } return null; } log.debug("Searching classpath for resource: {}", localResourcePath); resource = ClassUtils.getDefaultClassLoader().getResource(localResourcePath); if (resource == null) { log.debug("Searching classpath for resource: {}", localResourcePath.substring(1)); resource = ClassUtils.getDefaultClassLoader().getResource(localResourcePath.substring(1)); } } if (resource == null) { if (resources.length > 1) { log.debug("Combined resource not found: {}", localResourcePath); } return null; } else { log.debug(resource.toExternalForm()); resources[i] = resource; } } return resources; }
Example 20
Source File: SqlActivityPermissionEntity.java From openwebflow with BSD 2-Clause "Simplified" License | 4 votes |
public void deserializeProperties() { _grantedGroupIds = StringUtils.delimitedListToStringArray(_grantedGroupString, ";"); _grantedUserIds = StringUtils.delimitedListToStringArray(_grantedUserString, ";"); }