Example usage for org.springframework.util StringUtils split

List of usage examples for org.springframework.util StringUtils split

Introduction

In this page you can find the example usage for org.springframework.util StringUtils split.

Prototype

@Nullable
public static String[] split(@Nullable String toSplit, @Nullable String delimiter) 

Source Link

Document

Split a String at the first occurrence of the delimiter.

Usage

From source file:ubic.gemma.web.propertyeditor.UserRolesPropertyEditor.java

@Override
public void setAsText(String text) throws IllegalArgumentException {
    if (!StringUtils.hasText(text)) {
        setValue(null);/* www.j  ava2  s.c o  m*/
    } else {
        roles = new HashSet<UserRole>();
        String trim = text.trim();
        String[] roleNames = null;
        if (trim.contains(COMMA_DELIM))
            roleNames = StringUtils.split(trim, COMMA_DELIM);
        else
            roleNames = new String[] { trim };
        if (roleNames != null && roleNames.length != 0) {
            for (String roleName : roleNames) {
                log.debug(roleName);
                UserRole role = new UserRoleImpl();
                role.setName(roleName);
                roles.add(role);
            }
            setValue(roles);
        } else {
            throw new IllegalArgumentException("Could not parse role(s): " + text);
        }
    }

}