org.springframework.util.StringUtils#commaDelimitedListToStringArray ( )源码实例Demo

下面列出了org.springframework.util.StringUtils#commaDelimitedListToStringArray ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * 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);
}
 
源代码2 项目: bdf3   文件: ControlUtils.java
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;

}
 
@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);
}
 
@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);
}
 
@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;
}
 
@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;
}
 
源代码7 项目: cacheonix-core   文件: JbossCacheFlushingModel.java
/**
 * 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);
}
 
源代码8 项目: spring-analysis-note   文件: CacheAdviceParser.java
<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;
}
 
源代码9 项目: cacheonix-core   文件: OsCacheCachingModel.java
/**
 * 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);
}
 
/**
 * 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)));
	}
}
 
源代码11 项目: lams   文件: MethodNameBasedMBeanInfoAssembler.java
/**
 * 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)));
	}
}
 
源代码12 项目: lams   文件: MethodExclusionMBeanInfoAssembler.java
/**
 * 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)));
	}
}
 
@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;
}
 
源代码14 项目: blog_demos   文件: BeanDefinitionParserDelegate.java
/**
 * 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);
}
 
源代码15 项目: lams   文件: TxAdviceBeanDefinitionParser.java
private void addRollbackRuleAttributesTo(List<RollbackRuleAttribute> rollbackRules, String rollbackForValue) {
	String[] exceptionTypeNames = StringUtils.commaDelimitedListToStringArray(rollbackForValue);
	for (String typeName : exceptionTypeNames) {
		rollbackRules.add(new RollbackRuleAttribute(StringUtils.trimWhitespace(typeName)));
	}
}
 
/**
 * 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;
}
 
@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);
}
 
源代码18 项目: lams   文件: TxAdviceBeanDefinitionParser.java
private void addNoRollbackRuleAttributesTo(List<RollbackRuleAttribute> rollbackRules, String noRollbackForValue) {
	String[] exceptionTypeNames = StringUtils.commaDelimitedListToStringArray(noRollbackForValue);
	for (String typeName : exceptionTypeNames) {
		rollbackRules.add(new NoRollbackRuleAttribute(StringUtils.trimWhitespace(typeName)));
	}
}
 
/**
 * 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);
	}
}
 
/**
 * 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);
}