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

The following examples show how to use org.springframework.util.StringUtils#commaDelimitedListToStringArray() . 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: GroovyMarkupConfigurer.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Create a parent ClassLoader for Groovy to use as parent ClassLoader
 * when loading and compiling templates.
 */
protected ClassLoader createTemplateClassLoader() throws IOException {
	String[] paths = StringUtils.commaDelimitedListToStringArray(getResourceLoaderPath());
	List<URL> urls = new ArrayList<URL>();
	for (String path : paths) {
		Resource[] resources = getApplicationContext().getResources(path);
		if (resources.length > 0) {
			for (Resource resource : resources) {
				if (resource.exists()) {
					urls.add(resource.getURL());
				}
			}
		}
	}
	ClassLoader classLoader = getApplicationContext().getClassLoader();
	return (urls.size() > 0 ? new URLClassLoader(urls.toArray(new URL[urls.size()]), classLoader) : classLoader);
}
 
Example 2
Source File: OsCacheCachingModel.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Sets the cache groups from a comma-delimited list of values.
 * 
 * @param csvGroups
 *          the comma-delimited list of values containing the cache groups.
 */
public final void setGroups(String csvGroups) {
  String[] newGroups = null;
  if (StringUtils.hasText(csvGroups)) {
    newGroups = StringUtils.commaDelimitedListToStringArray(csvGroups);
  }
  setGroups(newGroups);
}
 
Example 3
Source File: CredhubEnvironmentRepository.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Override
public Environment findOne(String application, String profilesList, String label) {
	if (StringUtils.isEmpty(profilesList)) {
		profilesList = DEFAULT_PROFILE;
	}
	if (StringUtils.isEmpty(label)) {
		label = DEFAULT_LABEL;
	}

	String[] profiles = StringUtils.commaDelimitedListToStringArray(profilesList);

	Environment environment = new Environment(application, profiles, label, null,
			null);
	for (String profile : profiles) {
		environment.add(new PropertySource(
				"credhub-" + application + "-" + profile + "-" + label,
				findProperties(application, profile, label)));
		if (!DEFAULT_APPLICATION.equals(application)) {
			addDefaultPropertySource(environment, DEFAULT_APPLICATION, profile,
					label);
		}
	}

	if (!Arrays.asList(profiles).contains(DEFAULT_PROFILE)) {
		addDefaultPropertySource(environment, application, DEFAULT_PROFILE, label);
	}

	if (!Arrays.asList(profiles).contains(DEFAULT_PROFILE)
			&& !DEFAULT_APPLICATION.equals(application)) {
		addDefaultPropertySource(environment, DEFAULT_APPLICATION, DEFAULT_PROFILE,
				label);
	}

	return environment;
}
 
Example 4
Source File: MethodExclusionMBeanInfoAssembler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the mappings of bean keys to a comma-separated list of method names.
 * <p>These method names are <b>ignored</b> when creating the management interface.
 * <p>The property key must match the bean key and the property value must match
 * the list of method names. When searching for method names to ignore for a bean,
 * Spring will check these mappings first.
 */
public void setIgnoredMethodMappings(Properties mappings) {
	this.ignoredMethodMappings = new HashMap<String, Set<String>>();
	for (Enumeration<?> en = mappings.keys(); en.hasMoreElements();) {
		String beanKey = (String) en.nextElement();
		String[] methodNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey));
		this.ignoredMethodMappings.put(beanKey, new HashSet<String>(Arrays.asList(methodNames)));
	}
}
 
Example 5
Source File: MethodNameBasedMBeanInfoAssembler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the mappings of bean keys to a comma-separated list of method names.
 * The property key should match the bean key and the property value should match
 * the list of method names. When searching for method names for a bean, Spring
 * will check these mappings first.
 * @param mappings the mappins of bean keys to method names
 */
public void setMethodMappings(Properties mappings) {
	this.methodMappings = new HashMap<String, Set<String>>();
	for (Enumeration<?> en = mappings.keys(); en.hasMoreElements();) {
		String beanKey = (String) en.nextElement();
		String[] methodNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey));
		this.methodMappings.put(beanKey, new HashSet<String>(Arrays.asList(methodNames)));
	}
}
 
Example 6
Source File: MethodExclusionMBeanInfoAssembler.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Set the mappings of bean keys to a comma-separated list of method names.
 * <p>These method names are <b>ignored</b> when creating the management interface.
 * <p>The property key must match the bean key and the property value must match
 * the list of method names. When searching for method names to ignore for a bean,
 * Spring will check these mappings first.
 */
