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

The following examples show how to use org.springframework.util.StringUtils#trimAllWhitespace() .
Example 1
Project: camunda-bpm-platform   File: DefaultProcessEngineConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
private void setProcessEngineName(SpringProcessEngineConfiguration configuration) {
  String processEngineName = StringUtils.trimAllWhitespace(camundaBpmProperties.getProcessEngineName());
  if (!StringUtils.isEmpty(processEngineName) && !processEngineName.contains("-")) {

    if (camundaBpmProperties.getGenerateUniqueProcessEngineName()) {
      if (!processEngineName.equals(ProcessEngines.NAME_DEFAULT)) {
        throw new RuntimeException(String.format("A unique processEngineName cannot be generated "
          + "if a custom processEngineName is already set: %s", processEngineName));
      }
      processEngineName = CamundaBpmProperties.getUniqueName(camundaBpmProperties.UNIQUE_ENGINE_NAME_PREFIX);
    }

    configuration.setProcessEngineName(processEngineName);
  } else {
    logger.warn("Ignoring invalid processEngineName='{}' - must not be null, blank or contain hyphen", camundaBpmProperties.getProcessEngineName());
  }
}
 
Example 2
Project: spring-boot-data-geode   File: EmailGenerator.java    License: Apache License 2.0 5 votes vote down vote up
public static String generate(String name, String email) {

		Assert.hasText(name, "Name is required");

		if (!StringUtils.hasText(email)) {

			name = name.toLowerCase();
			name = StringUtils.trimAllWhitespace(name);
			email = String.format("%1$s%2$s", name,
				AT_EMAIL_ADDRESSES.get(index.nextInt(AT_EMAIL_ADDRESSES.size())));
		}

		return email;
	}
 
Example 3
Project: Milkomeda   File: ConditionPropertySource.java    License: MIT License 5 votes vote down vote up
private boolean getBoolValue(String range) {
    range = StringUtils.trimAllWhitespace(range);
    String[] parts = StringUtils.commaDelimitedListToStringArray(range);
    if (parts.length != 2) {
        throw new IllegalArgumentException("Condition.bool set args error.");
    }
    return parts[0].equals(parts[1]);
}
 
Example 4
Project: citrus-admin   File: AbstractModelConverter.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Build Java code snippet from given model and identifier.
 * @param model
 * @param id
 * @return
 */
public String getJavaConfig(T model, String id) {
    StringBuilder builder = new StringBuilder();

    String methodName;
    String beanId = StringUtils.hasText(id) ? id : StringUtils.uncapitalize(model.getClass().getSimpleName());
    Matcher matcher = invalidMethodNamePattern.matcher(beanId);
    if (matcher.find()) {
        methodName = StringUtils.trimAllWhitespace(beanId.replaceAll("\\.", "").replaceAll("-", ""));
        builder.append(String.format("%n\[email protected](\"%s\")%n", beanId));
    } else {
        methodName = beanId;
        builder.append(String.format("%n\[email protected]%n"));
    }

    builder.append(String.format("\tpublic %s %s() {%n", getSourceModelClass().getSimpleName(), methodName));

    builder.append(String.format("\t\t%s %s = new %s();%n", getSourceModelClass().getSimpleName(), methodName, getSourceModelClass().getSimpleName()));

    ReflectionUtils.doWithMethods(model.getClass(), method -> {
        Object object = ReflectionUtils.invokeMethod(method, model);
        if (object != null) {
            Optional<AbstractModelConverter.MethodCallDecorator> decorator = decorators.stream().filter(d -> d.supports(getSetterMethod(method.getName()))).findAny();
            if (decorator.isPresent()) {
                if (decorator.get().allowMethodCall(object)) {
                    builder.append(decorator.get().decorate(methodName, String.format("\t\t%s.%s(%s);%n", methodName, decorator.get().decorateMethodName(), decorator.get().decorateArgument(object)), object));
                }
            } else if (object instanceof String) {
                builder.append(String.format("\t\t%s.%s(\"%s\");%n", methodName, getSetterMethod(method.getName()), object));
            } else {
                builder.append(String.format("\t\t%s.%s(%s);%n", methodName, getSetterMethod(method.getName()), object));
            }
        }
    }, method -> (method.getName().startsWith("get") || method.getName().startsWith("is"))
            && !method.getName().equals("getClass")
            && !method.getName().equals("getId")
            && method.getParameterCount() == 0);

    builder.append(String.format("\t\treturn %s;%n", methodName));
    builder.append(String.format("\t}%n"));

    return builder.toString();
}
 
