Java Code Examples for org.springframework.util.StringUtils#collectionToDelimitedString()

The following examples show how to use org.springframework.util.StringUtils#collectionToDelimitedString() . These examples are extracted from open source projects. 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
/**
 * Look up the object with the given name.
 * <p>Note: Not intended for direct use by applications.
 * Will be used by any standard InitialContext JNDI lookups.
 * @throws javax.naming.NameNotFoundException if the object could not be found
 */
@Override
public Object lookup(String lookupName) throws NameNotFoundException {
	String name = this.root + lookupName;
	if (logger.isDebugEnabled()) {
		logger.debug("Static JNDI lookup: [" + name + "]");
	}
	if ("".equals(name)) {
		return new SimpleNamingContext(this.root, this.boundObjects, this.environment);
	}
	Object found = this.boundObjects.get(name);
	if (found == null) {
		if (!name.endsWith("/")) {
			name = name + "/";
		}
		for (String boundName : this.boundObjects.keySet()) {
			if (boundName.startsWith(name)) {
				return new SimpleNamingContext(name, this.boundObjects, this.environment);
			}
		}
		throw new NameNotFoundException(
				"Name [" + this.root + lookupName + "] not bound; " + this.boundObjects.size() + " bindings: [" +
				StringUtils.collectionToDelimitedString(this.boundObjects.keySet(), ",") + "]");
	}
	return found;
}
 
Example 2
Source Project: spring-analysis-note   File: HttpServletBean.java    License: MIT License 6 votes vote down vote up
/**
 * Create new ServletConfigPropertyValues.
 * @param config the ServletConfig we'll use to take PropertyValues from
 * @param requiredProperties set of property names we need, where
 * we can't accept default values
 * @throws ServletException if any required properties are missing
 */
public ServletConfigPropertyValues(ServletConfig config, Set<String> requiredProperties)
		throws ServletException {

	Set<String> missingProps = (!CollectionUtils.isEmpty(requiredProperties) ?
			new HashSet<>(requiredProperties) : null);

	Enumeration<String> paramNames = config.getInitParameterNames();
	while (paramNames.hasMoreElements()) {
		String property = paramNames.nextElement();
		Object value = config.getInitParameter(property);
		addPropertyValue(new PropertyValue(property, value));
		if (missingProps != null) {
			missingProps.remove(property);
		}
	}

	// Fail if we are still missing properties.
	if (!CollectionUtils.isEmpty(missingProps)) {
		throw new ServletException(
				"Initialization from ServletConfig for servlet '" + config.getServletName() +
				"' failed; the following required properties were missing: " +
				StringUtils.collectionToDelimitedString(missingProps, ", "));
	}
}
 
Example 3
Source Project: spring-data-dev-tools   File: Version.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {

	List<Integer> digits = new ArrayList<Integer>();
	digits.add(major);
	digits.add(minor);

	if (build != 0 || bugfix != 0) {
		digits.add(bugfix);
	}

	if (build != 0) {
		digits.add(build);
	}

	return StringUtils.collectionToDelimitedString(digits, ".");
}
 
Example 4
/**
 * Look up the object with the given name.
 * <p>Note: Not intended for direct use by applications.
 * Will be used by any standard InitialContext JNDI lookups.
 * @throws javax.naming.NameNotFoundException if the object could not be found
 */
@Override
public Object lookup(String lookupName) throws NameNotFoundException {
	String name = this.root + lookupName;
	if (logger.isDebugEnabled()) {
		logger.debug("Static JNDI lookup: [" + name + "]");
	}
	if ("".equals(name)) {
		return new SimpleNamingContext(this.root, this.boundObjects, this.environment);
	}
	Object found = this.boundObjects.get(name);
	if (found == null) {
		if (!name.endsWith("/")) {
			name = name + "/";
		}
		for (String boundName : this.boundObjects.keySet()) {
			if (boundName.startsWith(name)) {
				return new SimpleNamingContext(name, this.boundObjects, this.environment);
			}
		}
		throw new NameNotFoundException(
				"Name [" + this.root + lookupName + "] not bound; " + this.boundObjects.size() + " bindings: [" +
				StringUtils.collectionToDelimitedString(this.boundObjects.keySet(), ",") + "]");
	}
	return found;
}
 
Example 5
Source Project: spring-vault   File: Version.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {

	List<Integer> digits = new ArrayList<Integer>();
	digits.add(this.major);
	digits.add(this.minor);

	if (this.build != 0 || this.bugfix != 0) {
		digits.add(this.bugfix);
	}

	if (this.build != 0) {
		digits.add(this.build);
	}

	return StringUtils.collectionToDelimitedString(digits, ".") + (isEnterprise() ? "+ent" : "");
}
 
Example 6
/**
 * Look up the object with the given name.
 * <p>Note: Not intended for direct use by applications.
 * Will be used by any standard InitialContext JNDI lookups.
 * @throws javax.naming.NameNotFoundException if the object could not be found
 */
