Skip to content

Instantly share code, notes, and snippets.

@kuckmc01
Created January 19, 2018 18:35
Show Gist options
  • Save kuckmc01/ce8275f5e3e8ad62d1306d3e1f4a63a8 to your computer and use it in GitHub Desktop.
Save kuckmc01/ce8275f5e3e8ad62d1306d3e1f4a63a8 to your computer and use it in GitHub Desktop.
public String[] getValuesAsStringArray(final Resource resource, final String propertyToExtract){
try {
final Node node = resource.adaptTo(Node.class);
final Property property = node.getProperty(propertyToExtract);
final Resource childProperty = resource.getChild(propertyToExtract);
if(property.isMultiple() && childProperty != null){
return childProperty.adaptTo(String[].class);
}else{
return new String[]{ childProperty.adaptTo(String.class) };
}
} catch (RepositoryException e) {
log.error("Problem accessing node information ",e);
}
return new String[]{""};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment