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

The following examples show how to use org.springframework.util.StringUtils#trimArrayElements() . 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: StringArrayPropertyEditor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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 2
Source File: AbstractBeanDefinitionParser.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@Nullable
public final BeanDefinition parse(Element element, ParserContext parserContext) {
	// 注释 3.10 实际自定义标签解析器调用的方法,在 parseInternal 方法中,调用了我们重载的方法
	AbstractBeanDefinition definition = parseInternal(element, parserContext);
	if (definition != null && !parserContext.isNested()) {
		try {
			String id = resolveId(element, definition, parserContext);
			if (!StringUtils.hasText(id)) {
				parserContext.getReaderContext().error(
						"Id is required for element '" + parserContext.getDelegate().getLocalName(element)
								+ "' when used as a top-level tag", element);
			}
			String[] aliases = null;
			if (shouldParseNameAsAliases()) {
				String name = element.getAttribute(NAME_ATTRIBUTE);
				if (StringUtils.hasLength(name)) {
					aliases = StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(name));
				}
			}
			// 组装成 BeanDefinitionHolder
			BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases);
			// 注册 bean 信息
			registerBeanDefinition(holder, parserContext.getRegistry());
			if (shouldFireEvents()) {
				BeanComponentDefinition componentDefinition = new BeanComponentDefinition(holder);
				postProcessComponentDefinition(componentDefinition);
				parserContext.registerComponent(componentDefinition);
			}
		}
		catch (BeanDefinitionStoreException ex) {
			String msg = ex.getMessage();
			parserContext.getReaderContext().error((msg != null ? msg : ex.toString()), element);
			return null;
		}
	}
	return definition;
}
 
Example 3
Source File: StringArrayPropertyEditor.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 4
Source File: AbstractBeanDefinitionParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
@Nullable
public final BeanDefinition parse(Element element, ParserContext parserContext) {
	AbstractBeanDefinition definition = parseInternal(element, parserContext);
	if (definition != null && !parserContext.isNested()) {
		try {
			String id = resolveId(element, definition, parserContext);
			if (!StringUtils.hasText(id)) {
				parserContext.getReaderContext().error(
						"Id is required for element '" + parserContext.getDelegate().getLocalName(element)
								+ "' when used as a top-level tag", element);
			}
			String[] aliases = null;
			if (shouldParseNameAsAliases()) {
				String name = element.getAttribute(NAME_ATTRIBUTE);
				if (StringUtils.hasLength(name)) {
					aliases = StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(name));
				}
			}
			BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases);
			registerBeanDefinition(holder, parserContext.getRegistry());
			if (shouldFireEvents()) {
				BeanComponentDefinition componentDefinition = new BeanComponentDefinition(holder);
				postProcessComponentDefinition(componentDefinition);
				parserContext.registerComponent(componentDefinition);
			}
		}
		catch (BeanDefinitionStoreException ex) {
			String msg = ex.getMessage();
			parserContext.getReaderContext().error((msg != null ? msg : ex.toString()), element);
			return null;
		}
	}
	return definition;
}
 
Example 5
Source File: SpringProfileAction.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
private boolean acceptsProfiles(InterpretationContext ic, Attributes attributes) {
	String[] profileNames = StringUtils
			.trimArrayElements(StringUtils.commaDelimitedListToStringArray(attributes.getValue(NAME_ATTRIBUTE)));
	if (profileNames.length != 0) {
		for (String profileName : profileNames) {
			OptionHelper.substVars(profileName, ic, this.context);
		}
		return this.environment != null && this.environment.acceptsProfiles(profileNames);
	}
	return false;
}
 
Example 6
Source File: StringArrayPropertyEditor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setAsText(String text) throws IllegalArgumentException {
	String[] array = StringUtils.delimitedListToStringArray(text, this.separator, this.charsToDelete);
	if (trimValues) {
		array = StringUtils.trimArrayElements(array);
	}
	if (this.emptyArrayAsNull && array.length == 0) {
		setValue(null);
	}
	else {
		setValue(array);
	}
}
 
Example 7
Source File: AbstractBeanDefinitionParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final BeanDefinition parse(Element element, ParserContext parserContext) {
	AbstractBeanDefinition definition = parseInternal(element, parserContext);
	if (definition != null && !parserContext.isNested()) {
		try {
			String id = resolveId(element, definition, parserContext);
			if (!StringUtils.hasText(id)) {
				parserContext.getReaderContext().error(
						"Id is required for element '" + parserContext.getDelegate().getLocalName(element)
								+ "' when used as a top-level tag", element);
			}
			String[] aliases = null;
			if (shouldParseNameAsAliases()) {
				String name = element.getAttribute(NAME_ATTRIBUTE);
				if (StringUtils.hasLength(name)) {
					aliases = StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(name));
				}
			}
			BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases);
			registerBeanDefinition(holder, parserContext.getRegistry());
			if (shouldFireEvents()) {
				BeanComponentDefinition componentDefinition = new BeanComponentDefinition(holder);
				postProcessComponentDefinition(componentDefinition);
				parserContext.registerComponent(componentDefinition);
			}
		}
		catch (BeanDefinitionStoreException ex) {
			parserContext.getReaderContext().error(ex.getMessage(), element);
			return null;
		}
	}
	return definition;
}
 
