Java Code Examples for org.springframework.util.StringUtils.containsWhitespace()

The following are Jave code examples for showing how to use containsWhitespace() of the org.springframework.util.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Building-Web-Apps-with-Spring-5-and-Angular   File: SignupInterceptor.java   View Source Code Vote up 5 votes
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
	
       String emailAddress = request.getParameter("email");
       String password = request.getParameter("password");
       
       if(StringUtils.isEmpty(emailAddress) || StringUtils.containsWhitespace(emailAddress) ||
       		StringUtils.isEmpty(password) || StringUtils.containsWhitespace(password)) {
       	throw new Exception("Invalid Email Address or Password. Please try again.");
       }
       
       return true;
}
 
Example 2
Project: lams   File: TransactionAttributeEditor.java   View Source Code Vote up 4 votes
/**
 * Format is PROPAGATION_NAME,ISOLATION_NAME,readOnly,timeout_NNNN,+Exception1,-Exception2.
 * Null or the empty string means that the method is non transactional.
 * @see java.beans.PropertyEditor#setAsText(java.lang.String)
 */
@Override
public void setAsText(String text) throws IllegalArgumentException {
	if (StringUtils.hasLength(text)) {
		// tokenize it with ","
		String[] tokens = StringUtils.commaDelimitedListToStringArray(text);
		RuleBasedTransactionAttribute attr = new RuleBasedTransactionAttribute();
		for (int i = 0; i < tokens.length; i++) {
			// Trim leading and trailing whitespace.
			String token = StringUtils.trimWhitespace(tokens[i].trim());
			// Check whether token contains illegal whitespace within text.
			if (StringUtils.containsWhitespace(token)) {
				throw new IllegalArgumentException(
						"Transaction attribute token contains illegal whitespace: [" + token + "]");
			}
			// Check token type.
			if (token.startsWith(RuleBasedTransactionAttribute.PREFIX_PROPAGATION)) {
				attr.setPropagationBehaviorName(token);
			}
			else if (token.startsWith(RuleBasedTransactionAttribute.PREFIX_ISOLATION)) {
				attr.setIsolationLevelName(token);
			}
			else if (token.startsWith(RuleBasedTransactionAttribute.PREFIX_TIMEOUT)) {
				String value = token.substring(DefaultTransactionAttribute.PREFIX_TIMEOUT.length());
				attr.setTimeout(Integer.parseInt(value));
			}
			else if (token.equals(RuleBasedTransactionAttribute.READ_ONLY_MARKER)) {
				attr.setReadOnly(true);
			}
			else if (token.startsWith(RuleBasedTransactionAttribute.PREFIX_COMMIT_RULE)) {
				attr.getRollbackRules().add(new NoRollbackRuleAttribute(token.substring(1)));
			}
			else if (token.startsWith(RuleBasedTransactionAttribute.PREFIX_ROLLBACK_RULE)) {
				attr.getRollbackRules().add(new RollbackRuleAttribute(token.substring(1)));
			}
			else {
				throw new IllegalArgumentException("Invalid transaction attribute token: [" + token + "]");
			}
		}
		setValue(attr);
	}
	else {
		setValue(null);
	}
}