String displayName = reader.getAttribute("displayName");
String login = reader.getAttribute("login");
String password = reader.getAttribute("password");
String roles = reader.getAttribute("roles");
User user = new User();
// User
user.setDisplayName(displayName);
user.setLogin(login);
user.setPassword(password);
// Roles
if (roles.length() == 0)
{
// Set at least author role for each user
roles = User.Role.AUTHOR.toString();
}
String[] roleNames = roles.split(",");
Set<User.Role> roleSet = new HashSet<User.Role>();
for (String roleName : roleNames)
{
try
{
roleSet.add(User.Role.valueOf(roleName.toUpperCase()));
}
catch (IllegalArgumentException e)
{
logger.warn("No user role for this value: <" + roleName + "> !");
}
}
user.setRoles(roleSet);
return user;
}