@Override
public Object lookup(String lookupName) throws NameNotFoundException {
	String name = this.root + lookupName;
	if (logger.isDebugEnabled()) {
		logger.debug("Static JNDI lookup: [" + name + "]");
	}
	if ("".equals(name)) {
		return new SimpleNamingContext(this.root, this.boundObjects, this.environment);
	}
	Object found = this.boundObjects.get(name);
	if (found == null) {
		if (!name.endsWith("/")) {
			name = name + "/";
		}
		for (String boundName : this.boundObjects.keySet()) {
			if (boundName.startsWith(name)) {
				return new SimpleNamingContext(name, this.boundObjects, this.environment);
			}
		}
		throw new NameNotFoundException(
				"Name [" + this.root + lookupName + "] not bound; " + this.boundObjects.size() + " bindings: [" +
				StringUtils.collectionToDelimitedString(this.boundObjects.keySet(), ",") + "]");
	}
	return found;
}
 
Example 7
@Override
protected synchronized ExitStatus run(OptionSet options) throws Exception {
	String charset = "UTF-8";
	if(options.has(charsetOption)){
		charset = options.valueOf(charsetOption);
	}
	String text = StringUtils
			.collectionToDelimitedString(options.nonOptionArguments(), " ");
	try {
		Charset.forName(charset);
		String outText = URLDecoder.decode(text, charset);
		System.out.println(outText);
		return ExitStatus.OK;
	} catch (UnsupportedCharsetException e){
		System.out.println("Unsupported Character Set");
		return ExitStatus.ERROR;
	}
}
 
Example 8
private static String computeDependenciesId(List<String> dependencies) {
	if (ObjectUtils.isEmpty(dependencies)) {
		return "_none";
	}
	Collections.sort(dependencies);
	return StringUtils.collectionToDelimitedString(dependencies, " ");
}
 
Example 9
private String[] parsedDependencyPathEmptyByDefault(String path, String delimiter) {
	String trimmedPath = path.startsWith(delimiter) ? path.substring(1) : path;
	String[] splitPath = trimmedPath.split(delimiter);
	String stubsGroupId = "";
	String stubsArtifactId = "";
	String stubsClassifier = "";
	if (splitPath.length >= 2) {
		LinkedList<String> list = new LinkedList<>(Arrays.asList(splitPath));
		String lastElement = list.removeLast();
		stubsGroupId = StringUtils.collectionToDelimitedString(list, ".");
		stubsArtifactId = lastElement;
		stubsClassifier = DEFAULT_STUBS_CLASSIFIER;
	}
	return new String[] { stubsGroupId, stubsArtifactId, stubsClassifier };
}
 
Example 10
/**
 * Create a new stream.
 *
 * @param streamName stream name
 * @param dsl DSL definition for stream
 * @param description description of the stream definition
 * @param deploy if {@code true}, the stream is deployed upon creation (default is
 *     {@code false})
 * @return the created stream definition already exists
 * @throws InvalidStreamDefinitionException if there are errors in parsing the stream DSL,
 *     resolving the name, or type of applications in the stream
 */
public StreamDefinition createStream(String streamName, String dsl, String description, boolean deploy) {
	StreamDefinition streamDefinition = createStreamDefinition(streamName, dsl, description);
	List<String> errorMessages = new ArrayList<>();

	for (StreamAppDefinition streamAppDefinition : this.streamDefinitionService.getAppDefinitions(streamDefinition)) {
		final String appName = streamAppDefinition.getRegisteredAppName();
		ApplicationType applicationType = streamAppDefinition.getApplicationType();
		if (!streamValidationService.isRegistered(appName, applicationType)) {
			errorMessages.add(
					String.format("Application name '%s' with type '%s' does not exist in the app registry.",
							appName, applicationType));
		}
	}

	if (!errorMessages.isEmpty()) {
		throw new InvalidStreamDefinitionException(
				StringUtils.collectionToDelimitedString(errorMessages, "\n"));
	}

	if (this.streamDefinitionRepository.existsById(streamName)) {
		throw new DuplicateStreamDefinitionException(String.format(
				"Cannot create stream %s because another one has already " + "been created with the same name",
				streamName));
	}
	final StreamDefinition savedStreamDefinition = this.streamDefinitionRepository.save(streamDefinition);

	if (deploy) {
		this.deployStream(streamName, new HashMap<>());
	}

	auditRecordService.populateAndSaveAuditRecord(
			AuditOperationType.STREAM, AuditActionType.CREATE, streamDefinition.getName(),
			StreamDefinitionServiceUtils.sanitizeStreamDefinition(streamDefinition.getName(),
					streamDefinitionService.getAppDefinitions(streamDefinition)), null);

	return streamDefinition;

}
 
