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

The following examples show how to use org.springframework.util.StringUtils#trimAllWhitespace() . 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
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
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
Source 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
/**
 * 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
@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
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
/**
 * 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
/**
 * 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
/**
 * 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
/**
 * 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
/**
 * 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
/**
 * 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
/**
 * 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
/**
 * 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
/**
 * 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
/**
 * 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
/**
 * 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
/**
 * 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
/**
 * 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
/**
 * 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);
}