public void setIgnoredMethodMappings(Properties mappings) {
	this.ignoredMethodMappings = new HashMap<String, Set<String>>();
	for (Enumeration<?> en = mappings.keys(); en.hasMoreElements();) {
		String beanKey = (String) en.nextElement();
		String[] methodNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey));
		this.ignoredMethodMappings.put(beanKey, new HashSet<String>(Arrays.asList(methodNames)));
	}
}
 
Example 7
Source File: ControlUtils.java    From bdf3 with Apache License 2.0 5 votes vote down vote up
private static Set<String> getComponentPermissionSupportTypes() {
	if (componentPermissionSupportTypes != null) {
		return componentPermissionSupportTypes;
	}
	String componentPermissionSupportType = Configure.getString("bdf3.componentPermissionSupportType");
	if (!StringUtils.isEmpty(componentPermissionSupportType)) {
		String[] types = StringUtils.commaDelimitedListToStringArray(componentPermissionSupportType);
		componentPermissionSupportTypes = new HashSet<>();
		for (String t : types) {
			componentPermissionSupportTypes.add(t);
		}
	}
	return componentPermissionSupportTypes;

}
 
Example 8
Source File: CacheAdviceParser.java    From spring-analysis-note with MIT License 5 votes vote down vote up
<T extends CacheOperation.Builder> T merge(Element element, ReaderContext readerCtx, T builder) {
	String cache = element.getAttribute("cache");

	// sanity check
	String[] localCaches = this.caches;
	if (StringUtils.hasText(cache)) {
		localCaches = StringUtils.commaDelimitedListToStringArray(cache.trim());
	}
	if (localCaches != null) {
		builder.setCacheNames(localCaches);
	}
	else {
		readerCtx.error("No cache specified for " + element.getNodeName(), element);
	}

	builder.setKey(getAttributeValue(element, "key", this.key));
	builder.setKeyGenerator(getAttributeValue(element, "key-generator", this.keyGenerator));
	builder.setCacheManager(getAttributeValue(element, "cache-manager", this.cacheManager));
	builder.setCondition(getAttributeValue(element, "condition", this.condition));

	if (StringUtils.hasText(builder.getKey()) && StringUtils.hasText(builder.getKeyGenerator())) {
		throw new IllegalStateException("Invalid cache advice configuration on '" +
				element.toString() + "'. Both 'key' and 'keyGenerator' attributes have been set. " +
				"These attributes are mutually exclusive: either set the SpEL expression used to" +
				"compute the key at runtime or set the name of the KeyGenerator bean to use.");
	}

	return builder;
}
 
Example 9
Source File: JbossCacheFlushingModel.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Sets the names of the nodes to remove from the cache.
 * 
 * @param csvNodes
 *          a comma-separated list of Strings containing the nodes to remove
 *          from the cache
 */
public void setNodes(String csvNodes) {
  String[] newNodeFqns = null;
  if (csvNodes != null) {
    newNodeFqns = StringUtils.commaDelimitedListToStringArray(csvNodes);
  }
  setNodes(newNodeFqns);
}
 
Example 10
Source File: JdbcEnvironmentRepository.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Override
public Environment findOne(String application, String profile, String label) {
	String config = application;
	if (StringUtils.isEmpty(label)) {
		label = "master";
	}
	if (StringUtils.isEmpty(profile)) {
		profile = "default";
	}
	if (!profile.startsWith("default")) {
		profile = "default," + profile;
	}
	String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
	Environment environment = new Environment(application, profiles, label, null,
			null);
	if (!config.startsWith("application")) {
		config = "application," + config;
	}
	List<String> applications = new ArrayList<String>(new LinkedHashSet<>(
			Arrays.asList(StringUtils.commaDelimitedListToStringArray(config))));
	List<String> envs = new ArrayList<String>(
			new LinkedHashSet<>(Arrays.asList(profiles)));
	Collections.reverse(applications);
	Collections.reverse(envs);
	for (String app : applications) {
		for (String env : envs) {
			Map<String, String> next = (Map<String, String>) this.jdbc.query(this.sql,
					new Object[] { app, env, label }, this.extractor);
			if (!next.isEmpty()) {
				environment.add(new PropertySource(app + "-" + env, next));
			}
		}
	}
	return environment;
}
 
Example 11
Source File: RedisEnvironmentRepository.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Override
public Environment findOne(String application, String profile, String label) {
	String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
	Environment environment = new Environment(application, profiles, label, null,
			null);
	final List<String> keys = addKeys(application, Arrays.asList(profiles));
	keys.forEach(it -> {
		Map<?, ?> m = redis.opsForHash().entries(it);
		environment.add(new PropertySource("redis:" + it, m));
	});
	return environment;
}
 