Example 11
Source Project: spring-cloud-cli   File: DecryptCommand.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected synchronized ExitStatus run(OptionSet options) throws Exception {
	TextEncryptor encryptor = createEncryptor(options);
	String text = StringUtils.collectionToDelimitedString(
			options.nonOptionArguments(), " ");
	if (text.startsWith("{cipher}")) {
		text = text.substring("{cipher}".length());
	}
	System.out.println(encryptor.decrypt(text));
	return ExitStatus.OK;
}
 
Example 12
/**
 * Parse the given property name into the corresponding property name tokens.
 * @param propertyName the property name to parse
 * @return representation of the parsed property tokens
 */
private PropertyTokenHolder getPropertyNameTokens(String propertyName) {
	PropertyTokenHolder tokens = new PropertyTokenHolder();
	String actualName = null;
	List<String> keys = new ArrayList<String>(2);
	int searchIndex = 0;
	while (searchIndex != -1) {
		int keyStart = propertyName.indexOf(PROPERTY_KEY_PREFIX, searchIndex);
		searchIndex = -1;
		if (keyStart != -1) {
			int keyEnd = propertyName.indexOf(PROPERTY_KEY_SUFFIX, keyStart + PROPERTY_KEY_PREFIX.length());
			if (keyEnd != -1) {
				if (actualName == null) {
					actualName = propertyName.substring(0, keyStart);
				}
				String key = propertyName.substring(keyStart + PROPERTY_KEY_PREFIX.length(), keyEnd);
				if ((key.startsWith("'") && key.endsWith("'")) || (key.startsWith("\"") && key.endsWith("\""))) {
					key = key.substring(1, key.length() - 1);
				}
				keys.add(key);
				searchIndex = keyEnd + PROPERTY_KEY_SUFFIX.length();
			}
		}
	}
	tokens.actualName = (actualName != null ? actualName : propertyName);
	tokens.canonicalName = tokens.actualName;
	if (!keys.isEmpty()) {
		tokens.canonicalName +=
				PROPERTY_KEY_PREFIX +
						StringUtils.collectionToDelimitedString(keys, PROPERTY_KEY_SUFFIX + PROPERTY_KEY_PREFIX) +
						PROPERTY_KEY_SUFFIX;
		tokens.keys = StringUtils.toStringArray(keys);
	}
	return tokens;
}
 
Example 13
Source Project: spring-cloud-cli   File: EncryptCommand.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected synchronized ExitStatus run(OptionSet options) throws Exception {
	TextEncryptor encryptor = createEncryptor(options);
	String text = StringUtils.collectionToDelimitedString(
			options.nonOptionArguments(), " ");
	System.out.println(formatCipher(options, encryptor.encrypt(text)));
	return ExitStatus.OK;
}
 
Example 14
/**
 * Gets display name.
 *
 * @return the display name
 */
public String getDisplayName() {
    final Collection<String> items = getDisplayNames();
    if (items.isEmpty()) {
        return this.registeredService.getName();
    }
    return StringUtils.collectionToDelimitedString(items, ".");
}
 
Example 15
public String trimHash(String part) {
    if (part == null) {
        throw new IllegalStateException("Resource name part must not be null!");
    }
    LOGGER.debug("Trim the hash part from the end: {}", part);
    String[] parts = part.split(DELIMITER);
    String trimmed = part;
    try {
        trimmed = StringUtils.collectionToDelimitedString(Arrays.asList(Arrays.copyOf(parts, parts.length - 1)), DELIMITER);
    } catch (NumberFormatException ignored) {
        LOGGER.debug("No need to trim hash: {}", part);
    }

    return trimmed;
}
 
Example 16
Source Project: openapi-generator   File: ApiClient.java    License: Apache License 2.0 4 votes vote down vote up
private String collectionToString(Collection<?> collection) {
    return StringUtils.collectionToDelimitedString(collection, separator);
}
 
Example 17
@SuppressWarnings("unchecked")
@Override
public String getAsText() {
	return StringUtils.collectionToDelimitedString((Collection<String>) getValue(), ";");
}
 
Example 18
private String jsonArrayOfMappings(Collection<String> mappings) {
	return "[" + StringUtils.collectionToDelimitedString(mappings, ",\n") + "]";
}
 
Example 19
Source Project: MaxKey   File: OAuth2Utils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Formats a set of string values into a format appropriate for sending as a single-valued form value.
 * 
 * @param value The value of the parameter.
 * @return The value formatted for form submission etc, or null if the input is empty
 */
public static String formatParameterList(Collection<String> value) {
	return value == null ? null : StringUtils.collectionToDelimitedString(value, " ");
}
 
Example 20
/**
 * Gets privacy statement uRL.
 *
 * @return the privacy statement uRL
 */
public String getPrivacyStatementURL() {
    final Collection<String> items = getPrivacyStatementURLs();
    return StringUtils.collectionToDelimitedString(items, ".");
}