Example 5
Project: spring-boot-data-geode   File: JsonCacheDataImporterExporterIntegrationTests.java    License: Apache License 2.0 3 votes vote down vote up
@Test
public void exportFromExampleRegionToJson() {

	try {
		System.setProperty(EXPORT_ENABLED_PROPERTY, Boolean.TRUE.toString());

		StringWriter writer = new StringWriter();

		writerSupplier = () -> writer;

		Region<Long, Customer> example =
			getExampleRegion(newApplicationContext(withResource("data-example.json")));

		assertExampleRegion(example);
		assertThat(example).isEmpty();

		Customer playDoe = Customer.newCustomer(42L, "Play Doe");

		example.put(playDoe.getId(), playDoe);

		assertThat(example).hasSize(1);
		assertThat(example.get(42L)).isEqualTo(playDoe);

		closeApplicationContext();

		String actualJson = StringUtils.trimAllWhitespace(writer.toString());

		String expectedJson = String.format("[{\"@type\":\"%s\",\"id\":42,\"name\":\"PlayDoe\"}]",
			playDoe.getClass().getName());

		assertThat(actualJson).isEqualTo(expectedJson);
	}
	finally {
		System.clearProperty(EXPORT_ENABLED_PROPERTY);
	}
}
 
Example 6
Project: spring-boot-data-geode   File: ClusterAwareConfiguration.java    License: Apache License 2.0 3 votes vote down vote up
private String[] trim(String[] array) {

			array = ArrayUtils.nullSafeArray(array, String.class);

			for (int index = 0; index < array.length; index++) {
				array[index] = StringUtils.trimAllWhitespace(array[index]);
			}

			return array;
		}
 
Example 7
Project: blog_demos   File: FieldRetrievingFactoryBean.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Set the name of the field to be retrieved.
 * Refers to either a static field or a non-static field,
 * depending on a target object being set.
 * @see #setTargetClass
 * @see #setTargetObject
 */
public void setTargetField(String targetField) {
	this.targetField = StringUtils.trimAllWhitespace(targetField);
}
 
Example 8
Project: spring4-understanding   File: FieldRetrievingFactoryBean.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * The bean name of this FieldRetrievingFactoryBean will be interpreted
 * as "staticField" pattern, if neither "targetClass" nor "targetObject"
 * nor "targetField" have been specified.
 * This allows for concise bean definitions with just an id/name.
 */
@Override
public void setBeanName(String beanName) {
	this.beanName = StringUtils.trimAllWhitespace(BeanFactoryUtils.originalBeanName(beanName));
}
 
Example 9
Project: spring-analysis-note   File: FieldRetrievingFactoryBean.java    License: MIT License 2 votes vote down vote up
/**
 * Set the name of the field to be retrieved.
 * Refers to either a static field or a non-static field,
 * depending on a target object being set.
 * @see #setTargetClass
 * @see #setTargetObject
 */
public void setTargetField(@Nullable String targetField) {
	this.targetField = (targetField != null ? StringUtils.trimAllWhitespace(targetField) : null);
}
 
Example 10
Project: spring-analysis-note   File: FieldRetrievingFactoryBean.java    License: MIT License 2 votes vote down vote up
/**
 * Set a fully qualified static field name to retrieve,
 * e.g. "example.MyExampleClass.MY_EXAMPLE_FIELD".
 * Convenient alternative to specifying targetClass and targetField.
 * @see #setTargetClass
 * @see #setTargetField
 */
public void setStaticField(String staticField) {
	this.staticField = StringUtils.trimAllWhitespace(staticField);
}
 
Example 11
Project: java-technology-stack   File: PropertyPathFactoryBean.java    License: MIT License 2 votes vote down vote up
/**
 * Specify the name of a target bean to apply the property path to.
 * Alternatively, specify a target object directly.
 * @param targetBeanName the bean name to be looked up in the
 * containing bean factory (e.g. "testBean")
 * @see #setTargetObject
 */