Example 8
Source File: StringArrayPropertyEditor.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
@Override
public void setAsText(String text) throws IllegalArgumentException {
	String[] array = StringUtils.delimitedListToStringArray(text, this.separator, this.charsToDelete);
	if (trimValues) {
		array = StringUtils.trimArrayElements(array);
	}
	if (this.emptyArrayAsNull && array.length == 0) {
		setValue(null);
	}
	else {
		setValue(array);
	}
}
 
Example 9
Source File: AbstractBeanDefinitionParser.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
@Override
public final BeanDefinition parse(Element element, ParserContext parserContext) {
	AbstractBeanDefinition definition = parseInternal(element, parserContext);
	if (definition != null && !parserContext.isNested()) {
		try {
			String id = resolveId(element, definition, parserContext);
			if (!StringUtils.hasText(id)) {
				parserContext.getReaderContext().error(
						"Id is required for element '" + parserContext.getDelegate().getLocalName(element)
								+ "' when used as a top-level tag", element);
			}
			String[] aliases = new String[0];
			String name = element.getAttribute(NAME_ATTRIBUTE);
			if (StringUtils.hasLength(name)) {
				aliases = StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(name));
			}
			BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases);
			registerBeanDefinition(holder, parserContext.getRegistry());
			if (shouldFireEvents()) {
				BeanComponentDefinition componentDefinition = new BeanComponentDefinition(holder);
				postProcessComponentDefinition(componentDefinition);
				parserContext.registerComponent(componentDefinition);
			}
		}
		catch (BeanDefinitionStoreException ex) {
			parserContext.getReaderContext().error(ex.getMessage(), element);
			return null;
		}
	}
	return definition;
}
 
Example 10
Source File: StringArrayPropertyEditor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void setAsText(String text) throws IllegalArgumentException {
	String[] array = StringUtils.delimitedListToStringArray(text, this.separator, this.charsToDelete);
	if (trimValues) {
		array = StringUtils.trimArrayElements(array);
	}
	if (this.emptyArrayAsNull && array.length == 0) {
		setValue(null);
	}
	else {
		setValue(array);
	}
}
 
Example 11
Source File: AbstractBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public final BeanDefinition parse(Element element, ParserContext parserContext) {
	AbstractBeanDefinition definition = parseInternal(element, parserContext);
	if (definition != null && !parserContext.isNested()) {
		try {
			String id = resolveId(element, definition, parserContext);
			if (!StringUtils.hasText(id)) {
				parserContext.getReaderContext().error(
						"Id is required for element '" + parserContext.getDelegate().getLocalName(element)
								+ "' when used as a top-level tag", element);
			}
			String[] aliases = null;
			if (shouldParseNameAsAliases()) {
				String name = element.getAttribute(NAME_ATTRIBUTE);
				if (StringUtils.hasLength(name)) {
					aliases = StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(name));
				}
			}
			BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases);
			registerBeanDefinition(holder, parserContext.getRegistry());
			if (shouldFireEvents()) {
				BeanComponentDefinition componentDefinition = new BeanComponentDefinition(holder);
				postProcessComponentDefinition(componentDefinition);
				parserContext.registerComponent(componentDefinition);
			}
		}
		catch (BeanDefinitionStoreException ex) {
			parserContext.getReaderContext().error(ex.getMessage(), element);
			return null;
		}
	}
	return definition;
}
 
Example 12
Source File: LogbackAccessJoranConfigurator.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException {
    depth++;
    if (depth != 1) {
        return;
    }
    String profiles = OptionHelper.substVars(attributes.getValue(NAME_ATTRIBUTE), ic, context);
    String[] normalizedProfiles = StringUtils.commaDelimitedListToStringArray(profiles);
    normalizedProfiles = StringUtils.trimArrayElements(normalizedProfiles);
    accepts = normalizedProfiles.length > 0 && environment.acceptsProfiles(normalizedProfiles);
    ic.addInPlayListener(this);
}
 
Example 13
Source File: RedissonNamespaceParserSupport.java    From redisson with Apache License 2.0 5 votes vote down vote up
public String[] parseAliase(Element element) {
    if (element == null) {
        return null;
    }
    String[] aliases = null;
    String name = element.getAttribute(NAME_ATTRIBUTE);
    if (StringUtils.hasLength(name)) {
        aliases = StringUtils.trimArrayElements(
                StringUtils.commaDelimitedListToStringArray(name));
    }
    return aliases;
}
 
Example 14
Source File: AudienceValidator.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	this.audience = this.audienceProvider.getAudience();
	Assert.notNull(this.audience, "Audience cannot be null.");
	this.audiences = StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(this.audience));
}