Example 12
Source File: AbstractPropertyLoadingBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected void doParse(Element element, BeanDefinitionBuilder builder) {
	String location = element.getAttribute("location");
	if (StringUtils.hasLength(location)) {
		String[] locations = StringUtils.commaDelimitedListToStringArray(location);
		builder.addPropertyValue("locations", locations);
	}

	String propertiesRef = element.getAttribute("properties-ref");
	if (StringUtils.hasLength(propertiesRef)) {
		builder.addPropertyReference("properties", propertiesRef);
	}

	String fileEncoding = element.getAttribute("file-encoding");
	if (StringUtils.hasLength(fileEncoding)) {
		builder.addPropertyValue("fileEncoding", fileEncoding);
	}

	String order = element.getAttribute("order");
	if (StringUtils.hasLength(order)) {
		builder.addPropertyValue("order", Integer.valueOf(order));
	}

	builder.addPropertyValue("ignoreResourceNotFound",
			Boolean.valueOf(element.getAttribute("ignore-resource-not-found")));

	builder.addPropertyValue("localOverride",
			Boolean.valueOf(element.getAttribute("local-override")));

	builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
}
 
Example 13
Source File: AbstractPropertyLoadingBeanDefinitionParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
	String location = element.getAttribute("location");
	if (StringUtils.hasLength(location)) {
		location = parserContext.getReaderContext().getEnvironment().resolvePlaceholders(location);
		String[] locations = StringUtils.commaDelimitedListToStringArray(location);
		builder.addPropertyValue("locations", locations);
	}

	String propertiesRef = element.getAttribute("properties-ref");
	if (StringUtils.hasLength(propertiesRef)) {
		builder.addPropertyReference("properties", propertiesRef);
	}

	String fileEncoding = element.getAttribute("file-encoding");
	if (StringUtils.hasLength(fileEncoding)) {
		builder.addPropertyValue("fileEncoding", fileEncoding);
	}

	String order = element.getAttribute("order");
	if (StringUtils.hasLength(order)) {
		builder.addPropertyValue("order", Integer.valueOf(order));
	}

	builder.addPropertyValue("ignoreResourceNotFound",
			Boolean.valueOf(element.getAttribute("ignore-resource-not-found")));

	builder.addPropertyValue("localOverride",
			Boolean.valueOf(element.getAttribute("local-override")));

	builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
}
 
Example 14
Source File: TxAdviceBeanDefinitionParser.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void addRollbackRuleAttributesTo(List<RollbackRuleAttribute> rollbackRules, String rollbackForValue) {
	String[] exceptionTypeNames = StringUtils.commaDelimitedListToStringArray(rollbackForValue);
	for (String typeName : exceptionTypeNames) {
		rollbackRules.add(new RollbackRuleAttribute(StringUtils.trimWhitespace(typeName)));
	}
}
 