public void setTargetBeanName(String targetBeanName) {
	this.targetBeanName = StringUtils.trimAllWhitespace(targetBeanName);
}
 
Example 12
Project: java-technology-stack   File: PropertyPathFactoryBean.java    License: MIT License 2 votes vote down vote up
/**
 * Specify the property path to apply to the target.
 * @param propertyPath the property path, potentially nested
 * (e.g. "age" or "spouse.age")
 */
public void setPropertyPath(String propertyPath) {
	this.propertyPath = StringUtils.trimAllWhitespace(propertyPath);
}
 
Example 13
Project: java-technology-stack   File: PropertyPathFactoryBean.java    License: MIT License 2 votes vote down vote up
/**
 * The bean name of this PropertyPathFactoryBean will be interpreted
 * as "beanName.property" pattern, if neither "targetObject" nor
 * "targetBeanName" nor "propertyPath" have been specified.
 * This allows for concise bean definitions with just an id/name.
 */
@Override
public void setBeanName(String beanName) {
	this.beanName = StringUtils.trimAllWhitespace(BeanFactoryUtils.originalBeanName(beanName));
}
 
Example 14
Project: java-technology-stack   File: FieldRetrievingFactoryBean.java    License: MIT License 2 votes vote down vote up
/**
 * Set a fully qualified static field name to retrieve,
 * e.g. "example.MyExampleClass.MY_EXAMPLE_FIELD".
 * Convenient alternative to specifying targetClass and targetField.
 * @see #setTargetClass
 * @see #setTargetField
 */
public void setStaticField(String staticField) {
	this.staticField = StringUtils.trimAllWhitespace(staticField);
}
 
Example 15
Project: java-technology-stack   File: FieldRetrievingFactoryBean.java    License: MIT License 2 votes vote down vote up
/**
 * The bean name of this FieldRetrievingFactoryBean will be interpreted
 * as "staticField" pattern, if neither "targetClass" nor "targetObject"
 * nor "targetField" have been specified.
 * This allows for concise bean definitions with just an id/name.
 */
@Override
public void setBeanName(String beanName) {
	this.beanName = StringUtils.trimAllWhitespace(BeanFactoryUtils.originalBeanName(beanName));
}
 
Example 16
Project: lams   File: FieldRetrievingFactoryBean.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set a fully qualified static field name to retrieve,
 * e.g. "example.MyExampleClass.MY_EXAMPLE_FIELD".
 * Convenient alternative to specifying targetClass and targetField.
 * @see #setTargetClass
 * @see #setTargetField
 */
public void setStaticField(String staticField) {
	this.staticField = StringUtils.trimAllWhitespace(staticField);
}
 
Example 17
Project: spring4-understanding   File: FieldRetrievingFactoryBean.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Set the name of the field to be retrieved.
 * Refers to either a static field or a non-static field,
 * depending on a target object being set.
 * @see #setTargetClass
 * @see #setTargetObject
 */
public void setTargetField(String targetField) {
	this.targetField = StringUtils.trimAllWhitespace(targetField);
}
 
Example 18
Project: lams   File: PropertyPathFactoryBean.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Specify the name of a target bean to apply the property path to.
 * Alternatively, specify a target object directly.
 * @param targetBeanName the bean name to be looked up in the
 * containing bean factory (e.g. "testBean")
 * @see #setTargetObject
 */
public void setTargetBeanName(String targetBeanName) {
	this.targetBeanName = StringUtils.trimAllWhitespace(targetBeanName);
}
 
Example 19
Project: lams   File: PropertyPathFactoryBean.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Specify the property path to apply to the target.
 * @param propertyPath the property path, potentially nested
 * (e.g. "age" or "spouse.age")
 */
public void setPropertyPath(String propertyPath) {
	this.propertyPath = StringUtils.trimAllWhitespace(propertyPath);
}
 
Example 20
Project: spring4-understanding   File: PropertyPathFactoryBean.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Specify the name of a target bean to apply the property path to.
 * Alternatively, specify a target object directly.
 * @param targetBeanName the bean name to be looked up in the
 * containing bean factory (e.g. "testBean")
 * @see #setTargetObject
 */
public void setTargetBeanName(String targetBeanName) {
	this.targetBeanName = StringUtils.trimAllWhitespace(targetBeanName);
}