String[] attributes = StringUtils.split(definition);
if (attributes == null || attributes.length == 0) {
return null;
}
FetchRequest fetch = FetchRequest.createFetchRequest();
//parse the definition by tokenizing it to get the resulting attribute-specific config
//
//e.g. for a value of
//
// "email, firstName[required=true], lastName"
//
// the resulting token array would equal
//
// { "email", "firstName[required=true]", "lastName" }
//
for (String attribute : attributes) {
//strip the name and extract any attribute-specific config between brackets [ ]
String[] nameAndConfig = attribute.split("\\[", 2);
String name = nameAndConfig[0];
String config = null;
if (nameAndConfig.length == 2) {
config = nameAndConfig[1];
//if there was an open bracket, there was a close bracket, so strip it too:
config = config.substring(0, config.length() - 1);
}
AttributeDefinition ad = toDefinition(name, config);
try {
fetch.addAttribute(ad.getName(), ad.getUri(), ad.isRequired(), ad.getCount());
} catch (MessageException e) {
throw new OpenIdException("Unable to correctly add 'fetch' attribute.", e);
}
}