Example 15
Source File: UriComponentsBuilder.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Create a new {@code UriComponents} object from the URI associated with
 * the given HttpRequest while also overlaying with values from the headers
 * "Forwarded" (<a href="http://tools.ietf.org/html/rfc7239">RFC 7239</a>, or
 * "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if "Forwarded" is
 * not found.
 * @param request the source request
 * @return the URI components of the URI
 * @since 4.1.5
 */
public static UriComponentsBuilder fromHttpRequest(HttpRequest request) {
	URI uri = request.getURI();
	UriComponentsBuilder builder = UriComponentsBuilder.fromUri(uri);

	String scheme = uri.getScheme();
	String host = uri.getHost();
	int port = uri.getPort();

	String forwardedHeader = request.getHeaders().getFirst("Forwarded");
	if (StringUtils.hasText(forwardedHeader)) {
		String forwardedToUse = StringUtils.commaDelimitedListToStringArray(forwardedHeader)[0];
		Matcher m = FORWARDED_HOST_PATTERN.matcher(forwardedToUse);
		if (m.find()) {
			host = m.group(1).trim();
		}
		m = FORWARDED_PROTO_PATTERN.matcher(forwardedToUse);
		if (m.find()) {
			scheme = m.group(1).trim();
		}
	}
	else {
		String hostHeader = request.getHeaders().getFirst("X-Forwarded-Host");
		if (StringUtils.hasText(hostHeader)) {
			String[] hosts = StringUtils.commaDelimitedListToStringArray(hostHeader);
			String hostToUse = hosts[0];
			if (hostToUse.contains(":")) {
				String[] hostAndPort = StringUtils.split(hostToUse, ":");
				host = hostAndPort[0];
				port = Integer.parseInt(hostAndPort[1]);
			}
			else {
				host = hostToUse;
				port = -1;
			}
		}

		String portHeader = request.getHeaders().getFirst("X-Forwarded-Port");
		if (StringUtils.hasText(portHeader)) {
			String[] ports = StringUtils.commaDelimitedListToStringArray(portHeader);
			port = Integer.parseInt(ports[0]);
		}

		String protocolHeader = request.getHeaders().getFirst("X-Forwarded-Proto");
		if (StringUtils.hasText(protocolHeader)) {
			String[] protocols = StringUtils.commaDelimitedListToStringArray(protocolHeader);
			scheme = protocols[0];
		}
	}

	builder.scheme(scheme);
	builder.host(host);
	builder.port(null);
	if (scheme.equals("http") && port != 80 || scheme.equals("https") && port != 443) {
		builder.port(port);
	}
	return builder;
}
 
Example 16
Source File: GenericConversionServiceTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public Integer[] convert(String source) {
	String[] srcArray = StringUtils.commaDelimitedListToStringArray(source);
	return Arrays.stream(srcArray).map(s -> s.substring(1)).map(Integer::valueOf).toArray(Integer[]::new);
}
 
Example 17
Source File: TxAdviceBeanDefinitionParser.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void addNoRollbackRuleAttributesTo(List<RollbackRuleAttribute> rollbackRules, String noRollbackForValue) {
	String[] exceptionTypeNames = StringUtils.commaDelimitedListToStringArray(noRollbackForValue);
	for (String typeName : exceptionTypeNames) {
		rollbackRules.add(new NoRollbackRuleAttribute(StringUtils.trimWhitespace(typeName)));
	}
}
 
Example 18
Source File: VelocityEngineFactory.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize a Velocity resource loader for the given VelocityEngine:
 * either a standard Velocity FileResourceLoader or a SpringResourceLoader.
 * <p>Called by {@code createVelocityEngine()}.
 * @param velocityEngine the VelocityEngine to configure
 * @param resourceLoaderPath the path to load Velocity resources from
 * @see org.apache.velocity.runtime.resource.loader.FileResourceLoader
 * @see SpringResourceLoader
 * @see #initSpringResourceLoader
 * @see #createVelocityEngine()
 */
protected void initVelocityResourceLoader(VelocityEngine velocityEngine, String resourceLoaderPath) {
	if (isPreferFileSystemAccess()) {
		// Try to load via the file system, fall back to SpringResourceLoader
		// (for hot detection of template changes, if possible).
		try {
			StringBuilder resolvedPath = new StringBuilder();
			String[] paths = StringUtils.commaDelimitedListToStringArray(resourceLoaderPath);
			for (int i = 0; i < paths.length; i++) {
				String path = paths[i];
				Resource resource = getResourceLoader().getResource(path);
				File file = resource.getFile();  // will fail if not resolvable in the file system
				if (logger.isDebugEnabled()) {
					logger.debug("Resource loader path [" + path + "] resolved to file [" + file.getAbsolutePath() + "]");
				}
				resolvedPath.append(file.getAbsolutePath());
				if (i < paths.length - 1) {
					resolvedPath.append(',');
				}
			}
			velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
			velocityEngine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true");
			velocityEngine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, resolvedPath.toString());
		}
		catch (IOException ex) {
			if (logger.isDebugEnabled()) {
				logger.debug("Cannot resolve resource loader path [" + resourceLoaderPath +
						"] to [java.io.File]: using SpringResourceLoader", ex);
			}
			initSpringResourceLoader(velocityEngine, resourceLoaderPath);
		}
	}
	else {
		// Always load via SpringResourceLoader
		// (without hot detection of template changes).
		if (logger.isDebugEnabled()) {
			logger.debug("File system access not preferred: using SpringResourceLoader");
		}
		initSpringResourceLoader(velocityEngine, resourceLoaderPath);
	}
}
 
Example 19
Source File: BeanDefinitionParserDelegate.java    From blog_demos with Apache License 2.0 4 votes vote down vote up
/**
 * Return any patterns provided in the 'default-autowire-candidates'
 * attribute of the top-level {@code &lt;beans/&gt;} element.
 */
public String[] getAutowireCandidatePatterns() {
	String candidatePattern = this.defaults.getAutowireCandidates();
	return (candidatePattern != null ? StringUtils.commaDelimitedListToStringArray(candidatePattern) : null);
}
 
Example 20
Source File: AbstractAspectJAdvice.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Set by creator of this advice object if the argument names are known.
 * <p>This could be for example because they have been explicitly specified in XML,
 * or in an advice annotation.
 * @param argNames comma delimited list of arg names
 */
public void setArgumentNames(String argNames) {
	String[] tokens = StringUtils.commaDelimitedListToStringArray(argNames);
	setArgumentNamesFromStringArray(tokens);
}